Remove root_helper arg from external_process

Partially-Implements: blueprint rootwrap-daemon-mode
Change-Id: Icdfc3ac4812154bcd628f9a224ef516d55b41cfd
This commit is contained in:
Terry Wilson 2015-02-09 21:01:38 -06:00 committed by Henry Gessau
parent 3486a33994
commit 04d2e9b412
14 changed files with 15 additions and 32 deletions

View File

@ -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):

View File

@ -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:

View File

@ -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,

View File

@ -431,6 +431,5 @@ class KeepalivedManager(KeepalivedNotifierMixin):
return external_process.ProcessManager(
conf,
resource_id,
root_helper,
namespace,
pids_path=conf_path)

View File

@ -142,7 +142,6 @@ class MetadataDriver(advanced_service.AdvancedService):
return external_process.ProcessManager(
conf,
router_id,
config.get_root_helper(conf),
ns_name)
@classmethod

View File

@ -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())

View File

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

View File

@ -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):

View File

@ -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

View File

@ -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):

View File

@ -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,

View File

@ -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,

View File

@ -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)]

View File

@ -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: