Use prolianutils module for ilo driver tests

This change adds all components on proliantutils module
to third_party_driver_mocks. This enables the ilo driver
tests to use the proliantutils module when it is available, and
use the mocks when proliantutils module is not available. This
commit modifies all the ilo driver tests to use the imported
proliantutils module (rather than mocking it completely).

Change-Id: Ief88b194374585c7cfc3c3804b4ea04620fe21e7
Closes-bug: 1416421
This commit is contained in:
Ramakrishnan G 2015-01-30 15:29:54 +00:00
parent dc5b9c65d0
commit c6f4431994
4 changed files with 75 additions and 93 deletions

View File

@ -110,13 +110,13 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
self.node = obj_utils.create_test_node(self.context,
driver='fake_ilo', driver_info=self.info)
@mock.patch.object(ilo_common, 'ilo_client')
@mock.patch.object(ilo_client, 'IloClient')
def test_get_ilo_object(self, ilo_client_mock):
self.info['client_timeout'] = 60
self.info['client_port'] = 443
ilo_client_mock.IloClient.return_value = 'ilo_object'
ilo_client_mock.return_value = 'ilo_object'
returned_ilo_object = ilo_common.get_ilo_object(self.node)
ilo_client_mock.IloClient.assert_called_with(
ilo_client_mock.assert_called_with(
self.info['ilo_address'],
self.info['ilo_username'],
self.info['ilo_password'],
@ -124,12 +124,12 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
self.info['client_port'])
self.assertEqual('ilo_object', returned_ilo_object)
@mock.patch.object(ilo_common, 'ilo_client')
def test_get_ilo_license(self, ilo_client_mock):
@mock.patch.object(ilo_common, 'get_ilo_object')
def test_get_ilo_license(self, get_ilo_object_mock):
ilo_advanced_license = {'LICENSE_TYPE': 'iLO 3 Advanced'}
ilo_standard_license = {'LICENSE_TYPE': 'iLO 3'}
ilo_mock_object = ilo_client_mock.IloClient.return_value
ilo_mock_object = get_ilo_object_mock.return_value
ilo_mock_object.get_all_licenses.return_value = ilo_advanced_license
license = ilo_common.get_ilo_license(self.node)
@ -139,11 +139,11 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
license = ilo_common.get_ilo_license(self.node)
self.assertEqual(ilo_common.STANDARD_LICENSE, license)
@mock.patch.object(ilo_common, 'ilo_client')
def test_get_ilo_license_fail(self, ilo_client_mock):
ilo_client_mock.IloError = Exception
ilo_mock_object = ilo_client_mock.IloClient.return_value
ilo_mock_object.get_all_licenses.side_effect = [Exception()]
@mock.patch.object(ilo_common, 'get_ilo_object')
def test_get_ilo_license_fail(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
exc = ilo_client.IloError('error')
ilo_mock_object.get_all_licenses.side_effect = exc
self.assertRaises(exception.IloOperationError,
ilo_common.get_ilo_license,
self.node)
@ -241,10 +241,9 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
files_info=files_info,
parameters=deploy_args)
@mock.patch.object(ilo_common, 'ilo_client')
def test_attach_vmedia(self, ilo_client_mock):
ilo_client_mock.IloError = Exception
ilo_mock_object = ilo_client_mock.IloClient.return_value
@mock.patch.object(ilo_common, 'get_ilo_object')
def test_attach_vmedia(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
insert_media_mock = ilo_mock_object.insert_virtual_media
set_status_mock = ilo_mock_object.set_vm_status
@ -253,9 +252,15 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
set_status_mock.assert_called_once_with(device='FLOPPY',
boot_option='CONNECT', write_protect='YES')
set_status_mock.side_effect = Exception()
@mock.patch.object(ilo_common, 'get_ilo_object')
def test_attach_vmedia_fails(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
set_status_mock = ilo_mock_object.set_vm_status
exc = ilo_client.IloError('error')
set_status_mock.side_effect = exc
self.assertRaises(exception.IloOperationError,
ilo_common.attach_vmedia, self.node, 'FLOPPY', 'url')
ilo_common.attach_vmedia, self.node,
'FLOPPY', 'url')
@mock.patch.object(ilo_common, 'get_ilo_object')
def test_set_boot_mode(self, get_ilo_object_mock):
@ -279,17 +284,15 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
get_pending_boot_mode_mock.assert_called_once_with()
self.assertFalse(ilo_object_mock.set_pending_boot_mode.called)
@mock.patch.object(ilo_common, 'ilo_client')
@mock.patch.object(ilo_common, 'get_ilo_object')
def test_set_boot_mode_with_IloOperationError(self,
get_ilo_object_mock,
ilo_client_mock):
get_ilo_object_mock):
ilo_object_mock = get_ilo_object_mock.return_value
get_pending_boot_mode_mock = ilo_object_mock.get_pending_boot_mode
get_pending_boot_mode_mock.return_value = 'UEFI'
set_pending_boot_mode_mock = ilo_object_mock.set_pending_boot_mode
ilo_client_mock.IloError = Exception
set_pending_boot_mode_mock.side_effect = Exception
exc = ilo_client.IloError('error')
set_pending_boot_mode_mock.side_effect = exc
self.assertRaises(exception.IloOperationError,
ilo_common.set_boot_mode, self.node, 'bios')
get_ilo_object_mock.assert_called_once_with(self.node)
@ -298,12 +301,9 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
@mock.patch.object(driver_utils, 'rm_node_capability')
@mock.patch.object(driver_utils, 'add_node_capability')
@mock.patch.object(ilo_common, 'get_ilo_object')
@mock.patch.object(ilo_common, 'ilo_client')
def test_update_boot_mode_capability(self, ilo_client_mock,
get_ilo_object_mock,
def test_update_boot_mode_capability(self, get_ilo_object_mock,
add_node_capability_mock,
rm_node_capability_mock):
ilo_client_mock.IloCommandNotSupportedError = Exception
ilo_mock_obj = get_ilo_object_mock.return_value
ilo_mock_obj.get_pending_boot_mode.return_value = 'legacy'
@ -319,11 +319,9 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
@mock.patch.object(driver_utils, 'add_node_capability')
@mock.patch.object(ilo_common, 'get_ilo_object')
@mock.patch.object(ilo_common, 'ilo_client')
def test_update_boot_mode_capability_unknown(self, ilo_client_mock,
get_ilo_object_mock,
add_node_capability_mock):
ilo_client_mock.IloCommandNotSupportedError = Exception
def test_update_boot_mode_capability_unknown(self,
get_ilo_object_mock,
add_node_capability_mock):
ilo_mock_obj = get_ilo_object_mock.return_value
ilo_mock_obj.get_pending_boot_mode.return_value = 'UNKNOWN'
set_pending_boot_mode_mock = ilo_mock_obj.set_pending_boot_mode
@ -340,13 +338,12 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
@mock.patch.object(driver_utils, 'add_node_capability')
@mock.patch.object(ilo_common, 'get_ilo_object')
@mock.patch.object(ilo_common, 'ilo_client')
def test_update_boot_mode_capability_legacy(self, ilo_client_mock,
def test_update_boot_mode_capability_legacy(self,
get_ilo_object_mock,
add_node_capability_mock):
ilo_client_mock.IloCommandNotSupportedError = Exception
ilo_mock_obj = get_ilo_object_mock.return_value
ilo_mock_obj.get_pending_boot_mode.side_effect = Exception
exc = ilo_client.IloCommandNotSupportedError('error')
ilo_mock_obj.get_pending_boot_mode.side_effect = exc
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:

View File

@ -23,7 +23,6 @@ from ironic.common import boot_devices
from ironic.common import exception
from ironic.conductor import task_manager
from ironic.drivers.modules.ilo import common as ilo_common
from ironic.drivers.modules.ilo import management as ilo_management
from ironic.drivers.modules import ipmitool
from ironic.tests.conductor import utils as mgr_utils
from ironic.tests.db import base as db_base
@ -96,12 +95,11 @@ class IloManagementTestCase(db_base.DbTestCase):
ilo_mock.get_one_time_boot.assert_called_once_with()
ilo_mock.get_persistent_boot_device.assert_called_once_with()
@mock.patch.object(ilo_management, 'ilo_client')
@mock.patch.object(ilo_common, 'get_ilo_object')
def test_get_boot_device_fail(self, get_ilo_object_mock, ilo_mgmt_mock):
ilo_mgmt_mock.IloError = Exception
def test_get_boot_device_fail(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
ilo_mock_object.get_one_time_boot.side_effect = Exception()
exc = ilo_client.IloError('error')
ilo_mock_object.get_one_time_boot.side_effect = exc
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
@ -110,14 +108,12 @@ class IloManagementTestCase(db_base.DbTestCase):
task)
ilo_mock_object.get_one_time_boot.assert_called_once_with()
@mock.patch.object(ilo_management, 'ilo_client')
@mock.patch.object(ilo_common, 'get_ilo_object')
def test_get_boot_device_persistent_fail(self, get_ilo_object_mock,
ilo_mgmt_mock):
ilo_mgmt_mock.IloError = Exception
def test_get_boot_device_persistent_fail(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
ilo_mock_object.get_one_time_boot.return_value = 'Normal'
ilo_mock_object.get_persistent_boot_device.side_effect = Exception()
exc = ilo_client.IloError('error')
ilo_mock_object.get_persistent_boot_device.side_effect = exc
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
@ -148,12 +144,11 @@ class IloManagementTestCase(db_base.DbTestCase):
ilo_mock.update_persistent_boot.assert_called_once_with(
['NETWORK'])
@mock.patch.object(ilo_management, 'ilo_client')
@mock.patch.object(ilo_common, 'get_ilo_object')
def test_set_boot_device_fail(self, get_ilo_object_mock, ilo_mgmt_mock):
ilo_mgmt_mock.IloError = Exception
def test_set_boot_device_fail(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
ilo_mock_object.set_one_time_boot.side_effect = Exception()
exc = ilo_client.IloError('error')
ilo_mock_object.set_one_time_boot.side_effect = exc
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
@ -162,13 +157,11 @@ class IloManagementTestCase(db_base.DbTestCase):
task, boot_devices.PXE)
ilo_mock_object.set_one_time_boot.assert_called_once_with('NETWORK')
@mock.patch.object(ilo_management, 'ilo_client')
@mock.patch.object(ilo_common, 'get_ilo_object')
def test_set_boot_device_persistent_fail(self, get_ilo_object_mock,
ilo_mgmt_mock):
ilo_mgmt_mock.IloError = Exception
def test_set_boot_device_persistent_fail(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
ilo_mock_object.update_persistent_boot.side_effect = Exception()
exc = ilo_client.IloError('error')
ilo_mock_object.update_persistent_boot.side_effect = exc
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:

View File

@ -38,8 +38,7 @@ INFO_DICT = db_utils.get_test_ilo_info()
CONF = cfg.CONF
@mock.patch.object(ilo_common, 'ilo_client')
@mock.patch.object(ilo_power, 'ilo_client')
@mock.patch.object(ilo_common, 'get_ilo_object')
class IloPowerInternalMethodsTestCase(db_base.DbTestCase):
def setUp(self):
@ -53,9 +52,8 @@ class IloPowerInternalMethodsTestCase(db_base.DbTestCase):
CONF.set_override('power_retry', 2, 'ilo')
CONF.set_override('power_wait', 0, 'ilo')
def test__get_power_state(self, power_ilo_client_mock,
common_ilo_client_mock):
ilo_mock_object = common_ilo_client_mock.IloClient.return_value
def test__get_power_state(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
ilo_mock_object.get_host_power_status.return_value = 'ON'
self.assertEqual(
@ -68,32 +66,28 @@ class IloPowerInternalMethodsTestCase(db_base.DbTestCase):
ilo_mock_object.get_host_power_status.return_value = 'ERROR'
self.assertEqual(states.ERROR, ilo_power._get_power_state(self.node))
def test__get_power_state_fail(self, power_ilo_client_mock,
common_ilo_client_mock):
power_ilo_client_mock.IloError = Exception
ilo_mock_object = common_ilo_client_mock.IloClient.return_value
ilo_mock_object.get_host_power_status.side_effect = [Exception()]
def test__get_power_state_fail(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
exc = ilo_client.IloError('error')
ilo_mock_object.get_host_power_status.side_effect = exc
self.assertRaises(exception.IloOperationError,
ilo_power._get_power_state,
self.node)
ilo_power._get_power_state,
self.node)
ilo_mock_object.get_host_power_status.assert_called_once_with()
def test__set_power_state_invalid_state(self, power_ilo_client_mock,
common_ilo_client_mock):
def test__set_power_state_invalid_state(self, get_ilo_object_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
power_ilo_client_mock.IloError = Exception
self.assertRaises(exception.IloOperationError,
self.assertRaises(exception.InvalidParameterValue,
ilo_power._set_power_state,
task,
states.ERROR)
def test__set_power_state_reboot_fail(self, power_ilo_client_mock,
common_ilo_client_mock):
power_ilo_client_mock.IloError = Exception
ilo_mock_object = common_ilo_client_mock.IloClient.return_value
ilo_mock_object.reset_server.side_effect = Exception()
def test__set_power_state_reboot_fail(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
exc = ilo_client.IloError('error')
ilo_mock_object.reset_server.side_effect = exc
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
@ -103,10 +97,8 @@ class IloPowerInternalMethodsTestCase(db_base.DbTestCase):
states.REBOOT)
ilo_mock_object.reset_server.assert_called_once_with()
def test__set_power_state_reboot_ok(self, power_ilo_client_mock,
common_ilo_client_mock):
power_ilo_client_mock.IloError = Exception
ilo_mock_object = common_ilo_client_mock.IloClient.return_value
def test__set_power_state_reboot_ok(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
ilo_mock_object.get_host_power_status.side_effect = ['ON', 'OFF', 'ON']
with task_manager.acquire(self.context, self.node.uuid,
@ -115,10 +107,8 @@ class IloPowerInternalMethodsTestCase(db_base.DbTestCase):
ilo_mock_object.reset_server.assert_called_once_with()
def test__set_power_state_off_fail(self, power_ilo_client_mock,
common_ilo_client_mock):
power_ilo_client_mock.IloError = Exception
ilo_mock_object = common_ilo_client_mock.IloClient.return_value
def test__set_power_state_off_fail(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
ilo_mock_object.get_host_power_status.return_value = 'ON'
with task_manager.acquire(self.context, self.node.uuid,
@ -131,10 +121,8 @@ class IloPowerInternalMethodsTestCase(db_base.DbTestCase):
ilo_mock_object.get_host_power_status.assert_called_with()
ilo_mock_object.hold_pwr_btn.assert_called_once_with()
def test__set_power_state_on_ok(self, power_ilo_client_mock,
common_ilo_client_mock):
power_ilo_client_mock.IloError = Exception
ilo_mock_object = common_ilo_client_mock.IloClient.return_value
def test__set_power_state_on_ok(self, get_ilo_object_mock):
ilo_mock_object = get_ilo_object_mock.return_value
ilo_mock_object.get_host_power_status.side_effect = ['OFF', 'ON']
target_state = states.POWER_ON
@ -147,7 +135,7 @@ class IloPowerInternalMethodsTestCase(db_base.DbTestCase):
@mock.patch.object(manager_utils, 'node_set_boot_device')
@mock.patch.object(ilo_common, 'setup_vmedia_for_boot')
def test__attach_boot_iso(self, setup_vmedia_mock, set_boot_device_mock,
power_ilo_client_mock, common_ilo_client_mock):
get_ilo_object_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
task.node.instance_info['ilo_boot_iso'] = 'boot-iso'

View File

@ -84,11 +84,15 @@ if 'ironic.drivers.modules.ipminative' in sys.modules:
proliantutils = importutils.try_import('proliantutils')
if not proliantutils:
mock_proliant_utils = mock.MagicMock()
sys.modules['proliantutils'] = mock_proliant_utils
if 'ironic.drivers.ilo' in sys.modules:
reload(sys.modules['ironic.drivers.ilo'])
proliantutils = mock.MagicMock()
sys.modules['proliantutils'] = proliantutils
sys.modules['proliantutils.ilo'] = proliantutils.ilo
sys.modules['proliantutils.ilo.ribcl'] = proliantutils.ilo.ribcl
proliantutils.ilo.ribcl.IloError = type('IloError', (Exception,), {})
command_exception = type('IloCommandNotSupportedError', (Exception,), {})
proliantutils.ilo.ribcl.IloCommandNotSupportedError = command_exception
if 'ironic.drivers.ilo' in sys.modules:
reload(sys.modules['ironic.drivers.ilo'])
# attempt to load the external 'pywsman' library, which is required by