]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove the reference to non existing exception by linuxbridgeplugin.
authorYong Sheng Gong <gongysh@cn.ibm.com>
Wed, 30 May 2012 05:59:52 +0000 (13:59 +0800)
committerYong Sheng Gong <gongysh@cn.ibm.com>
Wed, 30 May 2012 23:51:25 +0000 (07:51 +0800)
Bug #1006221

According to plugin api of QuantumPluginBase, unplug_interface
should only raise exception.NetworkNotFound and exception.PortNotFound.
To unplug a non-attached port should not raise Exception.
After this modification, to unplug an non-attached port will have no impact.
In addition, I remove the 'network = db.network_get(net_id)' since
 'db.validate_port_ownership(tenant_id, net_id, port_id)' statement has taken
care of the check.

patch 2: split test case to test it exclusively compared to patch 1.
patch 3: remove added test statement in previous test case

Change-Id: I437c3f13fa7a81aeabcdfca7ba03e94a0a7aa32b

quantum/plugins/linuxbridge/LinuxBridgePlugin.py
quantum/plugins/linuxbridge/tests/unit/_test_linuxbridgeAgent.py

index 95f63810e87f88d9e622680a4c2bd6a2a2a6d924..dbe5d3ab62c95a85254b750f82acc77bc4512e94 100644 (file)
@@ -167,7 +167,6 @@ class LinuxBridgePlugin(QuantumPluginBase):
         """
         LOG.debug("LinuxBridgePlugin.get_all_ports() called")
         db.validate_network_ownership(tenant_id, net_id)
-        network = db.network_get(net_id)
         ports_list = db.port_list(net_id)
         ports_on_net = []
         for port in ports_list:
@@ -184,7 +183,6 @@ class LinuxBridgePlugin(QuantumPluginBase):
         """
         LOG.debug("LinuxBridgePlugin.get_port_details() called")
         db.validate_port_ownership(tenant_id, net_id, port_id)
-        network = db.network_get(net_id)
         port = db.port_get(port_id, net_id)
         new_port_dict = cutil.make_port_dict(port)
         return new_port_dict
@@ -197,7 +195,6 @@ class LinuxBridgePlugin(QuantumPluginBase):
         db.validate_network_ownership(tenant_id, net_id)
         port = db.port_create(net_id, port_state,
                               op_status=OperationalStatus.DOWN)
-        unique_port_id_string = port[const.UUID]
         new_port_dict = cutil.make_port_dict(port)
         return new_port_dict
 
@@ -207,7 +204,6 @@ class LinuxBridgePlugin(QuantumPluginBase):
         """
         LOG.debug("LinuxBridgePlugin.update_port() called")
         db.validate_port_ownership(tenant_id, net_id, port_id)
-        network = db.network_get(net_id)
         self._validate_port_state(kwargs["state"])
         port = db.port_update(port_id, net_id, **kwargs)
 
@@ -223,7 +219,6 @@ class LinuxBridgePlugin(QuantumPluginBase):
         """
         LOG.debug("LinuxBridgePlugin.delete_port() called")
         db.validate_port_ownership(tenant_id, net_id, port_id)
-        network = db.network_get(net_id)
         port = db.port_get(port_id, net_id)
         attachment_id = port[const.INTERFACEID]
         if not attachment_id:
@@ -241,7 +236,6 @@ class LinuxBridgePlugin(QuantumPluginBase):
         """
         LOG.debug("LinuxBridgePlugin.plug_interface() called")
         db.validate_port_ownership(tenant_id, net_id, port_id)
-        network = db.network_get(net_id)
         port = db.port_get(port_id, net_id)
         attachment_id = port[const.INTERFACEID]
         if attachment_id:
@@ -256,11 +250,9 @@ class LinuxBridgePlugin(QuantumPluginBase):
         """
         LOG.debug("LinuxBridgePlugin.unplug_interface() called")
         db.validate_port_ownership(tenant_id, net_id, port_id)
-        network = db.network_get(net_id)
         port = db.port_get(port_id, net_id)
         attachment_id = port[const.INTERFACEID]
         if attachment_id == None:
-            raise exc.InvalidDetach(port_id=port_id, net_id=net_id,
-                                    att_id=remote_interface_id)
+            return
         db.port_unset_attachment(port_id, net_id)
         db.port_update(port_id, net_id, op_status=OperationalStatus.DOWN)
index 63acd55a0d6146240a4609e176a2c1592d59c72e..dd45af1c38d2deeef4068163d6fa8fb9a9b11a62 100644 (file)
@@ -300,6 +300,23 @@ class LinuxBridgeAgentTest(unittest.TestCase):
 
         LOG.debug("test_test_process_unplugged_tap_interface -END")
 
+    def test_process_unplugged_interface_empty(
+        self, tenant_id="test_tenant", network_name="test_network"):
+        """ test to unplug not plugged port. It should not raise exception
+        """
+        LOG.debug("test_process_unplugged_interface_empty - START")
+        new_network = (
+            self._linuxbridge_plugin.create_network(tenant_id, network_name))
+        new_port = self._linuxbridge_plugin.create_port(
+            tenant_id, new_network[lconst.NET_ID], lconst.PORT_UP)
+        self._linuxbridge_plugin.unplug_interface(tenant_id,
+                                                  new_network[lconst.NET_ID],
+                                                  new_port[lconst.PORT_ID])
+        self.tearDownNetworkPort(tenant_id, new_network[lconst.NET_ID],
+                                 new_port[lconst.PORT_ID])
+
+        LOG.debug("test_process_unplugged_interface_empty -END")
+
     def test_process_unplugged_gw_interface(
         self, tenant_id="test_tenant", network_name="test_network",
         interface_id='fe701ddf-26a2-42ea-b9e6-7313d1c522cc',