From: Lubosz Kosnik Date: Wed, 21 Oct 2015 13:50:16 +0000 (+0200) Subject: Replace utils.exec for IpNeighComm LinuxBridge drv X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3aae4bd345a57a5692e1d5c9824988e666cb737c;p=openstack-build%2Fneutron-build.git Replace utils.exec for IpNeighComm LinuxBridge drv Replace all execution of "ip neigh" command using utils.exec for ip_lib.IpNeighCommand.(add,delete) in LinuxBridge driver Changed multiple which for one and fixed indentations Closes-Bug: #1311019 Change-Id: I1389941b7df11c089429f1de61eac6d7ea5d0e54 --- diff --git a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py index 89f819be2..1e3354a67 100644 --- a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -668,16 +668,10 @@ class LinuxBridgeManager(object): return (agent_ip in entries and mac in entries) def add_fdb_ip_entry(self, mac, ip, interface): - utils.execute(['ip', 'neigh', 'replace', ip, 'lladdr', mac, - 'dev', interface, 'nud', 'permanent'], - run_as_root=True, - check_exit_code=False) + ip_lib.IPDevice(interface).neigh.add(ip, mac) def remove_fdb_ip_entry(self, mac, ip, interface): - utils.execute(['ip', 'neigh', 'del', ip, 'lladdr', mac, - 'dev', interface], - run_as_root=True, - check_exit_code=False) + ip_lib.IPDevice(interface).neigh.delete(ip, mac) def add_fdb_bridge_entry(self, mac, agent_ip, interface, operation="add"): utils.execute(['bridge', 'fdb', operation, mac, 'dev', interface, diff --git a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py index d5eea954e..6e6092464 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py @@ -1145,7 +1145,9 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): 'segment_id': 1}} with mock.patch.object(utils, 'execute', - return_value='') as execute_fn: + return_value='') as execute_fn, \ + mock.patch.object(ip_lib.IpNeighCommand, 'add', + return_value='') as add_fn: self.lb_rpc.fdb_add(None, fdb_entries) expected = [ @@ -1156,16 +1158,13 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): 'dev', 'vxlan-1', 'dst', 'agent_ip'], run_as_root=True, check_exit_code=False), - mock.call(['ip', 'neigh', 'replace', 'port_ip', 'lladdr', - 'port_mac', 'dev', 'vxlan-1', 'nud', 'permanent'], - run_as_root=True, - check_exit_code=False), mock.call(['bridge', 'fdb', 'replace', 'port_mac', 'dev', 'vxlan-1', 'dst', 'agent_ip'], run_as_root=True, check_exit_code=False), ] execute_fn.assert_has_calls(expected) + add_fn.assert_called_with('port_ip', 'port_mac') def test_fdb_ignore(self): fdb_entries = {'net_id': @@ -1205,7 +1204,9 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): 'segment_id': 1}} with mock.patch.object(utils, 'execute', - return_value='') as execute_fn: + return_value='') as execute_fn, \ + mock.patch.object(ip_lib.IpNeighCommand, 'delete', + return_value='') as del_fn: self.lb_rpc.fdb_remove(None, fdb_entries) expected = [ @@ -1214,16 +1215,13 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): 'dev', 'vxlan-1', 'dst', 'agent_ip'], run_as_root=True, check_exit_code=False), - mock.call(['ip', 'neigh', 'del', 'port_ip', 'lladdr', - 'port_mac', 'dev', 'vxlan-1'], - run_as_root=True, - check_exit_code=False), mock.call(['bridge', 'fdb', 'del', 'port_mac', 'dev', 'vxlan-1', 'dst', 'agent_ip'], run_as_root=True, check_exit_code=False), ] execute_fn.assert_has_calls(expected) + del_fn.assert_called_with('port_ip', 'port_mac') def test_fdb_update_chg_ip(self): fdb_entries = {'chg_ip': @@ -1232,21 +1230,14 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): {'before': [['port_mac', 'port_ip_1']], 'after': [['port_mac', 'port_ip_2']]}}}} - with mock.patch.object(utils, 'execute', - return_value='') as execute_fn: + with mock.patch.object(ip_lib.IpNeighCommand, 'add', + return_value='') as add_fn, \ + mock.patch.object(ip_lib.IpNeighCommand, 'delete', + return_value='') as del_fn: self.lb_rpc.fdb_update(None, fdb_entries) - expected = [ - mock.call(['ip', 'neigh', 'replace', 'port_ip_2', 'lladdr', - 'port_mac', 'dev', 'vxlan-1', 'nud', 'permanent'], - run_as_root=True, - check_exit_code=False), - mock.call(['ip', 'neigh', 'del', 'port_ip_1', 'lladdr', - 'port_mac', 'dev', 'vxlan-1'], - run_as_root=True, - check_exit_code=False) - ] - execute_fn.assert_has_calls(expected) + del_fn.assert_called_with('port_ip_1', 'port_mac') + add_fn.assert_called_with('port_ip_2', 'port_mac') def test_fdb_update_chg_ip_empty_lists(self): fdb_entries = {'chg_ip': {'net_id': {'agent_ip': {}}}}