blob: 2a72c95d33620c5697d0353b5eb32aa7b461647d [file] [log] [blame]
Steve Bakerd2525a92013-05-06 15:29:03 +12001# vim: tabstop=4 shiftwidth=4 softtabstop=4
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
Steve Bakerd2525a92013-05-06 15:29:03 +120015import time
16
17from tempest import clients
18from tempest.common.utils.data_utils import rand_name
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040019from tempest.openstack.common import log as logging
Steve Bakerd2525a92013-05-06 15:29:03 +120020import tempest.test
21
22
23LOG = logging.getLogger(__name__)
24
25
26class BaseOrchestrationTest(tempest.test.BaseTestCase):
27 """Base test case class for all Orchestration API tests."""
28
29 @classmethod
30 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020031 super(BaseOrchestrationTest, cls).setUpClass()
Steve Bakerd2525a92013-05-06 15:29:03 +120032 os = clients.OrchestrationManager()
33 cls.orchestration_cfg = os.config.orchestration
Matthew Treinisha9d43882013-07-19 16:54:52 -040034 if not os.config.service_available.heat:
Steve Bakerd2525a92013-05-06 15:29:03 +120035 raise cls.skipException("Heat support is required")
Steve Baker6bf3d632013-06-24 14:44:40 +120036 cls.build_timeout = cls.orchestration_cfg.build_timeout
37 cls.build_interval = cls.orchestration_cfg.build_interval
Steve Bakerd2525a92013-05-06 15:29:03 +120038
39 cls.os = os
40 cls.orchestration_client = os.orchestration_client
Steve Baker38d8f092013-06-12 12:47:16 +120041 cls.servers_client = os.servers_client
Steve Bakerd2525a92013-05-06 15:29:03 +120042 cls.keypairs_client = os.keypairs_client
43 cls.stacks = []
Steve Bakerb1f67b52013-06-24 14:42:30 +120044 cls.keypairs = []
Steve Bakerd2525a92013-05-06 15:29:03 +120045
46 @classmethod
47 def _get_identity_admin_client(cls):
48 """
49 Returns an instance of the Identity Admin API client
50 """
51 os = clients.AdminManager(interface=cls._interface)
52 admin_client = os.identity_client
53 return admin_client
54
55 @classmethod
56 def _get_client_args(cls):
57
58 return (
59 cls.config,
60 cls.config.identity.admin_username,
61 cls.config.identity.admin_password,
62 cls.config.identity.uri
63 )
64
Steve Bakerb7942772013-06-27 10:23:28 +120065 @classmethod
66 def create_stack(cls, stack_name, template_data, parameters={}):
67 resp, body = cls.client.create_stack(
Steve Bakerd2525a92013-05-06 15:29:03 +120068 stack_name,
69 template=template_data,
70 parameters=parameters)
Steve Bakerd2525a92013-05-06 15:29:03 +120071 stack_id = resp['location'].split('/')[-1]
72 stack_identifier = '%s/%s' % (stack_name, stack_id)
Steve Bakerb7942772013-06-27 10:23:28 +120073 cls.stacks.append(stack_identifier)
Steve Bakerd2525a92013-05-06 15:29:03 +120074 return stack_identifier
75
76 @classmethod
77 def clear_stacks(cls):
78 for stack_identifier in cls.stacks:
79 try:
80 cls.orchestration_client.delete_stack(stack_identifier)
81 except Exception:
82 pass
83
84 for stack_identifier in cls.stacks:
85 try:
86 cls.orchestration_client.wait_for_stack_status(
87 stack_identifier, 'DELETE_COMPLETE')
88 except Exception:
89 pass
90
Steve Bakerb7942772013-06-27 10:23:28 +120091 @classmethod
Bartosz Górskiab33b7e2013-06-27 00:39:47 -070092 def _create_keypair(cls, name_start='keypair-heat-'):
93 kp_name = rand_name(name_start)
Steve Bakerb7942772013-06-27 10:23:28 +120094 resp, body = cls.keypairs_client.create_keypair(kp_name)
95 cls.keypairs.append(kp_name)
Steve Bakerd2525a92013-05-06 15:29:03 +120096 return body
97
98 @classmethod
Steve Bakerb1f67b52013-06-24 14:42:30 +120099 def clear_keypairs(cls):
100 for kp_name in cls.keypairs:
101 try:
102 cls.keypairs_client.delete_keypair(kp_name)
103 except Exception:
104 pass
105
106 @classmethod
Steve Bakerd2525a92013-05-06 15:29:03 +1200107 def tearDownClass(cls):
108 cls.clear_stacks()
Steve Bakerb1f67b52013-06-24 14:42:30 +1200109 cls.clear_keypairs()
Attila Fazekasf86fa312013-07-30 19:56:39 +0200110 super(BaseOrchestrationTest, cls).tearDownClass()
Steve Bakerd2525a92013-05-06 15:29:03 +1200111
112 def wait_for(self, condition):
113 """Repeatedly calls condition() until a timeout."""
114 start_time = int(time.time())
115 while True:
116 try:
117 condition()
118 except Exception:
119 pass
120 else:
121 return
122 if int(time.time()) - start_time >= self.build_timeout:
123 condition()
124 return
125 time.sleep(self.build_interval)
Steve Baker38d8f092013-06-12 12:47:16 +1200126
127 @staticmethod
128 def stack_output(stack, output_key):
129 """Return a stack output value for a give key."""
130 return next((o['output_value'] for o in stack['outputs']
131 if o['output_key'] == output_key), None)