Fix idrac Job.state renamed to Job.status

In python-dracclient 0.1.0, the Job.state field was renamed to
Job.status. The old name was left for backwards compatibility, but was
removed in python-dracclient 2.0.0.

This change uses the new field name, to avoid an AttributeError in
python-dracclient 2.0.0 onwards.

Also modifies the drac unit tests to use the Job, RAIDController,
PhysicalDisk and VirtualDisk objects from the dracclient library when
available.

Change-Id: I074347748e1ce0f749f47ce30d4cb123a70dc2b8
Story: 2005225
Task: 30007
This commit is contained in:
Mark Goddard 2019-03-13 17:25:02 +00:00
parent 601ab180b3
commit 82cd13177c
6 changed files with 88 additions and 43 deletions

View File

@ -841,9 +841,9 @@ class DracRAID(base.RAIDInterface):
for config_job_id in raid_config_job_ids:
config_job = drac_job.get_job(node, job_id=config_job_id)
if config_job.state == 'Completed':
if config_job.status == 'Completed':
finished_job_ids.append(config_job_id)
elif config_job.state == 'Failed':
elif config_job.status == 'Failed':
finished_job_ids.append(config_job_id)
self._set_raid_config_job_failure(node)

View File

@ -43,9 +43,9 @@ class DracJobTestCase(test_utils.BaseDracTest):
'start_time': '00000101000000',
'until_time': 'TIME_NA',
'message': 'Job in progress',
'state': 'Running',
'status': 'Running',
'percent_complete': 34}
self.job = test_utils.dict_to_namedtuple(values=self.job_dict)
self.job = test_utils.make_job(self.job_dict)
def test_get_job(self, mock_get_drac_client):
mock_client = mock.Mock()
@ -127,9 +127,9 @@ class DracVendorPassthruJobTestCase(test_utils.BaseDracTest):
'start_time': '00000101000000',
'until_time': 'TIME_NA',
'message': 'Job in progress',
'state': 'Running',
'status': 'Running',
'percent_complete': 34}
self.job = test_utils.dict_to_namedtuple(values=self.job_dict)
self.job = test_utils.make_job(self.job_dict)
def test_list_unfinished_jobs(self, mock_get_drac_client):
mock_client = mock.Mock()

View File

@ -42,7 +42,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase):
'start_time': '00000101000000',
'until_time': 'TIME_NA',
'message': 'Job in progress',
'state': 'Running',
'status': 'Running',
'percent_complete': 34}
self.virtual_disk = {
'id': 'Disk.Virtual.0:RAID.Integrated.1-1',
@ -51,8 +51,8 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase):
'controller': 'RAID.Integrated.1-1',
'raid_level': '1',
'size_mb': 571776,
'state': 'ok',
'raid_state': 'online',
'status': 'ok',
'raid_status': 'online',
'span_depth': 1,
'span_length': 2,
'pending_operations': None
@ -153,7 +153,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase):
# mock task
task = mock.Mock(node=self.node, context=self.context)
# mock dracclient.get_job
self.job['state'] = 'Completed'
self.job['status'] = 'Completed'
mock_client = mock.Mock()
mock_get_drac_client.return_value = mock_client
mock_client.get_job.return_value = test_utils.dict_to_namedtuple(
@ -183,7 +183,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase):
# mock task
task = mock.Mock(node=self.node, context=self.context)
# mock dracclient.get_job
self.job['state'] = 'Failed'
self.job['status'] = 'Failed'
self.job['message'] = 'boom'
mock_client = mock.Mock()
mock_get_drac_client.return_value = mock_client
@ -222,7 +222,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase):
# mock task
task = mock.Mock(node=self.node, context=self.context)
# mock dracclient.get_job
self.job['state'] = 'Completed'
self.job['status'] = 'Completed'
mock_client = mock.Mock()
mock_get_drac_client.return_value = mock_client
mock_client.get_job.return_value = test_utils.dict_to_namedtuple(
@ -261,7 +261,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase):
# mock task
task = mock.Mock(node=self.node, context=self.context)
# mock dracclient.get_job
self.job['state'] = 'Completed'
self.job['status'] = 'Completed'
mock_client = mock.Mock()
mock_get_drac_client.return_value = mock_client
mock_client.get_job.return_value = test_utils.dict_to_namedtuple(
@ -302,9 +302,9 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase):
# mock task
task = mock.Mock(node=self.node, context=self.context)
# mock dracclient.get_job
self.job['state'] = 'Completed'
self.job['status'] = 'Completed'
failed_job = self.job.copy()
failed_job['state'] = 'Failed'
failed_job['status'] = 'Failed'
failed_job['message'] = 'boom'
mock_client = mock.Mock()
mock_get_drac_client.return_value = mock_client

View File

@ -45,9 +45,11 @@ class DracQueryRaidConfigurationTestCase(test_utils.BaseDracTest):
'description': 'Integrated RAID Controller 1',
'manufacturer': 'DELL',
'model': 'PERC H710 Mini',
'firmware_version': '21.3.0-0009'}
self.raid_controller = test_utils.dict_to_namedtuple(
values=raid_controller_dict)
'primary_status': 'ok',
'firmware_version': '21.3.0-0009',
'bus': '1'}
self.raid_controller = test_utils.make_raid_controller(
raid_controller_dict)
virtual_disk_dict = {
'id': 'Disk.Virtual.0:RAID.Integrated.1-1',
@ -56,13 +58,13 @@ class DracQueryRaidConfigurationTestCase(test_utils.BaseDracTest):
'controller': 'RAID.Integrated.1-1',
'raid_level': '1',
'size_mb': 571776,
'state': 'ok',
'raid_state': 'online',
'status': 'ok',
'raid_status': 'online',
'span_depth': 1,
'span_length': 2,
'pending_operations': None}
self.virtual_disk = test_utils.dict_to_namedtuple(
values=virtual_disk_dict)
'pending_operations': None,
'physical_disks': []}
self.virtual_disk = test_utils.make_virtual_disk(virtual_disk_dict)
physical_disk_dict = {
'id': 'Disk.Bay.1:Enclosure.Internal.0-1:RAID.Integrated.1-1',
@ -77,10 +79,11 @@ class DracQueryRaidConfigurationTestCase(test_utils.BaseDracTest):
'free_size_mb': 571776,
'serial_number': 'S0M3EY2Z',
'firmware_version': 'LS0A',
'state': 'ok',
'raid_state': 'ready'}
self.physical_disk = test_utils.dict_to_namedtuple(
values=physical_disk_dict)
'status': 'ok',
'raid_status': 'ready',
'sas_address': '500056B37789ABE3',
'device_protocol': None}
self.physical_disk = test_utils.make_physical_disk(physical_disk_dict)
def test_list_raid_controllers(self, mock_get_drac_client):
mock_client = mock.Mock()
@ -287,8 +290,10 @@ class DracCreateRaidConfigurationHelpersTestCase(test_utils.BaseDracTest):
'free_size_mb': 571776,
'serial_number': 'S0M3EY2Z',
'firmware_version': 'LS0A',
'state': 'ok',
'raid_state': 'ready'}
'status': 'ok',
'raid_status': 'ready',
'sas_address': '500056B37789ABE3',
'device_protocol': None}
self.physical_disks = []
for i in range(8):
@ -330,8 +335,7 @@ class DracCreateRaidConfigurationHelpersTestCase(test_utils.BaseDracTest):
physical_disks = []
for disk in self.physical_disks:
physical_disks.append(
test_utils.dict_to_namedtuple(values=disk))
physical_disks.append(test_utils.make_physical_disk(disk))
return physical_disks
@ -539,8 +543,10 @@ class DracRaidInterfaceTestCase(test_utils.BaseDracTest):
'free_size_mb': 571776,
'serial_number': 'S0M3EY2Z',
'firmware_version': 'LS0A',
'state': 'ok',
'raid_state': 'ready'}
'status': 'ok',
'raid_status': 'ready',
'sas_address': '500056B37789ABE3',
'device_protocol': None}
self.physical_disks = []
for i in range(8):
@ -582,8 +588,7 @@ class DracRaidInterfaceTestCase(test_utils.BaseDracTest):
physical_disks = []
for disk in self.physical_disks:
physical_disks.append(
test_utils.dict_to_namedtuple(values=disk))
physical_disks.append(test_utils.make_physical_disk(disk))
return physical_disks
@ -1300,13 +1305,14 @@ class DracRaidInterfaceTestCase(test_utils.BaseDracTest):
'controller': 'RAID.Integrated.1-1',
'raid_level': '1',
'size_mb': 571776,
'state': 'ok',
'raid_state': 'online',
'status': 'ok',
'raid_status': 'online',
'span_depth': 1,
'span_length': 2,
'pending_operations': None}
'pending_operations': None,
'physical_disks': []}
mock_list_virtual_disks.return_value = [
test_utils.dict_to_namedtuple(values=virtual_disk_dict)]
test_utils.make_virtual_disk(virtual_disk_dict)]
mock_commit_config.return_value = '42'
with task_manager.acquire(self.context, self.node.uuid,
@ -1359,13 +1365,14 @@ class DracRaidInterfaceTestCase(test_utils.BaseDracTest):
'controller': 'RAID.Integrated.1-1',
'raid_level': '1',
'size_mb': 571776,
'state': 'ok',
'raid_state': 'online',
'status': 'ok',
'raid_status': 'online',
'span_depth': 1,
'span_length': 2,
'pending_operations': None}
'pending_operations': None,
'physical_disks': []}
mock_list_virtual_disks.return_value = [
test_utils.dict_to_namedtuple(values=virtual_disk_dict)]
test_utils.make_virtual_disk(virtual_disk_dict)]
expected_logical_disk = {'id': 'Disk.Virtual.0:RAID.Integrated.1-1',
'size_gb': 558,
'raid_level': '1',

View File

@ -13,12 +13,17 @@
import collections
from oslo_utils import importutils
from ironic.tests.unit.db import base as db_base
from ironic.tests.unit.db import utils as db_utils
INFO_DICT = db_utils.get_test_drac_info()
dracclient_job = importutils.try_import('dracclient.resources.job')
dracclient_raid = importutils.try_import('dracclient.resources.raid')
class BaseDracTest(db_base.DbTestCase):
def setUp(self):
@ -55,3 +60,31 @@ def dict_of_object(data):
dict_obj = DictToObj(v)
data[k] = dict_obj
return data
def make_job(job_dict):
if dracclient_job:
return dracclient_job.Job(**job_dict)
else:
return dict_to_namedtuple(values=job_dict)
def make_raid_controller(raid_controller_dict):
if dracclient_raid:
return dracclient_raid.RAIDController(**raid_controller_dict)
else:
return dict_to_namedtuple(values=raid_controller_dict)
def make_virtual_disk(virtual_disk_dict):
if dracclient_raid:
return dracclient_raid.VirtualDisk(**virtual_disk_dict)
else:
return dict_to_namedtuple(values=virtual_disk_dict)
def make_physical_disk(physical_disk_dict):
if dracclient_raid:
return dracclient_raid.PhysicalDisk(**physical_disk_dict)
else:
return dict_to_namedtuple(values=physical_disk_dict)

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Fixes an issue in the ``idrac`` RAID interface seen when creating RAID
configurations using ``python-dracclient`` version ``2.0.0`` or higher.