blob: 79f8f4a76686175ccd6526fedf50facadedc5d42 [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
Steve Baker38d8f092013-06-12 12:47:16 +120039 cls.servers_client = os.servers_client
Steve Bakerd2525a92013-05-06 15:29:03 +120040 cls.keypairs_client = os.keypairs_client
Steve Baker80252da2013-09-25 13:29:10 +120041 cls.network_client = os.network_client
Steve Bakerd2525a92013-05-06 15:29:03 +120042 cls.stacks = []
Steve Bakerb1f67b52013-06-24 14:42:30 +120043 cls.keypairs = []
Steve Bakerd2525a92013-05-06 15:29:03 +120044
45 @classmethod
Steve Baker80252da2013-09-25 13:29:10 +120046 def _get_default_network(cls):
47 resp, networks = cls.network_client.list_networks()
48 for net in networks['networks']:
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000049 if net['name'] == CONF.compute.fixed_network_name:
Steve Baker80252da2013-09-25 13:29:10 +120050 return net
51
52 @classmethod
Steve Bakerd2525a92013-05-06 15:29:03 +120053 def _get_identity_admin_client(cls):
54 """
55 Returns an instance of the Identity Admin API client
56 """
57 os = clients.AdminManager(interface=cls._interface)
58 admin_client = os.identity_client
59 return admin_client
60
61 @classmethod
Steve Bakerb7942772013-06-27 10:23:28 +120062 def create_stack(cls, stack_name, template_data, parameters={}):
63 resp, body = cls.client.create_stack(
Steve Bakerd2525a92013-05-06 15:29:03 +120064 stack_name,
65 template=template_data,
66 parameters=parameters)
Steve Bakerd2525a92013-05-06 15:29:03 +120067 stack_id = resp['location'].split('/')[-1]
68 stack_identifier = '%s/%s' % (stack_name, stack_id)
Steve Bakerb7942772013-06-27 10:23:28 +120069 cls.stacks.append(stack_identifier)
Steve Bakerd2525a92013-05-06 15:29:03 +120070 return stack_identifier
71
72 @classmethod
73 def clear_stacks(cls):
74 for stack_identifier in cls.stacks:
75 try:
76 cls.orchestration_client.delete_stack(stack_identifier)
Steve Baker8ba9e2d2014-03-24 15:37:15 +130077 except exceptions.NotFound:
Steve Bakerd2525a92013-05-06 15:29:03 +120078 pass
79
80 for stack_identifier in cls.stacks:
81 try:
82 cls.orchestration_client.wait_for_stack_status(
83 stack_identifier, 'DELETE_COMPLETE')
Steve Baker8ba9e2d2014-03-24 15:37:15 +130084 except exceptions.NotFound:
Steve Bakerd2525a92013-05-06 15:29:03 +120085 pass
86
Steve Bakerb7942772013-06-27 10:23:28 +120087 @classmethod
Bartosz Górskiab33b7e2013-06-27 00:39:47 -070088 def _create_keypair(cls, name_start='keypair-heat-'):
Masayuki Igawa259c1132013-10-31 17:48:44 +090089 kp_name = data_utils.rand_name(name_start)
Steve Bakerb7942772013-06-27 10:23:28 +120090 resp, body = cls.keypairs_client.create_keypair(kp_name)
91 cls.keypairs.append(kp_name)
Steve Bakerd2525a92013-05-06 15:29:03 +120092 return body
93
94 @classmethod
Steve Bakerb1f67b52013-06-24 14:42:30 +120095 def clear_keypairs(cls):
96 for kp_name in cls.keypairs:
97 try:
98 cls.keypairs_client.delete_keypair(kp_name)
99 except Exception:
100 pass
101
102 @classmethod
Steve Bakerd2525a92013-05-06 15:29:03 +1200103 def tearDownClass(cls):
104 cls.clear_stacks()
Steve Bakerb1f67b52013-06-24 14:42:30 +1200105 cls.clear_keypairs()
Attila Fazekasf86fa312013-07-30 19:56:39 +0200106 super(BaseOrchestrationTest, cls).tearDownClass()
Steve Bakerd2525a92013-05-06 15:29:03 +1200107
Steve Baker38d8f092013-06-12 12:47:16 +1200108 @staticmethod
109 def stack_output(stack, output_key):
110 """Return a stack output value for a give key."""
111 return next((o['output_value'] for o in stack['outputs']
112 if o['output_key'] == output_key), None)