Add network api test cases

I have added below test cases in tempest for network api's testing:-
1. port create
2. port delete
3. port list
4. port show
5. port update
6. network update
7. subnet update

Change-Id: I2233c926e2ade5ea023d0d67a1525067ef67254a
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index 8785e31..d3fa763 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -54,9 +54,12 @@
         cls.client = os.network_client
         cls.networks = []
         cls.subnets = []
+        cls.ports = []
 
     @classmethod
     def tearDownClass(cls):
+        for port in cls.ports:
+            cls.client.delete_port(port['id'])
         for subnet in cls.subnets:
             cls.client.delete_subnet(subnet['id'])
         for network in cls.networks:
@@ -98,3 +101,11 @@
         subnet = body['subnet']
         cls.subnets.append(subnet)
         return subnet
+
+    @classmethod
+    def create_port(cls, network):
+        """Wrapper utility that returns a test port."""
+        resp, body = cls.client.create_port(network['id'])
+        port = body['port']
+        cls.ports.append(port)
+        return port
diff --git a/tempest/api/network/test_networks.py b/tempest/api/network/test_networks.py
index de4f746..00a8ef7 100644
--- a/tempest/api/network/test_networks.py
+++ b/tempest/api/network/test_networks.py
@@ -35,6 +35,13 @@
         create a subnet for a tenant
         list tenant's subnets
         show a tenant subnet details
+        port create
+        port delete
+        port list
+        port show
+        port update
+        network update
+        subnet update
 
     v2.0 of the Neutron API is assumed. It is also assumed that the following
     options are defined in the [network] section of etc/tempest.conf:
@@ -53,21 +60,28 @@
         cls.name = cls.network['name']
         cls.subnet = cls.create_subnet(cls.network)
         cls.cidr = cls.subnet['cidr']
+        cls.port = cls.create_port(cls.network)
 
     @attr(type='gate')
-    def test_create_delete_network_subnet(self):
+    def test_create_update_delete_network_subnet(self):
         # Creates a network
         name = rand_name('network-')
         resp, body = self.client.create_network(name)
         self.assertEqual('201', resp['status'])
         network = body['network']
-        self.assertTrue(network['id'] is not None)
+        net_id = network['id']
+        # Verification of network update
+        new_name = "New_network"
+        resp, body = self.client.update_network(net_id, new_name)
+        self.assertEqual('200', resp['status'])
+        updated_net = body['network']
+        self.assertEqual(updated_net['name'], new_name)
         # Find a cidr that is not in use yet and create a subnet with it
         cidr = netaddr.IPNetwork(self.network_cfg.tenant_network_cidr)
         mask_bits = self.network_cfg.tenant_network_mask_bits
         for subnet_cidr in cidr.subnet(mask_bits):
             try:
-                resp, body = self.client.create_subnet(network['id'],
+                resp, body = self.client.create_subnet(net_id,
                                                        str(subnet_cidr))
                 break
             except exceptions.BadRequest as e:
@@ -76,11 +90,17 @@
                     raise
         self.assertEqual('201', resp['status'])
         subnet = body['subnet']
-        self.assertTrue(subnet['id'] is not None)
+        subnet_id = subnet['id']
+        # Verification of subnet update
+        new_subnet = "New_subnet"
+        resp, body = self.client.update_subnet(subnet_id, new_subnet)
+        self.assertEqual('200', resp['status'])
+        updated_subnet = body['subnet']
+        self.assertEqual(updated_subnet['name'], new_subnet)
         # Deletes subnet and network
-        resp, body = self.client.delete_subnet(subnet['id'])
+        resp, body = self.client.delete_subnet(subnet_id)
         self.assertEqual('204', resp['status'])
-        resp, body = self.client.delete_network(network['id'])
+        resp, body = self.client.delete_network(net_id)
         self.assertEqual('204', resp['status'])
 
     @attr(type='gate')
@@ -97,8 +117,12 @@
         # Verify the network exists in the list of all networks
         resp, body = self.client.list_networks()
         networks = body['networks']
-        found = any(n for n in networks if n['id'] == self.network['id'])
-        self.assertTrue(found)
+        found = None
+        for n in networks:
+            if (n['id'] == self.network['id']):
+                found = n['id']
+        msg = "Network list doesn't contain created network"
+        self.assertIsNotNone(found, msg)
 
     @attr(type='gate')
     def test_show_subnet(self):
@@ -114,8 +138,48 @@
         # Verify the subnet exists in the list of all subnets
         resp, body = self.client.list_subnets()
         subnets = body['subnets']
-        found = any(n for n in subnets if n['id'] == self.subnet['id'])
-        self.assertTrue(found)
+        found = None
+        for n in subnets:
+            if (n['id'] == self.subnet['id']):
+                found = n['id']
+        msg = "Subnet list doesn't contain created subnet"
+        self.assertIsNotNone(found, msg)
+
+    @attr(type='gate')
+    def test_create_update_delete_port(self):
+        # Verify that successful port creation & deletion
+        resp, body = self.client.create_port(self.network['id'])
+        self.assertEqual('201', resp['status'])
+        port = body['port']
+        # Verification of port update
+        new_port = "New_Port"
+        resp, body = self.client.update_port(port['id'], new_port)
+        self.assertEqual('200', resp['status'])
+        updated_port = body['port']
+        self.assertEqual(updated_port['name'], new_port)
+        # Verification of port delete
+        resp, body = self.client.delete_port(port['id'])
+        self.assertEqual('204', resp['status'])
+
+    @attr(type='gate')
+    def test_show_ports(self):
+        # Verify the details of port
+        resp, body = self.client.show_port(self.port['id'])
+        self.assertEqual('200', resp['status'])
+        port = body['port']
+        self.assertEqual(self.port['id'], port['id'])
+
+    @attr(type='gate')
+    def test_list_ports(self):
+        # Verify the port exists in the list of all ports
+        resp, body = self.client.list_ports()
+        self.assertEqual('200', resp['status'])
+        ports_list = body['ports']
+        found = None
+        for n in ports_list:
+            if (n['id'] == self.port['id']):
+                found = n['id']
+        self.assertIsNotNone(found, "Port list doesn't contain created port")
 
     @attr(type=['negative', 'gate'])
     def test_show_non_existent_network(self):
diff --git a/tempest/services/network/json/network_client.py b/tempest/services/network/json/network_client.py
index f96ed91..2c808a9 100644
--- a/tempest/services/network/json/network_client.py
+++ b/tempest/services/network/json/network_client.py
@@ -151,3 +151,39 @@
         resp, body = self.get(uri, self.headers)
         body = json.loads(body)
         return resp, body['quotas']
+
+    def update_subnet(self, subnet_id, new_name):
+        put_body = {
+            'subnet': {
+                'name': new_name,
+            }
+        }
+        body = json.dumps(put_body)
+        uri = '%s/subnets/%s' % (self.uri_prefix, subnet_id)
+        resp, body = self.put(uri, body=body, headers=self.headers)
+        body = json.loads(body)
+        return resp, body
+
+    def update_port(self, port_id, new_name):
+        put_body = {
+            'port': {
+                'name': new_name,
+            }
+        }
+        body = json.dumps(put_body)
+        uri = '%s/ports/%s' % (self.uri_prefix, port_id)
+        resp, body = self.put(uri, body=body, headers=self.headers)
+        body = json.loads(body)
+        return resp, body
+
+    def update_network(self, network_id, new_name):
+        put_body = {
+            "network": {
+                "name": new_name,
+            }
+        }
+        body = json.dumps(put_body)
+        uri = '%s/networks/%s' % (self.uri_prefix, network_id)
+        resp, body = self.put(uri, body=body, headers=self.headers)
+        body = json.loads(body)
+        return resp, body