Testcase to create bulk networks in one API call

Added "test_bulk_create_delete_network" test case in the
test_networks.py script of "api/networks" tests.
Also added supporting method "create_bulk_network" to
network_client.py.

Change-Id: I8325caf5405714686fa2e78c7c1589854e271860
Implements: blueprint quantum-test-extended-coverage
diff --git a/tempest/api/network/test_networks.py b/tempest/api/network/test_networks.py
index 00a8ef7..7dcbbd8 100644
--- a/tempest/api/network/test_networks.py
+++ b/tempest/api/network/test_networks.py
@@ -62,6 +62,18 @@
         cls.cidr = cls.subnet['cidr']
         cls.port = cls.create_port(cls.network)
 
+    def _delete_networks(self, created_networks):
+        for n in created_networks:
+            resp, body = self.client.delete_network(n['id'])
+            self.assertEqual(204, resp.status)
+        # Asserting that the networks are not found in the list after deletion
+        resp, body = self.client.list_networks()
+        networks_list = list()
+        for network in body['networks']:
+            networks_list.append(network['id'])
+        for n in created_networks:
+            self.assertNotIn(n['id'], networks_list)
+
     @attr(type='gate')
     def test_create_update_delete_network_subnet(self):
         # Creates a network
@@ -192,3 +204,20 @@
         non_exist_id = rand_name('subnet')
         self.assertRaises(exceptions.NotFound, self.client.show_subnet,
                           non_exist_id)
+
+    @attr(type='gate')
+    def test_bulk_create_delete_network(self):
+        # Creates 2 networks in one request
+        network_names = [rand_name('network-'), rand_name('network-')]
+        resp, body = self.client.create_bulk_network(2, network_names)
+        created_networks = body['networks']
+        self.assertEqual('201', resp['status'])
+        self.addCleanup(self._delete_networks, created_networks)
+        # Asserting that the networks are found in the list after creation
+        resp, body = self.client.list_networks()
+        networks_list = list()
+        for network in body['networks']:
+            networks_list.append(network['id'])
+        for n in created_networks:
+            self.assertIsNotNone(n['id'])
+            self.assertIn(n['id'], networks_list)
diff --git a/tempest/services/network/json/network_client.py b/tempest/services/network/json/network_client.py
index 2c808a9..cf2afb2 100644
--- a/tempest/services/network/json/network_client.py
+++ b/tempest/services/network/json/network_client.py
@@ -55,6 +55,17 @@
         body = json.loads(body)
         return resp, body
 
+    def create_bulk_network(self, count, names):
+        network_list = list()
+        for i in range(count):
+            network_list.append({'name': names[i]})
+        post_body = {'networks': network_list}
+        body = json.dumps(post_body)
+        uri = '%s/networks' % (self.uri_prefix)
+        resp, body = self.post(uri, headers=self.headers, body=body)
+        body = json.loads(body)
+        return resp, body
+
     def show_network(self, uuid):
         uri = '%s/networks/%s' % (self.uri_prefix, uuid)
         resp, body = self.get(uri, self.headers)