Clean-up Tempest test networks with project_id
Recently, Tempest test cases were added to test the creation
of networks with project_id. These test cases call the Tempest
network client directly. As a consequence, the test networks
are not cleaned-up after test execution.
This patchset adds a utility method to handle the creation of
networks with project_id that sets them up for deletion at the
end of the test
Change-Id: Id0caec5529f1b37a2abe22488b2f64f75fb56736
diff --git a/neutron/tests/tempest/api/base.py b/neutron/tests/tempest/api/base.py
index ffb2dfb..39c714c 100644
--- a/neutron/tests/tempest/api/base.py
+++ b/neutron/tests/tempest/api/base.py
@@ -93,7 +93,7 @@
super(BaseNetworkTest, cls).resource_setup()
cls.networks = []
- cls.shared_networks = []
+ cls.admin_networks = []
cls.subnets = []
cls.ports = []
cls.routers = []
@@ -162,8 +162,8 @@
cls._try_delete_resource(cls.client.delete_network,
network['id'])
- # Clean up shared networks
- for network in cls.shared_networks:
+ # Clean up admin networks
+ for network in cls.admin_networks:
cls._try_delete_resource(cls.admin_client.delete_network,
network['id'])
@@ -222,7 +222,24 @@
post_body.update({'name': network_name, 'shared': True})
body = cls.admin_client.create_network(**post_body)
network = body['network']
- cls.shared_networks.append(network)
+ cls.admin_networks.append(network)
+ return network
+
+ @classmethod
+ def create_network_keystone_v3(cls, network_name=None, project_id=None,
+ tenant_id=None, client=None):
+ """Wrapper utility that creates a test network with project_id."""
+ client = client or cls.client
+ network_name = network_name or data_utils.rand_name(
+ 'test-network-with-project_id')
+ project_id = cls.client.tenant_id
+ body = client.create_network_keystone_v3(network_name, project_id,
+ tenant_id)
+ network = body['network']
+ if client is cls.client:
+ cls.networks.append(network)
+ else:
+ cls.admin_networks.append(network)
return network
@classmethod