]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Partial commit
authorSalvatore Orlando <salvatore.orlando@eu.citrix.com>
Mon, 15 Aug 2011 23:23:46 +0000 (00:23 +0100)
committerSalvatore Orlando <salvatore.orlando@eu.citrix.com>
Mon, 15 Aug 2011 23:23:46 +0000 (00:23 +0100)
quantum/cli.py
quantum/cli_output.template
tests/unit/test_cli.py

index df4b71cd29a9d104eb5349e0b27a3a8134aa6619..fa326d9d4211e2dbcd18454c9799620d3d4c4b6c 100644 (file)
@@ -116,33 +116,35 @@ def api_delete_net(client, *args):
 def detail_net(manager, *args):
     tid, nid = args
     iface_list = manager.get_network_details(tid, nid)
+    output = prepare_output("detail_net", tenant_id,
+                            dict(network=iface_list))
+    #TODO(salvatore-orlando): delete here
     print "Remote Interfaces on Virtual Network:%s\n" % nid
     for iface in iface_list:
         print "\tRemote interface:%s" % iface
 
 
 def api_detail_net(client, *args):
-    tid, nid = args
+    tenant_id, network_id = args
     try:
-        res = client.list_network_details(nid)["networks"]["network"]
+        res = client.list_network_details(network_id)["networks"]["network"]
     except Exception, e:
         LOG.error("Failed to get network details: %s" % e)
         return
-
     try:
-        ports = client.list_ports(nid)
+        ports = client.list_ports(network_id)
     except Exception, e:
         LOG.error("Failed to list ports: %s" % e)
         return
 
-    print "Network %s (%s)" % (res['name'], res['id'])
-    print "Remote Interfaces on Virtual Network:%s\n" % nid
+    res['ports'] = ports
     for port in ports["ports"]:
-        pid = port["id"]
-        res = client.list_port_attachments(nid, pid)
-        LOG.debug(res)
-        remote_iface = res["attachment"]
-        print "\tRemote interface:%s" % remote_iface
+        att_data = client.list_port_attachments(network_id, port['id'])
+        port['attachment'] = att_data["attachment"]
+
+    output = prepare_output("detail_net", tenant_id,
+                            dict(network=res))
+    print output
 
 
 def rename_net(manager, *args):
index 2bbeb8721ff58c5f955244ad863ec3904002d86d..0c9084010d4a4a8ee29c070af5cb6b78afb2b1fb 100644 (file)
@@ -8,5 +8,11 @@ Virtual Networks on Tenant $tenant_id
 Created a new Virtual Network with ID: $network_id for Tenant $tenant_id
 #elif $cmd == 'delete_net'
 Deleted Virtual Network with ID: $network_id for Tenant $tenant_id
+#elif $cmd == 'detail_net'
+Network $network.name ($network.id)
+Remote Interfaces on Virtual Network
+#for $port in $network.port
+Port $port.id: $port.attachment
+#end for
 #end if
 
index 5b26debe59d3c1548bcbc82692a0baf68889a618..47b7d97a03b12f432b3ed30bd0f83c6c0dc88a3a 100644 (file)
@@ -84,6 +84,18 @@ class CLITest(unittest.TestCase):
             # Verify!
             # Must add newline at the end to match effect of print call
             self.assertEquals(self.fake_stdout.make_string(), output + '\n')
+
+    def _verify_delete_network(self, network_id):
+            # Verification - get raw result from db
+            nw_list = db.network_list(self.tenant_id)
+            if len(nw_list) != 0:
+                self.fail("DB should not contain any network")
+            # Fill CLI template
+            output = cli.prepare_output('delete_net', self.tenant_id,
+                                        dict(network_id=network_id))
+            # Verify!
+            # Must add newline at the end to match effect of print call
+            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
         
     def test_list_networks(self):
         try: 
@@ -123,7 +135,6 @@ class CLITest(unittest.TestCase):
         except: 
             LOG.exception("Exception caught: %s", sys.exc_info())
             self.fail("test_create_network failed due to an exception")
-
     
     def test_create_network_api(self):
         try: 
@@ -134,3 +145,40 @@ class CLITest(unittest.TestCase):
         except: 
             LOG.exception("Exception caught: %s", sys.exc_info())
             self.fail("test_create_network_api failed due to an exception")
+    
+    def _prepare_test_delete_network(self):
+        # Pre-populate data for testing using db api
+        db.network_create(self.tenant_id, self.network_name_1)
+        net_id = db.network_list(self.tenant_id)[0]['uuid']
+        return net_id
+
+    def test_delete_network(self):
+        try: 
+            network_id = self._prepare_test_delete_network()
+            cli.delete_net(self.manager, self.tenant_id, network_id)
+            LOG.debug("Operation completed. Verifying result")
+            LOG.debug(self.fake_stdout.content)
+            self._verify_delete_network(network_id)
+        except: 
+            LOG.exception("Exception caught: %s", sys.exc_info())
+            self.fail("test_delete_network failed due to an exception")
+
+    
+    def test_delete_network_api(self):
+        try: 
+            network_id = self._prepare_test_delete_network()
+            cli.api_delete_net(self.client, self.tenant_id, network_id)
+            LOG.debug("Operation completed. Verifying result")
+            LOG.debug(self.fake_stdout.content)
+            self._verify_delete_network(network_id)  
+        except: 
+            LOG.exception("Exception caught: %s", sys.exc_info())
+            self.fail("test_delete_network_api failed due to an exception")
+            
+    def test_detail_network_api(self):
+            # Load some data into the datbase
+            net = db.network_create(self.tenant_id, self.network_name_1)
+            db.port_create(net['uuid'])       
+            port = db.port_create(net['uuid'])
+            cli.api_detail_net(self.client, self.tenant_id, net['uuid'])
+            db.port_set_attachment(port['uuid'], net['uuid'], "test_iface_id")
\ No newline at end of file