Create stack in class setup, rather than instance.
The intent of creating the instance in a setup method
was so that the test methods could share a single instance to perform
their tests.
However, doing it in setUp() resulted in an instance per test method,
which is the opposite of the original intent.
Moving instance creation to the class setup means only one instance is
created.
Change-Id: Ie54573e7371e53a60350a3693a740ac56925b520
diff --git a/tempest/api/orchestration/base.py b/tempest/api/orchestration/base.py
index 0e50ac3..6d6000a 100644
--- a/tempest/api/orchestration/base.py
+++ b/tempest/api/orchestration/base.py
@@ -62,15 +62,15 @@
cls.config.identity.uri
)
- def create_stack(self, stack_name, template_data, parameters={}):
- resp, body = self.client.create_stack(
+ @classmethod
+ def create_stack(cls, stack_name, template_data, parameters={}):
+ resp, body = cls.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)
+ cls.stacks.append(stack_identifier)
return stack_identifier
@classmethod
@@ -88,11 +88,11 @@
except Exception:
pass
- def _create_keypair(self, namestart='keypair-heat-'):
+ @classmethod
+ def _create_keypair(cls, namestart='keypair-heat-'):
kp_name = rand_name(namestart)
- resp, body = self.keypairs_client.create_keypair(kp_name)
- self.assertEqual(body['name'], kp_name)
- self.keypairs.append(kp_name)
+ resp, body = cls.keypairs_client.create_keypair(kp_name)
+ cls.keypairs.append(kp_name)
return body
@classmethod
diff --git a/tempest/api/orchestration/stacks/test_instance_cfn_init.py b/tempest/api/orchestration/stacks/test_instance_cfn_init.py
index e3b8162..add8588 100644
--- a/tempest/api/orchestration/stacks/test_instance_cfn_init.py
+++ b/tempest/api/orchestration/stacks/test_instance_cfn_init.py
@@ -119,23 +119,21 @@
raise cls.skipException("No image available to test")
cls.client = cls.orchestration_client
- def setUp(self):
- super(InstanceCfnInitTestJSON, self).setUp()
stack_name = rand_name('heat')
- if self.orchestration_cfg.keypair_name:
- keypair_name = self.orchestration_cfg.keypair_name
+ if cls.orchestration_cfg.keypair_name:
+ keypair_name = cls.orchestration_cfg.keypair_name
else:
- self.keypair = self._create_keypair()
- keypair_name = self.keypair['name']
+ cls.keypair = cls._create_keypair()
+ keypair_name = cls.keypair['name']
# create the stack
- self.stack_identifier = self.create_stack(
+ cls.stack_identifier = cls.create_stack(
stack_name,
- self.template,
+ cls.template,
parameters={
'KeyName': keypair_name,
- 'InstanceType': self.orchestration_cfg.instance_type,
- 'ImageId': self.orchestration_cfg.image_ref
+ 'InstanceType': cls.orchestration_cfg.instance_type,
+ 'ImageId': cls.orchestration_cfg.image_ref
})
@attr(type='gate')