Merge "Add 169.254.169.254 when enable force_metadata"

This commit is contained in:
Jenkins 2016-06-29 23:23:39 +00:00 committed by Gerrit Code Review
commit 0953371e12
2 changed files with 44 additions and 12 deletions

View File

@ -1259,7 +1259,7 @@ class DeviceManager(object):
net = netaddr.IPNetwork(subnet.cidr)
ip_cidrs.append('%s/%s' % (gateway, net.prefixlen))
if self.conf.enable_isolated_metadata:
if self.conf.force_metadata or self.conf.enable_isolated_metadata:
ip_cidrs.append(METADATA_DEFAULT_CIDR)
self.driver.init_l3(interface_name, ip_cidrs,

View File

@ -2024,6 +2024,8 @@ class TestDeviceManager(TestConfBase):
# Create DeviceManager.
self.conf.register_opt(cfg.BoolOpt('enable_isolated_metadata',
default=False))
self.conf.register_opt(cfg.BoolOpt('force_metadata',
default=False))
plugin = mock.Mock()
device = mock.Mock()
mock_IPDevice.return_value = device
@ -2093,15 +2095,16 @@ class TestDeviceManager(TestConfBase):
self._test_setup(self.mock_load_interface_driver,
self.mock_ip_lib, use_gateway_ips=True)
def test_setup_reserved(self):
"""Test reserved port case of DeviceManager's DHCP port setup
logic.
"""
def _test_setup_reserved(self, enable_isolated_metadata=False,
force_metadata=False):
with mock.patch.object(dhcp.ip_lib, 'IPDevice') as mock_IPDevice:
# Create DeviceManager.
self.conf.register_opt(cfg.BoolOpt('enable_isolated_metadata',
default=False))
self.conf.register_opt(
cfg.BoolOpt('enable_isolated_metadata',
default=enable_isolated_metadata))
self.conf.register_opt(
cfg.BoolOpt('force_metadata',
default=force_metadata))
plugin = mock.Mock()
device = mock.Mock()
mock_IPDevice.return_value = device
@ -2128,19 +2131,48 @@ class TestDeviceManager(TestConfBase):
plugin.update_dhcp_port.assert_called_with(reserved_port.id,
mock.ANY)
except_ips = ['192.168.0.6/24']
if enable_isolated_metadata or force_metadata:
except_ips.append(dhcp.METADATA_DEFAULT_CIDR)
mgr.driver.init_l3.assert_called_with('ns-XXX',
['192.168.0.6/24'],
except_ips,
namespace='qdhcp-ns')
def test_setup_reserved_and_disable_metadata(self):
"""Test reserved port case of DeviceManager's DHCP port setup
logic which metadata disabled.
"""
self._test_setup_reserved()
def test_setup_reserved_with_isolated_metadata_enable(self):
"""Test reserved port case of DeviceManager's DHCP port setup
logic which isolated_ metadata enabled.
"""
self._test_setup_reserved(enable_isolated_metadata=True)
def test_setup_reserved_with_force_metadata_enable(self):
"""Test reserved port case of DeviceManager's DHCP port setup
logic which force_metadata enabled.
"""
self._test_setup_reserved(force_metadata=True)
def test_setup_reserved_and_enable_metadata(self):
"""Test reserved port case of DeviceManager's DHCP port setup
logic which both isolated_metadata and force_metadata enabled.
"""
self._test_setup_reserved(enable_isolated_metadata=True,
force_metadata=True)
def test_setup_reserved_2(self):
"""Test scenario where a network has two reserved ports, and
update_dhcp_port fails for the first of those.
"""
with mock.patch.object(dhcp.ip_lib, 'IPDevice') as mock_IPDevice:
# Create DeviceManager.
self.conf.register_opt(cfg.BoolOpt('enable_isolated_metadata',
default=False))
self.conf.register_opt(
cfg.BoolOpt('enable_isolated_metadata', default=False))
self.conf.register_opt(
cfg.BoolOpt('force_metadata', default=False))
plugin = mock.Mock()
device = mock.Mock()
mock_IPDevice.return_value = device