]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Replace utils.exec for IpNeighComm LinuxBridge drv
authorLubosz Kosnik <lubosz.kosnik@intel.com>
Wed, 21 Oct 2015 13:50:16 +0000 (15:50 +0200)
committerLubosz Kosnik <lubosz.kosnik@intel.com>
Mon, 26 Oct 2015 14:41:06 +0000 (15:41 +0100)
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

neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py
neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py

index 89f819be2af3cc8aa6d2ea96810092eca020f3c7..1e3354a672815c06b7514e274aba6c15b9e16c9d 100644 (file)
@@ -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,
index d5eea954ee00ed1437ce037606dea084aa4973ac..6e6092464f93d473dc95770488af7f120248fef5 100644 (file)
@@ -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': {}}}}