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/admin/test_networks.py b/neutron/tests/tempest/api/admin/test_networks.py
index f363e09..1068c0b 100644
--- a/neutron/tests/tempest/api/admin/test_networks.py
+++ b/neutron/tests/tempest/api/admin/test_networks.py
@@ -25,8 +25,8 @@
         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 @@
         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 @@
 
         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'])
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
diff --git a/neutron/tests/tempest/api/test_networks.py b/neutron/tests/tempest/api/test_networks.py
index 439d7a9..279964a 100644
--- a/neutron/tests/tempest/api/test_networks.py
+++ b/neutron/tests/tempest/api/test_networks.py
@@ -106,8 +106,7 @@
         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'])