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 | |
| 15 | from tcp_tests import settings_oslo |
| 16 | |
| 17 | |
| 18 | class EnvironmentManagerEmpty(object): |
| 19 | """Class-helper for creating VMs via devops environments""" |
| 20 | |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 21 | __config = None |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 22 | |
| 23 | def __init__(self, config=None): |
| 24 | """Initializing class instance and create the environment |
| 25 | |
| 26 | :param config: oslo.config object |
| 27 | :param config.hardware.conf_path: path to devops YAML template |
| 28 | :param config.hardware.current_snapshot: name of the snapshot that |
| 29 | descriebe environment status. |
| 30 | """ |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 31 | self.__config = config |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 32 | |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 33 | def get_ssh_data(self, roles=None): |
| 34 | raise Exception("EnvironmentManagerEmpty doesn't have SSH details. " |
| 35 | "Please provide SSH details in config.underlay.ssh") |
| 36 | |
Dennis Dmitriev | 411dd10 | 2017-09-15 16:04:47 +0300 | [diff] [blame] | 37 | def create_snapshot(self, name, **kwargs): |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 38 | """Store environmetn state into the config object |
| 39 | |
| 40 | - Store the state of the environment <name> to the 'config' object |
| 41 | - Save 'config' object to a file 'config_<name>.ini' |
| 42 | """ |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 43 | self.__config.hardware.current_snapshot = name |
| 44 | settings_oslo.save_config(self.__config, name) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 45 | |
| 46 | def revert_snapshot(self, name): |
| 47 | """Check the current state <name> of the environment |
| 48 | |
| 49 | - Check that the <name> matches the current state of the environment |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 50 | that is stored in the 'self.__config.hardware.current_snapshot' |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 51 | - Try to reload 'config' object from a file 'config_<name>.ini' |
| 52 | If the file not found, then pass with defaults. |
| 53 | - Set <name> as the current state of the environment after reload |
| 54 | |
| 55 | :param name: string |
| 56 | """ |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 57 | if self.__config.hardware.current_snapshot != name: |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 58 | raise Exception( |
| 59 | "EnvironmentManagerEmpty cannot revert nodes from {} to {}" |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 60 | .format(self.__config.hardware.current_snapshot, name)) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 61 | |
| 62 | def start(self): |
| 63 | """Start environment""" |
| 64 | pass |
| 65 | |
| 66 | def resume(self): |
| 67 | """Resume environment""" |
| 68 | pass |
| 69 | |
| 70 | def suspend(self): |
| 71 | """Suspend environment""" |
| 72 | pass |
| 73 | |
| 74 | def stop(self): |
| 75 | """Stop environment""" |
| 76 | pass |
| 77 | |
| 78 | def has_snapshot(self, name): |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 79 | return self.__config.hardware.current_snapshot == name |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 80 | |
| 81 | def has_snapshot_config(self, name): |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 82 | return self.__config.hardware.current_snapshot == name |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 83 | |
| 84 | def delete_environment(self): |
| 85 | """Delete environment""" |
| 86 | pass |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 87 | |
| 88 | def warm_shutdown_nodes(self, underlay, nodes_prefix, timeout=600): |
| 89 | raise Exception( |
| 90 | "Node shutdown method unsupported on this environment manager") |
| 91 | |
| 92 | def warm_restart_nodes(self, underlay, nodes_prefix, timeout=600): |
| 93 | raise Exception( |
| 94 | "Node restart method unsupported on this environment manager") |