summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/drivers/modules
diff options
context:
space:
mode:
authorDuc Truong <duct@nvidia.com>2023-02-15 20:40:24 +0000
committerDuc Truong <duct@nvidia.com>2023-03-01 16:44:40 -0800
commit005f21c0df8634563f1e7eac7bb1a6b00df9ea4f (patch)
tree2c5c6ff0d533d662b9ec2b18f3372065683142ac /ironic/tests/unit/drivers/modules
parent381a0eac427dd532e9033ac04f0bd629064b6df0 (diff)
downloadironic-005f21c0df8634563f1e7eac7bb1a6b00df9ea4f.tar.gz
Fix auth_protocol and priv_protocol for SNMP v3
SNMP driver was using the wrong dictionary key to retrieve auth_protocol and priv_protocol from driver info. As a result, the SNMP client was created with empty strings for both those fields. Any nodes configured to use SNMP v3 with those fields failed because the SNMP driver was unable to perform power related operations due to authentication error. - Use correct keys for snmp auth_protocol and priv_protocol when creating SNMP client - Sanitize snmp auth_key and priv_key in API results Story: 2010613 Task: 47535 Change-Id: I5efd3c9f79a021f1a8e613c3d13b6596a7972672
Diffstat (limited to 'ironic/tests/unit/drivers/modules')
-rw-r--r--ironic/tests/unit/drivers/modules/test_snmp.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/ironic/tests/unit/drivers/modules/test_snmp.py b/ironic/tests/unit/drivers/modules/test_snmp.py
index 5391d7ac5..e1b6fc1df 100644
--- a/ironic/tests/unit/drivers/modules/test_snmp.py
+++ b/ironic/tests/unit/drivers/modules/test_snmp.py
@@ -46,6 +46,41 @@ class SNMPClientTestCase(base.TestCase):
self.value = 'value'
@mock.patch.object(pysnmp, 'SnmpEngine', autospec=True)
+ def test__get_client(self, mock_snmpengine):
+ driver_info = db_utils.get_test_snmp_info(
+ snmp_address=self.address,
+ snmp_port=self.port,
+ snmp_user='test-user',
+ snmp_auth_protocol='sha',
+ snmp_auth_key='test-auth-key',
+ snmp_priv_protocol='aes',
+ snmp_priv_key='test-priv-key',
+ snmp_context_engine_id='test-engine-id',
+ snmp_context_name='test-context-name',
+ snmp_version='3')
+ node = obj_utils.get_test_node(
+ self.context,
+ driver_info=driver_info)
+ info = snmp._parse_driver_info(node)
+
+ client = snmp._get_client(info)
+
+ mock_snmpengine.assert_called_once_with()
+ self.assertEqual(self.address, client.address)
+ self.assertEqual(int(self.port), client.port)
+ self.assertEqual(snmp.SNMP_V3, client.version)
+ self.assertNotIn('read_community', client.__dict__)
+ self.assertNotIn('write_community', client.__dict__)
+ self.assertEqual('test-user', client.user)
+ self.assertEqual(pysnmp.usmHMACSHAAuthProtocol, client.auth_proto)
+ self.assertEqual('test-auth-key', client.auth_key)
+ self.assertEqual(pysnmp.usmAesCfb128Protocol, client.priv_proto)
+ self.assertEqual('test-priv-key', client.priv_key)
+ self.assertEqual('test-engine-id', client.context_engine_id)
+ self.assertEqual('test-context-name', client.context_name)
+ self.assertEqual(mock_snmpengine.return_value, client.snmp_engine)
+
+ @mock.patch.object(pysnmp, 'SnmpEngine', autospec=True)
def test___init__(self, mock_snmpengine):
client = snmp.SNMPClient(self.address, self.port, snmp.SNMP_V1)
mock_snmpengine.assert_called_once_with()