From dc7e4d26ae795b34a9cab44e3c047452198b997e Mon Sep 17 00:00:00 2001 From: Dongcan Ye Date: Fri, 17 May 2019 05:04:47 +0000 Subject: [PATCH] pxe_filter: fix get blacklist error According to [1], the Port address and extra field in the same level. Method _get_blacklist should pass port list instead port.address list for InfiniBand mapping. [1] https://github.com/openstack/ironic/blob/master/ironic/objects/port.py Story: 2005729 Task: 31077 Change-Id: Iedc321c840f18fc1aa856b857da2c35318a538ae --- ironic_inspector/pxe_filter/iptables.py | 4 ++-- ironic_inspector/test/unit/test_iptables.py | 18 +++++++++++------- ...-filter-get-blacklist-2dde59d51c1d010f.yaml | 6 ++++++ 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/fix-pxe-filter-get-blacklist-2dde59d51c1d010f.yaml diff --git a/ironic_inspector/pxe_filter/iptables.py b/ironic_inspector/pxe_filter/iptables.py index 62480c654..37c37ed2e 100644 --- a/ironic_inspector/pxe_filter/iptables.py +++ b/ironic_inspector/pxe_filter/iptables.py @@ -232,9 +232,9 @@ def _ib_mac_to_rmac_mapping(ports): def _get_blacklist(ironic): - ports = [port.address for port in + ports = [port for port in ir_utils.call_with_retries(ironic.port.list, limit=0, fields=['address', 'extra']) if port.address not in node_cache.active_macs()] _ib_mac_to_rmac_mapping(ports) - return ports + return [port.address for port in ports] diff --git a/ironic_inspector/test/unit/test_iptables.py b/ironic_inspector/test/unit/test_iptables.py index 1e86190a5..d874a5cc4 100644 --- a/ironic_inspector/test/unit/test_iptables.py +++ b/ironic_inspector/test/unit/test_iptables.py @@ -386,10 +386,11 @@ class TestGetBlacklist(test_base.BaseTest): self.mock_ironic = mock.Mock() def test_active_port(self): - self.mock_ironic.port.list.return_value = [ + mock_ports_list = [ mock.Mock(address='foo'), mock.Mock(address='bar'), ] + self.mock_ironic.port.list.return_value = mock_ports_list self.mock_active_macs.return_value = {'foo'} ports = iptables._get_blacklist(self.mock_ironic) @@ -397,16 +398,18 @@ class TestGetBlacklist(test_base.BaseTest): self.assertEqual(['bar'], ports) self.mock_ironic.port.list.assert_called_once_with( limit=0, fields=['address', 'extra']) - self.mock__ib_mac_to_rmac_mapping.assert_called_once_with(ports) + self.mock__ib_mac_to_rmac_mapping.assert_called_once_with( + [mock_ports_list[1]]) @mock.patch('time.sleep', lambda _x: None) def test_retry_on_port_list_failure(self): + mock_ports_list = [ + mock.Mock(address='foo'), + mock.Mock(address='bar'), + ] self.mock_ironic.port.list.side_effect = [ ironic_exc.ConnectionRefused('boom'), - [ - mock.Mock(address='foo'), - mock.Mock(address='bar'), - ] + mock_ports_list ] self.mock_active_macs.return_value = {'foo'} @@ -415,4 +418,5 @@ class TestGetBlacklist(test_base.BaseTest): self.assertEqual(['bar'], ports) self.mock_ironic.port.list.assert_called_with( limit=0, fields=['address', 'extra']) - self.mock__ib_mac_to_rmac_mapping.assert_called_once_with(ports) + self.mock__ib_mac_to_rmac_mapping.assert_called_once_with( + [mock_ports_list[1]]) diff --git a/releasenotes/notes/fix-pxe-filter-get-blacklist-2dde59d51c1d010f.yaml b/releasenotes/notes/fix-pxe-filter-get-blacklist-2dde59d51c1d010f.yaml new file mode 100644 index 000000000..ca28a6a7f --- /dev/null +++ b/releasenotes/notes/fix-pxe-filter-get-blacklist-2dde59d51c1d010f.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes an issue while mapping port InfiniBand MAC + address to EthernetOverInfiniBand MAC. Prior to this fix, + it will fail to map and raise an exception.