Merge "Make object attribute names and values consistent"

This commit is contained in:
Jenkins 2016-08-15 08:48:24 +00:00 committed by Gerrit Code Review
commit 865315f7be
5 changed files with 124 additions and 46 deletions

View File

@ -16,5 +16,12 @@ POWER_ON = 'POWER_ON'
POWER_OFF = 'POWER_OFF'
REBOOT = 'REBOOT'
PRIMARY_STATUS = {
'0': 'unknown',
'1': 'ok',
'2': 'degraded',
'3': 'error'
}
# binary unit constants
UNITS_KI = 2 ** 10

View File

@ -17,13 +17,6 @@ from dracclient import constants
from dracclient.resources import uris
from dracclient import utils
PRIMARY_STATUS = {
'0': 'Unknown',
'1': 'OK',
'2': 'Degraded',
'3': 'Error'
}
CPU_CHARACTERISTICS_64BIT = '4'
NIC_LINK_SPEED_MBPS = {
@ -58,7 +51,7 @@ CPU = collections.namedtuple(
Memory = collections.namedtuple(
'Memory',
['id', 'size', 'speed_mhz', 'manufacturer', 'model', 'status'])
['id', 'size_mb', 'speed_mhz', 'manufacturer', 'model', 'status'])
NIC = collections.namedtuple(
'NIC',
@ -100,7 +93,8 @@ class InventoryManagement(object):
cores=int(self._get_cpu_attr(cpu, 'NumberOfProcessorCores')),
speed_mhz=int(self._get_cpu_attr(cpu, 'CurrentClockSpeed')),
model=self._get_cpu_attr(cpu, 'Model'),
status=PRIMARY_STATUS[self._get_cpu_attr(cpu, 'PrimaryStatus')],
status=constants.PRIMARY_STATUS[
self._get_cpu_attr(cpu, 'PrimaryStatus')],
ht_enabled=bool(self._get_cpu_attr(cpu, 'HyperThreadingEnabled',
allow_missing=True)),
turbo_enabled=bool(self._get_cpu_attr(cpu, 'TurboModeEnabled',
@ -131,15 +125,14 @@ class InventoryManagement(object):
return [self._parse_memory(memory) for memory in installed_memory]
def _parse_memory(self, memory):
return Memory(id=self._get_memory_attr(memory, 'FQDD'),
size=int(self._get_memory_attr(memory, 'Size')),
speed_mhz=int(self._get_memory_attr(memory, 'Speed')),
manufacturer=self._get_memory_attr(memory,
'Manufacturer'),
model=self._get_memory_attr(memory, 'Model'),
status=PRIMARY_STATUS[self._get_memory_attr(
memory,
'PrimaryStatus')])
return Memory(
id=self._get_memory_attr(memory, 'FQDD'),
size_mb=int(self._get_memory_attr(memory, 'Size')),
speed_mhz=int(self._get_memory_attr(memory, 'Speed')),
manufacturer=self._get_memory_attr(memory, 'Manufacturer'),
model=self._get_memory_attr(memory, 'Model'),
status=constants.PRIMARY_STATUS[
self._get_memory_attr(memory, 'PrimaryStatus')])
def _get_memory_attr(self, memory, attr_name):
return utils.get_wsman_resource_attr(memory, uris.DCIM_MemoryView,

View File

@ -12,13 +12,34 @@
# under the License.
import collections
import logging
from dracclient.resources import uris
from dracclient import utils
from dracclient import wsman
Job = collections.namedtuple('Job', ['id', 'name', 'start_time', 'until_time',
'message', 'state', 'percent_complete'])
LOG = logging.getLogger(__name__)
JobTuple = collections.namedtuple(
'Job',
['id', 'name', 'start_time', 'until_time', 'message', 'status',
'percent_complete'])
class Job(JobTuple):
def __new__(cls, **kwargs):
if 'state' in kwargs:
LOG.warning('Job.state is deprecated. Use Job.status instead.')
kwargs['status'] = kwargs['state']
del kwargs['state']
return super(Job, cls).__new__(cls, **kwargs)
@property
def state(self):
LOG.warning('Job.state is deprecated. Use Job.status instead.')
return self.status
class JobManagement(object):
@ -182,7 +203,7 @@ class JobManagement(object):
start_time=self._get_job_attr(drac_job, 'JobStartTime'),
until_time=self._get_job_attr(drac_job, 'JobUntilTime'),
message=self._get_job_attr(drac_job, 'Message'),
state=self._get_job_attr(drac_job, 'JobStatus'),
status=self._get_job_attr(drac_job, 'JobStatus'),
percent_complete=self._get_job_attr(drac_job,
'PercentComplete'))

View File

@ -12,11 +12,15 @@
# under the License.
import collections
import logging
from dracclient import constants
from dracclient import exceptions
from dracclient.resources import uris
from dracclient import utils
LOG = logging.getLogger(__name__)
RAID_LEVELS = {
'non-raid': '1',
'0': '2',
@ -30,13 +34,6 @@ RAID_LEVELS = {
REVERSE_RAID_LEVELS = dict((v, k) for (k, v) in RAID_LEVELS.items())
DISK_STATUS = {
'0': 'unknown',
'1': 'ok',
'2': 'degraded',
'3': 'error'
}
DISK_RAID_STATUS = {
'0': 'unknown',
'1': 'ready',
@ -71,20 +68,81 @@ PHYSICAL_DISK_BUS_PROTOCOL = {
'6': 'sas'
}
PhysicalDisk = collections.namedtuple(
PhysicalDiskTuple = collections.namedtuple(
'PhysicalDisk',
['id', 'description', 'controller', 'manufacturer', 'model', 'media_type',
'interface_type', 'size_mb', 'free_size_mb', 'serial_number',
'firmware_version', 'state', 'raid_state'])
'firmware_version', 'status', 'raid_status'])
class PhysicalDisk(PhysicalDiskTuple):
def __new__(cls, **kwargs):
if 'state' in kwargs:
LOG.warning('PhysicalDisk.state is deprecated. '
'Use PhysicalDisk.status instead.')
kwargs['status'] = kwargs['state']
del kwargs['state']
if 'raid_state' in kwargs:
LOG.warning('PhysicalDisk.raid_state is deprecated. '
'Use PhysicalDisk.raid_status instead.')
kwargs['raid_status'] = kwargs['raid_state']
del kwargs['raid_state']
return super(PhysicalDisk, cls).__new__(cls, **kwargs)
@property
def state(self):
LOG.warning('PhysicalDisk.state is deprecated. '
'Use PhysicalDisk.status instead.')
return self.status
@property
def raid_state(self):
LOG.warning('PhysicalDisk.raid_state is deprecated. '
'Use PhysicalDisk.raid_status instead.')
return self.raid_status
RAIDController = collections.namedtuple(
'RAIDController', ['id', 'description', 'manufacturer', 'model',
'firmware_version'])
VirtualDisk = collections.namedtuple(
VirtualDiskTuple = collections.namedtuple(
'VirtualDisk',
['id', 'name', 'description', 'controller', 'raid_level', 'size_mb',
'state', 'raid_state', 'span_depth', 'span_length', 'pending_operations'])
'status', 'raid_status', 'span_depth', 'span_length',
'pending_operations'])
class VirtualDisk(VirtualDiskTuple):
def __new__(cls, **kwargs):
if 'state' in kwargs:
LOG.warning('VirtualDisk.state is deprecated. '
'Use VirtualDisk.status instead.')
kwargs['status'] = kwargs['state']
del kwargs['state']
if 'raid_state' in kwargs:
LOG.warning('VirtualDisk.raid_state is deprecated. '
'Use VirtualDisk.raid_status instead.')
kwargs['raid_status'] = kwargs['raid_state']
del kwargs['raid_state']
return super(VirtualDisk, cls).__new__(cls, **kwargs)
@property
def state(self):
LOG.warning('VirtualDisk.state is deprecated. '
'Use VirtualDisk.status instead.')
return self.status
@property
def raid_state(self):
LOG.warning('VirtualDisk.raid_state is deprecated. '
'Use VirtualDisk.raid_status instead.')
return self.raid_status
class RAIDManagement(object):
@ -167,8 +225,8 @@ class RAIDManagement(object):
controller=fqdd.split(':')[1],
raid_level=REVERSE_RAID_LEVELS[drac_raid_level],
size_mb=int(size_b) / 2 ** 20,
state=DISK_STATUS[drac_status],
raid_state=DISK_RAID_STATUS[drac_raid_status],
status=constants.PRIMARY_STATUS[drac_status],
raid_status=DISK_RAID_STATUS[drac_raid_status],
span_depth=int(self._get_virtual_disk_attr(drac_disk,
'SpanDepth')),
span_length=int(self._get_virtual_disk_attr(drac_disk,
@ -227,8 +285,8 @@ class RAIDManagement(object):
'SerialNumber'),
firmware_version=self._get_physical_disk_attr(drac_disk,
'Revision'),
state=DISK_STATUS[drac_status],
raid_state=DISK_RAID_STATUS[drac_raid_status])
status=constants.PRIMARY_STATUS[drac_status],
raid_status=DISK_RAID_STATUS[drac_raid_status])
def _get_physical_disk_attr(self, drac_disk, attr_name):
return utils.get_wsman_resource_attr(

View File

@ -445,7 +445,7 @@ class ClientJobManagementTestCase(base.BaseTest):
start_time='TIME_NA',
until_time='TIME_NA',
message='NA',
state='Pending',
status='Pending',
percent_complete='0')
mock_enumerate.return_value = lxml.etree.fromstring(
test_utils.JobEnumerations[uris.DCIM_LifecycleJob]['ok'])
@ -666,8 +666,8 @@ class ClientRAIDManagementTestCase(base.BaseTest):
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)
@ -693,8 +693,8 @@ class ClientRAIDManagementTestCase(base.BaseTest):
free_size_mb=571776,
serial_number='S0M3EY2Z',
firmware_version='LS0A',
state='ok',
raid_state='ready')
status='ok',
raid_status='ready')
mock_requests.post(
'https://1.2.3.4:443/wsman',
@ -1060,7 +1060,7 @@ class ClientInventoryManagementTestCase(base.BaseTest):
cores=6,
speed_mhz=2400,
model='Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz',
status='OK',
status='ok',
ht_enabled=True,
turbo_enabled=True,
vt_enabled=True,
@ -1080,7 +1080,7 @@ class ClientInventoryManagementTestCase(base.BaseTest):
cores=8,
speed_mhz=1900,
model='Intel(R) Xeon(R) CPU E5-2440 v2 @ 1.90GHz',
status='OK',
status='ok',
ht_enabled=False,
turbo_enabled=False,
vt_enabled=False,
@ -1098,12 +1098,11 @@ class ClientInventoryManagementTestCase(base.BaseTest):
def test_list_memory(self, mock_requests):
expected_memory = [inventory.Memory(
id='DIMM.Socket.A1',
size=16384,
size_mb=16384,
speed_mhz=2133,
manufacturer='Samsung',
model='DDR4 DIMM',
status='OK',
)]
status='ok')]
mock_requests.post(
'https://1.2.3.4:443/wsman',