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 | |
| 33 | def lvm_storages(self): |
| 34 | """Returns data of lvm_storages on nodes in environment |
| 35 | |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 36 | It's expected that data of self.__config.lvm_storages will be |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 37 | like this: |
| 38 | { |
| 39 | "node1": { |
| 40 | "device": "vdb" |
| 41 | }, |
| 42 | "node2": { |
| 43 | "device": "vdb" |
| 44 | }, |
| 45 | "node3": { |
| 46 | "device": "vdb" |
| 47 | }, |
| 48 | } |
| 49 | :rtype: dict |
| 50 | """ |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 51 | return self.__config.underlay.lvm |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 52 | |
| 53 | def get_ssh_data(self, roles=None): |
| 54 | raise Exception("EnvironmentManagerEmpty doesn't have SSH details. " |
| 55 | "Please provide SSH details in config.underlay.ssh") |
| 56 | |
Dennis Dmitriev | 411dd10 | 2017-09-15 16:04:47 +0300 | [diff] [blame] | 57 | def create_snapshot(self, name, **kwargs): |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 58 | """Store environmetn state into the config object |
| 59 | |
| 60 | - Store the state of the environment <name> to the 'config' object |
| 61 | - Save 'config' object to a file 'config_<name>.ini' |
| 62 | """ |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 63 | self.__config.hardware.current_snapshot = name |
| 64 | settings_oslo.save_config(self.__config, name) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 65 | |
| 66 | def revert_snapshot(self, name): |
| 67 | """Check the current state <name> of the environment |
| 68 | |
| 69 | - Check that the <name> matches the current state of the environment |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 70 | that is stored in the 'self.__config.hardware.current_snapshot' |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 71 | - Try to reload 'config' object from a file 'config_<name>.ini' |
| 72 | If the file not found, then pass with defaults. |
| 73 | - Set <name> as the current state of the environment after reload |
| 74 | |
| 75 | :param name: string |
| 76 | """ |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 77 | if self.__config.hardware.current_snapshot != name: |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 78 | raise Exception( |
| 79 | "EnvironmentManagerEmpty cannot revert nodes from {} to {}" |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 80 | .format(self.__config.hardware.current_snapshot, name)) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 81 | |
| 82 | def start(self): |
| 83 | """Start environment""" |
| 84 | pass |
| 85 | |
| 86 | def resume(self): |
| 87 | """Resume environment""" |
| 88 | pass |
| 89 | |
| 90 | def suspend(self): |
| 91 | """Suspend environment""" |
| 92 | pass |
| 93 | |
| 94 | def stop(self): |
| 95 | """Stop environment""" |
| 96 | pass |
| 97 | |
| 98 | def has_snapshot(self, name): |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 99 | return self.__config.hardware.current_snapshot == name |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 100 | |
| 101 | def has_snapshot_config(self, name): |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 102 | return self.__config.hardware.current_snapshot == name |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 103 | |
| 104 | def delete_environment(self): |
| 105 | """Delete environment""" |
| 106 | pass |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 107 | |
| 108 | def warm_shutdown_nodes(self, underlay, nodes_prefix, timeout=600): |
| 109 | raise Exception( |
| 110 | "Node shutdown method unsupported on this environment manager") |
| 111 | |
| 112 | def warm_restart_nodes(self, underlay, nodes_prefix, timeout=600): |
| 113 | raise Exception( |
| 114 | "Node restart method unsupported on this environment manager") |