blob: b69cc49dab3581bf82902e592e18261b66d16ca1 [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 Treinishf4a9b0f2013-07-26 16:58:26 -040015from tempest.openstack.common import log as logging
Steve Bakerd2525a92013-05-06 15:29:03 +120016import tempest.test
17
18
19LOG = logging.getLogger(__name__)
20
21
22class BaseOrchestrationTest(tempest.test.BaseTestCase):
23 """Base test case class for all Orchestration API tests."""
24
25 @classmethod
26 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020027 super(BaseOrchestrationTest, cls).setUpClass()
Steve Bakerd2525a92013-05-06 15:29:03 +120028 os = clients.OrchestrationManager()
29 cls.orchestration_cfg = os.config.orchestration
Steve Baker80252da2013-09-25 13:29:10 +120030 cls.compute_cfg = os.config.compute
Matthew Treinisha9d43882013-07-19 16:54:52 -040031 if not os.config.service_available.heat:
Steve Bakerd2525a92013-05-06 15:29:03 +120032 raise cls.skipException("Heat support is required")
Steve Baker6bf3d632013-06-24 14:44:40 +120033 cls.build_timeout = cls.orchestration_cfg.build_timeout
34 cls.build_interval = cls.orchestration_cfg.build_interval
Steve Bakerd2525a92013-05-06 15:29:03 +120035
36 cls.os = os
37 cls.orchestration_client = os.orchestration_client
Steve Baker38d8f092013-06-12 12:47:16 +120038 cls.servers_client = os.servers_client
Steve Bakerd2525a92013-05-06 15:29:03 +120039 cls.keypairs_client = os.keypairs_client
Steve Baker80252da2013-09-25 13:29:10 +120040 cls.network_client = os.network_client
Steve Bakerd2525a92013-05-06 15:29:03 +120041 cls.stacks = []
Steve Bakerb1f67b52013-06-24 14:42:30 +120042 cls.keypairs = []
Steve Bakerd2525a92013-05-06 15:29:03 +120043
44 @classmethod
Steve Baker80252da2013-09-25 13:29:10 +120045 def _get_default_network(cls):
46 resp, networks = cls.network_client.list_networks()
47 for net in networks['networks']:
48 if net['name'] == cls.compute_cfg.fixed_network_name:
49 return net
50
51 @classmethod
Steve Bakerd2525a92013-05-06 15:29:03 +120052 def _get_identity_admin_client(cls):
53 """
54 Returns an instance of the Identity Admin API client
55 """
56 os = clients.AdminManager(interface=cls._interface)
57 admin_client = os.identity_client
58 return admin_client
59
60 @classmethod
61 def _get_client_args(cls):
62
63 return (
64 cls.config,
65 cls.config.identity.admin_username,
66 cls.config.identity.admin_password,
67 cls.config.identity.uri
68 )
69
Steve Bakerb7942772013-06-27 10:23:28 +120070 @classmethod
71 def create_stack(cls, stack_name, template_data, parameters={}):
72 resp, body = cls.client.create_stack(
Steve Bakerd2525a92013-05-06 15:29:03 +120073 stack_name,
74 template=template_data,
75 parameters=parameters)
Steve Bakerd2525a92013-05-06 15:29:03 +120076 stack_id = resp['location'].split('/')[-1]
77 stack_identifier = '%s/%s' % (stack_name, stack_id)
Steve Bakerb7942772013-06-27 10:23:28 +120078 cls.stacks.append(stack_identifier)
Steve Bakerd2525a92013-05-06 15:29:03 +120079 return stack_identifier
80
81 @classmethod
82 def clear_stacks(cls):
83 for stack_identifier in cls.stacks:
84 try:
85 cls.orchestration_client.delete_stack(stack_identifier)
86 except Exception:
87 pass
88
89 for stack_identifier in cls.stacks:
90 try:
91 cls.orchestration_client.wait_for_stack_status(
92 stack_identifier, 'DELETE_COMPLETE')
93 except Exception:
94 pass
95
Steve Bakerb7942772013-06-27 10:23:28 +120096 @classmethod
Bartosz Górskiab33b7e2013-06-27 00:39:47 -070097 def _create_keypair(cls, name_start='keypair-heat-'):
Masayuki Igawa259c1132013-10-31 17:48:44 +090098 kp_name = data_utils.rand_name(name_start)
Steve Bakerb7942772013-06-27 10:23:28 +120099 resp, body = cls.keypairs_client.create_keypair(kp_name)
100 cls.keypairs.append(kp_name)
Steve Bakerd2525a92013-05-06 15:29:03 +1200101 return body
102
103 @classmethod
Steve Bakerb1f67b52013-06-24 14:42:30 +1200104 def clear_keypairs(cls):
105 for kp_name in cls.keypairs:
106 try:
107 cls.keypairs_client.delete_keypair(kp_name)
108 except Exception:
109 pass
110
111 @classmethod
Steve Bakerd2525a92013-05-06 15:29:03 +1200112 def tearDownClass(cls):
113 cls.clear_stacks()
Steve Bakerb1f67b52013-06-24 14:42:30 +1200114 cls.clear_keypairs()
Attila Fazekasf86fa312013-07-30 19:56:39 +0200115 super(BaseOrchestrationTest, cls).tearDownClass()
Steve Bakerd2525a92013-05-06 15:29:03 +1200116
Steve Baker38d8f092013-06-12 12:47:16 +1200117 @staticmethod
118 def stack_output(stack, output_key):
119 """Return a stack output value for a give key."""
120 return next((o['output_value'] for o in stack['outputs']
121 if o['output_key'] == output_key), None)