blob: b6c03e09a10012bb41c07f4890f206ca719b7109 [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 +120015from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090016from tempest.common.utils import data_utils
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
20
21LOG = logging.getLogger(__name__)
22
23
24class BaseOrchestrationTest(tempest.test.BaseTestCase):
25 """Base test case class for all Orchestration API tests."""
26
27 @classmethod
28 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020029 super(BaseOrchestrationTest, cls).setUpClass()
Steve Bakerd2525a92013-05-06 15:29:03 +120030 os = clients.OrchestrationManager()
31 cls.orchestration_cfg = os.config.orchestration
Steve Baker80252da2013-09-25 13:29:10 +120032 cls.compute_cfg = os.config.compute
Matthew Treinisha9d43882013-07-19 16:54:52 -040033 if not os.config.service_available.heat:
Steve Bakerd2525a92013-05-06 15:29:03 +120034 raise cls.skipException("Heat support is required")
Steve Baker6bf3d632013-06-24 14:44:40 +120035 cls.build_timeout = cls.orchestration_cfg.build_timeout
36 cls.build_interval = cls.orchestration_cfg.build_interval
Steve Bakerd2525a92013-05-06 15:29:03 +120037
38 cls.os = os
39 cls.orchestration_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']:
50 if net['name'] == cls.compute_cfg.fixed_network_name:
51 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
63 def _get_client_args(cls):
64
65 return (
66 cls.config,
67 cls.config.identity.admin_username,
68 cls.config.identity.admin_password,
69 cls.config.identity.uri
70 )
71
Steve Bakerb7942772013-06-27 10:23:28 +120072 @classmethod
73 def create_stack(cls, stack_name, template_data, parameters={}):
74 resp, body = cls.client.create_stack(
Steve Bakerd2525a92013-05-06 15:29:03 +120075 stack_name,
76 template=template_data,
77 parameters=parameters)
Steve Bakerd2525a92013-05-06 15:29:03 +120078 stack_id = resp['location'].split('/')[-1]
79 stack_identifier = '%s/%s' % (stack_name, stack_id)
Steve Bakerb7942772013-06-27 10:23:28 +120080 cls.stacks.append(stack_identifier)
Steve Bakerd2525a92013-05-06 15:29:03 +120081 return stack_identifier
82
83 @classmethod
84 def clear_stacks(cls):
85 for stack_identifier in cls.stacks:
86 try:
87 cls.orchestration_client.delete_stack(stack_identifier)
88 except Exception:
89 pass
90
91 for stack_identifier in cls.stacks:
92 try:
93 cls.orchestration_client.wait_for_stack_status(
94 stack_identifier, 'DELETE_COMPLETE')
95 except Exception:
96 pass
97
Steve Bakerb7942772013-06-27 10:23:28 +120098 @classmethod
Bartosz Górskiab33b7e2013-06-27 00:39:47 -070099 def _create_keypair(cls, name_start='keypair-heat-'):
Masayuki Igawa259c1132013-10-31 17:48:44 +0900100 kp_name = data_utils.rand_name(name_start)
Steve Bakerb7942772013-06-27 10:23:28 +1200101 resp, body = cls.keypairs_client.create_keypair(kp_name)
102 cls.keypairs.append(kp_name)
Steve Bakerd2525a92013-05-06 15:29:03 +1200103 return body
104
105 @classmethod
Steve Bakerb1f67b52013-06-24 14:42:30 +1200106 def clear_keypairs(cls):
107 for kp_name in cls.keypairs:
108 try:
109 cls.keypairs_client.delete_keypair(kp_name)
110 except Exception:
111 pass
112
113 @classmethod
Steve Bakerd2525a92013-05-06 15:29:03 +1200114 def tearDownClass(cls):
115 cls.clear_stacks()
Steve Bakerb1f67b52013-06-24 14:42:30 +1200116 cls.clear_keypairs()
Attila Fazekasf86fa312013-07-30 19:56:39 +0200117 super(BaseOrchestrationTest, cls).tearDownClass()
Steve Bakerd2525a92013-05-06 15:29:03 +1200118
Steve Baker38d8f092013-06-12 12:47:16 +1200119 @staticmethod
120 def stack_output(stack, output_key):
121 """Return a stack output value for a give key."""
122 return next((o['output_value'] for o in stack['outputs']
123 if o['output_key'] == output_key), None)