Merge "Move create_keypair to api.base module and add creation params."
diff --git a/neutron_tempest_plugin/api/base.py b/neutron_tempest_plugin/api/base.py
index 6246eb7..2f5446c 100644
--- a/neutron_tempest_plugin/api/base.py
+++ b/neutron_tempest_plugin/api/base.py
@@ -124,6 +124,7 @@
cls.projects = []
cls.log_objects = []
cls.reserved_subnet_cidrs = set()
+ cls.keypairs = []
@classmethod
def resource_cleanup(cls):
@@ -221,6 +222,9 @@
cls._try_delete_resource(cls.admin_client.delete_log,
log_object['id'])
+ for keypair in cls.keypairs:
+ cls._try_delete_resource(cls.delete_keypair, keypair)
+
super(BaseNetworkTest, cls).resource_cleanup()
@classmethod
@@ -593,6 +597,23 @@
cls.security_groups.append(body['security_group'])
return body['security_group']
+ @classmethod
+ def create_keypair(cls, client=None, name=None, **kwargs):
+ client = client or cls.os_primary.keypairs_client
+ name = name or data_utils.rand_name('keypair-test')
+ keypair = client.create_keypair(name=name, **kwargs)['keypair']
+
+ # save client for later cleanup
+ keypair['client'] = client
+ cls.keypairs.append(keypair)
+ return keypair
+
+ @classmethod
+ def delete_keypair(cls, keypair, client=None):
+ client = (client or keypair.get('client') or
+ cls.os_primary.keypairs_client)
+ client.delete_keypair(keypair_name=keypair['name'])
+
class BaseAdminNetworkTest(BaseNetworkTest):
diff --git a/neutron_tempest_plugin/scenario/base.py b/neutron_tempest_plugin/scenario/base.py
index b76a81a..45914c5 100644
--- a/neutron_tempest_plugin/scenario/base.py
+++ b/neutron_tempest_plugin/scenario/base.py
@@ -33,20 +33,6 @@
class BaseTempestTestCase(base_api.BaseNetworkTest):
- @classmethod
- def resource_setup(cls):
- super(BaseTempestTestCase, cls).resource_setup()
-
- cls.keypairs = []
-
- @classmethod
- def resource_cleanup(cls):
- for keypair in cls.keypairs:
- client = keypair['client']
- client.delete_keypair(
- keypair_name=keypair['keypair']['name'])
-
- super(BaseTempestTestCase, cls).resource_cleanup()
def create_server(self, flavor_ref, image_ref, key_name, networks,
**kwargs):
@@ -105,17 +91,6 @@
return server
@classmethod
- def create_keypair(cls, client=None):
- client = client or cls.os_primary.keypairs_client
- name = data_utils.rand_name('keypair-test')
- body = client.create_keypair(name=name)
- body.update(client=client)
- if client is cls.os_primary.keypairs_client:
- cls.keypairs.append(body)
-
- return body['keypair']
-
- @classmethod
def create_secgroup_rules(cls, rule_list, secgroup_id=None,
client=None):
client = client or cls.os_primary.network_client