Merge "Try to enable dnsmasq process several times" into stable/queens
This commit is contained in:
commit
63b43a065b
|
@ -39,6 +39,7 @@ from neutron.agent.linux import ip_lib
|
||||||
from neutron.agent.linux import iptables_manager
|
from neutron.agent.linux import iptables_manager
|
||||||
from neutron.cmd import runtime_checks as checks
|
from neutron.cmd import runtime_checks as checks
|
||||||
from neutron.common import constants as n_const
|
from neutron.common import constants as n_const
|
||||||
|
from neutron.common import exceptions as n_exc
|
||||||
from neutron.common import ipv6_utils
|
from neutron.common import ipv6_utils
|
||||||
from neutron.common import utils as common_utils
|
from neutron.common import utils as common_utils
|
||||||
from neutron.ipam import utils as ipam_utils
|
from neutron.ipam import utils as ipam_utils
|
||||||
|
@ -216,13 +217,26 @@ class DhcpLocalProcess(DhcpBase):
|
||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
"""Enables DHCP for this network by spawning a local process."""
|
"""Enables DHCP for this network by spawning a local process."""
|
||||||
if self.active:
|
try:
|
||||||
self.restart()
|
common_utils.wait_until_true(self._enable)
|
||||||
elif self._enable_dhcp():
|
except common_utils.WaitTimeout:
|
||||||
fileutils.ensure_tree(self.network_conf_dir, mode=0o755)
|
LOG.error("Failed to start DHCP process for network %s",
|
||||||
interface_name = self.device_manager.setup(self.network)
|
self.network.id)
|
||||||
self.interface_name = interface_name
|
|
||||||
self.spawn_process()
|
def _enable(self):
|
||||||
|
try:
|
||||||
|
if self.active:
|
||||||
|
self.restart()
|
||||||
|
elif self._enable_dhcp():
|
||||||
|
fileutils.ensure_tree(self.network_conf_dir, mode=0o755)
|
||||||
|
interface_name = self.device_manager.setup(self.network)
|
||||||
|
self.interface_name = interface_name
|
||||||
|
self.spawn_process()
|
||||||
|
return True
|
||||||
|
except n_exc.ProcessExecutionError as error:
|
||||||
|
LOG.debug("Spawning DHCP process for network %s failed; "
|
||||||
|
"Error: %s", self.network.id, error)
|
||||||
|
return False
|
||||||
|
|
||||||
def _get_process_manager(self, cmd_callback=None):
|
def _get_process_manager(self, cmd_callback=None):
|
||||||
return external_process.ProcessManager(
|
return external_process.ProcessManager(
|
||||||
|
@ -236,10 +250,9 @@ class DhcpLocalProcess(DhcpBase):
|
||||||
def disable(self, retain_port=False, block=False):
|
def disable(self, retain_port=False, block=False):
|
||||||
"""Disable DHCP for this network by killing the local process."""
|
"""Disable DHCP for this network by killing the local process."""
|
||||||
self.process_monitor.unregister(self.network.id, DNSMASQ_SERVICE_NAME)
|
self.process_monitor.unregister(self.network.id, DNSMASQ_SERVICE_NAME)
|
||||||
pm = self._get_process_manager()
|
self._get_process_manager().disable()
|
||||||
pm.disable()
|
|
||||||
if block:
|
if block:
|
||||||
common_utils.wait_until_true(lambda: not pm.active)
|
common_utils.wait_until_true(lambda: not self.active)
|
||||||
if not retain_port:
|
if not retain_port:
|
||||||
self._destroy_namespace_and_port()
|
self._destroy_namespace_and_port()
|
||||||
self._remove_config_files()
|
self._remove_config_files()
|
||||||
|
|
|
@ -25,6 +25,7 @@ from oslo_utils import fileutils
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from neutron.agent.linux import dhcp
|
from neutron.agent.linux import dhcp
|
||||||
|
from neutron.common import exceptions as n_exc
|
||||||
from neutron.conf.agent import common as config
|
from neutron.conf.agent import common as config
|
||||||
from neutron.conf.agent import dhcp as dhcp_config
|
from neutron.conf.agent import dhcp as dhcp_config
|
||||||
from neutron.conf import common as base_config
|
from neutron.conf import common as base_config
|
||||||
|
@ -1096,23 +1097,30 @@ class TestDhcpLocalProcess(TestBase):
|
||||||
def test_enable(self, ensure_dir):
|
def test_enable(self, ensure_dir):
|
||||||
attrs_to_mock = dict(
|
attrs_to_mock = dict(
|
||||||
[(a, mock.DEFAULT) for a in
|
[(a, mock.DEFAULT) for a in
|
||||||
['active', 'interface_name']]
|
['active', 'interface_name', 'spawn_process']]
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch.multiple(LocalChild, **attrs_to_mock) as mocks:
|
with mock.patch.multiple(LocalChild, **attrs_to_mock) as mocks:
|
||||||
mocks['active'].__get__ = mock.Mock(return_value=False)
|
mocks['active'].__get__ = mock.Mock(return_value=False)
|
||||||
mocks['interface_name'].__set__ = mock.Mock()
|
mocks['interface_name'].__set__ = mock.Mock()
|
||||||
|
mocks['spawn_process'].side_effect = [
|
||||||
|
n_exc.ProcessExecutionError(
|
||||||
|
returncode=2, message="Test dnsmasq start failed"),
|
||||||
|
None]
|
||||||
lp = LocalChild(self.conf,
|
lp = LocalChild(self.conf,
|
||||||
FakeDualNetwork())
|
FakeDualNetwork())
|
||||||
|
|
||||||
lp.enable()
|
lp.enable()
|
||||||
|
|
||||||
self.mock_mgr.assert_has_calls(
|
self.mock_mgr.assert_has_calls(
|
||||||
[mock.call(self.conf, None),
|
[mock.call(self.conf, None),
|
||||||
mock.call().setup(mock.ANY)])
|
mock.call().setup(mock.ANY)])
|
||||||
self.assertEqual(lp.called, ['spawn'])
|
self.assertEqual(2, mocks['interface_name'].__set__.call_count)
|
||||||
self.assertTrue(mocks['interface_name'].__set__.called)
|
ensure_dir.assert_has_calls([
|
||||||
ensure_dir.assert_called_with(
|
mock.call(
|
||||||
'/dhcp/cccccccc-cccc-cccc-cccc-cccccccccccc', mode=0o755)
|
'/dhcp/cccccccc-cccc-cccc-cccc-cccccccccccc', mode=0o755),
|
||||||
|
mock.call(
|
||||||
|
'/dhcp/cccccccc-cccc-cccc-cccc-cccccccccccc', mode=0o755)])
|
||||||
|
|
||||||
def _assert_disabled(self, lp):
|
def _assert_disabled(self, lp):
|
||||||
self.assertTrue(lp.process_monitor.unregister.called)
|
self.assertTrue(lp.process_monitor.unregister.called)
|
||||||
|
|
Loading…
Reference in New Issue