111 lines
3.4 KiB
Python
111 lines
3.4 KiB
Python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import logging
|
|
import time
|
|
|
|
from tempest import clients
|
|
from tempest.common.utils.data_utils import rand_name
|
|
import tempest.test
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class BaseOrchestrationTest(tempest.test.BaseTestCase):
|
|
"""Base test case class for all Orchestration API tests."""
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
|
|
os = clients.OrchestrationManager()
|
|
cls.orchestration_cfg = os.config.orchestration
|
|
if not cls.orchestration_cfg.heat_available:
|
|
raise cls.skipException("Heat support is required")
|
|
|
|
cls.os = os
|
|
cls.orchestration_client = os.orchestration_client
|
|
cls.keypairs_client = os.keypairs_client
|
|
cls.stacks = []
|
|
|
|
@classmethod
|
|
def _get_identity_admin_client(cls):
|
|
"""
|
|
Returns an instance of the Identity Admin API client
|
|
"""
|
|
os = clients.AdminManager(interface=cls._interface)
|
|
admin_client = os.identity_client
|
|
return admin_client
|
|
|
|
@classmethod
|
|
def _get_client_args(cls):
|
|
|
|
return (
|
|
cls.config,
|
|
cls.config.identity.admin_username,
|
|
cls.config.identity.admin_password,
|
|
cls.config.identity.uri
|
|
)
|
|
|
|
def create_stack(self, stack_name, template_data, parameters={}):
|
|
resp, body = self.client.create_stack(
|
|
stack_name,
|
|
template=template_data,
|
|
parameters=parameters)
|
|
self.assertEqual('201', resp['status'])
|
|
stack_id = resp['location'].split('/')[-1]
|
|
stack_identifier = '%s/%s' % (stack_name, stack_id)
|
|
self.stacks.append(stack_identifier)
|
|
return stack_identifier
|
|
|
|
@classmethod
|
|
def clear_stacks(cls):
|
|
for stack_identifier in cls.stacks:
|
|
try:
|
|
cls.orchestration_client.delete_stack(stack_identifier)
|
|
except Exception:
|
|
pass
|
|
|
|
for stack_identifier in cls.stacks:
|
|
try:
|
|
cls.orchestration_client.wait_for_stack_status(
|
|
stack_identifier, 'DELETE_COMPLETE')
|
|
except Exception:
|
|
pass
|
|
|
|
def _create_keypair(self, namestart='keypair-heat-'):
|
|
kp_name = rand_name(namestart)
|
|
resp, body = self.keypairs_client.create_keypair(kp_name)
|
|
self.assertEqual(body['name'], kp_name)
|
|
return body
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
cls.clear_stacks()
|
|
|
|
def wait_for(self, condition):
|
|
"""Repeatedly calls condition() until a timeout."""
|
|
start_time = int(time.time())
|
|
while True:
|
|
try:
|
|
condition()
|
|
except Exception:
|
|
pass
|
|
else:
|
|
return
|
|
if int(time.time()) - start_time >= self.build_timeout:
|
|
condition()
|
|
return
|
|
time.sleep(self.build_interval)
|