summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/drivers
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-11-29 04:32:18 +0000
committerGerrit Code Review <review@openstack.org>2022-11-29 04:32:18 +0000
commit7a7ca835431c88a3717a4c44e604117acf82f057 (patch)
treef48a313d187c2a06428d501021f410ac455d2ba1 /ironic/tests/unit/drivers
parent5b194c2d424634e5cc08a59095bacb4c852af1a3 (diff)
parente482d4012ce006c485b572ddba275da3365d345f (diff)
downloadironic-7a7ca835431c88a3717a4c44e604117acf82f057.tar.gz
Merge "Add SNMPv3 authentication functionality" into bugfix/19.0
Diffstat (limited to 'ironic/tests/unit/drivers')
-rw-r--r--ironic/tests/unit/drivers/modules/irmc/test_boot.py5
-rw-r--r--ironic/tests/unit/drivers/modules/irmc/test_common.py238
2 files changed, 235 insertions, 8 deletions
diff --git a/ironic/tests/unit/drivers/modules/irmc/test_boot.py b/ironic/tests/unit/drivers/modules/irmc/test_boot.py
index 54f92967e..a1252621e 100644
--- a/ironic/tests/unit/drivers/modules/irmc/test_boot.py
+++ b/ironic/tests/unit/drivers/modules/irmc/test_boot.py
@@ -41,6 +41,7 @@ from ironic.drivers.modules.irmc import common as irmc_common
from ironic.drivers.modules.irmc import management as irmc_management
from ironic.drivers.modules import pxe
from ironic.drivers.modules import pxe_base
+from ironic.drivers.modules import snmp
from ironic.tests import base
from ironic.tests.unit.db import utils as db_utils
from ironic.tests.unit.drivers.modules.irmc import test_common
@@ -60,10 +61,10 @@ PARSED_IFNO = {
'irmc_client_timeout': 60,
'irmc_snmp_community': 'public',
'irmc_snmp_port': 161,
- 'irmc_snmp_version': 'v2c',
- 'irmc_snmp_security': None,
+ 'irmc_snmp_version': snmp.SNMP_V2C,
'irmc_sensor_method': 'ipmitool',
'irmc_verify_ca': True,
+ 'irmc_snmp_security': None,
}
diff --git a/ironic/tests/unit/drivers/modules/irmc/test_common.py b/ironic/tests/unit/drivers/modules/irmc/test_common.py
index c5c70bf95..4263351ac 100644
--- a/ironic/tests/unit/drivers/modules/irmc/test_common.py
+++ b/ironic/tests/unit/drivers/modules/irmc/test_common.py
@@ -23,8 +23,10 @@ from oslo_config import cfg
from oslo_utils import uuidutils
from ironic.common import exception
+from ironic.common import utils
from ironic.conductor import task_manager
from ironic.drivers.modules.irmc import common as irmc_common
+from ironic.drivers.modules import snmp
from ironic.tests.unit.db import base as db_base
from ironic.tests.unit.db import utils as db_utils
from ironic.tests.unit.drivers import third_party_driver_mock_specs \
@@ -55,7 +57,9 @@ class BaseIRMCTest(db_base.DbTestCase):
class IRMCValidateParametersTestCase(BaseIRMCTest):
- def test_parse_driver_info(self):
+ @mock.patch.object(utils, 'is_fips_enabled',
+ return_value=False, autospec=True)
+ def test_parse_driver_info(self, mock_check_fips):
info = irmc_common.parse_driver_info(self.node)
self.assertEqual('1.2.3.4', info['irmc_address'])
@@ -65,13 +69,81 @@ class IRMCValidateParametersTestCase(BaseIRMCTest):
self.assertEqual(80, info['irmc_port'])
self.assertEqual('digest', info['irmc_auth_method'])
self.assertEqual('ipmitool', info['irmc_sensor_method'])
- self.assertEqual('v2c', info['irmc_snmp_version'])
+ self.assertEqual(snmp.SNMP_V2C, info['irmc_snmp_version'])
self.assertEqual(161, info['irmc_snmp_port'])
self.assertEqual('public', info['irmc_snmp_community'])
self.assertFalse(info['irmc_snmp_security'])
self.assertTrue(info['irmc_verify_ca'])
- def test_parse_driver_option_default(self):
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_snmpv3_support_auth(self, mock_scci_module):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_user'] = 'admin0'
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
+
+ scci_version_list = ['0.10.1', '0.11.3', '0.12.2']
+ for ver in scci_version_list:
+ with self.subTest(ver=ver):
+ mock_scci_module.__version__ = ver
+ info = irmc_common.parse_driver_info(self.node)
+
+ self.assertEqual('1.2.3.4', info['irmc_address'])
+ self.assertEqual('admin0', info['irmc_username'])
+ self.assertEqual('fake0', info['irmc_password'])
+ self.assertEqual(60, info['irmc_client_timeout'])
+ self.assertEqual(80, info['irmc_port'])
+ self.assertEqual('digest', info['irmc_auth_method'])
+ self.assertEqual('ipmitool', info['irmc_sensor_method'])
+ self.assertEqual(snmp.SNMP_V3, info['irmc_snmp_version'])
+ self.assertEqual(161, info['irmc_snmp_port'])
+ self.assertEqual('public', info['irmc_snmp_community'])
+ self.assertEqual('admin0', info['irmc_snmp_user'])
+ self.assertEqual(snmp.snmp_auth_protocols['sha'],
+ info['irmc_snmp_auth_proto'])
+ self.assertEqual('valid_key', info['irmc_snmp_auth_password'])
+ self.assertEqual(snmp.snmp_priv_protocols['aes'],
+ info['irmc_snmp_priv_proto'])
+ self.assertEqual('valid_key', info['irmc_snmp_priv_password'])
+
+ @mock.patch.object(irmc_common, 'LOG', autospec=True)
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_snmpv3_not_support_auth(self, mock_scci_module,
+ mock_LOG):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_user'] = 'admin0'
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
+
+ scci_version_list = ['0.10.0', '0.11.0', '0.11.2',
+ '0.12.0', '0.12.1', '0.13.0']
+ for ver in scci_version_list:
+ with self.subTest(ver=ver):
+ mock_scci_module.__version__ = ver
+ info = irmc_common.parse_driver_info(self.node)
+
+ self.assertEqual('1.2.3.4', info['irmc_address'])
+ self.assertEqual('admin0', info['irmc_username'])
+ self.assertEqual('fake0', info['irmc_password'])
+ self.assertEqual(60, info['irmc_client_timeout'])
+ self.assertEqual(80, info['irmc_port'])
+ self.assertEqual('digest', info['irmc_auth_method'])
+ self.assertEqual('ipmitool', info['irmc_sensor_method'])
+ self.assertEqual(snmp.SNMP_V3, info['irmc_snmp_version'])
+ self.assertEqual(161, info['irmc_snmp_port'])
+ self.assertEqual('public', info['irmc_snmp_community'])
+ self.assertEqual('admin0', info['irmc_snmp_user'])
+ self.assertEqual('admin0', info['irmc_snmp_security'])
+ self.assertNotIn('irmc_snmp_auth_proto', info)
+ self.assertNotIn('irmc_snmp_auth_password', info)
+ self.assertNotIn('irmc_snmp_priv_proto', info)
+ self.assertNotIn('irmc_snmp_priv_password', info)
+ mock_LOG.warning.assert_called_once()
+ mock_LOG.warning.reset_mock()
+
+ @mock.patch.object(utils, 'is_fips_enabled',
+ return_value=False, autospec=True)
+ def test_parse_driver_option_default(self, mock_check_fips):
self.node.driver_info = {
"irmc_address": "1.2.3.4",
"irmc_username": "admin0",
@@ -133,8 +205,16 @@ class IRMCValidateParametersTestCase(BaseIRMCTest):
self.assertRaises(exception.InvalidParameterValue,
irmc_common.parse_driver_info, self.node)
+ @mock.patch.object(utils, 'is_fips_enabled',
+ return_value=True, autospec=True)
+ def test_parse_driver_info_invalid_snmp_version_fips(self,
+ mock_check_fips):
+ self.assertRaises(exception.InvalidParameterValue,
+ irmc_common.parse_driver_info, self.node)
+ self.assertEqual(1, mock_check_fips.call_count)
+
def test_parse_driver_info_invalid_snmp_port(self):
- self.node.driver_info['irmc_snmp_port'] = '161'
+ self.node.driver_info['irmc_snmp_port'] = '161p'
self.assertRaises(exception.InvalidParameterValue,
irmc_common.parse_driver_info, self.node)
@@ -144,18 +224,164 @@ class IRMCValidateParametersTestCase(BaseIRMCTest):
self.assertRaises(exception.InvalidParameterValue,
irmc_common.parse_driver_info, self.node)
+ def test_parse_driver_info_missing_snmp_user(self):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
+ self.assertRaises(exception.MissingParameterValue,
+ irmc_common.parse_driver_info, self.node)
+
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_missing_snmp_auth_password(self,
+ mock_scci_module):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_user'] = 'admin0'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
+ scci_version_list = ['0.10.1', '0.11.3', '0.12.2']
+ for ver in scci_version_list:
+ with self.subTest(ver=ver):
+ mock_scci_module.__version__ = ver
+ self.assertRaises(exception.MissingParameterValue,
+ irmc_common.parse_driver_info, self.node)
+
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_missing_snmp_priv_password(self,
+ mock_scci_module):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_user'] = 'admin0'
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ scci_version_list = ['0.10.1', '0.11.3', '0.12.2']
+ for ver in scci_version_list:
+ with self.subTest(ver=ver):
+ mock_scci_module.__version__ = ver
+ self.assertRaises(exception.MissingParameterValue,
+ irmc_common.parse_driver_info, self.node)
+
+ @mock.patch.object(irmc_common, 'LOG', autospec=True)
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_ignoring_snmp_security(self, mock_scci_module,
+ mock_LOG):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_user'] = 'admin0'
+ self.node.driver_info['irmc_snmp_security'] = 'security'
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
+ mock_scci_module.__version__ = '0.12.2'
+ info = irmc_common.parse_driver_info(self.node)
+ self.assertEqual('admin0', info['irmc_snmp_user'])
+ mock_LOG.warning.assert_called_once()
+ mock_LOG.warning.reset_mock
+
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_using_snmp_security_(self, mock_scci_module):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_security'] = 'admin0'
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
+ mock_scci_module.__version__ = '0.12.2'
+ info = irmc_common.parse_driver_info(self.node)
+ self.assertEqual('admin0', info['irmc_snmp_user'])
+
def test_parse_driver_info_invalid_snmp_security(self):
self.node.driver_info['irmc_snmp_version'] = 'v3'
self.node.driver_info['irmc_snmp_security'] = 100
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
self.assertRaises(exception.InvalidParameterValue,
irmc_common.parse_driver_info, self.node)
- def test_parse_driver_info_empty_snmp_security(self):
+ def test_parse_driver_info_invalid_snmp_user(self):
self.node.driver_info['irmc_snmp_version'] = 'v3'
- self.node.driver_info['irmc_snmp_security'] = ''
+ self.node.driver_info['irmc_snmp_user'] = 100
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
self.assertRaises(exception.InvalidParameterValue,
irmc_common.parse_driver_info, self.node)
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_invalid_snmp_auth_password(self,
+ mock_scci_module):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_user'] = 'admin0'
+ self.node.driver_info['irmc_snmp_auth_password'] = 100
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
+ scci_version_list = ['0.10.1', '0.11.3', '0.12.2']
+ for ver in scci_version_list:
+ with self.subTest(ver=ver):
+ mock_scci_module.__version__ = ver
+ self.assertRaises(exception.InvalidParameterValue,
+ irmc_common.parse_driver_info, self.node)
+
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_short_snmp_auth_password(self,
+ mock_scci_module):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_user'] = 'admin0'
+ self.node.driver_info['irmc_snmp_auth_password'] = 'short'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
+ scci_version_list = ['0.10.1', '0.11.3', '0.12.2']
+ for ver in scci_version_list:
+ with self.subTest(ver=ver):
+ mock_scci_module.__version__ = ver
+ self.assertRaises(exception.InvalidParameterValue,
+ irmc_common.parse_driver_info, self.node)
+
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_invalid_snmp_priv_password(self,
+ mock_scci_module):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_user'] = 'admin0'
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_password'] = 100
+ scci_version_list = ['0.10.1', '0.11.3', '0.12.2']
+ for ver in scci_version_list:
+ with self.subTest(ver=ver):
+ mock_scci_module.__version__ = ver
+ self.assertRaises(exception.InvalidParameterValue,
+ irmc_common.parse_driver_info, self.node)
+
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_short_snmp_priv_password(self,
+ mock_scci_module):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_user'] = 'admin0'
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'short'
+ scci_version_list = ['0.10.1', '0.11.3', '0.12.2']
+ for ver in scci_version_list:
+ with self.subTest(ver=ver):
+ mock_scci_module.__version__ = ver
+ self.assertRaises(exception.InvalidParameterValue,
+ irmc_common.parse_driver_info, self.node)
+
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_invalid_snmp_auth_proto(self, mock_scci_module):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_user'] = 'admin0'
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_auth_proto'] = 'invalid'
+ scci_version_list = ['0.10.1', '0.11.3', '0.12.2']
+ for ver in scci_version_list:
+ with self.subTest(ver=ver):
+ mock_scci_module.__version__ = ver
+ self.assertRaises(exception.InvalidParameterValue,
+ irmc_common.parse_driver_info, self.node)
+
+ @mock.patch.object(irmc_common, 'scci_mod', spec_set=['__version__'])
+ def test_parse_driver_info_invalid_snmp_priv_proto(self, mock_scci_module):
+ self.node.driver_info['irmc_snmp_version'] = 'v3'
+ self.node.driver_info['irmc_snmp_user'] = 'admin0'
+ self.node.driver_info['irmc_snmp_auth_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_password'] = 'valid_key'
+ self.node.driver_info['irmc_snmp_priv_proto'] = 'invalid'
+ scci_version_list = ['0.10.1', '0.11.3', '0.12.2']
+ for ver in scci_version_list:
+ with self.subTest(ver=ver):
+ mock_scci_module.__version__ = ver
+ self.assertRaises(exception.InvalidParameterValue,
+ irmc_common.parse_driver_info, self.node)
+
@mock.patch.object(os.path, 'isabs', return_value=True, autospec=True)
@mock.patch.object(os.path, 'isdir', return_value=True, autospec=True)
def test_parse_driver_info_dir_path_verify_ca(self, mock_isdir,