Fix races in advertise_address unit tests

This was testing that _check_for_iscsi was called, which is part of
evaluate_hardware_support for the in-tree hardware manager.
evaluate_hardware_support is called at hardware manager instantiation,
which can happen when dispatch_to_managers is called. The hardware
manager instances are cached, so calling dispatch_to_managers won't
always invoke _check_for_iscsi. As such, these tests were intermittently
failing.

Mock _check_for_iscsi at the class level for these tests (since it's
unrelated), and don't check that it was called.

Change-Id: Iefca50c4c231c5eafd199bf8da6649bc3008a8fa
This commit is contained in:
Jim Rollenhagen 2016-07-26 10:22:41 -04:00
parent e9dd5d3db0
commit 7ab53e34b0

@ -410,6 +410,7 @@ class TestAgentStandalone(test_base.BaseTestCase):
self.assertFalse(self.agent.api_client.lookup_node.called)
@mock.patch.object(hardware, '_check_for_iscsi', lambda: None)
@mock.patch.object(hardware.GenericHardwareManager, '_wait_for_disks',
lambda self: None)
@mock.patch.object(socket, 'gethostbyname', autospec=True)
@ -439,11 +440,10 @@ class TestAdvertiseAddress(test_base.BaseTestCase):
self.assertFalse(mock_exec.called)
self.assertFalse(mock_gethostbyname.called)
@mock.patch.object(hardware, '_check_for_iscsi', autospec=True)
@mock.patch.object(hardware.GenericHardwareManager, 'get_ipv4_addr',
autospec=True)
def test_with_network_interface(self, mock_get_ipv4, mock_check_for_iscsi,
mock_exec, mock_gethostbyname):
def test_with_network_interface(self, mock_get_ipv4, mock_exec,
mock_gethostbyname):
self.agent.network_interface = 'em1'
mock_get_ipv4.return_value = '1.2.3.4'
@ -453,13 +453,10 @@ class TestAdvertiseAddress(test_base.BaseTestCase):
mock_get_ipv4.assert_called_once_with(mock.ANY, 'em1')
self.assertFalse(mock_exec.called)
self.assertFalse(mock_gethostbyname.called)
self.assertTrue(mock_check_for_iscsi.called)
@mock.patch.object(hardware, '_check_for_iscsi', autospec=True)
@mock.patch.object(hardware.GenericHardwareManager, 'get_ipv4_addr',
autospec=True)
def test_with_network_interface_failed(self, mock_get_ipv4,
mock_check_for_iscsi,
mock_exec,
mock_gethostbyname):
self.agent.network_interface = 'em1'
@ -471,7 +468,6 @@ class TestAdvertiseAddress(test_base.BaseTestCase):
mock_get_ipv4.assert_called_once_with(mock.ANY, 'em1')
self.assertFalse(mock_exec.called)
self.assertFalse(mock_gethostbyname.called)
self.assertTrue(mock_check_for_iscsi.called)
def test_route_with_ip(self, mock_exec, mock_gethostbyname):
self.agent.api_url = 'http://1.2.1.2:8081/v1'