blob: 702d723d2113fe31053d97621144c9de0a21529b [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
15from tcp_tests import settings_oslo
16
17
18class EnvironmentManagerEmpty(object):
19 """Class-helper for creating VMs via devops environments"""
20
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030021 _config = None
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030022
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 """
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030031 self._config = config
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030032
33 def lvm_storages(self):
34 """Returns data of lvm_storages on nodes in environment
35
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030036 It's expected that data of self._config.lvm_storages will be
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030037 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 """
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030051 return self._config.underlay.lvm
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030052
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
57 def create_snapshot(self, name, description=None):
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 """
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030063 self._config.hardware.current_snapshot = name
64 settings_oslo.save_config(self._config, name)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030065
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
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030070 that is stored in the 'self._config.hardware.current_snapshot'
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030071 - 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 """
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030077 if self._config.hardware.current_snapshot != name:
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030078 raise Exception(
79 "EnvironmentManagerEmpty cannot revert nodes from {} to {}"
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030080 .format(self._config.hardware.current_snapshot, name))
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030081
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):
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030099 return self._config.hardware.current_snapshot == name
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300100
101 def has_snapshot_config(self, name):
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +0300102 return self._config.hardware.current_snapshot == name
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300103
104 def delete_environment(self):
105 """Delete environment"""
106 pass