From 21fd100a98c152086193607cd311c2ee03b82643 Mon Sep 17 00:00:00 2001 From: Carl Baldwin Date: Fri, 28 Jun 2013 03:07:00 +0000 Subject: [PATCH] Update code to properly use dict returned from get_gateway. Calling get_gateway was a late addition to my code to add a default route in the DHCP namespace. The code did not properly handle the dict returned from that method. This changes it to properly extract the 'gateway' attribute from the dict. Change-Id: I9823a31feee7ab333c277fc6e78f366408393155 Fixes: Bug #1195543 --- quantum/agent/dhcp_agent.py | 2 ++ quantum/tests/unit/test_dhcp_agent.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/quantum/agent/dhcp_agent.py b/quantum/agent/dhcp_agent.py index 2c51861e7..5e54c4bb9 100644 --- a/quantum/agent/dhcp_agent.py +++ b/quantum/agent/dhcp_agent.py @@ -547,6 +547,8 @@ class DeviceManager(object): """ device = self._get_device(network) gateway = device.route.get_gateway() + if gateway: + gateway = gateway['gateway'] for subnet in network.subnets: skip_subnet = ( diff --git a/quantum/tests/unit/test_dhcp_agent.py b/quantum/tests/unit/test_dhcp_agent.py index 4f0f63951..3005eff0d 100644 --- a/quantum/tests/unit/test_dhcp_agent.py +++ b/quantum/tests/unit/test_dhcp_agent.py @@ -1227,7 +1227,7 @@ class TestDeviceManager(base.BaseTestCase): def test_set_default_route_no_subnet_delete_gateway(self): device = mock.Mock() - device.route.get_gateway.return_value = '192.168.0.1' + device.route.get_gateway.return_value = dict(gateway='192.168.0.1') # Try a namespace but no subnet where a gateway needs to be deleted. dh = self._get_device_manager_with_mock_device(cfg.CONF, device) @@ -1241,7 +1241,7 @@ class TestDeviceManager(base.BaseTestCase): def test_set_default_route_no_gateway(self): device = mock.Mock() - device.route.get_gateway.return_value = '192.168.0.1' + device.route.get_gateway.return_value = dict(gateway='192.168.0.1') # Try a subnet with no gateway dh = self._get_device_manager_with_mock_device(cfg.CONF, device) @@ -1255,7 +1255,7 @@ class TestDeviceManager(base.BaseTestCase): def test_set_default_route_do_nothing(self): device = mock.Mock() - device.route.get_gateway.return_value = '192.168.0.1' + device.route.get_gateway.return_value = dict(gateway='192.168.0.1') # Try a subnet where the gateway doesn't change. Should do nothing. dh = self._get_device_manager_with_mock_device(cfg.CONF, device) @@ -1269,7 +1269,7 @@ class TestDeviceManager(base.BaseTestCase): def test_set_default_route_change_gateway(self): device = mock.Mock() - device.route.get_gateway.return_value = '192.168.0.2' + device.route.get_gateway.return_value = dict(gateway='192.168.0.2') # Try a subnet with a gateway this is different than the current. dh = self._get_device_manager_with_mock_device(cfg.CONF, device) -- 2.45.2