Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 1 | # Copyright 2016 Mirantis, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Dennis Dmitriev | fa1774a | 2019-05-28 15:27:44 +0300 | [diff] [blame^] | 15 | from tcp_tests import settings |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 16 | from tcp_tests import settings_oslo |
Dennis Dmitriev | fa1774a | 2019-05-28 15:27:44 +0300 | [diff] [blame^] | 17 | from tcp_tests import logger |
| 18 | |
| 19 | LOG = logger.logger |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 20 | |
| 21 | |
| 22 | class EnvironmentManagerEmpty(object): |
| 23 | """Class-helper for creating VMs via devops environments""" |
| 24 | |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 25 | __config = None |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 26 | |
| 27 | def __init__(self, config=None): |
| 28 | """Initializing class instance and create the environment |
| 29 | |
| 30 | :param config: oslo.config object |
| 31 | :param config.hardware.conf_path: path to devops YAML template |
| 32 | :param config.hardware.current_snapshot: name of the snapshot that |
| 33 | descriebe environment status. |
| 34 | """ |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 35 | self.__config = config |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 36 | |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 37 | def get_ssh_data(self, roles=None): |
| 38 | raise Exception("EnvironmentManagerEmpty doesn't have SSH details. " |
| 39 | "Please provide SSH details in config.underlay.ssh") |
| 40 | |
Dennis Dmitriev | 411dd10 | 2017-09-15 16:04:47 +0300 | [diff] [blame] | 41 | def create_snapshot(self, name, **kwargs): |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 42 | """Store environmetn state into the config object |
| 43 | |
| 44 | - Store the state of the environment <name> to the 'config' object |
| 45 | - Save 'config' object to a file 'config_<name>.ini' |
| 46 | """ |
Dennis Dmitriev | fa1774a | 2019-05-28 15:27:44 +0300 | [diff] [blame^] | 47 | if not settings.MAKE_SNAPSHOT_STAGES: |
| 48 | msg = ("[ SKIP snapshot '{0}' because MAKE_SNAPSHOT_STAGES=false ]" |
| 49 | .format(name)) |
| 50 | LOG.info("\n\n{0}\n{1}".format(msg, '*' * len(msg))) |
| 51 | return |
| 52 | |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 53 | self.__config.hardware.current_snapshot = name |
| 54 | settings_oslo.save_config(self.__config, name) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 55 | |
| 56 | def revert_snapshot(self, name): |
| 57 | """Check the current state <name> of the environment |
| 58 | |
| 59 | - Check that the <name> matches the current state of the environment |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 60 | that is stored in the 'self.__config.hardware.current_snapshot' |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 61 | - Try to reload 'config' object from a file 'config_<name>.ini' |
| 62 | If the file not found, then pass with defaults. |
| 63 | - Set <name> as the current state of the environment after reload |
| 64 | |
| 65 | :param name: string |
| 66 | """ |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 67 | if self.__config.hardware.current_snapshot != name: |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 68 | raise Exception( |
| 69 | "EnvironmentManagerEmpty cannot revert nodes from {} to {}" |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 70 | .format(self.__config.hardware.current_snapshot, name)) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 71 | |
| 72 | def start(self): |
| 73 | """Start environment""" |
| 74 | pass |
| 75 | |
| 76 | def resume(self): |
| 77 | """Resume environment""" |
| 78 | pass |
| 79 | |
| 80 | def suspend(self): |
| 81 | """Suspend environment""" |
| 82 | pass |
| 83 | |
| 84 | def stop(self): |
| 85 | """Stop environment""" |
| 86 | pass |
| 87 | |
| 88 | def has_snapshot(self, name): |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 89 | return self.__config.hardware.current_snapshot == name |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 90 | |
| 91 | def has_snapshot_config(self, name): |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 92 | return self.__config.hardware.current_snapshot == name |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 93 | |
| 94 | def delete_environment(self): |
| 95 | """Delete environment""" |
| 96 | pass |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 97 | |
| 98 | def warm_shutdown_nodes(self, underlay, nodes_prefix, timeout=600): |
| 99 | raise Exception( |
| 100 | "Node shutdown method unsupported on this environment manager") |
| 101 | |
| 102 | def warm_restart_nodes(self, underlay, nodes_prefix, timeout=600): |
| 103 | raise Exception( |
| 104 | "Node restart method unsupported on this environment manager") |