From: Terry Wilson Date: Tue, 10 Feb 2015 03:01:38 +0000 (-0600) Subject: Remove root_helper arg from external_process X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=04d2e9b412b76aaa31ce00cb022b6c6ea56c2a60;p=openstack-build%2Fneutron-build.git Remove root_helper arg from external_process Partially-Implements: blueprint rootwrap-daemon-mode Change-Id: Icdfc3ac4812154bcd628f9a224ef516d55b41cfd --- diff --git a/neutron/agent/dhcp/agent.py b/neutron/agent/dhcp/agent.py index ef878f64d..cdbd755ab 100644 --- a/neutron/agent/dhcp/agent.py +++ b/neutron/agent/dhcp/agent.py @@ -69,7 +69,6 @@ class DhcpAgent(manager.Manager): self._populate_networks_cache() self._process_monitor = external_process.ProcessMonitor( config=self.conf, - root_helper=self.root_helper, resource_type='dhcp') def _populate_networks_cache(self): diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index 2fda9adb4..c39e52ad9 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -152,7 +152,6 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, self.process_monitor = external_process.ProcessMonitor( config=self.conf, - root_helper=self.root_helper, resource_type='router') try: diff --git a/neutron/agent/linux/external_process.py b/neutron/agent/linux/external_process.py index f6fc83fd1..4159ac8d5 100644 --- a/neutron/agent/linux/external_process.py +++ b/neutron/agent/linux/external_process.py @@ -45,14 +45,12 @@ class ProcessManager(object): Note: The manager expects uuid to be in cmdline. """ - def __init__(self, conf, uuid, root_helper='sudo', - namespace=None, service=None, pids_path=None, - default_cmd_callback=None, + def __init__(self, conf, uuid, namespace=None, service=None, + pids_path=None, default_cmd_callback=None, cmd_addl_env=None, pid_file=None): self.conf = conf self.uuid = uuid - self.root_helper = root_helper self.namespace = namespace self.default_cmd_callback = default_cmd_callback self.cmd_addl_env = cmd_addl_env @@ -74,7 +72,7 @@ class ProcessManager(object): cmd_callback = self.default_cmd_callback cmd = cmd_callback(self.get_pid_file_name()) - ip_wrapper = ip_lib.IPWrapper(self.root_helper, self.namespace) + ip_wrapper = ip_lib.IPWrapper(namespace=self.namespace) ip_wrapper.netns.execute(cmd, addl_env=self.cmd_addl_env) elif reload_cfg: self.reload_cfg() @@ -87,7 +85,7 @@ class ProcessManager(object): if self.active: cmd = ['kill', '-%s' % (sig), pid] - utils.execute(cmd, self.root_helper) + utils.execute(cmd, run_as_root=True) # In the case of shutting down, remove the pid file if sig == '9': fileutils.delete_if_exists(self.get_pid_file_name()) @@ -131,18 +129,15 @@ ServiceId = collections.namedtuple('ServiceId', ['uuid', 'service']) class ProcessMonitor(object): - def __init__(self, config, root_helper, resource_type): + def __init__(self, config, resource_type): """Handle multiple process managers and watch over all of them. :param config: oslo config object with the agent configuration. :type config: oslo_config.ConfigOpts - :param root_helper: root helper to be used with new ProcessManagers - :type root_helper: str :param resource_type: can be dhcp, router, load_balancer, etc. :type resource_type: str """ self._config = config - self._root_helper = root_helper self._resource_type = resource_type self._process_managers = {} @@ -250,7 +245,6 @@ class ProcessMonitor(object): cmd_addl_env, pid_file): return ProcessManager(conf=self._config, uuid=uuid, - root_helper=self._root_helper, namespace=namespace, service=service, default_cmd_callback=cmd_callback, diff --git a/neutron/agent/linux/keepalived.py b/neutron/agent/linux/keepalived.py index ef6c9f77e..bf43832d1 100644 --- a/neutron/agent/linux/keepalived.py +++ b/neutron/agent/linux/keepalived.py @@ -431,6 +431,5 @@ class KeepalivedManager(KeepalivedNotifierMixin): return external_process.ProcessManager( conf, resource_id, - root_helper, namespace, pids_path=conf_path) diff --git a/neutron/agent/metadata/driver.py b/neutron/agent/metadata/driver.py index 97cf34974..130a2ce34 100644 --- a/neutron/agent/metadata/driver.py +++ b/neutron/agent/metadata/driver.py @@ -142,7 +142,6 @@ class MetadataDriver(advanced_service.AdvancedService): return external_process.ProcessManager( conf, router_id, - config.get_root_helper(conf), ns_name) @classmethod diff --git a/neutron/cmd/netns_cleanup.py b/neutron/cmd/netns_cleanup.py index 8dcf2978f..c1e7dd2ff 100644 --- a/neutron/cmd/netns_cleanup.py +++ b/neutron/cmd/netns_cleanup.py @@ -73,10 +73,9 @@ def setup_conf(): return conf -def _get_dhcp_process_monitor(config, root_helper): +def _get_dhcp_process_monitor(config): return external_process.ProcessMonitor( config=config, - root_helper=root_helper, resource_type='dhcp') @@ -88,7 +87,7 @@ def kill_dhcp(conf, namespace): dhcp_driver = importutils.import_object( conf.dhcp_driver, conf=conf, - process_monitor=_get_dhcp_process_monitor(conf, root_helper), + process_monitor=_get_dhcp_process_monitor(conf), network=dhcp.NetModel(conf.use_namespaces, {'id': network_id}), root_helper=root_helper, plugin=FakeDhcpPlugin()) diff --git a/neutron/tests/functional/agent/linux/test_keepalived.py b/neutron/tests/functional/agent/linux/test_keepalived.py index 70565c8f1..e8bfbfd05 100644 --- a/neutron/tests/functional/agent/linux/test_keepalived.py +++ b/neutron/tests/functional/agent/linux/test_keepalived.py @@ -38,7 +38,6 @@ class KeepalivedManagerTestCase(functional_base.BaseSudoTestCase, process = external_process.ProcessManager( cfg.CONF, 'router1', - self.root_helper, namespace=None, pids_path=cfg.CONF.state_path) self.assertTrue(process.active) diff --git a/neutron/tests/functional/agent/linux/test_process_monitor.py b/neutron/tests/functional/agent/linux/test_process_monitor.py index 139683d23..70492b7ba 100644 --- a/neutron/tests/functional/agent/linux/test_process_monitor.py +++ b/neutron/tests/functional/agent/linux/test_process_monitor.py @@ -41,7 +41,6 @@ class BaseTestProcessMonitor(base.BaseSudoTestCase): def build_process_monitor(self): return external_process.ProcessMonitor( config=cfg.CONF, - root_helper=None, resource_type='test') def _make_cmdline_callback(self, uuid): diff --git a/neutron/tests/functional/agent/test_l3_agent.py b/neutron/tests/functional/agent/test_l3_agent.py index cff480ad7..af3961904 100755 --- a/neutron/tests/functional/agent/test_l3_agent.py +++ b/neutron/tests/functional/agent/test_l3_agent.py @@ -132,7 +132,6 @@ class L3AgentTestFramework(base.BaseOVSLinuxTestCase): pm = external_process.ProcessManager( conf, router.router_id, - self.root_helper, router.ns_name) return pm.active diff --git a/neutron/tests/unit/agent/linux/test_process_monitor.py b/neutron/tests/unit/agent/linux/test_process_monitor.py index ecc47fcdf..0e65144cc 100644 --- a/neutron/tests/unit/agent/linux/test_process_monitor.py +++ b/neutron/tests/unit/agent/linux/test_process_monitor.py @@ -47,7 +47,6 @@ class BaseTestProcessMonitor(base.BaseTestCase): conf.AGENT.check_child_processes = True self.pmonitor = external_process.ProcessMonitor( config=conf, - root_helper=None, resource_type='test') def get_monitored_process_manager(self, uuid, service=None): diff --git a/neutron/tests/unit/agent/metadata/test_driver.py b/neutron/tests/unit/agent/metadata/test_driver.py index afc860373..568ac0a9a 100644 --- a/neutron/tests/unit/agent/metadata/test_driver.py +++ b/neutron/tests/unit/agent/metadata/test_driver.py @@ -19,7 +19,6 @@ import mock from oslo_config import cfg -from neutron.agent.common import config as agent_config from neutron.agent.l3 import config as l3_config from neutron.agent.metadata import driver as metadata_driver from neutron.openstack.common import uuidutils @@ -38,7 +37,6 @@ class TestMetadataDriver(base.BaseTestCase): super(TestMetadataDriver, self).setUp() cfg.CONF.register_opts(l3_config.OPTS) cfg.CONF.register_opts(metadata_driver.MetadataDriver.OPTS) - agent_config.register_root_helper(cfg.CONF) def test_metadata_nat_rules(self): rules = ('PREROUTING', '-s 0.0.0.0/0 -d 169.254.169.254/32 ' @@ -83,7 +81,7 @@ class TestMetadataDriver(base.BaseTestCase): mock.patch(ip_class_path)) as (geteuid, getegid, ip_mock): driver._spawn_metadata_proxy(router_id, router_ns, cfg.CONF) ip_mock.assert_has_calls([ - mock.call('sudo', router_ns), + mock.call(namespace=router_ns), mock.call().netns.execute([ 'neutron-ns-metadata-proxy', mock.ANY, diff --git a/neutron/tests/unit/test_dhcp_agent.py b/neutron/tests/unit/test_dhcp_agent.py index 37c527aa3..5255de955 100644 --- a/neutron/tests/unit/test_dhcp_agent.py +++ b/neutron/tests/unit/test_dhcp_agent.py @@ -564,7 +564,6 @@ class TestDhcpAgentEventHandler(base.BaseTestCase): def _process_manager_constructor_call(self): return mock.call(conf=cfg.CONF, uuid=FAKE_NETWORK_UUID, - root_helper='sudo', namespace=FAKE_NETWORK_DHCP_NS, service=None, default_cmd_callback=mock.ANY, diff --git a/neutron/tests/unit/test_l3_agent.py b/neutron/tests/unit/test_l3_agent.py index 1c0ee4d3f..7b486e66f 100644 --- a/neutron/tests/unit/test_l3_agent.py +++ b/neutron/tests/unit/test_l3_agent.py @@ -1165,7 +1165,6 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): service=process, default_cmd_callback=mock.ANY, namespace=ri.ns_name, - root_helper=self.conf.AGENT.root_helper, conf=self.conf, pid_file=None, cmd_addl_env=None)] diff --git a/neutron/tests/unit/test_linux_external_process.py b/neutron/tests/unit/test_linux_external_process.py index 25fb25292..4cf5bf3aa 100644 --- a/neutron/tests/unit/test_linux_external_process.py +++ b/neutron/tests/unit/test_linux_external_process.py @@ -66,7 +66,7 @@ class TestProcessManager(base.BaseTestCase): manager.enable(callback) callback.assert_called_once_with('pidfile') ip_lib.assert_has_calls([ - mock.call.IPWrapper('sudo', 'ns'), + mock.call.IPWrapper(namespace='ns'), mock.call.IPWrapper().netns.execute(['the', 'cmd'], addl_env=None)]) @@ -87,10 +87,12 @@ class TestProcessManager(base.BaseTestCase): pid.__get__ = mock.Mock(return_value=4) with mock.patch.object(ep.ProcessManager, 'active') as active: active.__get__ = mock.Mock(return_value=True) - manager = ep.ProcessManager(self.conf, 'uuid') - manager.disable() - self.execute(['kill', '-9', 4], 'sudo') + + with mock.patch.object(ep, 'utils') as utils: + manager.disable() + utils.assert_has_calls( + mock.call.execute(['kill', '-9', 4], run_as_root=True)) def test_disable_namespace(self): with mock.patch.object(ep.ProcessManager, 'pid') as pid: @@ -103,7 +105,7 @@ class TestProcessManager(base.BaseTestCase): with mock.patch.object(ep, 'utils') as utils: manager.disable() utils.assert_has_calls( - mock.call.execute(['kill', '-9', 4], 'sudo')) + mock.call.execute(['kill', '-9', 4], run_as_root=True)) def test_disable_not_active(self): with mock.patch.object(ep.ProcessManager, 'pid') as pid: