]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove root_helper arg for ovs_lib
authorTerry Wilson <twilson@redhat.com>
Mon, 9 Feb 2015 04:43:31 +0000 (22:43 -0600)
committerTerry Wilson <twilson@redhat.com>
Thu, 12 Feb 2015 21:33:31 +0000 (15:33 -0600)
Stop passing root_helper in ovs_lib classes and instead rely on
execute() looking up the root_helper from the config.

Partially-Implements: blueprint rootwrap-daemon-mode
Change-Id: I24c29a1964582dabaa04358e05be903c8cb49229

22 files changed:
neutron/agent/linux/interface.py
neutron/agent/linux/ovs_lib.py
neutron/agent/ovsdb/impl_vsctl.py
neutron/cmd/netns_cleanup.py
neutron/cmd/ovs_cleanup.py
neutron/cmd/sanity/checks.py
neutron/plugins/bigswitch/agent/restproxy_agent.py
neutron/plugins/ibm/agent/sdnve_neutron_agent.py
neutron/plugins/nec/agent/nec_neutron_agent.py
neutron/plugins/ofagent/agent/ofa_neutron_agent.py
neutron/plugins/oneconvergence/agent/nvsd_neutron_agent.py
neutron/plugins/openvswitch/agent/ovs_neutron_agent.py
neutron/tests/functional/agent/linux/base.py
neutron/tests/functional/agent/test_l3_agent.py
neutron/tests/functional/agent/test_ovs_lib.py
neutron/tests/unit/agent/linux/test_ovs_lib.py
neutron/tests/unit/ofagent/test_ofa_neutron_agent.py
neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py
neutron/tests/unit/openvswitch/test_ovs_tunnel.py
neutron/tests/unit/test_linux_interface.py
neutron/tests/unit/test_netns_cleanup.py
neutron/tests/unit/test_ovs_cleanup.py

index bd1714fcc89829c1f788b132f2bc7dc1124106b2..13e429fc3dfdd63bcef96aaca35771518581ebdc 100644 (file)
@@ -219,7 +219,7 @@ class OVSInterfaceDriver(LinuxInterfaceDriver):
         if internal:
             attrs.insert(0, ('type', 'internal'))
 
-        ovs = ovs_lib.OVSBridge(bridge, self.root_helper)
+        ovs = ovs_lib.OVSBridge(bridge)
         ovs.replace_port(device_name, *attrs)
 
     def plug(self, network_id, port_id, device_name, mac_address,
@@ -274,7 +274,7 @@ class OVSInterfaceDriver(LinuxInterfaceDriver):
 
         tap_name = self._get_tap_name(device_name, prefix)
         self.check_bridge_exists(bridge)
-        ovs = ovs_lib.OVSBridge(bridge, self.root_helper)
+        ovs = ovs_lib.OVSBridge(bridge)
 
         try:
             ovs.delete_port(tap_name)
index 1c05c2220e6128d157376aaa7c4e4c8b426a49e6..5eb3d025250735267de4d3512ecea617131240c4 100644 (file)
@@ -96,14 +96,13 @@ class VifPort(object):
 
 class BaseOVS(object):
 
-    def __init__(self, root_helper):
-        self.root_helper = root_helper
+    def __init__(self):
         self.vsctl_timeout = cfg.CONF.ovs_vsctl_timeout
         self.ovsdb = ovsdb.API.get(self)
 
     def add_bridge(self, bridge_name):
         self.ovsdb.add_br(bridge_name).execute()
-        return OVSBridge(bridge_name, self.root_helper)
+        return OVSBridge(bridge_name)
 
     def delete_bridge(self, bridge_name):
         self.ovsdb.del_br(bridge_name).execute()
@@ -138,8 +137,8 @@ class BaseOVS(object):
 
 
 class OVSBridge(BaseOVS):
-    def __init__(self, br_name, root_helper):
-        super(OVSBridge, self).__init__(root_helper)
+    def __init__(self, br_name):
+        super(OVSBridge, self).__init__()
         self.br_name = br_name
 
     def set_controller(self, controllers):
@@ -199,7 +198,7 @@ class OVSBridge(BaseOVS):
     def run_ofctl(self, cmd, args, process_input=None):
         full_args = ["ovs-ofctl", cmd, self.br_name] + args
         try:
-            return utils.execute(full_args, root_helper=self.root_helper,
+            return utils.execute(full_args, run_as_root=True,
                                  process_input=process_input)
         except Exception as e:
             LOG.error(_LE("Unable to execute %(cmd)s. Exception: "
@@ -294,7 +293,7 @@ class OVSBridge(BaseOVS):
         args = ["xe", "vif-param-get", "param-name=other-config",
                 "param-key=nicira-iface-id", "uuid=%s" % xs_vif_uuid]
         try:
-            return utils.execute(args, root_helper=self.root_helper).strip()
+            return utils.execute(args, run_as_root=True).strip()
         except Exception as e:
             with excutils.save_and_reraise_exception():
                 LOG.error(_LE("Unable to execute %(cmd)s. "
@@ -398,7 +397,7 @@ class OVSBridge(BaseOVS):
 
     def get_local_port_mac(self):
         """Retrieve the mac of the bridge's local port."""
-        address = ip_lib.IPDevice(self.br_name, self.root_helper).link.address
+        address = ip_lib.IPDevice(self.br_name).link.address
         if address:
             return address
         else:
index f6d7ea12a68c43fc52b38795db46b9bf201b1602..3ffca811c96eeb5a6b54e91fdcd5dbcf4136e994 100644 (file)
@@ -59,8 +59,7 @@ class Transaction(ovsdb.Transaction):
         full_args = ["ovs-vsctl"] + self.opts + args
         try:
             # We log our own errors, so never have utils.execute do it
-            return utils.execute(full_args,
-                                 root_helper=self.context.root_helper,
+            return utils.execute(full_args, run_as_root=True,
                                  log_fail_as_error=False).rstrip()
         except Exception:
             with excutils.save_and_reraise_exception() as ctxt:
index d0a6bcf97a124701bcbdc6c7ba755c2fd765d2cb..8dcf2978f373a44b7f6679ba13acb523dbcf5f2c 100644 (file)
@@ -117,12 +117,11 @@ def unplug_device(conf, device):
     try:
         device.link.delete()
     except RuntimeError:
-        root_helper = agent_config.get_root_helper(conf)
         # Maybe the device is OVS port, so try to delete
-        ovs = ovs_lib.BaseOVS(root_helper)
+        ovs = ovs_lib.BaseOVS()
         bridge_name = ovs.get_bridge_for_iface(device.name)
         if bridge_name:
-            bridge = ovs_lib.OVSBridge(bridge_name, root_helper)
+            bridge = ovs_lib.OVSBridge(bridge_name)
             bridge.delete_port(device.name)
         else:
             LOG.debug('Unable to find bridge for device: %s', device.name)
index 8ba33abd4575c87b4830282d82ccf7e2e252ba0a..a5010466a820752c5056e6451406e14556bea2d2 100644 (file)
@@ -49,27 +49,26 @@ def setup_conf():
     conf.register_opts(interface.OPTS)
     agent_config.register_interface_driver_opts_helper(conf)
     agent_config.register_use_namespaces_opts_helper(conf)
-    agent_config.register_root_helper(conf)
     return conf
 
 
-def collect_neutron_ports(bridges, root_helper):
+def collect_neutron_ports(bridges):
     """Collect ports created by Neutron from OVS."""
     ports = []
     for bridge in bridges:
-        ovs = ovs_lib.OVSBridge(bridge, root_helper)
+        ovs = ovs_lib.OVSBridge(bridge)
         ports += [port.port_name for port in ovs.get_vif_ports()]
     return ports
 
 
-def delete_neutron_ports(ports, root_helper):
+def delete_neutron_ports(ports):
     """Delete non-internal ports created by Neutron
 
     Non-internal OVS ports need to be removed manually.
     """
     for port in ports:
         if ip_lib.device_exists(port):
-            device = ip_lib.IPDevice(port, root_helper)
+            device = ip_lib.IPDevice(port)
             device.link.delete()
             LOG.info(_LI("Deleting port: %s"), port)
 
@@ -86,7 +85,7 @@ def main():
 
     configuration_bridges = set([conf.ovs_integration_bridge,
                                  conf.external_network_bridge])
-    ovs = ovs_lib.BaseOVS(conf.AGENT.root_helper)
+    ovs = ovs_lib.BaseOVS()
     ovs_bridges = set(ovs.get_bridges())
     available_configuration_bridges = configuration_bridges & ovs_bridges
 
@@ -98,15 +97,14 @@ def main():
     # Collect existing ports created by Neutron on configuration bridges.
     # After deleting ports from OVS bridges, we cannot determine which
     # ports were created by Neutron, so port information is collected now.
-    ports = collect_neutron_ports(available_configuration_bridges,
-                                  conf.AGENT.root_helper)
+    ports = collect_neutron_ports(available_configuration_bridges)
 
     for bridge in bridges:
         LOG.info(_LI("Cleaning bridge: %s"), bridge)
-        ovs = ovs_lib.OVSBridge(bridge, conf.AGENT.root_helper)
+        ovs = ovs_lib.OVSBridge(bridge)
         ovs.delete_ports(all_ports=conf.ovs_all_ports)
 
     # Remove remaining ports created by Neutron (usually veth pair)
-    delete_neutron_ports(ports, conf.AGENT.root_helper)
+    delete_neutron_ports(ports)
 
     LOG.info(_LI("OVS cleanup completed successfully"))
index 094305661f69ff78c4e6323854ba764ced416101..99b1c787083f75a38b5ee4c50b2ab379d4396772 100644 (file)
@@ -36,7 +36,7 @@ MINIMUM_DNSMASQ_VERSION = 2.67
 
 def ovs_vxlan_supported(root_helper, from_ip='192.0.2.1', to_ip='192.0.2.2'):
     name = "vxlantest-" + utils.get_random_string(6)
-    with ovs_lib.OVSBridge(name, root_helper) as br:
+    with ovs_lib.OVSBridge(name) as br:
         port = br.add_tunnel_port(from_ip, to_ip, const.TYPE_VXLAN)
         return port != ovs_lib.INVALID_OFPORT
 
@@ -54,7 +54,7 @@ def patch_supported(root_helper):
     name = "patchtest-" + seed
     peer_name = "peertest0-" + seed
     patch_name = "peertest1-" + seed
-    with ovs_lib.OVSBridge(name, root_helper) as br:
+    with ovs_lib.OVSBridge(name) as br:
         port = br.add_patch_port(patch_name, peer_name)
         return port != ovs_lib.INVALID_OFPORT
 
@@ -76,7 +76,7 @@ def ofctl_arg_supported(root_helper, cmd, **kwargs):
     :returns: a boolean if the supplied arguments are supported.
     """
     br_name = 'br-test-%s' % utils.get_random_string(6)
-    with ovs_lib.OVSBridge(br_name, root_helper) as test_br:
+    with ovs_lib.OVSBridge(br_name) as test_br:
         full_args = ["ovs-ofctl", cmd, test_br.br_name,
                      ovs_lib._build_flow_expr_str(kwargs, cmd.split('-')[0])]
         try:
index e59e5e4671c5bf50015aadf845a6fa8b2e1912f0..85689469c61857969473d1b48ab4dcf8cfe0e115 100644 (file)
@@ -49,7 +49,7 @@ class IVSBridge(ovs_lib.OVSBridge):
     def run_vsctl(self, args, check_error=False):
         full_args = ["ivs-ctl"] + args
         try:
-            return utils.execute(full_args, root_helper=self.root_helper)
+            return utils.execute(full_args, run_as_root=True)
         except Exception as e:
             with excutils.save_and_reraise_exception() as ctxt:
                 LOG.error(_LE("Unable to execute %(cmd)s. "
@@ -83,9 +83,9 @@ class RestProxyAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin):
                                                      self.sg_plugin_rpc,
                                                      root_helper)
         if vs == 'ivs':
-            self.int_br = IVSBridge(integ_br, root_helper)
+            self.int_br = IVSBridge(integ_br)
         else:
-            self.int_br = ovs_lib.OVSBridge(integ_br, root_helper)
+            self.int_br = ovs_lib.OVSBridge(integ_br)
 
     def _setup_rpc(self):
         self.topic = topics.AGENT
index ff417fbddb6c37c1ab29c031fa877c7c77af5637..72d39ad11245c5e6e9e0222e8c6318eec182d018 100644 (file)
@@ -164,7 +164,7 @@ class SdnveNeutronAgent(object):
         :returns: the integration bridge
         '''
 
-        int_br = ovs_lib.OVSBridge(bridge_name, self.root_helper)
+        int_br = ovs_lib.OVSBridge(bridge_name)
         if reset_br:
             int_br.reset_bridge()
             int_br.remove_all_flows()
index 816e66f882958c847865a6415aa1aff10a267920..f50887ff4e672806a7efa813a743e49e66d076f2 100755 (executable)
@@ -101,7 +101,7 @@ class NECNeutronAgent(object):
         :param root_helper: utility to use when running shell cmds.
         :param polling_interval: interval (secs) to check the bridge.
         '''
-        self.int_br = ovs_lib.OVSBridge(integ_br, root_helper)
+        self.int_br = ovs_lib.OVSBridge(integ_br)
         self.polling_interval = polling_interval
         self.cur_ports = []
         self.need_sync = True
index 6525df0af18d65ef4384b7cc6a71a63eef495afa..f4877a50758473a2b1d740e2fcc75cdc0e2ea468 100644 (file)
@@ -81,8 +81,8 @@ class LocalVLANMapping(object):
 
 
 class Bridge(flows.OFAgentIntegrationBridge, ovs_lib.OVSBridge):
-    def __init__(self, br_name, root_helper, ryuapp):
-        super(Bridge, self).__init__(br_name, root_helper)
+    def __init__(self, br_name, ryuapp):
+        super(Bridge, self).__init__(br_name)
         self.datapath_id = None
         self.datapath = None
         self.ryuapp = ryuapp
@@ -225,7 +225,7 @@ class OFANeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
         # Keep track of int_br's device count for use by _report_state()
         self.int_br_device_count = 0
 
-        self.int_br = Bridge(integ_br, self.root_helper, self.ryuapp)
+        self.int_br = Bridge(integ_br, self.ryuapp)
         # Stores port update notifications for processing in main loop
         self.updated_ports = set()
         self.setup_rpc()
index c4996e6308718ae29dd231c1276e6aff4ef3a4a3..d0e0764ba2d865f7cb32df520c4a3b23458b2e5d 100644 (file)
@@ -77,7 +77,7 @@ class NVSDNeutronAgent(object):
 
     def __init__(self, integ_br, root_helper, polling_interval):
         super(NVSDNeutronAgent, self).__init__()
-        self.int_br = ovs_lib.OVSBridge(integ_br, root_helper)
+        self.int_br = ovs_lib.OVSBridge(integ_br)
         self.polling_interval = polling_interval
         self.root_helper = root_helper
         self.setup_rpc()
index 333e14c90f565c8944a37ac994ff2bf634692c40..d94c1dc0ed978ec84a1681c214ae6b4c1b06d724 100644 (file)
@@ -188,7 +188,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
         # Keep track of int_br's device count for use by _report_state()
         self.int_br_device_count = 0
 
-        self.int_br = ovs_lib.OVSBridge(integ_br, self.root_helper)
+        self.int_br = ovs_lib.OVSBridge(integ_br)
         self.setup_integration_br()
         # Stores port update notifications for processing in main rpc loop
         self.updated_ports = set()
@@ -735,7 +735,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
 
     def setup_ancillary_bridges(self, integ_br, tun_br):
         '''Setup ancillary bridges - for example br-ex.'''
-        ovs = ovs_lib.BaseOVS(self.root_helper)
+        ovs = ovs_lib.BaseOVS()
         ovs_bridges = set(ovs.get_bridges())
         # Remove all known bridges
         ovs_bridges.remove(integ_br)
@@ -754,7 +754,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
         ovs_bridges.difference_update(br_names)
         ancillary_bridges = []
         for bridge in ovs_bridges:
-            br = ovs_lib.OVSBridge(bridge, self.root_helper)
+            br = ovs_lib.OVSBridge(bridge)
             LOG.info(_LI('Adding %s to list of bridges.'), bridge)
             ancillary_bridges.append(br)
         return ancillary_bridges
@@ -768,7 +768,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
         :param tun_br_name: the name of the tunnel bridge.
         '''
         if not self.tun_br:
-            self.tun_br = ovs_lib.OVSBridge(tun_br_name, self.root_helper)
+            self.tun_br = ovs_lib.OVSBridge(tun_br_name)
 
         self.tun_br.reset_bridge(secure_mode=True)
         self.patch_tun_ofport = self.int_br.add_patch_port(
@@ -895,7 +895,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
         self.int_ofports = {}
         self.phys_ofports = {}
         ip_wrapper = ip_lib.IPWrapper(self.root_helper)
-        ovs = ovs_lib.BaseOVS(self.root_helper)
+        ovs = ovs_lib.BaseOVS()
         ovs_bridges = ovs.get_bridges()
         for physical_network, bridge in bridge_mappings.iteritems():
             LOG.info(_LI("Mapping physical network %(physical_network)s to "
@@ -910,7 +910,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
                           {'physical_network': physical_network,
                            'bridge': bridge})
                 sys.exit(1)
-            br = ovs_lib.OVSBridge(bridge, self.root_helper)
+            br = ovs_lib.OVSBridge(bridge)
             br.remove_all_flows()
             br.add_flow(priority=1, actions="normal")
             self.phys_brs[physical_network] = br
index eed65578078d0457e4693d2af152e9f7412e383a..a3051c8909960841e2b7112ecbb9f4fe0d4fbad5 100644 (file)
@@ -126,7 +126,7 @@ class BaseOVSLinuxTestCase(testscenarios.WithScenarios, BaseLinuxTestCase):
     def setUp(self):
         super(BaseOVSLinuxTestCase, self).setUp()
         self.config(group='OVS', ovsdb_interface=self.ovsdb_interface)
-        self.ovs = ovs_lib.BaseOVS(self.root_helper)
+        self.ovs = ovs_lib.BaseOVS()
         self.ip = ip_lib.IPWrapper(self.root_helper)
 
     def create_ovs_bridge(self, br_prefix=BR_PREFIX):
@@ -135,7 +135,7 @@ class BaseOVSLinuxTestCase(testscenarios.WithScenarios, BaseLinuxTestCase):
         return br
 
     def get_ovs_bridge(self, br_name):
-        return ovs_lib.OVSBridge(br_name, self.root_helper)
+        return ovs_lib.OVSBridge(br_name)
 
     def create_ovs_port_in_ns(self, br, ns):
         def create_port(name):
index 619670055e394f3cd675c6f48828ad631972026b..cff480ad7ec2c7d7ef8f6eedc17cd63d645c0299 100755 (executable)
@@ -258,7 +258,7 @@ class L3AgentTestFramework(base.BaseOVSLinuxTestCase):
 
     def _assert_interfaces_deleted_from_ovs(self):
         def assert_ovs_bridge_empty(bridge_name):
-            bridge = ovs_lib.OVSBridge(bridge_name, self.root_helper)
+            bridge = ovs_lib.OVSBridge(bridge_name)
             self.assertFalse(bridge.get_port_name_list())
 
         assert_ovs_bridge_empty(self.agent.conf.ovs_integration_bridge)
index 4f6f2e62288576f74fd3561a904910ac332fe935..3ed3e6313fa7f09044708e3ae675bbdd6ae5e720 100644 (file)
@@ -220,7 +220,7 @@ class OVSLibTestCase(base.BaseOVSLinuxTestCase):
 
     def test_bridge_lifecycle_ovsbridge(self):
         name = base.get_rand_name(prefix=base.BR_PREFIX)
-        br = ovs_lib.OVSBridge(name, self.root_helper)
+        br = ovs_lib.OVSBridge(name)
         self.assertEqual(br.br_name, name)
         # Make sure that instantiating an OVSBridge does not actually create
         self.assertFalse(self.ovs.bridge_exists(name))
index 303d3265a24441a0c811c2265dd5f1690cefd4b6..2376fdbd509cb848005c870c62619ae40f85d028 100644 (file)
@@ -58,8 +58,7 @@ class OVS_Lib_Test(base.BaseTestCase):
         super(OVS_Lib_Test, self).setUp()
         self.BR_NAME = "br-int"
 
-        self.root_helper = 'sudo'
-        self.br = ovs_lib.OVSBridge(self.BR_NAME, self.root_helper)
+        self.br = ovs_lib.OVSBridge(self.BR_NAME)
         self.execute = mock.patch.object(
             utils, "execute", spec=utils.execute).start()
 
@@ -74,12 +73,11 @@ class OVS_Lib_Test(base.BaseTestCase):
 
     def _vsctl_mock(self, *args):
         cmd = self._vsctl_args(*args)
-        return mock.call(cmd, root_helper=self.root_helper,
-                         log_fail_as_error=False)
+        return mock.call(cmd, run_as_root=True, log_fail_as_error=False)
 
     def _verify_vsctl_mock(self, *args):
         cmd = self._vsctl_args(*args)
-        self.execute.assert_called_once_with(cmd, root_helper=self.root_helper,
+        self.execute.assert_called_once_with(cmd, run_as_root=True,
                                              log_fail_as_error=False)
 
     def test_vifport(self):
@@ -223,48 +221,55 @@ class OVS_Lib_Test(base.BaseTestCase):
         self.br.add_flow(**flow_dict_6)
         self.br.add_flow(**flow_dict_7)
         expected_calls = [
-            mock.call(["ovs-ofctl", "add-flows", self.BR_NAME, '-'],
-                      process_input=OFCTLParamListMatcher(
-                          "hard_timeout=0,idle_timeout=0,"
-                          "priority=2,dl_src=ca:fe:de:ad:be:ef,"
-                          "actions=strip_vlan,output:0"),
-                      root_helper=self.root_helper),
-            mock.call(["ovs-ofctl", "add-flows", self.BR_NAME, '-'],
-                      process_input=OFCTLParamListMatcher(
-                          "hard_timeout=0,idle_timeout=0,"
-                          "priority=1,actions=normal"),
-                      root_helper=self.root_helper),
-            mock.call(["ovs-ofctl", "add-flows", self.BR_NAME, '-'],
-                      process_input=OFCTLParamListMatcher(
-                          "hard_timeout=0,idle_timeout=0,"
-                          "priority=2,actions=drop"),
-                      root_helper=self.root_helper),
-            mock.call(["ovs-ofctl", "add-flows", self.BR_NAME, '-'],
-                      process_input=OFCTLParamListMatcher(
-                          "hard_timeout=0,idle_timeout=0,priority=2,"
-                          "in_port=%s,actions=drop" % ofport),
-                      root_helper=self.root_helper),
-            mock.call(["ovs-ofctl", "add-flows", self.BR_NAME, '-'],
-                      process_input=OFCTLParamListMatcher(
-                          "hard_timeout=0,idle_timeout=0,"
-                          "priority=4,dl_vlan=%s,in_port=%s,"
-                          "actions=strip_vlan,set_tunnel:%s,normal"
-                          % (vid, ofport, lsw_id)),
-                      root_helper=self.root_helper),
-            mock.call(["ovs-ofctl", "add-flows", self.BR_NAME, '-'],
-                      process_input=OFCTLParamListMatcher(
-                          "hard_timeout=0,idle_timeout=0,priority=3,"
-                          "tun_id=%s,actions=mod_vlan_vid:%s,"
-                          "output:%s" % (lsw_id, vid, ofport)),
-                      root_helper=self.root_helper),
-            mock.call(["ovs-ofctl", "add-flows", self.BR_NAME, '-'],
-                      process_input=OFCTLParamListMatcher(
-                          "hard_timeout=0,idle_timeout=0,priority=4,"
-                          "nw_src=%s,arp,actions=drop" % cidr),
-                      root_helper=self.root_helper),
+            self._ofctl_mock("add-flows", self.BR_NAME, '-',
+                             process_input=OFCTLParamListMatcher(
+                                 "hard_timeout=0,idle_timeout=0,"
+                                 "priority=2,dl_src=ca:fe:de:ad:be:ef,"
+                                 "actions=strip_vlan,output:0")),
+            self._ofctl_mock("add-flows", self.BR_NAME, '-',
+                             process_input=OFCTLParamListMatcher(
+                                 "hard_timeout=0,idle_timeout=0,"
+                                 "priority=1,actions=normal")),
+            self._ofctl_mock("add-flows", self.BR_NAME, '-',
+                             process_input=OFCTLParamListMatcher(
+                                 "hard_timeout=0,idle_timeout=0,"
+                                 "priority=2,actions=drop")),
+            self._ofctl_mock("add-flows", self.BR_NAME, '-',
+                             process_input=OFCTLParamListMatcher(
+                                 "hard_timeout=0,idle_timeout=0,priority=2,"
+                                 "in_port=%s,actions=drop" % ofport)),
+            self._ofctl_mock("add-flows", self.BR_NAME, '-',
+                             process_input=OFCTLParamListMatcher(
+                                 "hard_timeout=0,idle_timeout=0,"
+                                 "priority=4,dl_vlan=%s,in_port=%s,"
+                                 "actions=strip_vlan,set_tunnel:%s,normal" %
+                                 (vid, ofport, lsw_id))),
+            self._ofctl_mock("add-flows", self.BR_NAME, '-',
+                             process_input=OFCTLParamListMatcher(
+                                 "hard_timeout=0,idle_timeout=0,priority=3,"
+                                 "tun_id=%s,actions=mod_vlan_vid:%s,"
+                                 "output:%s" % (lsw_id, vid, ofport))),
+            self._ofctl_mock("add-flows", self.BR_NAME, '-',
+                             process_input=OFCTLParamListMatcher(
+                                 "hard_timeout=0,idle_timeout=0,priority=4,"
+                                 "nw_src=%s,arp,actions=drop" % cidr)),
         ]
         self.execute.assert_has_calls(expected_calls)
 
+    def _ofctl_args(self, cmd, *args):
+        cmd = ['ovs-ofctl', cmd]
+        cmd += args
+        return cmd
+
+    def _ofctl_mock(self, cmd, *args, **kwargs):
+        cmd = self._ofctl_args(cmd, *args)
+        return mock.call(cmd, run_as_root=True, **kwargs)
+
+    def _verify_ofctl_mock(self, cmd, *args, **kwargs):
+        cmd = self._ofctl_args(cmd, *args)
+        return self.execute.assert_called_once_with(cmd, run_as_root=True,
+                                                    **kwargs)
+
     def test_add_flow_timeout_set(self):
         flow_dict = collections.OrderedDict([
             ('priority', 1),
@@ -273,21 +278,19 @@ class OVS_Lib_Test(base.BaseTestCase):
             ('actions', 'normal')])
 
         self.br.add_flow(**flow_dict)
-        self.execute.assert_called_once_with(
-            ["ovs-ofctl", "add-flows", self.BR_NAME, '-'],
+        self._verify_ofctl_mock(
+            "add-flows", self.BR_NAME, '-',
             process_input="hard_timeout=1000,idle_timeout=2000,priority=1,"
-                          "actions=normal",
-            root_helper=self.root_helper)
+            "actions=normal")
 
     def test_add_flow_default_priority(self):
         flow_dict = collections.OrderedDict([('actions', 'normal')])
 
         self.br.add_flow(**flow_dict)
-        self.execute.assert_called_once_with(
-            ["ovs-ofctl", "add-flows", self.BR_NAME, '-'],
+        self._verify_ofctl_mock(
+            "add-flows", self.BR_NAME, '-',
             process_input="hard_timeout=0,idle_timeout=0,priority=1,"
-                          "actions=normal",
-            root_helper=self.root_helper)
+                          "actions=normal")
 
     def _test_get_port_ofport(self, ofport, expected_result):
         pname = "tap99"
@@ -319,10 +322,7 @@ class OVS_Lib_Test(base.BaseTestCase):
         self.execute.return_value = 'ignore\nflow-1\n'
         # counts the number of flows as total lines of output - 2
         self.assertEqual(self.br.count_flows(), 1)
-        self.execute.assert_called_once_with(
-            ["ovs-ofctl", "dump-flows", self.BR_NAME],
-            root_helper=self.root_helper,
-            process_input=None)
+        self._verify_ofctl_mock("dump-flows", self.BR_NAME, process_input=None)
 
     def test_delete_flow(self):
         ofport = "5"
@@ -332,15 +332,12 @@ class OVS_Lib_Test(base.BaseTestCase):
         self.br.delete_flows(tun_id=lsw_id)
         self.br.delete_flows(dl_vlan=vid)
         expected_calls = [
-            mock.call(["ovs-ofctl", "del-flows", self.BR_NAME, '-'],
-                      process_input="in_port=" + ofport,
-                      root_helper=self.root_helper),
-            mock.call(["ovs-ofctl", "del-flows", self.BR_NAME, '-'],
-                      process_input="tun_id=%s" % lsw_id,
-                      root_helper=self.root_helper),
-            mock.call(["ovs-ofctl", "del-flows", self.BR_NAME, '-'],
-                      process_input="dl_vlan=%s" % vid,
-                      root_helper=self.root_helper),
+            self._ofctl_mock("del-flows", self.BR_NAME, '-',
+                             process_input="in_port=" + ofport),
+            self._ofctl_mock("del-flows", self.BR_NAME, '-',
+                             process_input="tun_id=%s" % lsw_id),
+            self._ofctl_mock("del-flows", self.BR_NAME, '-',
+                             process_input="dl_vlan=%s" % vid),
         ]
         self.execute.assert_has_calls(expected_calls)
 
@@ -498,7 +495,7 @@ class OVS_Lib_Test(base.BaseTestCase):
             expected_calls_and_values.append(
                 (mock.call(["xe", "vif-param-get", "param-name=other-config",
                             "param-key=nicira-iface-id", "uuid=" + vif_id],
-                           root_helper=self.root_helper),
+                           run_as_root=True),
                  vif_id)
             )
         tools.setup_mock_calls(self.execute, expected_calls_and_values)
index 8398a2394b1781e821f2dfbb3dceddee7412d3e9..1875e9526c56c92fb0b181718b2baf83b8e2ad93 100644 (file)
@@ -93,7 +93,7 @@ class TestOFANeutronAgentBridge(ofa_test_base.OFAAgentTestBase):
         self.br_name = 'bridge1'
         self.root_helper = 'fake_helper'
         self.ovs = self.mod_agent.Bridge(
-            self.br_name, self.root_helper, self.ryuapp)
+            self.br_name, self.ryuapp)
 
     def test_find_datapath_id(self):
         with mock.patch.object(self.ovs, 'get_datapath_id',
index 3e124fbf69a75d250e708bdba954e4186733d845..05f2887b15f56cc33fa90f078f0cde886b3d0355 100644 (file)
@@ -267,7 +267,7 @@ class TestOvsNeutronAgent(base.BaseTestCase):
         self.assertEqual(expected, actual)
 
     def test_update_ports_returns_changed_vlan(self):
-        br = ovs_lib.OVSBridge('br-int', 'sudo')
+        br = ovs_lib.OVSBridge('br-int')
         mac = "ca:fe:de:ad:be:ef"
         port = ovs_lib.VifPort(1, 1, 1, mac, br)
         lvm = ovs_neutron_agent.LocalVLANMapping(
index 4ab73e1db244ea6d614fd4ab8fcb4b99b1e284ca..08d48baf74fa588c8dc74bc11f06c2227ecff994 100644 (file)
@@ -99,7 +99,7 @@ class TunnelTest(base.BaseTestCase):
         }
 
         self.mock_bridge = mock.patch.object(ovs_lib, 'OVSBridge').start()
-        self.mock_bridge.side_effect = (lambda br_name, root_helper:
+        self.mock_bridge.side_effect = (lambda br_name:
                                         self.ovs_bridges[br_name])
 
         self.mock_int_bridge = self.ovs_bridges[self.INT_BRIDGE]
@@ -139,9 +139,9 @@ class TunnelTest(base.BaseTestCase):
 
     def _define_expected_calls(self):
         self.mock_bridge_expected = [
-            mock.call(self.INT_BRIDGE, 'sudo'),
-            mock.call(self.MAP_TUN_BRIDGE, 'sudo'),
-            mock.call(self.TUN_BRIDGE, 'sudo'),
+            mock.call(self.INT_BRIDGE),
+            mock.call(self.MAP_TUN_BRIDGE),
+            mock.call(self.TUN_BRIDGE),
         ]
 
         self.mock_int_bridge = self.ovs_bridges[self.INT_BRIDGE]
@@ -564,9 +564,9 @@ class TunnelTestUseVethInterco(TunnelTest):
 
     def _define_expected_calls(self):
         self.mock_bridge_expected = [
-            mock.call(self.INT_BRIDGE, 'sudo'),
-            mock.call(self.MAP_TUN_BRIDGE, 'sudo'),
-            mock.call(self.TUN_BRIDGE, 'sudo'),
+            mock.call(self.INT_BRIDGE),
+            mock.call(self.MAP_TUN_BRIDGE),
+            mock.call(self.TUN_BRIDGE),
         ]
 
         self.mock_int_bridge_expected = [
index ee6967e0675ccabc03e932d2fcfd5806da0a354a..827f5033e7b69272626fa9724575e4a8d630e8b8 100644 (file)
@@ -262,7 +262,7 @@ class TestOVSInterfaceDriver(TestBase):
         with mock.patch('neutron.agent.linux.ovs_lib.OVSBridge') as ovs_br:
             ovs = interface.OVSInterfaceDriver(self.conf)
             ovs.unplug('tap0')
-            ovs_br.assert_has_calls([mock.call(bridge, 'sudo'),
+            ovs_br.assert_has_calls([mock.call(bridge),
                                      mock.call().delete_port('tap0')])
 
 
@@ -336,7 +336,7 @@ class TestOVSInterfaceDriverWithVeth(TestOVSInterfaceDriver):
         with mock.patch('neutron.agent.linux.ovs_lib.OVSBridge') as ovs_br:
             ovs = interface.OVSInterfaceDriver(self.conf)
             ovs.unplug('ns-0', bridge=bridge)
-            ovs_br.assert_has_calls([mock.call(bridge, 'sudo'),
+            ovs_br.assert_has_calls([mock.call(bridge),
                                      mock.call().delete_port('tap0')])
         self.ip_dev.assert_has_calls([mock.call('ns-0', 'sudo', None),
                                       mock.call().link.delete()])
index 1417ea3af13dd8850ea81a3f7157f0df04a5cf3a..9ca96c3ce115cb28d147c575c93144f402636b71 100644 (file)
@@ -113,8 +113,7 @@ class TestNetnsCleanup(base.BaseTestCase):
                 util.unplug_device(conf, device)
 
                 mock_get_bridge_for_iface.assert_called_once_with('tap1')
-                ovs_br_cls.assert_called_once_with('br-int',
-                                                   conf.AGENT.root_helper)
+                ovs_br_cls.assert_called_once_with('br-int')
                 ovs_bridge.assert_has_calls(
                     [mock.call.delete_port(device.name)])
 
index 2e474c127804d14c6d51d6755669932d6522bf12..9fc5d8561ee4c41fd4cbdc3e613b468ba1a8d869 100644 (file)
@@ -60,8 +60,8 @@ class TestOVSCleanup(base.BaseTestCase):
                 util.main()
                 ovs.assert_has_calls([mock.call().delete_ports(
                     all_ports=False)])
-                collect.assert_called_once_with(set(bridges), 'dummy_sudo')
-                delete.assert_called_once_with(ports, 'dummy_sudo')
+                collect.assert_called_once_with(set(bridges))
+                delete.assert_called_once_with(ports)
 
     def test_collect_neutron_ports(self):
         port1 = ovs_lib.VifPort('tap1234', 1, uuidutils.generate_uuid(),
@@ -75,7 +75,7 @@ class TestOVSCleanup(base.BaseTestCase):
         with mock.patch('neutron.agent.linux.ovs_lib.OVSBridge') as ovs:
             ovs.return_value.get_vif_ports.side_effect = ports
             bridges = ['br-int', 'br-ex']
-            ret = util.collect_neutron_ports(bridges, 'dummy_sudo')
+            ret = util.collect_neutron_ports(bridges)
             self.assertEqual(ret, portnames)
 
     def test_delete_neutron_ports(self):
@@ -86,10 +86,10 @@ class TestOVSCleanup(base.BaseTestCase):
                               side_effect=port_found),
             mock.patch.object(ip_lib, 'IPDevice')
         ) as (device_exists, ip_dev):
-            util.delete_neutron_ports(ports, 'dummy_sudo')
+            util.delete_neutron_ports(ports)
             device_exists.assert_has_calls([mock.call(p) for p in ports])
             ip_dev.assert_has_calls(
-                [mock.call('tap1234', 'dummy_sudo'),
+                [mock.call('tap1234'),
                  mock.call().link.delete(),
-                 mock.call('tap09ab', 'dummy_sudo'),
+                 mock.call('tap09ab'),
                  mock.call().link.delete()])