blob: 99b5c011e945c9c98fbb949f433cd5f9d9a99925 [file] [log] [blame]
Dennis Dmitriev6f59add2016-10-18 13:45:27 +03001# 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 Dmitrievfa1774a2019-05-28 15:27:44 +030015from tcp_tests import settings
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030016from tcp_tests import settings_oslo
Dennis Dmitrievfa1774a2019-05-28 15:27:44 +030017from tcp_tests import logger
18
19LOG = logger.logger
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030020
21
22class EnvironmentManagerEmpty(object):
23 """Class-helper for creating VMs via devops environments"""
24
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +030025 __config = None
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030026
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 Dmitriev2d60c8e2017-05-12 18:34:01 +030035 self.__config = config
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030036
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030037 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 Dmitriev411dd102017-09-15 16:04:47 +030041 def create_snapshot(self, name, **kwargs):
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030042 """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 Dmitrievfa1774a2019-05-28 15:27:44 +030047 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 Dmitriev2d60c8e2017-05-12 18:34:01 +030053 self.__config.hardware.current_snapshot = name
54 settings_oslo.save_config(self.__config, name)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030055
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 Dmitriev2d60c8e2017-05-12 18:34:01 +030060 that is stored in the 'self.__config.hardware.current_snapshot'
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030061 - 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 Dmitriev2d60c8e2017-05-12 18:34:01 +030067 if self.__config.hardware.current_snapshot != name:
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030068 raise Exception(
69 "EnvironmentManagerEmpty cannot revert nodes from {} to {}"
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +030070 .format(self.__config.hardware.current_snapshot, name))
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030071
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 Dmitriev2d60c8e2017-05-12 18:34:01 +030089 return self.__config.hardware.current_snapshot == name
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030090
91 def has_snapshot_config(self, name):
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +030092 return self.__config.hardware.current_snapshot == name
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030093
94 def delete_environment(self):
95 """Delete environment"""
96 pass
Vladimir Jigulinee1faa52018-06-25 13:00:51 +040097
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")