Merge "Fix handling OctetString for pysnmp"

This commit is contained in:
Zuul 2020-09-30 09:06:34 +00:00 committed by Gerrit Code Review
commit 672c61938e
5 changed files with 25 additions and 6 deletions

View File

@ -110,7 +110,7 @@ def _get_mac_addresses(node):
d_info['irmc_snmp_security'])
node_classes = snmp_client.get_next(NODE_CLASS_OID)
mac_addresses = [':'.join(['%02x' % ord(x) for x in mac])
mac_addresses = [':'.join(['%02x' % 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)

View File

@ -18,6 +18,8 @@ Test class for iRMC Inspection Driver
from unittest import mock
from pysnmp.proto import rfc1902
from ironic.common import exception
from ironic.common import states
from ironic.common import utils
@ -38,12 +40,23 @@ class IRMCInspectInternalMethodsTestCase(test_common.BaseIRMCTest):
@mock.patch('ironic.drivers.modules.irmc.inspect.snmp.SNMPClient',
spec_set=True, autospec=True)
def test__get_mac_addresses(self, snmpclient_mock):
# NOTE(yushiro): In pysnmp 4.4.12, SNMPClient returns following type:
# node classes: pysnmp.proto.rfc1902.Integer32
# mac addresses: pysnmp.proto.rfc1902.OctetString
snmpclient_mock.return_value = mock.Mock(
**{'get_next.side_effect': [[2, 2, 7],
['\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']
**{'get_next.side_effect': [
[
rfc1902.Integer32(2),
rfc1902.Integer32(2),
rfc1902.Integer32(7)
], [
rfc1902.OctetString('\x90\x1b\x0e\xa5\x70\x37'),
rfc1902.OctetString('\x90\x1b\x0e\xa5\x70\x38'),
rfc1902.OctetString('\x90\x1b\x0e\xa5\x70\x39')
]]}
)
inspected_macs = ['90:1b:0e:a5:70:37', '90:1b:0e:a5:70:38']
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
result = irmc_inspect._get_mac_addresses(task.node)

View File

@ -95,6 +95,7 @@ pyOpenSSL==19.1.0
pyparsing==2.4.7
pyperclip==1.8.0
pysendfile==2.0.0
pysnmp==4.4.12
python-cinderclient==3.3.0
python-dateutil==2.8.1
python-editor==1.0.4

View File

@ -0,0 +1,4 @@
---
fixes:
- |
Fixed iRMC inspection for getting MAC address.

View File

@ -16,6 +16,7 @@ testtools>=2.2.0 # MIT
WebTest>=2.0.27 # MIT
bashate>=0.5.1 # Apache-2.0
pycodestyle>=2.0.0,<2.6.0 # MIT
pysnmp>=4.4.12
flake8-import-order>=0.17.1 # LGPLv3
Pygments>=2.2.0 # BSD
bandit!=1.6.0,>=1.1.0,<2.0.0 # Apache-2.0