blob: df3efdb1a370c24edf41dbe19502fd5bbdb9990c [file] [log] [blame]
Steve Bakerd2525a92013-05-06 15:29:03 +12001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
Sean Daguee0a65d12014-03-25 15:59:16 -040013import os.path
14
Steve Bakerd2525a92013-05-06 15:29:03 +120015from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090016from tempest.common.utils import data_utils
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000017from tempest import config
Steve Baker8ba9e2d2014-03-24 15:37:15 +130018from tempest import exceptions
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
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000022CONF = config.CONF
Steve Bakerd2525a92013-05-06 15:29:03 +120023
24LOG = logging.getLogger(__name__)
25
26
27class BaseOrchestrationTest(tempest.test.BaseTestCase):
28 """Base test case class for all Orchestration API tests."""
29
30 @classmethod
31 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020032 super(BaseOrchestrationTest, cls).setUpClass()
Steve Baker61d8c442014-04-16 12:03:37 +120033 cls.os = clients.Manager()
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000034 if not CONF.service_available.heat:
Steve Bakerd2525a92013-05-06 15:29:03 +120035 raise cls.skipException("Heat support is required")
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000036 cls.build_timeout = CONF.orchestration.build_timeout
37 cls.build_interval = CONF.orchestration.build_interval
Steve Bakerd2525a92013-05-06 15:29:03 +120038
Sean Daguee0a65d12014-03-25 15:59:16 -040039 cls.orchestration_client = cls.os.orchestration_client
40 cls.client = cls.orchestration_client
41 cls.servers_client = cls.os.servers_client
42 cls.keypairs_client = cls.os.keypairs_client
43 cls.network_client = cls.os.network_client
Steven Hardyb1f91982014-04-04 15:35:55 +010044 cls.volumes_client = cls.os.volumes_client
Steve Bakerd2525a92013-05-06 15:29:03 +120045 cls.stacks = []
Steve Bakerb1f67b52013-06-24 14:42:30 +120046 cls.keypairs = []
Steve Bakerd2525a92013-05-06 15:29:03 +120047
48 @classmethod
Steve Baker80252da2013-09-25 13:29:10 +120049 def _get_default_network(cls):
50 resp, networks = cls.network_client.list_networks()
51 for net in networks['networks']:
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000052 if net['name'] == CONF.compute.fixed_network_name:
Steve Baker80252da2013-09-25 13:29:10 +120053 return net
54
55 @classmethod
Steve Bakerd2525a92013-05-06 15:29:03 +120056 def _get_identity_admin_client(cls):
Steven Hardy48ec7052014-03-28 14:06:27 +000057 """Returns an instance of the Identity Admin API client."""
Sean Daguee0a65d12014-03-25 15:59:16 -040058 manager = clients.AdminManager(interface=cls._interface)
59 admin_client = manager.identity_client
Steve Bakerd2525a92013-05-06 15:29:03 +120060 return admin_client
61
62 @classmethod
Steven Hardy00de7582014-05-07 15:18:52 +010063 def create_stack(cls, stack_name, template_data, parameters={},
64 environment=None):
Steve Bakerb7942772013-06-27 10:23:28 +120065 resp, body = cls.client.create_stack(
Steve Bakerd2525a92013-05-06 15:29:03 +120066 stack_name,
67 template=template_data,
Steven Hardy00de7582014-05-07 15:18:52 +010068 parameters=parameters,
69 environment=environment)
Steve Bakerd2525a92013-05-06 15:29:03 +120070 stack_id = resp['location'].split('/')[-1]
71 stack_identifier = '%s/%s' % (stack_name, stack_id)
Steve Bakerb7942772013-06-27 10:23:28 +120072 cls.stacks.append(stack_identifier)
Steve Bakerd2525a92013-05-06 15:29:03 +120073 return stack_identifier
74
75 @classmethod
Steven Hardy5be93e82014-04-02 21:24:05 +010076 def _clear_stacks(cls):
Steve Bakerd2525a92013-05-06 15:29:03 +120077 for stack_identifier in cls.stacks:
78 try:
Sean Daguead824912014-03-25 14:56:35 -040079 cls.client.delete_stack(stack_identifier)
Steve Baker8ba9e2d2014-03-24 15:37:15 +130080 except exceptions.NotFound:
Steve Bakerd2525a92013-05-06 15:29:03 +120081 pass
82
83 for stack_identifier in cls.stacks:
84 try:
Sean Daguead824912014-03-25 14:56:35 -040085 cls.client.wait_for_stack_status(
Steve Bakerd2525a92013-05-06 15:29:03 +120086 stack_identifier, 'DELETE_COMPLETE')
Steve Baker8ba9e2d2014-03-24 15:37:15 +130087 except exceptions.NotFound:
Steve Bakerd2525a92013-05-06 15:29:03 +120088 pass
89
Steve Bakerb7942772013-06-27 10:23:28 +120090 @classmethod
Bartosz Górskiab33b7e2013-06-27 00:39:47 -070091 def _create_keypair(cls, name_start='keypair-heat-'):
Masayuki Igawa259c1132013-10-31 17:48:44 +090092 kp_name = data_utils.rand_name(name_start)
Steve Bakerb7942772013-06-27 10:23:28 +120093 resp, body = cls.keypairs_client.create_keypair(kp_name)
94 cls.keypairs.append(kp_name)
Steve Bakerd2525a92013-05-06 15:29:03 +120095 return body
96
97 @classmethod
Steven Hardy5be93e82014-04-02 21:24:05 +010098 def _clear_keypairs(cls):
Steve Bakerb1f67b52013-06-24 14:42:30 +120099 for kp_name in cls.keypairs:
100 try:
101 cls.keypairs_client.delete_keypair(kp_name)
102 except Exception:
103 pass
104
105 @classmethod
Sean Daguee0a65d12014-03-25 15:59:16 -0400106 def load_template(cls, name, ext='yaml'):
Qiu Hua Qiaof6368772014-04-01 01:12:39 -0500107 loc = ["stacks", "templates", "%s.%s" % (name, ext)]
108 fullpath = os.path.join(os.path.dirname(__file__), *loc)
Sean Daguee0a65d12014-03-25 15:59:16 -0400109
110 with open(fullpath, "r") as f:
111 content = f.read()
112 return content
113
114 @classmethod
Steve Bakerd2525a92013-05-06 15:29:03 +1200115 def tearDownClass(cls):
Steven Hardy5be93e82014-04-02 21:24:05 +0100116 cls._clear_stacks()
117 cls._clear_keypairs()
Attila Fazekasf86fa312013-07-30 19:56:39 +0200118 super(BaseOrchestrationTest, cls).tearDownClass()
Steve Bakerd2525a92013-05-06 15:29:03 +1200119
Steve Baker38d8f092013-06-12 12:47:16 +1200120 @staticmethod
121 def stack_output(stack, output_key):
Steven Hardy48ec7052014-03-28 14:06:27 +0000122 """Return a stack output value for a given key."""
Steve Baker38d8f092013-06-12 12:47:16 +1200123 return next((o['output_value'] for o in stack['outputs']
124 if o['output_key'] == output_key), None)
Steven Hardye2a74442014-03-25 12:10:52 +0000125
126 def assert_fields_in_dict(self, obj, *fields):
127 for field in fields:
128 self.assertIn(field, obj)
129
130 def list_resources(self, stack_identifier):
131 """Get a dict mapping of resource names to types."""
132 resp, resources = self.client.list_resources(stack_identifier)
133 self.assertEqual('200', resp['status'])
134 self.assertIsInstance(resources, list)
135 for res in resources:
136 self.assert_fields_in_dict(res, 'logical_resource_id',
137 'resource_type', 'resource_status',
138 'updated_time')
139
140 return dict((r['resource_name'], r['resource_type'])
141 for r in resources)
Steven Hardy8b54fc52014-03-28 16:15:51 +0000142
143 def get_stack_output(self, stack_identifier, output_key):
144 resp, body = self.client.get_stack(stack_identifier)
145 self.assertEqual('200', resp['status'])
146 return self.stack_output(body, output_key)