Remove the reference to non existing exception by linuxbridgeplugin.

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
This commit is contained in:
Yong Sheng Gong 2012-05-30 13:59:52 +08:00
parent 5485491b9c
commit 37b1448ca6
2 changed files with 18 additions and 9 deletions

View 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)

View 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',