From df06a848f12d2d4712fc2fc59976d0ddc44dbddc Mon Sep 17 00:00:00 2001 From: Naohiro Tamura Date: Thu, 31 Mar 2016 01:01:17 +0900 Subject: [PATCH] Normalize MAC OctetString to fix InvalidMAC exception This patch adds a step of MAC OctetString normalization to fix InvalidMAC exception in iRMC inspection module. Closes-Bug: #1564190 Change-Id: Ic2a5aaf2beadf06d69864ac7ea0d7a9aadebdc83 --- ironic/drivers/modules/irmc/inspect.py | 3 ++- ironic/tests/unit/drivers/modules/irmc/test_inspect.py | 6 +++--- releasenotes/notes/fix-mac-address-48060f9e2847a38c.yaml | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/fix-mac-address-48060f9e2847a38c.yaml diff --git a/ironic/drivers/modules/irmc/inspect.py b/ironic/drivers/modules/irmc/inspect.py index 8eece97b85..cc192fd97e 100644 --- a/ironic/drivers/modules/irmc/inspect.py +++ b/ironic/drivers/modules/irmc/inspect.py @@ -99,7 +99,8 @@ def _get_mac_addresses(node): d_info['irmc_snmp_security']) node_classes = snmp_client.get_next(NODE_CLASS_OID) - mac_addresses = snmp_client.get_next(MAC_ADDRESS_OID) + mac_addresses = [':'.join(['%02x' % ord(x) for x in mac]) + for mac in snmp_client.get_next(MAC_ADDRESS_OID)] return [a for c, a in zip(node_classes, mac_addresses) if c == NODE_CLASS_OID_VALUE['primary']] diff --git a/ironic/tests/unit/drivers/modules/irmc/test_inspect.py b/ironic/tests/unit/drivers/modules/irmc/test_inspect.py index cf89b89e19..c74f51edb5 100644 --- a/ironic/tests/unit/drivers/modules/irmc/test_inspect.py +++ b/ironic/tests/unit/drivers/modules/irmc/test_inspect.py @@ -49,9 +49,9 @@ class IRMCInspectInternalMethodsTestCase(db_base.DbTestCase): def test__get_mac_addresses(self, snmpclient_mock): snmpclient_mock.return_value = mock.Mock( **{'get_next.side_effect': [[2, 2, 7], - ['aa:aa:aa:aa:aa:aa', - 'bb:bb:bb:bb:bb:bb', - 'cc:cc:cc:cc:cc:cc']]}) + ['\xaa\xaa\xaa\xaa\xaa\xaa', + '\xbb\xbb\xbb\xbb\xbb\xbb', + '\xcc\xcc\xcc\xcc\xcc\xcc']]}) inspected_macs = ['aa:aa:aa:aa:aa:aa', 'bb:bb:bb:bb:bb:bb'] with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: diff --git a/releasenotes/notes/fix-mac-address-48060f9e2847a38c.yaml b/releasenotes/notes/fix-mac-address-48060f9e2847a38c.yaml new file mode 100644 index 0000000000..4484598678 --- /dev/null +++ b/releasenotes/notes/fix-mac-address-48060f9e2847a38c.yaml @@ -0,0 +1,3 @@ +--- +fixes: + - This fixes InvalidMAC exception of iRMC out-of-band inspection.