summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYushiro FURUKAWA <y.furukawa_2@jp.fujitsu.com>2020-09-08 23:54:45 +0900
committerYushiro FURUKAWA <y.furukawa_2@jp.fujitsu.com>2020-09-29 13:00:52 +0000
commit0e399f750ad88823c4d8c6355b70f23d98797ee8 (patch)
treefa0f6a34a2cfe81f319aa65a82690fc06eb9d19f
parent2151d660d2156c5f75986fbebe2fc7f35b0de81b (diff)
downloadironic-0e399f750ad88823c4d8c6355b70f23d98797ee8.tar.gz
Fix handling OctetString for pysnmp
This commit fixes getting MAC address while inspection for iRMC driver. To remove ord() in retrieving MAC address, it can avoid the following exception: TypeError: ord() expected string of length 1, but int found Also, this commit sets the following type of mock for UT. So, I add 'pysnmp'[1] into test-requirements.txt and lower-constraints.txt. * pysnmp.proto.rfc1902.OctetString * pysnmp.proto.rfc1902.Integer32 [1] https://bit.ly/3bDeTCH Change-Id: I1e013a93854e01a7060e1fc48aac091e7e9b74cb
-rw-r--r--ironic/drivers/modules/irmc/inspect.py2
-rw-r--r--ironic/tests/unit/drivers/modules/irmc/test_inspect.py23
-rw-r--r--lower-constraints.txt1
-rw-r--r--releasenotes/notes/fix-irmc-inspection-c9ae3864a96b2588.yaml4
-rw-r--r--test-requirements.txt1
5 files changed, 25 insertions, 6 deletions
diff --git a/ironic/drivers/modules/irmc/inspect.py b/ironic/drivers/modules/irmc/inspect.py
index 87b8fb928..4e148ee5c 100644
--- a/ironic/drivers/modules/irmc/inspect.py
+++ b/ironic/drivers/modules/irmc/inspect.py
@@ -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)
diff --git a/ironic/tests/unit/drivers/modules/irmc/test_inspect.py b/ironic/tests/unit/drivers/modules/irmc/test_inspect.py
index 0a6eeb399..9eb8dbb85 100644
--- a/ironic/tests/unit/drivers/modules/irmc/test_inspect.py
+++ b/ironic/tests/unit/drivers/modules/irmc/test_inspect.py
@@ -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)
diff --git a/lower-constraints.txt b/lower-constraints.txt
index 3d89103c0..b0c82690c 100644
--- a/lower-constraints.txt
+++ b/lower-constraints.txt
@@ -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
diff --git a/releasenotes/notes/fix-irmc-inspection-c9ae3864a96b2588.yaml b/releasenotes/notes/fix-irmc-inspection-c9ae3864a96b2588.yaml
new file mode 100644
index 000000000..e3e717b2a
--- /dev/null
+++ b/releasenotes/notes/fix-irmc-inspection-c9ae3864a96b2588.yaml
@@ -0,0 +1,4 @@
+---
+fixes:
+ - |
+ Fixed iRMC inspection for getting MAC address. \ No newline at end of file
diff --git a/test-requirements.txt b/test-requirements.txt
index bb792c420..fb628fe40 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -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