[Functional] Fix mocks of the create_dhcp_port method
In dhcp agent functional tests test_force_metadata_for_subnet_create_delete and test_enable_isolated_metadata_for_subnet_create_delete it may happen that it will hit xlock error from iptables-restore command. Normally it is handled properly and DeviceManager.setup() method is then called again. But in those functional tests there was no mock of the create_dhcp_port but there was mock for get_dhcp_port and update_dhcp_port instead. Because of that when during first call of setup() method iptables exception was raised, during the second call of the setup() method wrong object was put in the network.ports and test was failing due to that. Workflow of that test is like below: 1. Call DeviceManager.setup() method 2. This method as one of the first steps will call _update_dhcp_port which will replace dhcp port prepared for test with some other mock, 3. During first run "port" variable in DeviceManager.setup() method is correct so all will work fine but if we hit iptables xlock error, setup() method will be called again and 4. Now "port" local variable is already update by _update_dhcp_port method thus test setup() method will fail as interface_name is now wrong. To avoid such issue this patch changed dhcp_port_mock to be "proper" DictModel() object instead of mock.Mock() and ensures that this will be set in network.ports even after "create_dhcp_port" will be called. Closes-Bug: #1922684 Change-Id: I3f7dfdcbb3a54252bb1b3d2fa50eebcac3d00cba
This commit is contained in:
parent
da2cc29ec0
commit
6533337716
|
@ -358,17 +358,12 @@ class DHCPAgentOVSTestCase(DHCPAgentOVSTestFramework):
|
|||
new_network.subnets.append(dhcp_enabled_ipv4_subnet)
|
||||
|
||||
self.mock_plugin_api.get_network_info.return_value = new_network
|
||||
fixed_ip_mock = mock.Mock(
|
||||
ip_address='192.168.10.2',
|
||||
subnet_id=dhcp_enabled_ipv4_subnet.id)
|
||||
dhcp_port_mock = mock.Mock(
|
||||
dns_assignment={},
|
||||
extra_dhcp_opts=[],
|
||||
fixed_ips=[fixed_ip_mock],
|
||||
id=new_network.ports[0].id,
|
||||
dhcp_port_mock = self.create_port_dict(
|
||||
network.id, dhcp_enabled_ipv4_subnet.id,
|
||||
mac_address=str(self._DHCP_PORT_MAC_ADDRESS))
|
||||
self.mock_plugin_api.get_dhcp_port.return_value = dhcp_port_mock
|
||||
self.mock_plugin_api.update_dhcp_port.return_value = dhcp_port_mock
|
||||
self.mock_plugin_api.create_dhcp_port.return_value = dhcp_port_mock
|
||||
network.ports = []
|
||||
new_network.ports = []
|
||||
|
||||
self.agent.refresh_dhcp_helper(network.id)
|
||||
# Metadata proxy should be spawned for the newly added subnet
|
||||
|
|
Loading…
Reference in New Issue