Don't run metadata proxy when it is not needed
Bug #1159015 Change-Id: I6063e75525a2a727d063bb1745c897ac8c4ba3e8
This commit is contained in:
parent
916d54d010
commit
a397df38c7
@ -64,8 +64,8 @@ class DhcpAgent(manager.Manager):
|
||||
help=_("Support Metadata requests on isolated networks.")),
|
||||
cfg.BoolOpt('enable_metadata_network', default=False,
|
||||
help=_("Allows for serving metadata requests from a "
|
||||
"dedicate network. Requires "
|
||||
"enable isolated_metadata = True ")),
|
||||
"dedicated network. Requires "
|
||||
"enable_isolated_metadata = True")),
|
||||
]
|
||||
|
||||
def __init__(self, host=None):
|
||||
@ -184,7 +184,8 @@ class DhcpAgent(manager.Manager):
|
||||
for subnet in network.subnets:
|
||||
if subnet.enable_dhcp:
|
||||
if self.call_driver('enable', network):
|
||||
if self.conf.use_namespaces:
|
||||
if (self.conf.use_namespaces and
|
||||
self.conf.enable_isolated_metadata):
|
||||
self.enable_isolated_metadata_proxy(network)
|
||||
self.cache.put(network)
|
||||
break
|
||||
@ -193,7 +194,8 @@ class DhcpAgent(manager.Manager):
|
||||
"""Disable DHCP for a network known to the agent."""
|
||||
network = self.cache.get_network_by_id(network_id)
|
||||
if network:
|
||||
if self.conf.use_namespaces:
|
||||
if (self.conf.use_namespaces and
|
||||
self.conf.enable_isolated_metadata):
|
||||
self.disable_isolated_metadata_proxy(network)
|
||||
if self.call_driver('disable', network):
|
||||
self.cache.remove(network)
|
||||
|
@ -439,13 +439,16 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
|
||||
cfg.CONF.reset()
|
||||
super(TestDhcpAgentEventHandler, self).tearDown()
|
||||
|
||||
def test_enable_dhcp_helper(self):
|
||||
def _enable_dhcp_helper(self, isolated_metadata=False):
|
||||
if isolated_metadata:
|
||||
cfg.CONF.set_override('enable_isolated_metadata', True)
|
||||
self.plugin.get_network_info.return_value = fake_network
|
||||
self.dhcp.enable_dhcp_helper(fake_network.id)
|
||||
self.plugin.assert_has_calls(
|
||||
[mock.call.get_network_info(fake_network.id)])
|
||||
self.call_driver.assert_called_once_with('enable', fake_network)
|
||||
self.cache.assert_has_calls([mock.call.put(fake_network)])
|
||||
if isolated_metadata:
|
||||
self.external_process.assert_has_calls([
|
||||
mock.call(
|
||||
cfg.CONF,
|
||||
@ -454,6 +457,14 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
|
||||
'qdhcp-12345678-1234-5678-1234567890ab'),
|
||||
mock.call().enable(mock.ANY)
|
||||
])
|
||||
else:
|
||||
self.assertFalse(self.external_process.call_count)
|
||||
|
||||
def test_enable_dhcp_helper_enable_isolated_metadata(self):
|
||||
self._enable_dhcp_helper(isolated_metadata=True)
|
||||
|
||||
def test_enable_dhcp_helper(self):
|
||||
self._enable_dhcp_helper()
|
||||
|
||||
def test_enable_dhcp_helper_down_network(self):
|
||||
self.plugin.get_network_info.return_value = fake_down_network
|
||||
@ -486,12 +497,15 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
|
||||
self.assertFalse(self.cache.called)
|
||||
self.assertFalse(self.external_process.called)
|
||||
|
||||
def test_disable_dhcp_helper_known_network(self):
|
||||
def _disable_dhcp_helper_known_network(self, isolated_metadata=False):
|
||||
if isolated_metadata:
|
||||
cfg.CONF.set_override('enable_isolated_metadata', True)
|
||||
self.cache.get_network_by_id.return_value = fake_network
|
||||
self.dhcp.disable_dhcp_helper(fake_network.id)
|
||||
self.cache.assert_has_calls(
|
||||
[mock.call.get_network_by_id(fake_network.id)])
|
||||
self.call_driver.assert_called_once_with('disable', fake_network)
|
||||
if isolated_metadata:
|
||||
self.external_process.assert_has_calls([
|
||||
mock.call(
|
||||
cfg.CONF,
|
||||
@ -500,16 +514,26 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
|
||||
'qdhcp-12345678-1234-5678-1234567890ab'),
|
||||
mock.call().disable()
|
||||
])
|
||||
else:
|
||||
self.assertFalse(self.external_process.call_count)
|
||||
|
||||
def test_disable_dhcp_helper_known_network_isolated_metadata(self):
|
||||
self._disable_dhcp_helper_known_network(isolated_metadata=True)
|
||||
|
||||
def test_disable_dhcp_helper_known_network(self):
|
||||
self._disable_dhcp_helper_known_network()
|
||||
|
||||
def test_disable_dhcp_helper_unknown_network(self):
|
||||
self.cache.get_network_by_id.return_value = None
|
||||
self.dhcp.disable_dhcp_helper('abcdef')
|
||||
self.cache.assert_has_calls(
|
||||
[mock.call.get_network_by_id('abcdef')])
|
||||
self.assertEqual(self.call_driver.call_count, 0)
|
||||
self.assertEqual(0, self.call_driver.call_count)
|
||||
self.assertFalse(self.external_process.called)
|
||||
|
||||
def test_disable_dhcp_helper_driver_failure(self):
|
||||
def _disable_dhcp_helper_driver_failure(self, isolated_metadata=False):
|
||||
if isolated_metadata:
|
||||
cfg.CONF.set_override('enable_isolated_metadata', True)
|
||||
self.cache.get_network_by_id.return_value = fake_network
|
||||
self.call_driver.return_value = False
|
||||
self.dhcp.disable_dhcp_helper(fake_network.id)
|
||||
@ -518,6 +542,7 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
|
||||
self.call_driver.assert_called_once_with('disable', fake_network)
|
||||
self.cache.assert_has_calls(
|
||||
[mock.call.get_network_by_id(fake_network.id)])
|
||||
if isolated_metadata:
|
||||
self.external_process.assert_has_calls([
|
||||
mock.call(
|
||||
cfg.CONF,
|
||||
@ -526,6 +551,14 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
|
||||
'qdhcp-12345678-1234-5678-1234567890ab'),
|
||||
mock.call().disable()
|
||||
])
|
||||
else:
|
||||
self.assertFalse(self.external_process.call_count)
|
||||
|
||||
def test_disable_dhcp_helper_driver_failure_isolated_metadata(self):
|
||||
self._disable_dhcp_helper_driver_failure(isolated_metadata=True)
|
||||
|
||||
def test_disable_dhcp_helper_driver_failure(self):
|
||||
self._disable_dhcp_helper_driver_failure()
|
||||
|
||||
def test_enable_isolated_metadata_proxy(self):
|
||||
class_path = 'quantum.agent.linux.external_process.ProcessManager'
|
||||
|
Loading…
Reference in New Issue
Block a user