Merge "ironic/tests/drivers/irmc: Add spec_set & autospec=True"
This commit is contained in:
commit
4a7f1c9b1a
@ -23,6 +23,7 @@ from ironic.drivers.modules.irmc import common as irmc_common
|
||||
from ironic.tests.conductor import utils as mgr_utils
|
||||
from ironic.tests.db import base as db_base
|
||||
from ironic.tests.db import utils as db_utils
|
||||
from ironic.tests.drivers import third_party_driver_mock_specs as mock_specs
|
||||
from ironic.tests.objects import utils as obj_utils
|
||||
|
||||
|
||||
@ -116,7 +117,8 @@ class IRMCCommonMethodsTestCase(db_base.DbTestCase):
|
||||
driver='fake_irmc',
|
||||
driver_info=self.info)
|
||||
|
||||
@mock.patch.object(irmc_common, 'scci')
|
||||
@mock.patch.object(irmc_common, 'scci',
|
||||
spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC)
|
||||
def test_get_irmc_client(self, mock_scci):
|
||||
self.info['irmc_port'] = 80
|
||||
self.info['irmc_auth_method'] = 'digest'
|
||||
@ -146,7 +148,8 @@ class IRMCCommonMethodsTestCase(db_base.DbTestCase):
|
||||
expected_info = dict(self.info, **ipmi_info)
|
||||
self.assertEqual(expected_info, actual_info)
|
||||
|
||||
@mock.patch.object(irmc_common, 'scci')
|
||||
@mock.patch.object(irmc_common, 'scci',
|
||||
spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC)
|
||||
def test_get_irmc_report(self, mock_scci):
|
||||
self.info['irmc_port'] = 80
|
||||
self.info['irmc_auth_method'] = 'digest'
|
||||
|
@ -31,6 +31,7 @@ from ironic.drivers import utils as driver_utils
|
||||
from ironic.tests.conductor import utils as mgr_utils
|
||||
from ironic.tests.db import base as db_base
|
||||
from ironic.tests.db import utils as db_utils
|
||||
from ironic.tests.drivers import third_party_driver_mock_specs as mock_specs
|
||||
from ironic.tests.objects import utils as obj_utils
|
||||
|
||||
INFO_DICT = db_utils.get_test_irmc_info()
|
||||
@ -56,14 +57,14 @@ class IRMCManagementTestCase(db_base.DbTestCase):
|
||||
shared=True) as task:
|
||||
self.assertEqual(expected, task.driver.get_properties())
|
||||
|
||||
@mock.patch.object(irmc_common, 'parse_driver_info')
|
||||
@mock.patch.object(irmc_common, 'parse_driver_info', autospec=True)
|
||||
def test_validate(self, mock_drvinfo):
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
shared=True) as task:
|
||||
task.driver.management.validate(task)
|
||||
mock_drvinfo.assert_called_once_with(task.node)
|
||||
|
||||
@mock.patch.object(irmc_common, 'parse_driver_info')
|
||||
@mock.patch.object(irmc_common, 'parse_driver_info', autospec=True)
|
||||
def test_validate_fail(self, mock_drvinfo):
|
||||
side_effect = exception.InvalidParameterValue("Invalid Input")
|
||||
mock_drvinfo.side_effect = side_effect
|
||||
@ -81,7 +82,8 @@ class IRMCManagementTestCase(db_base.DbTestCase):
|
||||
self.assertEqual(sorted(expected), sorted(task.driver.management.
|
||||
get_supported_boot_devices()))
|
||||
|
||||
@mock.patch.object(ipmitool.IPMIManagement, 'set_boot_device')
|
||||
@mock.patch.object(ipmitool.IPMIManagement, 'set_boot_device',
|
||||
autospec=True)
|
||||
def test_management_interface_set_boot_device_no_mode_ok(
|
||||
self,
|
||||
set_boot_device_mock):
|
||||
@ -90,11 +92,12 @@ class IRMCManagementTestCase(db_base.DbTestCase):
|
||||
shared=False) as task:
|
||||
task.driver.management.set_boot_device(task, boot_devices.PXE)
|
||||
set_boot_device_mock.assert_called_once_with(
|
||||
task,
|
||||
task.driver.management, task,
|
||||
boot_devices.PXE,
|
||||
False)
|
||||
|
||||
@mock.patch.object(ipmitool.IPMIManagement, 'set_boot_device')
|
||||
@mock.patch.object(ipmitool.IPMIManagement, 'set_boot_device',
|
||||
autospec=True)
|
||||
def test_management_interface_set_boot_device_bios_ok(
|
||||
self,
|
||||
set_boot_device_mock):
|
||||
@ -103,7 +106,7 @@ class IRMCManagementTestCase(db_base.DbTestCase):
|
||||
driver_utils.add_node_capability(task, 'boot_mode', 'bios')
|
||||
task.driver.management.set_boot_device(task, boot_devices.PXE)
|
||||
set_boot_device_mock.assert_called_once_with(
|
||||
task,
|
||||
task.driver.management, task,
|
||||
boot_devices.PXE,
|
||||
False)
|
||||
|
||||
@ -189,8 +192,9 @@ class IRMCManagementTestCase(db_base.DbTestCase):
|
||||
task,
|
||||
"unknown")
|
||||
|
||||
@mock.patch.object(irmc_management, 'scci')
|
||||
@mock.patch.object(irmc_common, 'get_irmc_report')
|
||||
@mock.patch.object(irmc_management, 'scci',
|
||||
spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC)
|
||||
@mock.patch.object(irmc_common, 'get_irmc_report', autospec=True)
|
||||
def test_management_interface_get_sensors_data_scci_ok(self,
|
||||
mock_get_irmc_report,
|
||||
mock_scci):
|
||||
@ -236,8 +240,9 @@ class IRMCManagementTestCase(db_base.DbTestCase):
|
||||
}
|
||||
self.assertEqual(expected, sensor_dict)
|
||||
|
||||
@mock.patch.object(irmc_management, 'scci')
|
||||
@mock.patch.object(irmc_common, 'get_irmc_report')
|
||||
@mock.patch.object(irmc_management, 'scci',
|
||||
spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC)
|
||||
@mock.patch.object(irmc_common, 'get_irmc_report', autospec=True)
|
||||
def test_management_interface_get_sensors_data_scci_ng(self,
|
||||
mock_get_irmc_report,
|
||||
mock_scci):
|
||||
@ -257,7 +262,8 @@ class IRMCManagementTestCase(db_base.DbTestCase):
|
||||
|
||||
self.assertEqual(len(sensor_dict), 0)
|
||||
|
||||
@mock.patch.object(ipmitool.IPMIManagement, 'get_sensors_data')
|
||||
@mock.patch.object(ipmitool.IPMIManagement, 'get_sensors_data',
|
||||
autospec=True)
|
||||
def test_management_interface_get_sensors_data_ipmitool_ok(
|
||||
self,
|
||||
get_sensors_data_mock):
|
||||
@ -265,9 +271,10 @@ class IRMCManagementTestCase(db_base.DbTestCase):
|
||||
with task_manager.acquire(self.context, self.node.uuid) as task:
|
||||
task.node.driver_info['irmc_sensor_method'] = 'ipmitool'
|
||||
task.driver.management.get_sensors_data(task)
|
||||
get_sensors_data_mock.assert_called_once_with(task)
|
||||
get_sensors_data_mock.assert_called_once_with(
|
||||
task.driver.management, task)
|
||||
|
||||
@mock.patch.object(irmc_common, 'get_irmc_report')
|
||||
@mock.patch.object(irmc_common, 'get_irmc_report', autospec=True)
|
||||
def test_management_interface_get_sensors_data_exception1(
|
||||
self,
|
||||
get_irmc_report_mock):
|
||||
|
@ -32,7 +32,7 @@ INFO_DICT = db_utils.get_test_irmc_info()
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
@mock.patch.object(irmc_common, 'get_irmc_client')
|
||||
@mock.patch.object(irmc_common, 'get_irmc_client', autospec=True)
|
||||
class IRMCPowerInternalMethodsTestCase(db_base.DbTestCase):
|
||||
|
||||
def setUp(self):
|
||||
@ -110,14 +110,14 @@ class IRMCPowerTestCase(db_base.DbTestCase):
|
||||
for prop in irmc_common.COMMON_PROPERTIES:
|
||||
self.assertIn(prop, properties)
|
||||
|
||||
@mock.patch.object(irmc_common, 'parse_driver_info')
|
||||
@mock.patch.object(irmc_common, 'parse_driver_info', autospec=True)
|
||||
def test_validate(self, mock_drvinfo):
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
shared=True) as task:
|
||||
task.driver.power.validate(task)
|
||||
mock_drvinfo.assert_called_once_with(task.node)
|
||||
|
||||
@mock.patch.object(irmc_common, 'parse_driver_info')
|
||||
@mock.patch.object(irmc_common, 'parse_driver_info', autospec=True)
|
||||
def test_validate_fail(self, mock_drvinfo):
|
||||
side_effect = exception.InvalidParameterValue("Invalid Input")
|
||||
mock_drvinfo.side_effect = side_effect
|
||||
@ -127,7 +127,8 @@ class IRMCPowerTestCase(db_base.DbTestCase):
|
||||
task.driver.power.validate,
|
||||
task)
|
||||
|
||||
@mock.patch('ironic.drivers.modules.irmc.power.ipmitool.IPMIPower')
|
||||
@mock.patch('ironic.drivers.modules.irmc.power.ipmitool.IPMIPower',
|
||||
autospec=True)
|
||||
def test_get_power_state(self, mock_IPMIPower):
|
||||
ipmi_power = mock_IPMIPower.return_value
|
||||
ipmi_power.get_power_state.return_value = states.POWER_ON
|
||||
@ -137,7 +138,7 @@ class IRMCPowerTestCase(db_base.DbTestCase):
|
||||
task.driver.power.get_power_state(task))
|
||||
ipmi_power.get_power_state.assert_called_once_with(task)
|
||||
|
||||
@mock.patch.object(irmc_power, '_set_power_state')
|
||||
@mock.patch.object(irmc_power, '_set_power_state', autospec=True)
|
||||
def test_set_power_state(self, mock_set_power):
|
||||
mock_set_power.return_value = states.POWER_ON
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
@ -145,22 +146,24 @@ class IRMCPowerTestCase(db_base.DbTestCase):
|
||||
task.driver.power.set_power_state(task, states.POWER_ON)
|
||||
mock_set_power.assert_called_once_with(task, states.POWER_ON)
|
||||
|
||||
@mock.patch.object(irmc_power, '_set_power_state')
|
||||
@mock.patch.object(irmc_power.IRMCPower, 'get_power_state')
|
||||
@mock.patch.object(irmc_power, '_set_power_state', autospec=True)
|
||||
@mock.patch.object(irmc_power.IRMCPower, 'get_power_state', autospec=True)
|
||||
def test_reboot_reboot(self, mock_get_power, mock_set_power):
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
shared=False) as task:
|
||||
mock_get_power.return_value = states.POWER_ON
|
||||
task.driver.power.reboot(task)
|
||||
mock_get_power.assert_called_once_with(task)
|
||||
mock_get_power.assert_called_once_with(
|
||||
task.driver.power, task)
|
||||
mock_set_power.assert_called_once_with(task, states.REBOOT)
|
||||
|
||||
@mock.patch.object(irmc_power, '_set_power_state')
|
||||
@mock.patch.object(irmc_power.IRMCPower, 'get_power_state')
|
||||
@mock.patch.object(irmc_power, '_set_power_state', autospec=True)
|
||||
@mock.patch.object(irmc_power.IRMCPower, 'get_power_state', autospec=True)
|
||||
def test_reboot_power_on(self, mock_get_power, mock_set_power):
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
shared=False) as task:
|
||||
mock_get_power.return_value = states.POWER_OFF
|
||||
task.driver.power.reboot(task)
|
||||
mock_get_power.assert_called_once_with(task)
|
||||
mock_get_power.assert_called_once_with(
|
||||
task.driver.power, task)
|
||||
mock_set_power.assert_called_once_with(task, states.POWER_ON)
|
||||
|
@ -27,3 +27,18 @@ PYWSMAN_SPEC = (
|
||||
'wsman_transport_set_verify_host',
|
||||
'wsman_transport_set_verify_peer',
|
||||
)
|
||||
|
||||
# scciclient
|
||||
SCCICLIENT_SPEC = (
|
||||
'irmc',
|
||||
)
|
||||
|
||||
SCCICLIENT_IRMC_SCCI_SPEC = (
|
||||
'POWER_OFF',
|
||||
'POWER_ON',
|
||||
'POWER_RESET',
|
||||
'SCCIClientError',
|
||||
'get_client',
|
||||
'get_report',
|
||||
'get_sensor_data',
|
||||
)
|
||||
|
@ -155,10 +155,11 @@ if 'ironic.drivers.modules.snmp' in sys.modules:
|
||||
# the optional drivers.modules.irmc module
|
||||
scciclient = importutils.try_import('scciclient')
|
||||
if not scciclient:
|
||||
mock_scciclient = mock.MagicMock()
|
||||
mock_scciclient = mock.MagicMock(spec_set=mock_specs.SCCICLIENT_SPEC)
|
||||
sys.modules['scciclient'] = mock_scciclient
|
||||
sys.modules['scciclient.irmc'] = mock_scciclient.irmc
|
||||
sys.modules['scciclient.irmc.scci'] = mock.MagicMock(
|
||||
spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC,
|
||||
POWER_OFF=mock.sentinel.POWER_OFF,
|
||||
POWER_ON=mock.sentinel.POWER_ON,
|
||||
POWER_RESET=mock.sentinel.POWER_RESET)
|
||||
|
Loading…
x
Reference in New Issue
Block a user