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
(cherry picked from commit 66df33613a)
This commit is contained in:
Miguel Lavalle 2016-09-21 16:41:47 -05:00 committed by Ihar Hrachyshka
parent f350bc2f1b
commit e85f0abb3d
3 changed files with 29 additions and 13 deletions

View File

@ -25,8 +25,8 @@ class NetworksTestAdmin(base.BaseAdminNetworkTest):
project_id = self.client.tenant_id # non-admin
name = 'admin-created-with-project_id'
body = self.admin_client.create_network_keystone_v3(name, project_id)
new_net = body['network']
new_net = self.create_network_keystone_v3(name, project_id,
client=self.admin_client)
self.assertEqual(name, new_net['name'])
self.assertEqual(project_id, new_net['project_id'])
self.assertEqual(project_id, new_net['tenant_id'])
@ -43,9 +43,8 @@ class NetworksTestAdmin(base.BaseAdminNetworkTest):
project_id = self.client.tenant_id # non-admin
name = 'created-with-project-and-tenant'
body = self.admin_client.create_network_keystone_v3(
name, project_id, tenant_id=project_id)
new_net = body['network']
new_net = self.create_network_keystone_v3(
name, project_id, tenant_id=project_id, client=self.admin_client)
self.assertEqual(name, new_net['name'])
self.assertEqual(project_id, new_net['project_id'])
self.assertEqual(project_id, new_net['tenant_id'])
@ -64,7 +63,8 @@ class NetworksTestAdmin(base.BaseAdminNetworkTest):
name = 'created-with-project-and-other-tenant'
e = self.assertRaises(lib_exc.BadRequest,
self.admin_client.create_network_keystone_v3,
name, project_id, tenant_id=other_tenant)
self.create_network_keystone_v3, name,
project_id, tenant_id=other_tenant,
client=self.admin_client)
expected_message = "'project_id' and 'tenant_id' do not match"
self.assertEqual(expected_message, e.resp_body['message'])

View File

@ -93,7 +93,7 @@ class BaseNetworkTest(test.BaseTestCase):
super(BaseNetworkTest, cls).resource_setup()
cls.networks = []
cls.shared_networks = []
cls.admin_networks = []
cls.subnets = []
cls.ports = []
cls.routers = []
@ -162,8 +162,8 @@ class BaseNetworkTest(test.BaseTestCase):
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 @@ class BaseNetworkTest(test.BaseTestCase):
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

View File

@ -106,8 +106,7 @@ class NetworksTestJSON(base.BaseNetworkTest):
project_id = self.client.tenant_id
name = 'created-with-project_id'
body = self.client.create_network_keystone_v3(name, project_id)
new_net = body['network']
new_net = self.create_network_keystone_v3(name, project_id)
self.assertEqual(name, new_net['name'])
self.assertEqual(project_id, new_net['project_id'])
self.assertEqual(project_id, new_net['tenant_id'])