blob: 9bf9568206c92de7e42f4aad21f5f7c85c3402e8 [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
Steve Bakerd2525a92013-05-06 15:29:03 +120013from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090014from tempest.common.utils import data_utils
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000015from tempest import config
Steve Baker8ba9e2d2014-03-24 15:37:15 +130016from tempest import exceptions
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040017from tempest.openstack.common import log as logging
Steve Bakerd2525a92013-05-06 15:29:03 +120018import tempest.test
19
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000020CONF = config.CONF
Steve Bakerd2525a92013-05-06 15:29:03 +120021
22LOG = logging.getLogger(__name__)
23
24
25class BaseOrchestrationTest(tempest.test.BaseTestCase):
26 """Base test case class for all Orchestration API tests."""
27
28 @classmethod
29 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020030 super(BaseOrchestrationTest, cls).setUpClass()
Steve Bakerd2525a92013-05-06 15:29:03 +120031 os = clients.OrchestrationManager()
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000032 if not CONF.service_available.heat:
Steve Bakerd2525a92013-05-06 15:29:03 +120033 raise cls.skipException("Heat support is required")
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000034 cls.build_timeout = CONF.orchestration.build_timeout
35 cls.build_interval = CONF.orchestration.build_interval
Steve Bakerd2525a92013-05-06 15:29:03 +120036
37 cls.os = os
38 cls.orchestration_client = os.orchestration_client
Sean Daguead824912014-03-25 14:56:35 -040039 cls.client = os.orchestration_client
Steve Baker38d8f092013-06-12 12:47:16 +120040 cls.servers_client = os.servers_client
Steve Bakerd2525a92013-05-06 15:29:03 +120041 cls.keypairs_client = os.keypairs_client
Steve Baker80252da2013-09-25 13:29:10 +120042 cls.network_client = os.network_client
Steve Bakerd2525a92013-05-06 15:29:03 +120043 cls.stacks = []
Steve Bakerb1f67b52013-06-24 14:42:30 +120044 cls.keypairs = []
Steve Bakerd2525a92013-05-06 15:29:03 +120045
46 @classmethod
Steve Baker80252da2013-09-25 13:29:10 +120047 def _get_default_network(cls):
48 resp, networks = cls.network_client.list_networks()
49 for net in networks['networks']:
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000050 if net['name'] == CONF.compute.fixed_network_name:
Steve Baker80252da2013-09-25 13:29:10 +120051 return net
52
53 @classmethod
Steve Bakerd2525a92013-05-06 15:29:03 +120054 def _get_identity_admin_client(cls):
55 """
56 Returns an instance of the Identity Admin API client
57 """
58 os = clients.AdminManager(interface=cls._interface)
59 admin_client = os.identity_client
60 return admin_client
61
62 @classmethod
Steve Bakerb7942772013-06-27 10:23:28 +120063 def create_stack(cls, stack_name, template_data, parameters={}):
64 resp, body = cls.client.create_stack(
Steve Bakerd2525a92013-05-06 15:29:03 +120065 stack_name,
66 template=template_data,
67 parameters=parameters)
Steve Bakerd2525a92013-05-06 15:29:03 +120068 stack_id = resp['location'].split('/')[-1]
69 stack_identifier = '%s/%s' % (stack_name, stack_id)
Steve Bakerb7942772013-06-27 10:23:28 +120070 cls.stacks.append(stack_identifier)
Steve Bakerd2525a92013-05-06 15:29:03 +120071 return stack_identifier
72
73 @classmethod
74 def clear_stacks(cls):
75 for stack_identifier in cls.stacks:
76 try:
Sean Daguead824912014-03-25 14:56:35 -040077 cls.client.delete_stack(stack_identifier)
Steve Baker8ba9e2d2014-03-24 15:37:15 +130078 except exceptions.NotFound:
Steve Bakerd2525a92013-05-06 15:29:03 +120079 pass
80
81 for stack_identifier in cls.stacks:
82 try:
Sean Daguead824912014-03-25 14:56:35 -040083 cls.client.wait_for_stack_status(
Steve Bakerd2525a92013-05-06 15:29:03 +120084 stack_identifier, 'DELETE_COMPLETE')
Steve Baker8ba9e2d2014-03-24 15:37:15 +130085 except exceptions.NotFound:
Steve Bakerd2525a92013-05-06 15:29:03 +120086 pass
87
Steve Bakerb7942772013-06-27 10:23:28 +120088 @classmethod
Bartosz Górskiab33b7e2013-06-27 00:39:47 -070089 def _create_keypair(cls, name_start='keypair-heat-'):
Masayuki Igawa259c1132013-10-31 17:48:44 +090090 kp_name = data_utils.rand_name(name_start)
Steve Bakerb7942772013-06-27 10:23:28 +120091 resp, body = cls.keypairs_client.create_keypair(kp_name)
92 cls.keypairs.append(kp_name)
Steve Bakerd2525a92013-05-06 15:29:03 +120093 return body
94
95 @classmethod
Steve Bakerb1f67b52013-06-24 14:42:30 +120096 def clear_keypairs(cls):
97 for kp_name in cls.keypairs:
98 try:
99 cls.keypairs_client.delete_keypair(kp_name)
100 except Exception:
101 pass
102
103 @classmethod
Steve Bakerd2525a92013-05-06 15:29:03 +1200104 def tearDownClass(cls):
105 cls.clear_stacks()
Steve Bakerb1f67b52013-06-24 14:42:30 +1200106 cls.clear_keypairs()
Attila Fazekasf86fa312013-07-30 19:56:39 +0200107 super(BaseOrchestrationTest, cls).tearDownClass()
Steve Bakerd2525a92013-05-06 15:29:03 +1200108
Steve Baker38d8f092013-06-12 12:47:16 +1200109 @staticmethod
110 def stack_output(stack, output_key):
111 """Return a stack output value for a give key."""
112 return next((o['output_value'] for o in stack['outputs']
113 if o['output_key'] == output_key), None)