Move create_keypair to api.base module and add creation params.
For coherence with other resources move create_keypair to base class
an add more creation parameters.
This also fix deletion of keypairs when are created with other
clients than default one.
Change-Id: Iff0b7ffdb17235a75c37a3890db1445b95547554
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):