summaryrefslogtreecommitdiff
path: root/watcher_tempest_plugin/tests/scenario/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'watcher_tempest_plugin/tests/scenario/base.py')
-rw-r--r--watcher_tempest_plugin/tests/scenario/base.py185
1 files changed, 0 insertions, 185 deletions
diff --git a/watcher_tempest_plugin/tests/scenario/base.py b/watcher_tempest_plugin/tests/scenario/base.py
deleted file mode 100644
index 18688b0..0000000
--- a/watcher_tempest_plugin/tests/scenario/base.py
+++ /dev/null
@@ -1,185 +0,0 @@
1# -*- encoding: utf-8 -*-
2# Copyright (c) 2016 b<>com
3#
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14# implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19from __future__ import unicode_literals
20
21import time
22
23from oslo_log import log
24from tempest import config
25from tempest import exceptions
26from tempest.lib.common.utils import data_utils
27from tempest.lib.common.utils import test_utils
28
29from watcher_tempest_plugin import infra_optim_clients as clients
30from watcher_tempest_plugin.tests.scenario import manager
31
32LOG = log.getLogger(__name__)
33CONF = config.CONF
34
35
36class BaseInfraOptimScenarioTest(manager.ScenarioTest):
37 """Base class for Infrastructure Optimization API tests."""
38
39 # States where the object is waiting for some event to perform a transition
40 IDLE_STATES = ('RECOMMENDED', 'FAILED', 'SUCCEEDED', 'CANCELLED')
41 # States where the object can only be DELETED (end of its life-cycle)
42 FINISHED_STATES = ('FAILED', 'SUCCEEDED', 'CANCELLED', 'SUPERSEDED')
43
44 @classmethod
45 def setup_credentials(cls):
46 cls._check_network_config()
47 super(BaseInfraOptimScenarioTest, cls).setup_credentials()
48 cls.mgr = clients.AdminManager()
49
50 @classmethod
51 def setup_clients(cls):
52 super(BaseInfraOptimScenarioTest, cls).setup_clients()
53 cls.client = cls.mgr.io_client
54
55 @classmethod
56 def resource_setup(cls):
57 super(BaseInfraOptimScenarioTest, cls).resource_setup()
58
59 @classmethod
60 def resource_cleanup(cls):
61 """Ensure that all created objects get destroyed."""
62 super(BaseInfraOptimScenarioTest, cls).resource_cleanup()
63
64 @classmethod
65 def wait_for(cls, condition, timeout=30):
66 start_time = time.time()
67 while time.time() - start_time < timeout:
68 if condition():
69 break
70 time.sleep(.5)
71
72 @classmethod
73 def _check_network_config(cls):
74 if not CONF.network.public_network_id:
75 msg = 'public network not defined.'
76 LOG.error(msg)
77 raise exceptions.InvalidConfiguration(msg)
78
79 @classmethod
80 def _are_all_action_plans_finished(cls):
81 _, action_plans = cls.client.list_action_plans()
82 return all([ap['state'] in cls.FINISHED_STATES
83 for ap in action_plans['action_plans']])
84
85 def wait_for_all_action_plans_to_finish(self):
86 assert test_utils.call_until_true(
87 func=self._are_all_action_plans_finished,
88 duration=300,
89 sleep_for=5
90 )
91
92 # ### AUDIT TEMPLATES ### #
93
94 def create_audit_template(self, goal, name=None, description=None,
95 strategy=None):
96 """Wrapper utility for creating a test audit template
97
98 :param goal: Goal UUID or name related to the audit template.
99 :param name: The name of the audit template. Default: My Audit Template
100 :param description: The description of the audit template.
101 :param strategy: Strategy UUID or name related to the audit template.
102 :return: A tuple with The HTTP response and its body
103 """
104 description = description or data_utils.rand_name(
105 'test-audit_template')
106 resp, body = self.client.create_audit_template(
107 name=name, description=description, goal=goal, strategy=strategy)
108
109 self.addCleanup(
110 self.delete_audit_template,
111 audit_template_uuid=body["uuid"]
112 )
113
114 return resp, body
115
116 def delete_audit_template(self, audit_template_uuid):
117 """Deletes a audit_template having the specified UUID
118
119 :param audit_template_uuid: The unique identifier of the audit template
120 :return: Server response
121 """
122 resp, _ = self.client.delete_audit_template(audit_template_uuid)
123 return resp
124
125 # ### AUDITS ### #
126
127 def create_audit(self, audit_template_uuid, audit_type='ONESHOT',
128 state=None, interval=None, parameters=None):
129 """Wrapper utility for creating a test audit
130
131 :param audit_template_uuid: Audit Template UUID this audit will use
132 :param type: Audit type (either ONESHOT or CONTINUOUS)
133 :param state: Audit state (str)
134 :param interval: Audit interval in seconds (int)
135 :param parameters: list of execution parameters
136 :return: A tuple with The HTTP response and its body
137 """
138 resp, body = self.client.create_audit(
139 audit_template_uuid=audit_template_uuid, audit_type=audit_type,
140 state=state, interval=interval, parameters=parameters)
141
142 self.addCleanup(self.delete_audit, audit_uuid=body["uuid"])
143 return resp, body
144
145 def delete_audit(self, audit_uuid):
146 """Deletes an audit having the specified UUID
147
148 :param audit_uuid: The unique identifier of the audit.
149 :return: the HTTP response
150 """
151
152 _, action_plans = self.client.list_action_plans(audit_uuid=audit_uuid)
153 for action_plan in action_plans.get("action_plans", []):
154 self.delete_action_plan(action_plan_uuid=action_plan["uuid"])
155
156 resp, _ = self.client.delete_audit(audit_uuid)
157 return resp
158
159 def has_audit_succeeded(self, audit_uuid):
160 _, audit = self.client.show_audit(audit_uuid)
161 if audit.get('state') in ('FAILED', 'CANCELLED'):
162 raise ValueError()
163
164 return audit.get('state') == 'SUCCEEDED'
165
166 @classmethod
167 def has_audit_finished(cls, audit_uuid):
168 _, audit = cls.client.show_audit(audit_uuid)
169 return audit.get('state') in cls.FINISHED_STATES
170
171 # ### ACTION PLANS ### #
172
173 def delete_action_plan(self, action_plan_uuid):
174 """Deletes an action plan having the specified UUID
175
176 :param action_plan_uuid: The unique identifier of the action plan.
177 :return: the HTTP response
178 """
179 resp, _ = self.client.delete_action_plan(action_plan_uuid)
180 return resp
181
182 def has_action_plan_finished(self, action_plan_uuid):
183 _, action_plan = self.client.show_action_plan(action_plan_uuid)
184 return action_plan.get('state') in ('FAILED', 'SUCCEEDED', 'CANCELLED',
185 'SUPERSEDED')