Reformat all files with black auto formatter

Change-Id: I037b6b4a8d08862893060c5fe85865e9e11ac486
This commit is contained in:
Lin Yang 2019-09-11 16:36:53 -07:00
parent 705bb7d4d2
commit 609075345c
95 changed files with 5017 additions and 3856 deletions

View File

@ -15,4 +15,4 @@
from rsd_lib.main import RSDLib
__all__ = ('RSDLib',)
__all__ = ("RSDLib",)

View File

@ -19,11 +19,11 @@ from sushy.resources import base
class StatusField(base.CompositeField):
"""This Field describes the status of a resource and its children."""
health = base.Field('Health')
health = base.Field("Health")
"""Represents health of resource w/o considering its dependent resources"""
health_rollup = base.Field('HealthRollup')
health_rollup = base.Field("HealthRollup")
"""Represents health state of resource and its dependent resources"""
state = base.Field('State')
state = base.Field("State")
"""Indicates the known state of the resource, such as if it is enabled."""

View File

@ -14,40 +14,33 @@
# under the License.
RESET_TYPE_VALUE = [
'On',
'ForceOff',
'GracefulShutdown',
'GracefulRestart',
'ForceRestart',
'Nmi',
'ForceOn',
'PushPowerButton'
"On",
"ForceOff",
"GracefulShutdown",
"GracefulRestart",
"ForceRestart",
"Nmi",
"ForceOn",
"PushPowerButton",
]
BOOT_SOURCE_TARGET_VALUE = [
'None',
'Pxe',
'Floppy',
'Cd',
'Usb',
'Hdd',
'BiosSetup',
'Utilities',
'Diags',
'SDCard',
'UefiTarget',
'UefiShell',
'UefiHttp',
"RemoteDrive"
"None",
"Pxe",
"Floppy",
"Cd",
"Usb",
"Hdd",
"BiosSetup",
"Utilities",
"Diags",
"SDCard",
"UefiTarget",
"UefiShell",
"UefiHttp",
"RemoteDrive",
]
BOOT_SOURCE_ENABLED_VALUE = {
'Once',
'Continuous',
'Disabled'
}
BOOT_SOURCE_ENABLED_VALUE = {"Once", "Continuous", "Disabled"}
BOOT_SOURCE_MODE_VALUE = {
'Legacy',
'UEFI'
}
BOOT_SOURCE_MODE_VALUE = {"Legacy", "UEFI"}

View File

@ -26,15 +26,22 @@ from rsd_lib.resources import v2_4
class RSDLib(base.ResourceBase):
_redfish_version = base.Field(['RedfishVersion'], required=True)
_redfish_version = base.Field(["RedfishVersion"], required=True)
"""FabricCollection path"""
_rsd_api_version = base.Field(['Oem', 'Intel_RackScale', 'ApiVersion'],
required=True)
_rsd_api_version = base.Field(
["Oem", "Intel_RackScale", "ApiVersion"], required=True
)
"""RSD API version"""
def __init__(self, base_url, username=None, password=None,
root_prefix='/redfish/v1/', verify=True):
def __init__(
self,
base_url,
username=None,
password=None,
root_prefix="/redfish/v1/",
verify=True,
):
"""A class representing a RootService
:param base_url: The base URL to the Redfish controller. It
@ -55,7 +62,8 @@ class RSDLib(base.ResourceBase):
self._root_prefix = root_prefix
super(RSDLib, self).__init__(
connector.Connector(base_url, username, password, verify),
path=self._root_prefix)
path=self._root_prefix,
)
def factory(self):
"""Return different resource module according to RSD API Version
@ -66,24 +74,40 @@ class RSDLib(base.ResourceBase):
if rsd_version < version.StrictVersion("2.2.0"):
# Use the interface of RSD API 2.1.0 to interact with RSD 2.1.0 and
# all previous version.
return v2_1.RSDLibV2_1(self._conn, self._root_prefix,
redfish_version=self._redfish_version)
elif version.StrictVersion("2.2.0") <= rsd_version \
and rsd_version < version.StrictVersion("2.3.0"):
return v2_1.RSDLibV2_1(
self._conn,
self._root_prefix,
redfish_version=self._redfish_version,
)
elif version.StrictVersion(
"2.2.0"
) <= rsd_version and rsd_version < version.StrictVersion("2.3.0"):
# Specific interface for RSD 2.2 version
return v2_2.RSDLibV2_2(self._conn, self._root_prefix,
redfish_version=self._redfish_version)
elif version.StrictVersion("2.3.0") <= rsd_version \
and rsd_version < version.StrictVersion("2.4.0"):
return v2_2.RSDLibV2_2(
self._conn,
self._root_prefix,
redfish_version=self._redfish_version,
)
elif version.StrictVersion(
"2.3.0"
) <= rsd_version and rsd_version < version.StrictVersion("2.4.0"):
# Specific interface for RSD 2.3 version
return v2_3.RSDLibV2_3(self._conn, self._root_prefix,
redfish_version=self._redfish_version)
elif version.StrictVersion("2.4.0") <= rsd_version \
and rsd_version < version.StrictVersion("2.5.0"):
return v2_3.RSDLibV2_3(
self._conn,
self._root_prefix,
redfish_version=self._redfish_version,
)
elif version.StrictVersion(
"2.4.0"
) <= rsd_version and rsd_version < version.StrictVersion("2.5.0"):
# Specific interface for RSD 2.4 version
return v2_4.RSDLibV2_4(self._conn, self._root_prefix,
redfish_version=self._redfish_version)
return v2_4.RSDLibV2_4(
self._conn,
self._root_prefix,
redfish_version=self._redfish_version,
)
else:
raise NotImplementedError(
"The rsd-lib library doesn't support RSD API "
"version {0}.".format(self._rsd_api_version))
"version {0}.".format(self._rsd_api_version)
)

View File

@ -68,96 +68,93 @@ from rsd_lib.resources.v2_1.task import task
from rsd_lib.resources.v2_1.task import task_service
RESOURCE_CLASS = {
'Chassis': chassis.Chassis,
'ChassisCollection': chassis.ChassisCollection,
'ComposedNode': node.Node,
'ComposedNodeCollection': node.NodeCollection,
'ComputerSystem': system.System,
'ComputerSystemCollection': system.SystemCollection,
'Drive': drive.Drive,
'Endpoint': endpoint.Endpoint,
'EndpointCollection': endpoint.EndpointCollection,
'EthernetInterface': ethernet_interface.EthernetInterface,
'EthernetInterfaceCollection':
"Chassis": chassis.Chassis,
"ChassisCollection": chassis.ChassisCollection,
"ComposedNode": node.Node,
"ComposedNodeCollection": node.NodeCollection,
"ComputerSystem": system.System,
"ComputerSystemCollection": system.SystemCollection,
"Drive": drive.Drive,
"Endpoint": endpoint.Endpoint,
"EndpointCollection": endpoint.EndpointCollection,
"EthernetInterface": ethernet_interface.EthernetInterface,
"EthernetInterfaceCollection":
ethernet_interface.EthernetInterfaceCollection,
'EthernetSwitch': ethernet_switch.EthernetSwitch,
'EthernetSwitchACL': ethernet_switch_acl.EthernetSwitchACL,
'EthernetSwitchACLCollection':
"EthernetSwitch": ethernet_switch.EthernetSwitch,
"EthernetSwitchACL": ethernet_switch_acl.EthernetSwitchACL,
"EthernetSwitchACLCollection":
ethernet_switch_acl.EthernetSwitchACLCollection,
'EthernetSwitchACLRule': ethernet_switch_acl_rule.EthernetSwitchACLRule,
'EthernetSwitchACLRuleCollection':
"EthernetSwitchACLRule": ethernet_switch_acl_rule.EthernetSwitchACLRule,
"EthernetSwitchACLRuleCollection":
ethernet_switch_acl_rule.EthernetSwitchACLRuleCollection,
'EthernetSwitchCollection': ethernet_switch.EthernetSwitchCollection,
'EthernetSwitchPort': ethernet_switch_port.EthernetSwitchPort,
'EthernetSwitchPortCollection':
"EthernetSwitchCollection": ethernet_switch.EthernetSwitchCollection,
"EthernetSwitchPort": ethernet_switch_port.EthernetSwitchPort,
"EthernetSwitchPortCollection":
ethernet_switch_port.EthernetSwitchPortCollection,
'EthernetSwitchStaticMAC':
"EthernetSwitchStaticMAC":
ethernet_switch_static_mac.EthernetSwitchStaticMAC,
'EthernetSwitchStaticMACCollection':
"EthernetSwitchStaticMACCollection":
ethernet_switch_static_mac.EthernetSwitchStaticMACCollection,
'EventDestination': event_destination.EventDestination,
'EventDestinationCollection': event_destination.EventDestinationCollection,
'EventService': event_service.EventService,
'Fabric': fabric.Fabric,
'FabricCollection': fabric.FabricCollection,
'LogEntry': log_entry.LogEntry,
'LogEntryCollection': log_entry.LogEntryCollection,
'LogService': log_service.LogService,
'LogServiceCollection': log_service.LogServiceCollection,
'LogicalDrive': logical_drive.LogicalDrive,
'LogicalDriveCollection': logical_drive.LogicalDriveCollection,
'Manager': manager.Manager,
'ManagerCollection': manager.ManagerCollection,
'ManagerNetworkProtocol': manager_network_protocol.ManagerNetworkProtocol,
'Memory': memory.Memory,
'MemoryCollection': memory.MemoryCollection,
'MessageRegistryFile': message_registry_file.MessageRegistryFile,
'MessageRegistryFileCollection':
"EventDestination": event_destination.EventDestination,
"EventDestinationCollection": event_destination.EventDestinationCollection,
"EventService": event_service.EventService,
"Fabric": fabric.Fabric,
"FabricCollection": fabric.FabricCollection,
"LogEntry": log_entry.LogEntry,
"LogEntryCollection": log_entry.LogEntryCollection,
"LogService": log_service.LogService,
"LogServiceCollection": log_service.LogServiceCollection,
"LogicalDrive": logical_drive.LogicalDrive,
"LogicalDriveCollection": logical_drive.LogicalDriveCollection,
"Manager": manager.Manager,
"ManagerCollection": manager.ManagerCollection,
"ManagerNetworkProtocol": manager_network_protocol.ManagerNetworkProtocol,
"Memory": memory.Memory,
"MemoryCollection": memory.MemoryCollection,
"MessageRegistryFile": message_registry_file.MessageRegistryFile,
"MessageRegistryFileCollection":
message_registry_file.MessageRegistryFileCollection,
'NetworkDeviceFunction': network_device_function.NetworkDeviceFunction,
'NetworkDeviceFunctionCollection':
"NetworkDeviceFunction": network_device_function.NetworkDeviceFunction,
"NetworkDeviceFunctionCollection":
network_device_function.NetworkDeviceFunctionCollection,
'NetworkInterface': network_interface.NetworkInterface,
'NetworkInterfaceCollection': network_interface.NetworkInterfaceCollection,
'PCIeDevice': pcie_device.PCIeDevice,
'PCIeFunction': pcie_function.PCIeFunction,
'PhysicalDrive': physical_drive.PhysicalDrive,
'PhysicalDriveCollection': physical_drive.PhysicalDriveCollection,
'Port': port.Port,
'PortCollection': port.PortCollection,
'Power': power.Power,
'PowerZone': power_zone.PowerZone,
'PowerZoneCollection': power_zone.PowerZoneCollection,
'Processor': processor.Processor,
'ProcessorCollection': processor.ProcessorCollection,
'RemoteTarget': remote_target.RemoteTarget,
'RemoteTargetCollection':
remote_target.RemoteTargetCollection,
'SerialInterface': serial_interface.SerialInterface,
'SerialInterfaceCollection': serial_interface.SerialInterfaceCollection,
'SimpleStorage': simple_storage.SimpleStorage,
'SimpleStorageCollection': simple_storage.SimpleStorageCollection,
'Storage': storage.Storage,
'StorageCollection': storage.StorageCollection,
'StorageService': storage_service.StorageService,
'StorageServiceCollection': storage_service.StorageServiceCollection,
'Switch': switch.Switch,
'SwitchCollection': switch.SwitchCollection,
'Task': task.Task,
'TaskCollection': task.TaskCollection,
'TaskService': task_service.TaskService,
'Thermal': thermal.Thermal,
'ThermalZone': thermal_zone.ThermalZone,
'ThermalZoneCollection':
thermal_zone.ThermalZoneCollection,
'VLanNetworkInterface':
vlan_network_interface.VLanNetworkInterface,
'VLanNetworkInterfaceCollection':
"NetworkInterface": network_interface.NetworkInterface,
"NetworkInterfaceCollection": network_interface.NetworkInterfaceCollection,
"PCIeDevice": pcie_device.PCIeDevice,
"PCIeFunction": pcie_function.PCIeFunction,
"PhysicalDrive": physical_drive.PhysicalDrive,
"PhysicalDriveCollection": physical_drive.PhysicalDriveCollection,
"Port": port.Port,
"PortCollection": port.PortCollection,
"Power": power.Power,
"PowerZone": power_zone.PowerZone,
"PowerZoneCollection": power_zone.PowerZoneCollection,
"Processor": processor.Processor,
"ProcessorCollection": processor.ProcessorCollection,
"RemoteTarget": remote_target.RemoteTarget,
"RemoteTargetCollection": remote_target.RemoteTargetCollection,
"SerialInterface": serial_interface.SerialInterface,
"SerialInterfaceCollection": serial_interface.SerialInterfaceCollection,
"SimpleStorage": simple_storage.SimpleStorage,
"SimpleStorageCollection": simple_storage.SimpleStorageCollection,
"Storage": storage.Storage,
"StorageCollection": storage.StorageCollection,
"StorageService": storage_service.StorageService,
"StorageServiceCollection": storage_service.StorageServiceCollection,
"Switch": switch.Switch,
"SwitchCollection": switch.SwitchCollection,
"Task": task.Task,
"TaskCollection": task.TaskCollection,
"TaskService": task_service.TaskService,
"Thermal": thermal.Thermal,
"ThermalZone": thermal_zone.ThermalZone,
"ThermalZoneCollection": thermal_zone.ThermalZoneCollection,
"VLanNetworkInterface": vlan_network_interface.VLanNetworkInterface,
"VLanNetworkInterfaceCollection":
vlan_network_interface.VLanNetworkInterfaceCollection,
'VirtualMedia': virtual_media.VirtualMedia,
'VirtualMediaCollection': virtual_media.VirtualMediaCollection,
'Volume': volume.Volume,
'VolumeCollection': volume.VolumeCollection,
'Zone': zone.Zone,
'ZoneCollection': zone.ZoneCollection
"VirtualMedia": virtual_media.VirtualMedia,
"VirtualMediaCollection": virtual_media.VirtualMediaCollection,
"Volume": volume.Volume,
"VolumeCollection": volume.VolumeCollection,
"Zone": zone.Zone,
"ZoneCollection": zone.ZoneCollection,
}

View File

@ -26,80 +26,88 @@ LOG = logging.getLogger(__name__)
class ClassToPriorityMappingField(base.ListField):
priority = base.Field('Priority', adapter=rsd_lib_utils.num_or_none)
priority = base.Field("Priority", adapter=rsd_lib_utils.num_or_none)
traffic_class = base.Field(
'TrafficClass', adapter=rsd_lib_utils.num_or_none)
"TrafficClass", adapter=rsd_lib_utils.num_or_none
)
class PriorityFlowControlField(base.CompositeField):
enabled = base.Field('Enabled', adapter=bool)
enabled = base.Field("Enabled", adapter=bool)
lossless_priorities = base.Field('LosslessPriorities')
lossless_priorities = base.Field("LosslessPriorities")
class PriorityToClassMappingField(base.ListField):
priority = base.Field('Priority', adapter=rsd_lib_utils.num_or_none)
priority = base.Field("Priority", adapter=rsd_lib_utils.num_or_none)
traffic_class = base.Field(
'TrafficClass', adapter=rsd_lib_utils.num_or_none)
"TrafficClass", adapter=rsd_lib_utils.num_or_none
)
class TrafficClassficationField(base.ListField):
port = base.Field('Port', adapter=rsd_lib_utils.num_or_none)
port = base.Field("Port", adapter=rsd_lib_utils.num_or_none)
protocol = base.Field('Protocol')
protocol = base.Field("Protocol")
traffic_class = base.Field(
'TrafficClass', adapter=rsd_lib_utils.num_or_none)
"TrafficClass", adapter=rsd_lib_utils.num_or_none
)
class TransmissionSelectionField(base.ListField):
bandwidth_percent = base.Field(
'BandwidthPercent', adapter=rsd_lib_utils.num_or_none)
"BandwidthPercent", adapter=rsd_lib_utils.num_or_none
)
traffic_class = base.Field(
'TrafficClass', adapter=rsd_lib_utils.num_or_none)
"TrafficClass", adapter=rsd_lib_utils.num_or_none
)
class EthernetSwitch(v2_2_ethernet_switch.EthernetSwitch):
class_to_priority_mapping = ClassToPriorityMappingField(
'ClassToPriorityMapping')
"ClassToPriorityMapping"
)
"""The ethernet switch class to priority mapping"""
dcbx_enabled = base.Field('DCBXEnabled', adapter=bool)
dcbx_enabled = base.Field("DCBXEnabled", adapter=bool)
"""The boolean indicate this dcbx is enabled or not"""
ets_enabled = base.Field('ETSEnabled', adapter=bool)
ets_enabled = base.Field("ETSEnabled", adapter=bool)
"""The boolean indicate this etse is enabled or not"""
lldp_enabled = base.Field('LLDPEnabled', adapter=bool)
lldp_enabled = base.Field("LLDPEnabled", adapter=bool)
"""The boolean indicate this lldp is enabled or not"""
max_acl_number = base.Field('MaxACLNumber')
max_acl_number = base.Field("MaxACLNumber")
"""The ethernet switch max acl number"""
metrics = base.Field('Metrics', default=(),
adapter=rsd_lib_utils.get_resource_identity)
metrics = base.Field(
"Metrics", default=(), adapter=rsd_lib_utils.get_resource_identity
)
"""The ethernet switch metrics"""
priority_flow_control = PriorityFlowControlField('PriorityFlowControl')
priority_flow_control = PriorityFlowControlField("PriorityFlowControl")
"""The ethernet switch priority flow control"""
priority_to_class_mapping = PriorityToClassMappingField(
'PriorityToClassMapping')
"PriorityToClassMapping"
)
"""The ethernet switch priority to class mapping"""
traffic_classification = TrafficClassficationField('TrafficClassification')
traffic_classification = TrafficClassficationField("TrafficClassification")
"""The ethernet switch traffic classification"""
transmission_selection = TransmissionSelectionField(
'TransmissionSelection')
"TransmissionSelection"
)
"""The ethernet switch transmission selection"""
class EthernetSwitchCollection(rsd_lib_base.ResourceCollectionBase):
@property
def _resource_type(self):
return EthernetSwitch

View File

@ -29,72 +29,77 @@ LOG = logging.getLogger(__name__)
class IdentifiersField(base.ListField):
name_format = base.Field('DurableNameFormat')
name = base.Field('DurableName')
name_format = base.Field("DurableNameFormat")
name = base.Field("DurableName")
class ConnectedEntitiesField(base.ListField):
entity_type = base.Field('EntityType')
entity_role = base.Field('EntityRole')
entity_link = base.Field('EntityLink',
adapter=rsd_lib_utils.get_resource_identity)
entity_type = base.Field("EntityType")
entity_role = base.Field("EntityRole")
entity_link = base.Field(
"EntityLink", adapter=rsd_lib_utils.get_resource_identity
)
class LinksField(base.CompositeField):
ports = base.Field('Ports', adapter=utils.get_members_identities)
endpoints = base.Field('Endpoints', adapter=utils.get_members_identities)
zones = base.Field(['Oem', 'Intel_RackScale', 'Zones'],
adapter=utils.get_members_identities)
interface = base.Field(['Oem', 'Intel_RackScale', 'Interface'],
adapter=rsd_lib_utils.get_resource_identity)
ports = base.Field("Ports", adapter=utils.get_members_identities)
endpoints = base.Field("Endpoints", adapter=utils.get_members_identities)
zones = base.Field(
["Oem", "Intel_RackScale", "Zones"],
adapter=utils.get_members_identities,
)
interface = base.Field(
["Oem", "Intel_RackScale", "Interface"],
adapter=rsd_lib_utils.get_resource_identity,
)
class IPTransportDetailsField(base.ListField):
transport_protocol = base.Field('TransportProtocol')
ipv4_address = base.Field(['IPv4Address', 'Address'])
ipv6_address = base.Field(['IPv6Address', 'Address'])
port = base.Field('Port', adapter=rsd_lib_utils.num_or_none)
transport_protocol = base.Field("TransportProtocol")
ipv4_address = base.Field(["IPv4Address", "Address"])
ipv6_address = base.Field(["IPv6Address", "Address"])
port = base.Field("Port", adapter=rsd_lib_utils.num_or_none)
class AuthenticationField(base.CompositeField):
username = base.Field('Username')
password = base.Field('Password')
username = base.Field("Username")
password = base.Field("Password")
class OemField(base.CompositeField):
authentication = AuthenticationField(['Intel_RackScale', 'Authentication'])
authentication = AuthenticationField(["Intel_RackScale", "Authentication"])
class Endpoint(rsd_lib_base.ResourceBase):
connected_entities = ConnectedEntitiesField('ConnectedEntities')
connected_entities = ConnectedEntitiesField("ConnectedEntities")
"""Entities connected to endpoint"""
description = base.Field('Description')
description = base.Field("Description")
"""The endpoint description"""
protocol = base.Field('EndpointProtocol')
protocol = base.Field("EndpointProtocol")
"""Protocol for endpoint (i.e. PCIe)"""
identifiers = IdentifiersField('Identifiers')
identifiers = IdentifiersField("Identifiers")
"""Identifiers for endpoint"""
identity = base.Field('Id', required=True)
identity = base.Field("Id", required=True)
"""The endpoint identity string"""
name = base.Field('Name')
name = base.Field("Name")
"""The endpoint name"""
status = rsd_lib_common.StatusField('Status')
status = rsd_lib_common.StatusField("Status")
"""The endpoint status"""
links = LinksField('Links')
links = LinksField("Links")
"""These links to related components of this endpoint"""
ip_transport_details = IPTransportDetailsField('IPTransportDetails')
ip_transport_details = IPTransportDetailsField("IPTransportDetails")
"""IP transport details info of this endpoint"""
oem = OemField('Oem')
oem = OemField("Oem")
"""The OEM additional info of this endpoint"""
def update_authentication(self, username=None, password=None):
@ -106,83 +111,100 @@ class Endpoint(rsd_lib_base.ResourceBase):
:raises: BadRequestError if at least one param isn't specified
"""
if username is None and password is None:
raise ValueError('At least "username" or "password" parameter has '
'to be specified')
raise ValueError(
'At least "username" or "password" parameter has '
"to be specified"
)
data = {
"Oem": {
"Intel_RackScale": {
"@odata.type": "#Intel.Oem.Endpoint",
"Authentication": {}
"Authentication": {},
}
}
}
if username is not None:
data['Oem']['Intel_RackScale']['Authentication']['Username'] = \
username
data["Oem"]["Intel_RackScale"]["Authentication"][
"Username"
] = username
if password is not None:
data['Oem']['Intel_RackScale']['Authentication']['Password'] = \
password
data["Oem"]["Intel_RackScale"]["Authentication"][
"Password"
] = password
self._conn.patch(self.path, data=data)
class EndpointCollection(rsd_lib_base.ResourceCollectionBase):
@property
def _resource_type(self):
return Endpoint
def _create_endpoint_request(self, identifiers, connected_entities,
protocol=None, ip_transport_details=None,
interface=None, authentication=None):
def _create_endpoint_request(
self,
identifiers,
connected_entities,
protocol=None,
ip_transport_details=None,
interface=None,
authentication=None,
):
request = {}
jsonschema.validate(identifiers,
endpoint_schemas.identifiers_req_schema)
request['Identifiers'] = identifiers
jsonschema.validate(
identifiers, endpoint_schemas.identifiers_req_schema
)
request["Identifiers"] = identifiers
jsonschema.validate(connected_entities,
endpoint_schemas.connected_entities_req_schema)
request['ConnectedEntities'] = connected_entities
jsonschema.validate(
connected_entities, endpoint_schemas.connected_entities_req_schema
)
request["ConnectedEntities"] = connected_entities
if protocol is not None:
jsonschema.validate(protocol, endpoint_schemas.protocol_req_schema)
request['EndpointProtocol'] = protocol
request["EndpointProtocol"] = protocol
if ip_transport_details is not None:
jsonschema.validate(
ip_transport_details,
endpoint_schemas.ip_transport_details_req_schema)
request['IPTransportDetails'] = ip_transport_details
endpoint_schemas.ip_transport_details_req_schema,
)
request["IPTransportDetails"] = ip_transport_details
if interface is not None:
jsonschema.validate(interface,
endpoint_schemas.interface_req_schema)
request['Links'] = {
jsonschema.validate(
interface, endpoint_schemas.interface_req_schema
)
request["Links"] = {
"Oem": {
"Intel_RackScale": {
"Interfaces": [
{
"@odata.id": interface
}
]
"Interfaces": [{"@odata.id": interface}]
}
}
}
if authentication is not None:
jsonschema.validate(authentication,
endpoint_schemas.authentication_req_schema)
request['Oem'] = {"Intel_RackScale":
{"Authentication": authentication}}
jsonschema.validate(
authentication, endpoint_schemas.authentication_req_schema
)
request["Oem"] = {
"Intel_RackScale": {"Authentication": authentication}
}
return request
def create_endpoint(self, identifiers, connected_entities, protocol=None,
ip_transport_details=None, interface=None,
authentication=None):
def create_endpoint(
self,
identifiers,
connected_entities,
protocol=None,
ip_transport_details=None,
interface=None,
authentication=None,
):
"""Create a new endpoint
:param identifiers: provides iQN or NQN of created entity
@ -199,9 +221,14 @@ class EndpointCollection(rsd_lib_base.ResourceCollectionBase):
:returns: The uri of the new endpoint
"""
properties = self._create_endpoint_request(
identifiers, connected_entities, protocol, ip_transport_details,
interface, authentication)
identifiers,
connected_entities,
protocol,
ip_transport_details,
interface,
authentication,
)
resp = self._conn.post(self._path, data=properties)
LOG.info("Endpoint created at %s", resp.headers['Location'])
endpoint_url = resp.headers['Location']
LOG.info("Endpoint created at %s", resp.headers["Location"])
endpoint_url = resp.headers["Location"]
return endpoint_url[endpoint_url.find(self._path):]

View File

@ -13,91 +13,87 @@
# under the License.
identifiers_req_schema = {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'DurableNameFormat': {
'type': 'string',
'enum': ['NQN', 'iQN']
},
'DurableName': {'type': 'string'}
"type": "array",
"items": {
"type": "object",
"properties": {
"DurableNameFormat": {"type": "string", "enum": ["NQN", "iQN"]},
"DurableName": {"type": "string"},
},
"required": ['DurableNameFormat', 'DurableName']
}
"required": ["DurableNameFormat", "DurableName"],
},
}
connected_entities_req_schema = {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'EntityLink': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
},
"required": ['@odata.id']
"type": "array",
"items": {
"type": "object",
"properties": {
"EntityLink": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
"required": ["@odata.id"],
},
'EntityRole': {
'type': 'string',
'enum': ['Initiator', 'Target', 'Both']
"EntityRole": {
"type": "string",
"enum": ["Initiator", "Target", "Both"],
},
'Identifiers': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'DurableNameFormat': {
'type': 'string',
'enum': ['NQN', 'iQN', 'FC_WWN', 'UUID', 'EUI',
'NAA', 'NSID', 'SystemPath', 'LUN']
"Identifiers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"DurableNameFormat": {
"type": "string",
"enum": [
"NQN",
"iQN",
"FC_WWN",
"UUID",
"EUI",
"NAA",
"NSID",
"SystemPath",
"LUN",
],
},
'DurableName': {'type': 'string'}
"DurableName": {"type": "string"},
},
"required": ['DurableNameFormat', 'DurableName']
}
}
"required": ["DurableNameFormat", "DurableName"],
},
},
},
"required": ['EntityLink', 'EntityRole']
}
"required": ["EntityLink", "EntityRole"],
},
}
protocol_req_schema = {
'type': 'string'
}
protocol_req_schema = {"type": "string"}
ip_transport_details_req_schema = {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'TransportProtocol': {'type': 'string'},
'IPv4Address': {
'type': 'object',
'properties': {
'Address': {'type': 'string'}
}
"type": "array",
"items": {
"type": "object",
"properties": {
"TransportProtocol": {"type": "string"},
"IPv4Address": {
"type": "object",
"properties": {"Address": {"type": "string"}},
},
'IPv6Address': {
'type': 'object',
'properties': {
'Address': {'type': 'string'}
}
"IPv6Address": {
"type": "object",
"properties": {"Address": {"type": "string"}},
},
'Port': {'type': 'number'}
}
}
"Port": {"type": "number"},
},
},
}
interface_req_schema = {
'type': 'string'
}
interface_req_schema = {"type": "string"}
authentication_req_schema = {
'type': 'object',
'properties': {
'Username': {'type': 'string'},
'Password': {'type': 'string'}
}
"type": "object",
"properties": {
"Username": {"type": "string"},
"Password": {"type": "string"},
},
}

View File

@ -28,26 +28,26 @@ LOG = logging.getLogger(__name__)
class Fabric(rsd_lib_base.ResourceBase):
description = base.Field('Description')
description = base.Field("Description")
"""The fabric description"""
fabric_type = base.Field('FabricType')
fabric_type = base.Field("FabricType")
"""The fabric type"""
identity = base.Field('Id', required=True)
identity = base.Field("Id", required=True)
"""The fabric identity string"""
max_zones = base.Field('MaxZones')
max_zones = base.Field("MaxZones")
"""Maximum number of zones for the fabric"""
name = base.Field('Name')
name = base.Field("Name")
"""The fabric name"""
status = rsd_lib_common.StatusField('Status')
status = rsd_lib_common.StatusField("Status")
def _get_endpoint_collection_path(self):
"""Helper function to find the EndpointCollection path"""
return utils.get_sub_resource_path_by(self, 'Endpoints')
return utils.get_sub_resource_path_by(self, "Endpoints")
@property
@utils.cache_it
@ -58,12 +58,14 @@ class Fabric(rsd_lib_base.ResourceBase):
refresh, this property is reset.
"""
return endpoint.EndpointCollection(
self._conn, self._get_endpoint_collection_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_endpoint_collection_path(),
redfish_version=self.redfish_version,
)
def _get_zone_collection_path(self):
"""Helper function to find the ZoneCollection path"""
return utils.get_sub_resource_path_by(self, 'Zones')
return utils.get_sub_resource_path_by(self, "Zones")
@property
@utils.cache_it
@ -74,12 +76,13 @@ class Fabric(rsd_lib_base.ResourceBase):
refresh, this property is reset.
"""
return zone.ZoneCollection(
self._conn, self._get_zone_collection_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_zone_collection_path(),
redfish_version=self.redfish_version,
)
class FabricCollection(rsd_lib_base.ResourceCollectionBase):
@property
def _resource_type(self):
return Fabric

View File

@ -21,7 +21,6 @@ LOG = logging.getLogger(__name__)
class Zone(v2_1_zone.Zone):
def update(self, endpoints):
"""Add or remove Endpoints from a Zone
@ -30,14 +29,14 @@ class Zone(v2_1_zone.Zone):
:param endpoints: a full representation of Endpoints array
"""
data = {"Links": {"Endpoints": []}}
data['Links']['Endpoints'] = [
{'@odata.id': endpoint} for endpoint in endpoints]
data["Links"]["Endpoints"] = [
{"@odata.id": endpoint} for endpoint in endpoints
]
self._conn.patch(self.path, data=data)
class ZoneCollection(v2_1_zone.ZoneCollection):
@property
def _resource_type(self):
return Zone
@ -49,10 +48,11 @@ class ZoneCollection(v2_1_zone.ZoneCollection):
:returns: The uri of the new zone
"""
data = {"Links": {"Endpoints": []}}
data['Links']['Endpoints'] = [
{'@odata.id': endpoint} for endpoint in endpoints]
data["Links"]["Endpoints"] = [
{"@odata.id": endpoint} for endpoint in endpoints
]
resp = self._conn.post(self.path, data=data)
LOG.info("Zone created at %s", resp.headers['Location'])
zone_uri = resp.headers['Location']
LOG.info("Zone created at %s", resp.headers["Location"])
zone_uri = resp.headers["Location"]
return zone_uri[zone_uri.find(self._path):]

View File

@ -20,7 +20,6 @@ from rsd_lib.resources.v2_3.system import ethernet_interface
class Manager(manager.Manager):
@property
@utils.cache_it
def ethernet_interfaces(self):
@ -37,7 +36,6 @@ class Manager(manager.Manager):
class ManagerCollection(manager.ManagerCollection):
@property
def _resource_type(self):
return Manager

View File

@ -27,19 +27,19 @@ NAME_MAPPING = {
"Required": "required",
"DataType": "data_type",
"ObjectDataType": "object_data_type",
"AllowableValues": "allowable_values"
"AllowableValues": "allowable_values",
}
class AttachResourceActionInfo(rsd_lib_base.ResourceBase):
identity = base.Field('Id', required=True)
identity = base.Field("Id", required=True)
"""The storage pool identity string"""
description = base.Field('Description')
description = base.Field("Description")
"""The storage pool description string"""
name = base.Field('Name')
name = base.Field("Name")
"""The storage pool name string"""
@property
@ -51,14 +51,15 @@ class AttachResourceActionInfo(rsd_lib_base.ResourceBase):
refresh, this property is reset.
"""
parameters = []
for i in self.json.get('Parameters'):
for i in self.json.get("Parameters"):
item = {}
for key in NAME_MAPPING:
item[NAME_MAPPING[key]] = i[key]
if item['name'] == 'Resource':
item['allowable_values'] = utils.get_members_identities(
item['allowable_values'])
if item["name"] == "Resource":
item["allowable_values"] = utils.get_members_identities(
item["allowable_values"]
)
parameters.append(item)

View File

@ -30,32 +30,34 @@ LOG = logging.getLogger(__name__)
class AttachEndpointActionField(base.CompositeField):
target_uri = base.Field('target', required=True)
action_info_path = base.Field('@Redfish.ActionInfo',
adapter=rsd_lib_utils.get_resource_identity)
target_uri = base.Field("target", required=True)
action_info_path = base.Field(
"@Redfish.ActionInfo", adapter=rsd_lib_utils.get_resource_identity
)
action_info = None
class DetachEndpointActionField(base.CompositeField):
target_uri = base.Field('target', required=True)
action_info_path = base.Field('@Redfish.ActionInfo',
adapter=rsd_lib_utils.get_resource_identity)
target_uri = base.Field("target", required=True)
action_info_path = base.Field(
"@Redfish.ActionInfo", adapter=rsd_lib_utils.get_resource_identity
)
action_info = None
class NodeActionsField(v2_1_node.NodeActionsField):
attach_endpoint = AttachEndpointActionField('#ComposedNode.AttachResource')
detach_endpoint = DetachEndpointActionField('#ComposedNode.DetachResource')
attach_endpoint = AttachEndpointActionField("#ComposedNode.AttachResource")
detach_endpoint = DetachEndpointActionField("#ComposedNode.DetachResource")
class Node(v2_1_node.Node):
clear_tpm_on_delete = base.Field('ClearTPMOnDelete', adapter=bool)
clear_tpm_on_delete = base.Field("ClearTPMOnDelete", adapter=bool)
"""This is used to specify if TPM module should be cleared on composed node
DELETE request
"""
_actions = NodeActionsField('Actions', required=True)
_actions = NodeActionsField("Actions", required=True)
def update(self, clear_tpm_on_delete):
"""Update properties of this composed node
@ -67,12 +69,12 @@ class Node(v2_1_node.Node):
"""
if not isinstance(clear_tpm_on_delete, bool):
raise exceptions.InvalidParameterValueError(
parameter='clear_tpm_on_delete', value=clear_tpm_on_delete,
valid_values=[True, False])
parameter="clear_tpm_on_delete",
value=clear_tpm_on_delete,
valid_values=[True, False],
)
data = {
'ClearTPMOnDelete': clear_tpm_on_delete
}
data = {"ClearTPMOnDelete": clear_tpm_on_delete}
self._conn.patch(self.path, data=data)
@ -80,14 +82,16 @@ class Node(v2_1_node.Node):
attach_endpoint_action = self._actions.attach_endpoint
if not attach_endpoint_action:
raise exceptions.MissingActionError(
action='#ComposedNode.AttachResource',
resource=self._path)
action="#ComposedNode.AttachResource", resource=self._path
)
if attach_endpoint_action.action_info is None:
attach_endpoint_action.action_info = \
attach_action_info.AttachResourceActionInfo(
self._conn, attach_endpoint_action.action_info_path,
redfish_version=self.redfish_version)
attach_endpoint_action.action_info = attach_action_info.\
AttachResourceActionInfo(
self._conn,
attach_endpoint_action.action_info_path,
redfish_version=self.redfish_version,
)
return attach_endpoint_action
def get_allowed_attach_endpoints(self):
@ -97,8 +101,8 @@ class Node(v2_1_node.Node):
"""
attach_action = self._get_attach_endpoint_action_element()
for i in attach_action.action_info.parameters:
if i['name'] == 'Resource':
return i['allowable_values']
if i["name"] == "Resource":
return i["allowable_values"]
return ()
def attach_endpoint(self, resource, protocol=None):
@ -114,14 +118,16 @@ class Node(v2_1_node.Node):
if resource and resource not in valid_endpoints:
raise exceptions.InvalidParameterValueError(
parameter='resource', value=resource,
valid_values=valid_endpoints)
parameter="resource",
value=resource,
valid_values=valid_endpoints,
)
data = {}
if resource is not None:
data['Resource'] = {'@odata.id': resource}
data["Resource"] = {"@odata.id": resource}
if protocol is not None:
data['Protocol'] = protocol
data["Protocol"] = protocol
self._conn.post(target_uri, data=data)
@ -129,14 +135,16 @@ class Node(v2_1_node.Node):
detach_endpoint_action = self._actions.detach_endpoint
if not detach_endpoint_action:
raise exceptions.MissingActionError(
action='#ComposedNode.DetachResource',
resource=self._path)
action="#ComposedNode.DetachResource", resource=self._path
)
if detach_endpoint_action.action_info is None:
detach_endpoint_action.action_info = \
attach_action_info.AttachResourceActionInfo(
self._conn, detach_endpoint_action.action_info_path,
redfish_version=self.redfish_version)
detach_endpoint_action.action_info = attach_action_info.\
AttachResourceActionInfo(
self._conn,
detach_endpoint_action.action_info_path,
redfish_version=self.redfish_version,
)
return detach_endpoint_action
def get_allowed_detach_endpoints(self):
@ -146,8 +154,8 @@ class Node(v2_1_node.Node):
"""
detach_action = self._get_detach_endpoint_action_element()
for i in detach_action.action_info.parameters:
if i['name'] == 'Resource':
return i['allowable_values']
if i["name"] == "Resource":
return i["allowable_values"]
return ()
def detach_endpoint(self, resource):
@ -162,12 +170,14 @@ class Node(v2_1_node.Node):
if resource not in valid_endpoints:
raise exceptions.InvalidParameterValueError(
parameter='resource', value=resource,
valid_values=valid_endpoints)
parameter="resource",
value=resource,
valid_values=valid_endpoints,
)
data = {}
if resource is not None:
data['Resource'] = {'@odata.id': resource}
data["Resource"] = {"@odata.id": resource}
self._conn.post(target_uri, data=data)
@ -180,72 +190,87 @@ class Node(v2_1_node.Node):
class NodeCollection(v2_2_node.NodeCollection):
@property
def _resource_type(self):
return Node
def _create_compose_request(self, name=None, description=None,
processor_req=None, memory_req=None,
remote_drive_req=None, local_drive_req=None,
ethernet_interface_req=None,
security_req=None, total_system_core_req=None,
total_system_memory_req=None):
def _create_compose_request(
self,
name=None,
description=None,
processor_req=None,
memory_req=None,
remote_drive_req=None,
local_drive_req=None,
ethernet_interface_req=None,
security_req=None,
total_system_core_req=None,
total_system_memory_req=None,
):
request = {}
if name is not None:
request['Name'] = name
request["Name"] = name
if description is not None:
request['Description'] = description
request["Description"] = description
if processor_req is not None:
validate(processor_req,
node_schemas.processor_req_schema)
request['Processors'] = processor_req
validate(processor_req, node_schemas.processor_req_schema)
request["Processors"] = processor_req
if memory_req is not None:
validate(memory_req,
node_schemas.memory_req_schema)
request['Memory'] = memory_req
validate(memory_req, node_schemas.memory_req_schema)
request["Memory"] = memory_req
if remote_drive_req is not None:
validate(remote_drive_req,
node_schemas.remote_drive_req_schema)
request['RemoteDrives'] = remote_drive_req
validate(remote_drive_req, node_schemas.remote_drive_req_schema)
request["RemoteDrives"] = remote_drive_req
if local_drive_req is not None:
validate(local_drive_req,
node_schemas.local_drive_req_schema)
request['LocalDrives'] = local_drive_req
validate(local_drive_req, node_schemas.local_drive_req_schema)
request["LocalDrives"] = local_drive_req
if ethernet_interface_req is not None:
validate(ethernet_interface_req,
node_schemas.ethernet_interface_req_schema)
request['EthernetInterfaces'] = ethernet_interface_req
validate(
ethernet_interface_req,
node_schemas.ethernet_interface_req_schema,
)
request["EthernetInterfaces"] = ethernet_interface_req
if security_req is not None:
validate(security_req,
node_schemas.security_req_schema)
request['Security'] = security_req
validate(security_req, node_schemas.security_req_schema)
request["Security"] = security_req
if total_system_core_req is not None:
validate(total_system_core_req,
node_schemas.total_system_core_req_schema)
request['TotalSystemCoreCount'] = total_system_core_req
validate(
total_system_core_req,
node_schemas.total_system_core_req_schema,
)
request["TotalSystemCoreCount"] = total_system_core_req
if total_system_memory_req is not None:
validate(total_system_memory_req,
node_schemas.total_system_memory_req_schema)
request['TotalSystemMemoryMiB'] = total_system_memory_req
validate(
total_system_memory_req,
node_schemas.total_system_memory_req_schema,
)
request["TotalSystemMemoryMiB"] = total_system_memory_req
return request
def compose_node(self, name=None, description=None,
processor_req=None, memory_req=None,
remote_drive_req=None, local_drive_req=None,
ethernet_interface_req=None, security_req=None,
total_system_core_req=None, total_system_memory_req=None):
def compose_node(
self,
name=None,
description=None,
processor_req=None,
memory_req=None,
remote_drive_req=None,
local_drive_req=None,
ethernet_interface_req=None,
security_req=None,
total_system_core_req=None,
total_system_memory_req=None,
):
"""Compose a node from RackScale hardware
:param name: Name of node
@ -275,7 +300,8 @@ class NodeCollection(v2_2_node.NodeCollection):
"""
target_uri = self._get_compose_action_element().target_uri
properties = self._create_compose_request(
name=name, description=description,
name=name,
description=description,
processor_req=processor_req,
memory_req=memory_req,
remote_drive_req=remote_drive_req,
@ -283,8 +309,9 @@ class NodeCollection(v2_2_node.NodeCollection):
ethernet_interface_req=ethernet_interface_req,
security_req=security_req,
total_system_core_req=total_system_core_req,
total_system_memory_req=total_system_memory_req)
total_system_memory_req=total_system_memory_req,
)
resp = self._conn.post(target_uri, data=properties)
LOG.info("Node created at %s", resp.headers['Location'])
node_url = resp.headers['Location']
LOG.info("Node created at %s", resp.headers["Location"])
node_url = resp.headers["Location"]
return node_url[node_url.find(self._path):]

View File

@ -13,208 +13,233 @@
# under the License.
processor_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'Model': {'type': 'string'},
'TotalCores': {'type': 'number'},
'AchievableSpeedMHz': {'type': 'number'},
'InstructionSet': {
'type': 'string',
'enum': ['x86', 'x86-64', 'IA-64', 'ARM-A32',
'ARM-A64', 'MIPS32', 'MIPS64', 'OEM']
},
'Oem': {
'type': 'object',
'properties': {
'Brand': {
'type': 'string',
'enum': ['E3', 'E5', 'E7', 'X3', 'X5', 'X7', 'I3',
'I5', 'I7', 'Silver', 'Gold', 'Platinum',
'Unknown']
"type": "array",
"items": [
{
"type": "object",
"properties": {
"Model": {"type": "string"},
"TotalCores": {"type": "number"},
"AchievableSpeedMHz": {"type": "number"},
"InstructionSet": {
"type": "string",
"enum": [
"x86",
"x86-64",
"IA-64",
"ARM-A32",
"ARM-A64",
"MIPS32",
"MIPS64",
"OEM",
],
},
"Oem": {
"type": "object",
"properties": {
"Brand": {
"type": "string",
"enum": [
"E3",
"E5",
"E7",
"X3",
"X5",
"X7",
"I3",
"I5",
"I7",
"Silver",
"Gold",
"Platinum",
"Unknown",
],
},
"Capabilities": {
"type": "array",
"items": [{"type": "string"}],
},
},
'Capabilities': {
'type': 'array',
'items': [{'type': 'string'}]
}
}
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"Chassis": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"ProcessorType": {
"type": "string",
"enum": [
"CPU",
"FPGA",
"GPU",
"DSP",
"Accelerator",
"OEM",
],
},
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'ProcessorType': {
'type': 'string',
'enum': ['CPU', 'FPGA', 'GPU', 'DSP', 'Accelerator', 'OEM']
}
},
'additionalProperties': False,
}]
"additionalProperties": False,
}
],
}
memory_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'CapacityMiB': {'type': 'number'},
'MemoryDeviceType': {
'type': 'string',
'enum': ['DDR', 'DDR2', 'DDR3', 'DDR4', 'DDR4_SDRAM',
'DDR4E_SDRAM', 'LPDDR4_SDRAM', 'DDR3_SDRAM',
'LPDDR3_SDRAM', 'DDR2_SDRAM', 'DDR2_SDRAM_FB_DIMM',
'DDR2_SDRAM_FB_DIMM_PROBE', 'DDR_SGRAM',
'DDR_SDRAM', 'ROM', 'SDRAM', 'EDO',
'FastPageMode', 'PipelinedNibble']
"type": "array",
"items": [
{
"type": "object",
"properties": {
"CapacityMiB": {"type": "number"},
"MemoryDeviceType": {
"type": "string",
"enum": [
"DDR",
"DDR2",
"DDR3",
"DDR4",
"DDR4_SDRAM",
"DDR4E_SDRAM",
"LPDDR4_SDRAM",
"DDR3_SDRAM",
"LPDDR3_SDRAM",
"DDR2_SDRAM",
"DDR2_SDRAM_FB_DIMM",
"DDR2_SDRAM_FB_DIMM_PROBE",
"DDR_SGRAM",
"DDR_SDRAM",
"ROM",
"SDRAM",
"EDO",
"FastPageMode",
"PipelinedNibble",
],
},
"SpeedMHz": {"type": "number"},
"Manufacturer": {"type": "string"},
"DataWidthBits": {"type": "number"},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"Chassis": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
},
'SpeedMHz': {'type': 'number'},
'Manufacturer': {'type': 'string'},
'DataWidthBits': {'type': 'number'},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
},
'additionalProperties': False,
}]
"additionalProperties": False,
}
],
}
remote_drive_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'CapacityGiB': {'type': 'number'},
'Protocol': {
'type': 'string',
'enum': ['iSCSI', 'NVMeOverFabrics']
},
'Master': {
'type': 'object',
'properties': {
'Type': {
'type': 'string',
'enum': ['Snapshot', 'Clone']
"type": "array",
"items": [
{
"type": "object",
"properties": {
"CapacityGiB": {"type": "number"},
"Protocol": {
"type": "string",
"enum": ["iSCSI", "NVMeOverFabrics"],
},
"Master": {
"type": "object",
"properties": {
"Type": {
"type": "string",
"enum": ["Snapshot", "Clone"],
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
}
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
},
'additionalProperties': False,
}]
"additionalProperties": False,
}
],
}
local_drive_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'CapacityGiB': {'type': 'number'},
'Type': {
'type': 'string',
'enum': ['HDD', 'SSD']
"type": "array",
"items": [
{
"type": "object",
"properties": {
"CapacityGiB": {"type": "number"},
"Type": {"type": "string", "enum": ["HDD", "SSD"]},
"MinRPM": {"type": "number"},
"SerialNumber": {"type": "string"},
"Interface": {
"type": "string",
"enum": ["SAS", "SATA", "NVMe"],
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"Chassis": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"FabricSwitch": {"type": "boolean"},
},
'MinRPM': {'type': 'number'},
'SerialNumber': {'type': 'string'},
'Interface': {
'type': 'string',
'enum': ['SAS', 'SATA', 'NVMe']
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'FabricSwitch': {'type': 'boolean'}
},
'additionalProperties': False,
}]
"additionalProperties": False,
}
],
}
ethernet_interface_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'SpeedMbps': {'type': 'number'},
'PrimaryVLAN': {'type': 'number'},
'VLANs': {
'type': 'array',
'additionalItems': {
'type': 'object',
'properties': {
'VLANId': {'type': 'number'},
'Tagged': {'type': 'boolean'}
}
}
"type": "array",
"items": [
{
"type": "object",
"properties": {
"SpeedMbps": {"type": "number"},
"PrimaryVLAN": {"type": "number"},
"VLANs": {
"type": "array",
"additionalItems": {
"type": "object",
"properties": {
"VLANId": {"type": "number"},
"Tagged": {"type": "boolean"},
},
},
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"Chassis": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
},
'additionalProperties': False,
}]
"additionalProperties": False,
}
],
}
security_req_schema = {
'type': 'object',
'properties': {
'TpmPresent': {'type': 'boolean'},
'TpmInterfaceType': {'type': 'string'},
'TxtEnabled': {'type': 'boolean'},
'ClearTPMOnDelete': {'type': 'boolean'}
"type": "object",
"properties": {
"TpmPresent": {"type": "boolean"},
"TpmInterfaceType": {"type": "string"},
"TxtEnabled": {"type": "boolean"},
"ClearTPMOnDelete": {"type": "boolean"},
},
'additionalProperties': False,
"additionalProperties": False,
}
total_system_core_req_schema = {
'type': 'number'
}
total_system_core_req_schema = {"type": "number"}
total_system_memory_req_schema = {
'type': 'number'
}
total_system_memory_req_schema = {"type": "number"}

View File

@ -23,124 +23,129 @@ from rsd_lib import utils as rsd_lib_utils
class LinksField(base.CompositeField):
chassis = base.Field('Chassis',
adapter=rsd_lib_utils.get_resource_identity)
chassis = base.Field(
"Chassis", adapter=rsd_lib_utils.get_resource_identity
)
"""Link to related chassis of this drive"""
volumes = base.Field('Volumes', default=(),
adapter=utils.get_members_identities)
volumes = base.Field(
"Volumes", default=(), adapter=utils.get_members_identities
)
"""Link to related volumes of this drive"""
endpoints = base.Field('Endpoints', default=(),
adapter=utils.get_members_identities)
endpoints = base.Field(
"Endpoints", default=(), adapter=utils.get_members_identities
)
"""Link to related endpoints of this drive"""
class OemField(base.CompositeField):
erased = base.Field(['Intel_RackScale', 'DriveErased'], adapter=bool,
required=True)
erase_on_detach = base.Field(['Intel_RackScale', 'EraseOnDetach'],
adapter=bool)
firmware_version = base.Field(['Intel_RackScale', 'FirmwareVersion'])
storage = base.Field(['Intel_RackScale', 'Storage'])
pcie_function = base.Field(['Intel_RackScale', 'PCIeFunction'])
erased = base.Field(
["Intel_RackScale", "DriveErased"], adapter=bool, required=True
)
erase_on_detach = base.Field(
["Intel_RackScale", "EraseOnDetach"], adapter=bool
)
firmware_version = base.Field(["Intel_RackScale", "FirmwareVersion"])
storage = base.Field(["Intel_RackScale", "Storage"])
pcie_function = base.Field(["Intel_RackScale", "PCIeFunction"])
class IdentifiersField(base.ListField):
durable_name = base.Field('DurableName')
durable_name_format = base.Field('DurableNameFormat')
durable_name = base.Field("DurableName")
durable_name_format = base.Field("DurableNameFormat")
class LocationField(base.ListField):
info = base.Field('Info')
info_format = base.Field('InfoFormat')
info = base.Field("Info")
info_format = base.Field("InfoFormat")
class Drive(rsd_lib_base.ResourceBase):
identity = base.Field('Id', required=True)
identity = base.Field("Id", required=True)
"""The drive identity string"""
name = base.Field('Name')
name = base.Field("Name")
"""The drive name string"""
protocol = base.Field('Protocol')
protocol = base.Field("Protocol")
"""The protocol of this drive"""
drive_type = base.Field('Type')
drive_type = base.Field("Type")
"""The protocol of this drive"""
media_type = base.Field('MediaType')
media_type = base.Field("MediaType")
"""The media type of this drive"""
capacity_bytes = base.Field('CapacityBytes',
adapter=rsd_lib_utils.num_or_none)
capacity_bytes = base.Field(
"CapacityBytes", adapter=rsd_lib_utils.num_or_none
)
"""The capacity in Bytes of this drive"""
manufacturer = base.Field('Manufacturer')
manufacturer = base.Field("Manufacturer")
"""The manufacturer of this drive"""
model = base.Field('Model')
model = base.Field("Model")
"""The drive model"""
revision = base.Field('Revision')
revision = base.Field("Revision")
"""The revision of this drive"""
sku = base.Field('SKU')
sku = base.Field("SKU")
"""The sku of this drive"""
serial_number = base.Field('SerialNumber')
serial_number = base.Field("SerialNumber")
"""The serial number of this drive"""
part_number = base.Field('PartNumber')
part_number = base.Field("PartNumber")
"""The part number of this drive"""
asset_tag = base.Field('AssetTag')
asset_tag = base.Field("AssetTag")
"""The asset tag of this drive"""
rotation_speed_rpm = base.Field('RotationSpeedRPM')
rotation_speed_rpm = base.Field("RotationSpeedRPM")
"""The rotation speed of this drive"""
identifiers = IdentifiersField('Identifiers')
identifiers = IdentifiersField("Identifiers")
"""These identifiers list of this drive"""
location = LocationField('Location')
location = LocationField("Location")
"""The location of this drive"""
status = rsd_lib_common.StatusField('Status')
status = rsd_lib_common.StatusField("Status")
"""The drive status"""
oem = OemField('Oem')
oem = OemField("Oem")
"""The OEM additional info of this drive"""
status_indicator = base.Field('StatusIndicator')
status_indicator = base.Field("StatusIndicator")
"""The status indicator state for the status indicator associated
with this drive"""
indicator_led = base.Field('IndicatorLED')
indicator_led = base.Field("IndicatorLED")
"""The indicator light state for the indicator light associated
with the drive"""
capable_speed_gbs = base.Field('CapableSpeedGbs')
capable_speed_gbs = base.Field("CapableSpeedGbs")
"""The current bus speed of the associated drive"""
negotiated_speed_gbs = base.Field('NegotiatedSpeedGbs')
negotiated_speed_gbs = base.Field("NegotiatedSpeedGbs")
"""The current bus speed of the associated drive"""
predicted_media_life_left_percent = base.Field(
'PredictedMediaLifeLeftPercent')
"PredictedMediaLifeLeftPercent"
)
"""An indicator of the percentage of life remaining in the drive's media"""
links = LinksField('Links')
links = LinksField("Links")
"""These links to related components of this volume"""
def _get_metrics_path(self):
"""Helper function to find the Metrics path"""
return utils.get_sub_resource_path_by(self,
['Links',
'Oem',
'Intel_RackScale',
'Metrics'])
return utils.get_sub_resource_path_by(
self, ["Links", "Oem", "Intel_RackScale", "Metrics"]
)
@property
@utils.cache_it
@ -151,12 +156,13 @@ class Drive(rsd_lib_base.ResourceBase):
refresh, this property is reset.
"""
return drive_metrics.DriveMetrics(
self._conn, self._get_metrics_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_metrics_path(),
redfish_version=self.redfish_version,
)
class DriveCollection(rsd_lib_base.ResourceCollectionBase):
@property
def _resource_type(self):
return Drive

View File

@ -19,63 +19,65 @@ from rsd_lib import utils as rsd_lib_utils
class LifeTimeField(base.CompositeField):
unit_size_bytes = base.Field('UnitSizeBytes',
adapter=rsd_lib_utils.num_or_none)
unit_size_bytes = base.Field(
"UnitSizeBytes", adapter=rsd_lib_utils.num_or_none
)
"""The size of a unit in bytes used by UnitsRead and UnitsWritten"""
units_read = base.Field('UnitsRead')
units_read = base.Field("UnitsRead")
"""The number of units of a read since reset """
units_written = base.Field('UnitsWritten')
units_written = base.Field("UnitsWritten")
"""The number of units of a written since reset"""
host_read_commands = base.Field('HostReadCommands')
host_read_commands = base.Field("HostReadCommands")
"""The number of read commands completed by the disk controller"""
host_write_commands = base.Field('HostWriteCommands')
host_write_commands = base.Field("HostWriteCommands")
"""The number of write commands completed by the disk controller"""
power_cycles = base.Field('PowerCycles')
power_cycles = base.Field("PowerCycles")
"""The number of power cycels of this drive"""
power_on_hours = base.Field('PowerOnHours')
power_on_hours = base.Field("PowerOnHours")
"""The number of power-on hours of this drive"""
controller_busy_time_minutes = base.Field('ControllerBusyTimeMinutes')
controller_busy_time_minutes = base.Field("ControllerBusyTimeMinutes")
"""The amount of time in minutes the driver controller is busy"""
class HealthDataField(base.CompositeField):
available_spare_percentage = base.Field('AvailableSparePercentage')
available_spare_percentage = base.Field("AvailableSparePercentage")
"""The percentage of the remaining spare capacity available"""
predicted_media_life_used_percent = base.Field(
'PredictedMediaLifeUsedPercent')
"PredictedMediaLifeUsedPercent"
)
"""The percentage of life remaining in the driver's media"""
unsafe_shutdowns = base.Field('UnsafeShutdowns')
unsafe_shutdowns = base.Field("UnsafeShutdowns")
"""The number of unsafe shutdowns of this drive"""
media_errors = base.Field('MediaErrors')
media_errors = base.Field("MediaErrors")
"""The number of media and data integrity errors of this drive"""
class DriveMetrics(rsd_lib_base.ResourceBase):
name = base.Field('Name')
name = base.Field("Name")
"""Drive metrics name"""
identity = base.Field('Id')
identity = base.Field("Id")
"""Drive metrics id"""
description = base.Field('Description')
description = base.Field("Description")
"""Drive metrics description"""
life_time = LifeTimeField('LifeTime')
life_time = LifeTimeField("LifeTime")
"""The life time metrics for this drive"""
health_data = HealthDataField('HealthData')
health_data = HealthDataField("HealthData")
"""The health data metrics for this drive"""
temperature_kelvin = base.Field('TemperatureKelvin')
temperature_kelvin = base.Field("TemperatureKelvin")
"""The temperature in Kelvin degrees of this drive"""

View File

@ -28,53 +28,58 @@ LOG = logging.getLogger(__name__)
class CapacityField(base.CompositeField):
allocated_bytes = base.Field(['Data', 'AllocatedBytes'],
adapter=rsd_lib_utils.num_or_none)
consumed_bytes = base.Field(['Data', 'ConsumedBytes'],
adapter=rsd_lib_utils.num_or_none)
guaranteed_bytes = base.Field(['Data', 'GuaranteedBytes'],
adapter=rsd_lib_utils.num_or_none)
provisioned_bytes = base.Field(['Data', 'ProvisionedBytes'],
adapter=rsd_lib_utils.num_or_none)
allocated_bytes = base.Field(
["Data", "AllocatedBytes"], adapter=rsd_lib_utils.num_or_none
)
consumed_bytes = base.Field(
["Data", "ConsumedBytes"], adapter=rsd_lib_utils.num_or_none
)
guaranteed_bytes = base.Field(
["Data", "GuaranteedBytes"], adapter=rsd_lib_utils.num_or_none
)
provisioned_bytes = base.Field(
["Data", "ProvisionedBytes"], adapter=rsd_lib_utils.num_or_none
)
class CapacitySourcesField(base.ListField):
providing_drives = base.Field('ProvidingDrives', default=(),
adapter=utils.get_members_identities)
provided_capacity = CapacityField('ProvidedCapacity')
providing_drives = base.Field(
"ProvidingDrives", default=(), adapter=utils.get_members_identities
)
provided_capacity = CapacityField("ProvidedCapacity")
class IdentifierField(base.CompositeField):
durable_name = base.Field('DurableName')
durable_name_format = base.Field('DurableNameFormat')
durable_name = base.Field("DurableName")
durable_name_format = base.Field("DurableNameFormat")
class StoragePool(rsd_lib_base.ResourceBase):
identity = base.Field('Id', required=True)
identity = base.Field("Id", required=True)
"""The storage pool identity string"""
description = base.Field('Description')
description = base.Field("Description")
"""The storage pool description string"""
name = base.Field('Name')
name = base.Field("Name")
"""The storage pool name string"""
status = rsd_lib_common.StatusField('Status')
status = rsd_lib_common.StatusField("Status")
"""The storage pool status"""
capacity = CapacityField('Capacity')
capacity = CapacityField("Capacity")
"""The storage pool capacity info"""
capacity_sources = CapacitySourcesField('CapacitySources')
capacity_sources = CapacitySourcesField("CapacitySources")
"""The storage pool capacity source info"""
identifier = IdentifierField('Identifier')
identifier = IdentifierField("Identifier")
"""These identifiers list of this volume"""
def _get_allocated_volumes_path(self):
"""Helper function to find the AllocatedVolumes path"""
return utils.get_sub_resource_path_by(self, 'AllocatedVolumes')
return utils.get_sub_resource_path_by(self, "AllocatedVolumes")
@property
@utils.cache_it
@ -85,12 +90,14 @@ class StoragePool(rsd_lib_base.ResourceBase):
refresh, this property is reset.
"""
return volume.VolumeCollection(
self._conn, self._get_allocated_volumes_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_allocated_volumes_path(),
redfish_version=self.redfish_version,
)
def _get_allocated_pools_path(self):
"""Helper function to find the AllocatedPools path"""
return utils.get_sub_resource_path_by(self, 'AllocatedPools')
return utils.get_sub_resource_path_by(self, "AllocatedPools")
@property
@utils.cache_it
@ -101,12 +108,13 @@ class StoragePool(rsd_lib_base.ResourceBase):
refresh, this property is reset.
"""
return StoragePoolCollection(
self._conn, self._get_allocated_pools_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_allocated_pools_path(),
redfish_version=self.redfish_version,
)
class StoragePoolCollection(rsd_lib_base.ResourceCollectionBase):
@property
def _resource_type(self):
return StoragePool

View File

@ -30,21 +30,21 @@ LOG = logging.getLogger(__name__)
class StorageService(rsd_lib_base.ResourceBase):
description = base.Field('Description')
description = base.Field("Description")
"""The storage service description"""
identity = base.Field('Id', required=True)
identity = base.Field("Id", required=True)
"""The storage service identity string"""
name = base.Field('Name')
name = base.Field("Name")
"""The storage service name"""
status = rsd_lib_common.StatusField('Status')
status = rsd_lib_common.StatusField("Status")
"""The storage service status"""
def _get_volume_collection_path(self):
"""Helper function to find the VolumeCollection path"""
return utils.get_sub_resource_path_by(self, 'Volumes')
return utils.get_sub_resource_path_by(self, "Volumes")
@property
@utils.cache_it
@ -55,12 +55,14 @@ class StorageService(rsd_lib_base.ResourceBase):
refresh, this property is reset.
"""
return volume.VolumeCollection(
self._conn, self._get_volume_collection_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_volume_collection_path(),
redfish_version=self.redfish_version,
)
def _get_storage_pool_collection_path(self):
"""Helper function to find the StoragePoolCollection path"""
return utils.get_sub_resource_path_by(self, 'StoragePools')
return utils.get_sub_resource_path_by(self, "StoragePools")
@property
@utils.cache_it
@ -71,12 +73,14 @@ class StorageService(rsd_lib_base.ResourceBase):
refresh, this property is reset.
"""
return storage_pool.StoragePoolCollection(
self._conn, self._get_storage_pool_collection_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_storage_pool_collection_path(),
redfish_version=self.redfish_version,
)
def _get_drive_collection_path(self):
"""Helper function to find the DriveCollection path"""
return utils.get_sub_resource_path_by(self, 'Drives')
return utils.get_sub_resource_path_by(self, "Drives")
@property
@utils.cache_it
@ -87,12 +91,14 @@ class StorageService(rsd_lib_base.ResourceBase):
refresh, this property is reset.
"""
return drive.DriveCollection(
self._conn, self._get_drive_collection_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_drive_collection_path(),
redfish_version=self.redfish_version,
)
def _get_endpoint_collection_path(self):
"""Helper function to find the EndpointCollection path"""
return utils.get_sub_resource_path_by(self, 'Endpoints')
return utils.get_sub_resource_path_by(self, "Endpoints")
@property
@utils.cache_it
@ -103,12 +109,13 @@ class StorageService(rsd_lib_base.ResourceBase):
refresh, this property is reset.
"""
return endpoint.EndpointCollection(
self._conn, self._get_endpoint_collection_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_endpoint_collection_path(),
redfish_version=self.redfish_version,
)
class StorageServiceCollection(rsd_lib_base.ResourceCollectionBase):
@property
def _resource_type(self):
return StorageService

View File

@ -30,98 +30,110 @@ LOG = logging.getLogger(__name__)
class CapacitySourcesField(base.ListField):
providing_pools = base.Field('ProvidingPools',
adapter=utils.get_members_identities)
providing_pools = base.Field(
"ProvidingPools", adapter=utils.get_members_identities
)
allocated_Bytes = base.Field(
['ProvidedCapacity', 'Data', 'AllocatedBytes'],
adapter=rsd_lib_utils.num_or_none)
["ProvidedCapacity", "Data", "AllocatedBytes"],
adapter=rsd_lib_utils.num_or_none,
)
class LinksField(base.CompositeField):
endpoints = base.Field(['Oem', 'Intel_RackScale', 'Endpoints'], default=(),
adapter=utils.get_members_identities)
endpoints = base.Field(
["Oem", "Intel_RackScale", "Endpoints"],
default=(),
adapter=utils.get_members_identities,
)
"""Link to related endpoints of this volume"""
metrics = base.Field(['Oem', 'Intel_RackScale', 'Metrics'],
adapter=rsd_lib_utils.get_resource_identity)
metrics = base.Field(
["Oem", "Intel_RackScale", "Metrics"],
adapter=rsd_lib_utils.get_resource_identity,
)
"""Link to telemetry metrics of this volume"""
class IdentifiersField(base.ListField):
durable_name = base.Field('DurableName')
durable_name_format = base.Field('DurableNameFormat')
durable_name = base.Field("DurableName")
durable_name_format = base.Field("DurableNameFormat")
class ReplicaInfosField(base.ListField):
replica_readonly_access = base.Field('ReplicaReadOnlyAccess')
replica_type = base.Field('ReplicaType')
replica_role = base.Field('ReplicaRole')
replica = base.Field('Replica',
adapter=rsd_lib_utils.get_resource_identity)
replica_readonly_access = base.Field("ReplicaReadOnlyAccess")
replica_type = base.Field("ReplicaType")
replica_role = base.Field("ReplicaRole")
replica = base.Field(
"Replica", adapter=rsd_lib_utils.get_resource_identity
)
class InitializeActionField(base.CompositeField):
target_uri = base.Field('target', required=True)
target_uri = base.Field("target", required=True)
class VolumeActionsField(base.CompositeField):
initialize = InitializeActionField('#Volume.Initialize')
initialize = InitializeActionField("#Volume.Initialize")
class Volume(rsd_lib_base.ResourceBase):
identity = base.Field('Id', required=True)
identity = base.Field("Id", required=True)
"""The volume identity string"""
description = base.Field('Description')
description = base.Field("Description")
"""The volume description string"""
name = base.Field('Name')
name = base.Field("Name")
"""The volume name string"""
model = base.Field('Model')
model = base.Field("Model")
"""The volume model"""
manufacturer = base.Field('Manufacturer')
manufacturer = base.Field("Manufacturer")
"""The volume manufacturer"""
access_capabilities = base.Field('AccessCapabilities')
access_capabilities = base.Field("AccessCapabilities")
"""The access capabilities of volume"""
capacity_bytes = base.Field('CapacityBytes',
adapter=rsd_lib_utils.num_or_none)
capacity_bytes = base.Field(
"CapacityBytes", adapter=rsd_lib_utils.num_or_none
)
"""The capacity of volume in bytes"""
allocated_Bytes = base.Field(['Capacity', 'Data', 'AllocatedBytes'],
adapter=rsd_lib_utils.num_or_none)
allocated_Bytes = base.Field(
["Capacity", "Data", "AllocatedBytes"],
adapter=rsd_lib_utils.num_or_none,
)
"""The allocated capacity of volume in bytes"""
capacity_sources = CapacitySourcesField('CapacitySources')
capacity_sources = CapacitySourcesField("CapacitySources")
"""The logical drive status"""
identifiers = IdentifiersField('Identifiers')
identifiers = IdentifiersField("Identifiers")
"""These identifiers list of this volume"""
links = LinksField('Links')
links = LinksField("Links")
"""These links to related components of this volume"""
replica_infos = ReplicaInfosField('ReplicaInfos')
replica_infos = ReplicaInfosField("ReplicaInfos")
"""These replica related info of this volume"""
status = rsd_lib_common.StatusField('Status')
status = rsd_lib_common.StatusField("Status")
"""The volume status"""
bootable = base.Field(['Oem', 'Intel_RackScale', 'Bootable'], adapter=bool)
bootable = base.Field(["Oem", "Intel_RackScale", "Bootable"], adapter=bool)
"""The bootable info of this volume"""
erased = base.Field(['Oem', 'Intel_RackScale', 'Erased'])
erased = base.Field(["Oem", "Intel_RackScale", "Erased"])
"""The erased info of this volume"""
erase_on_detach = base.Field(['Oem', 'Intel_RackScale', 'EraseOnDetach'],
adapter=bool)
erase_on_detach = base.Field(
["Oem", "Intel_RackScale", "EraseOnDetach"], adapter=bool
)
"""The rrase on detach info of this volume"""
_actions = VolumeActionsField('Actions', required=True)
_actions = VolumeActionsField("Actions", required=True)
def update(self, bootable=None, erased=None):
"""Update volume properties
@ -131,24 +143,28 @@ class Volume(rsd_lib_base.ResourceBase):
:raises: BadRequestError if at least one param isn't specified
"""
if bootable is None and erased is None:
raise ValueError('At least "bootable" or "erased" parameter has '
'to be specified')
raise ValueError(
'At least "bootable" or "erased" parameter has '
"to be specified"
)
if bootable and not isinstance(bootable, bool):
raise exceptions.InvalidParameterValueError(
parameter='bootable', value=bootable,
valid_values=[True, False])
parameter="bootable",
value=bootable,
valid_values=[True, False],
)
if erased and not isinstance(erased, bool):
raise exceptions.InvalidParameterValueError(
parameter='erased', value=erased,
valid_values=[True, False])
parameter="erased", value=erased, valid_values=[True, False]
)
data = {'Oem': {'Intel_RackScale': {}}}
data = {"Oem": {"Intel_RackScale": {}}}
if bootable is not None:
data['Oem']['Intel_RackScale']['Bootable'] = bootable
data["Oem"]["Intel_RackScale"]["Bootable"] = bootable
if erased is not None:
data['Oem']['Intel_RackScale']['Erased'] = erased
data["Oem"]["Intel_RackScale"]["Erased"] = erased
self._conn.patch(self.path, data=data)
@ -156,8 +172,8 @@ class Volume(rsd_lib_base.ResourceBase):
initialize_action = self._actions.initialize
if not initialize_action:
raise exceptions.MissingActionError(
action='#Volume.Initialize',
resource=self._path)
action="#Volume.Initialize", resource=self._path
)
return initialize_action
def initialize(self, init_type):
@ -166,11 +182,13 @@ class Volume(rsd_lib_base.ResourceBase):
:param type: volume initialize type
:raises: InvalidParameterValueError if invalid "type" parameter
"""
allowed_init_type_values = ['Fast', 'Slow']
allowed_init_type_values = ["Fast", "Slow"]
if init_type not in allowed_init_type_values:
raise exceptions.InvalidParameterValueError(
parameter='init_type', value=init_type,
valid_values=allowed_init_type_values)
parameter="init_type",
value=init_type,
valid_values=allowed_init_type_values,
)
data = {"InitializeType": init_type}
@ -179,11 +197,9 @@ class Volume(rsd_lib_base.ResourceBase):
def _get_metrics_path(self):
"""Helper function to find the Metrics path"""
return utils.get_sub_resource_path_by(self,
['Links',
'Oem',
'Intel_RackScale',
'Metrics'])
return utils.get_sub_resource_path_by(
self, ["Links", "Oem", "Intel_RackScale", "Metrics"]
)
@property
@utils.cache_it
@ -194,52 +210,64 @@ class Volume(rsd_lib_base.ResourceBase):
refresh, this property is reset.
"""
return volume_metrics.VolumeMetrics(
self._conn, self._get_metrics_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_metrics_path(),
redfish_version=self.redfish_version,
)
class VolumeCollection(rsd_lib_base.ResourceCollectionBase):
@property
def _resource_type(self):
return Volume
def _create_volume_request(self, capacity, access_capabilities=None,
capacity_sources=None, replica_infos=None,
bootable=None):
def _create_volume_request(
self,
capacity,
access_capabilities=None,
capacity_sources=None,
replica_infos=None,
bootable=None,
):
request = {}
jsonschema.validate(capacity,
volume_schemas.capacity_req_schema)
request['CapacityBytes'] = capacity
jsonschema.validate(capacity, volume_schemas.capacity_req_schema)
request["CapacityBytes"] = capacity
if access_capabilities is not None:
jsonschema.validate(
access_capabilities,
volume_schemas.access_capabilities_req_schema)
request['AccessCapabilities'] = access_capabilities
volume_schemas.access_capabilities_req_schema,
)
request["AccessCapabilities"] = access_capabilities
if capacity_sources is not None:
jsonschema.validate(capacity_sources,
volume_schemas.capacity_sources_req_schema)
request['CapacitySources'] = capacity_sources
jsonschema.validate(
capacity_sources, volume_schemas.capacity_sources_req_schema
)
request["CapacitySources"] = capacity_sources
if replica_infos is not None:
jsonschema.validate(replica_infos,
volume_schemas.replica_infos_req_schema)
request['ReplicaInfos'] = replica_infos
jsonschema.validate(
replica_infos, volume_schemas.replica_infos_req_schema
)
request["ReplicaInfos"] = replica_infos
if bootable is not None:
jsonschema.validate(bootable,
volume_schemas.bootable_req_schema)
request['Oem'] = {"Intel_RackScale": {"Bootable": bootable}}
jsonschema.validate(bootable, volume_schemas.bootable_req_schema)
request["Oem"] = {"Intel_RackScale": {"Bootable": bootable}}
return request
def create_volume(self, capacity, access_capabilities=None,
capacity_sources=None, replica_infos=None,
bootable=None):
def create_volume(
self,
capacity,
access_capabilities=None,
capacity_sources=None,
replica_infos=None,
bootable=None,
):
"""Create a new volume
:param capacity: Requested volume capacity in bytes
@ -250,10 +278,13 @@ class VolumeCollection(rsd_lib_base.ResourceCollectionBase):
:returns: The uri of the new volume
"""
properties = self._create_volume_request(
capacity=capacity, access_capabilities=access_capabilities,
capacity_sources=capacity_sources, replica_infos=replica_infos,
bootable=bootable)
capacity=capacity,
access_capabilities=access_capabilities,
capacity_sources=capacity_sources,
replica_infos=replica_infos,
bootable=bootable,
)
resp = self._conn.post(self._path, data=properties)
LOG.info("Volume created at %s", resp.headers['Location'])
volume_url = resp.headers['Location']
LOG.info("Volume created at %s", resp.headers["Location"])
volume_url = resp.headers["Location"]
return volume_url[volume_url.find(self._path):]

View File

@ -20,15 +20,16 @@ from rsd_lib import utils as rsd_lib_utils
class VolumeMetrics(rsd_lib_base.ResourceBase):
name = base.Field('Name')
name = base.Field("Name")
"""The volume metrics name"""
description = base.Field('Description')
description = base.Field("Description")
"""The volume metrics description"""
identity = base.Field('Id', required=True)
identity = base.Field("Id", required=True)
"""The volume metrics identity string"""
capacity_used_bytes = base.Field('CapacityUsedBytes',
adapter=rsd_lib_utils.num_or_none)
capacity_used_bytes = base.Field(
"CapacityUsedBytes", adapter=rsd_lib_utils.num_or_none
)
"""The capacity in bytes of the volume"""

View File

@ -12,55 +12,47 @@
# License for the specific language governing permissions and limitations
# under the License.
capacity_req_schema = {
'type': 'number'
}
capacity_req_schema = {"type": "number"}
access_capabilities_req_schema = {
'type': 'array',
'items': {
'type': 'string',
'enum': ['Read', 'Write', 'WriteOnce', 'Append', 'Streaming']
}
"type": "array",
"items": {
"type": "string",
"enum": ["Read", "Write", "WriteOnce", "Append", "Streaming"],
},
}
capacity_sources_req_schema = {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'ProvidingPools': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
},
'additionalProperties': False
}
"type": "array",
"items": {
"type": "object",
"properties": {
"ProvidingPools": {
"type": "array",
"items": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
"additionalProperties": False,
},
}
},
'additionalProperties': False
}
"additionalProperties": False,
},
}
replica_infos_req_schema = {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'ReplicaType': {'type': 'string'},
'Replica': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
"type": "array",
"items": {
"type": "object",
"properties": {
"ReplicaType": {"type": "string"},
"Replica": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
},
'additionalProperties': False
}
"additionalProperties": False,
},
}
bootable_req_schema = {
'type': 'boolean'
}
bootable_req_schema = {"type": "boolean"}

View File

@ -32,8 +32,9 @@ class OemField(base.CompositeField):
class LinksIntelRackScaleField(base.CompositeField):
neighbor_port = base.Field("NeighborPort",
adapter=rsd_lib_utils.get_resource_identity)
neighbor_port = base.Field(
"NeighborPort", adapter=rsd_lib_utils.get_resource_identity
)
"""The neighbor port of Rack ScaleIntel"""
@ -47,7 +48,8 @@ class LinksField(base.CompositeField):
""""The oem of Links"""
endpoints = base.Field(
"Endpoints", adapter=rsd_lib_utils.get_resource_identity)
"Endpoints", adapter=rsd_lib_utils.get_resource_identity
)
"""The value of this property shall be a reference to the resources that
this ethernet interface is associated with and shall reference a
resource of type Endpoint.
@ -56,7 +58,7 @@ class LinksField(base.CompositeField):
class EthernetInterface(ethernet_interface.EthernetInterface):
uefi_device_path = base.Field('UefiDevicePath')
uefi_device_path = base.Field("UefiDevicePath")
"""The value of the property shall be the UEFI device path to the device
that implements the interface (port).
"""
@ -68,9 +70,9 @@ class EthernetInterface(ethernet_interface.EthernetInterface):
"""The EthernetInterface links"""
class EthernetInterfaceCollection(ethernet_interface.
EthernetInterfaceCollection):
class EthernetInterfaceCollection(
ethernet_interface.EthernetInterfaceCollection
):
@property
def _resource_type(self):
return EthernetInterface

View File

@ -20,7 +20,6 @@ from rsd_lib.resources.v2_3.system import ethernet_interface
class System(system.System):
@property
@utils.cache_it
def ethernet_interfaces(self):
@ -37,7 +36,6 @@ class System(system.System):
class SystemCollection(system.SystemCollection):
@property
def _resource_type(self):
return System

View File

@ -29,172 +29,192 @@ LOG = logging.getLogger(__name__)
class IdentifiersField(base.ListField):
name_format = base.Field('DurableNameFormat')
name = base.Field('DurableName')
name_format = base.Field("DurableNameFormat")
name = base.Field("DurableName")
class PciIdField(base.ListField):
device_id = base.Field('DeviceId')
vendor_id = base.Field('VendorId')
subsystem_id = base.Field('SubsystemId')
subsystem_vendor_id = base.Field('SubsystemVendorId')
device_id = base.Field("DeviceId")
vendor_id = base.Field("VendorId")
subsystem_id = base.Field("SubsystemId")
subsystem_vendor_id = base.Field("SubsystemVendorId")
class ConnectedEntitiesField(base.ListField):
entity_type = base.Field('EntityType')
entity_role = base.Field('EntityRole')
entity_link = base.Field('EntityLink',
adapter=rsd_lib_utils.get_resource_identity)
identifiers = IdentifiersField('Identifiers')
entity_pci_id = PciIdField('EntityPciId')
entity_type = base.Field("EntityType")
entity_role = base.Field("EntityRole")
entity_link = base.Field(
"EntityLink", adapter=rsd_lib_utils.get_resource_identity
)
identifiers = IdentifiersField("Identifiers")
entity_pci_id = PciIdField("EntityPciId")
pci_function_number = base.Field(
'PciFunctionNumber', adapter=rsd_lib_utils.num_or_none)
pci_class_code = base.Field('PciClassCode')
"PciFunctionNumber", adapter=rsd_lib_utils.num_or_none
)
pci_class_code = base.Field("PciClassCode")
class LinksOemIntelRackScaleField(base.CompositeField):
zones = base.Field('Zones', adapter=utils.get_members_identities)
interfaces = base.Field('Interfaces', adapter=utils.get_members_identities)
zones = base.Field("Zones", adapter=utils.get_members_identities)
interfaces = base.Field("Interfaces", adapter=utils.get_members_identities)
class LinksOemField(base.CompositeField):
intel_rackscale = LinksOemIntelRackScaleField('Intel_RackScale')
intel_rackscale = LinksOemIntelRackScaleField("Intel_RackScale")
class LinksField(base.CompositeField):
ports = base.Field('Ports', adapter=utils.get_members_identities)
endpoints = base.Field('Endpoints', adapter=utils.get_members_identities)
oem = LinksOemField('Oem')
ports = base.Field("Ports", adapter=utils.get_members_identities)
endpoints = base.Field("Endpoints", adapter=utils.get_members_identities)
oem = LinksOemField("Oem")
class IPTransportDetailsField(base.ListField):
transport_protocol = base.Field('TransportProtocol')
ipv4_address = base.Field(['IPv4Address', 'Address'])
ipv6_address = base.Field(['IPv6Address', 'Address'])
port = base.Field('Port', adapter=rsd_lib_utils.num_or_none)
transport_protocol = base.Field("TransportProtocol")
ipv4_address = base.Field(["IPv4Address", "Address"])
ipv6_address = base.Field(["IPv6Address", "Address"])
port = base.Field("Port", adapter=rsd_lib_utils.num_or_none)
class AuthenticationField(base.CompositeField):
username = base.Field('Username')
password = base.Field('Password')
username = base.Field("Username")
password = base.Field("Password")
class OemIntelRackScaleField(base.CompositeField):
authentication = AuthenticationField('Authentication')
authentication = AuthenticationField("Authentication")
endpoint_protocol = base.Field('EndpointProtocol')
endpoint_protocol = base.Field("EndpointProtocol")
"""Protocol for endpoint (i.e. PCIe)"""
pcie_function = base.Field(
'PCIeFunction', adapter=rsd_lib_utils.get_resource_identity)
"PCIeFunction", adapter=rsd_lib_utils.get_resource_identity
)
"""A reference to the PCIe function that provides this processor
functionality
"""
class OemField(base.CompositeField):
intel_rackscale = OemIntelRackScaleField('Intel_RackScale')
intel_rackscale = OemIntelRackScaleField("Intel_RackScale")
class Endpoint(rsd_lib_base.ResourceBase):
identity = base.Field('Id', required=True)
identity = base.Field("Id", required=True)
"""The endpoint identity string"""
name = base.Field('Name')
name = base.Field("Name")
"""The endpoint name"""
description = base.Field('Description')
description = base.Field("Description")
"""The endpoint description"""
endpoint_protocol = base.Field('EndpointProtocol')
endpoint_protocol = base.Field("EndpointProtocol")
"""Protocol for endpoint (i.e. PCIe)"""
connected_entities = ConnectedEntitiesField('ConnectedEntities')
connected_entities = ConnectedEntitiesField("ConnectedEntities")
"""Entities connected to endpoint"""
identifiers = IdentifiersField('Identifiers')
identifiers = IdentifiersField("Identifiers")
"""Identifiers for endpoint"""
status = rsd_lib_common.StatusField('Status')
status = rsd_lib_common.StatusField("Status")
"""The endpoint status"""
pci_id = PciIdField('PciId')
pci_id = PciIdField("PciId")
"""PCI ID of the endpoint"""
host_reservation_memory_bytes = base.Field('HostReservationMemoryBytes')
host_reservation_memory_bytes = base.Field("HostReservationMemoryBytes")
"""The amount of memory in bytes that the Host should allocate to connect
to this endpoint
"""
ip_transport_details = IPTransportDetailsField('IPTransportDetails')
ip_transport_details = IPTransportDetailsField("IPTransportDetails")
"""IP transport details info of this endpoint"""
links = LinksField('Links')
links = LinksField("Links")
"""These links to related components of this endpoint"""
oem = OemField('Oem')
oem = OemField("Oem")
"""The OEM additional info of this endpoint"""
class EndpointCollection(rsd_lib_base.ResourceCollectionBase):
@property
def _resource_type(self):
return Endpoint
def _create_endpoint_request(self, connected_entities, identifiers=None,
protocol=None, pci_id=None,
host_reservation_memory_bytes=None,
ip_transport_details=None, links=None,
oem=None):
def _create_endpoint_request(
self,
connected_entities,
identifiers=None,
protocol=None,
pci_id=None,
host_reservation_memory_bytes=None,
ip_transport_details=None,
links=None,
oem=None,
):
request = {}
jsonschema.validate(connected_entities,
endpoint_schemas.connected_entities_req_schema)
request['ConnectedEntities'] = connected_entities
jsonschema.validate(
connected_entities, endpoint_schemas.connected_entities_req_schema
)
request["ConnectedEntities"] = connected_entities
if identifiers is not None:
jsonschema.validate(identifiers,
endpoint_schemas.identifiers_req_schema)
request['Identifiers'] = identifiers
jsonschema.validate(
identifiers, endpoint_schemas.identifiers_req_schema
)
request["Identifiers"] = identifiers
if protocol is not None:
jsonschema.validate(protocol, endpoint_schemas.protocol_req_schema)
request['EndpointProtocol'] = protocol
request["EndpointProtocol"] = protocol
if pci_id is not None:
jsonschema.validate(pci_id, endpoint_schemas.pci_id_req_schema)
request['PciId'] = pci_id
request["PciId"] = pci_id
if host_reservation_memory_bytes is not None:
jsonschema.validate(
host_reservation_memory_bytes,
endpoint_schemas.host_reservation_memory_bytes_req_schema)
request['HostReservationMemoryBytes'] = \
host_reservation_memory_bytes
endpoint_schemas.host_reservation_memory_bytes_req_schema,
)
request[
"HostReservationMemoryBytes"
] = host_reservation_memory_bytes
if ip_transport_details is not None:
jsonschema.validate(
ip_transport_details,
endpoint_schemas.ip_transport_details_req_schema)
request['IPTransportDetails'] = ip_transport_details
endpoint_schemas.ip_transport_details_req_schema,
)
request["IPTransportDetails"] = ip_transport_details
if links is not None:
jsonschema.validate(links, endpoint_schemas.links_req_schema)
request['Links'] = links
request["Links"] = links
if oem is not None:
jsonschema.validate(oem, endpoint_schemas.oem_req_schema)
request['Oem'] = oem
request["Oem"] = oem
return request
def create_endpoint(self, connected_entities, identifiers=None,
protocol=None, pci_id=None,
host_reservation_memory_bytes=None,
ip_transport_details=None, links=None, oem=None):
def create_endpoint(
self,
connected_entities,
identifiers=None,
protocol=None,
pci_id=None,
host_reservation_memory_bytes=None,
ip_transport_details=None,
links=None,
oem=None,
):
"""Create a new endpoint
:param connected_entities: provides information about entities
@ -208,10 +228,17 @@ class EndpointCollection(rsd_lib_base.ResourceCollectionBase):
:returns: The uri of the new endpoint
"""
properties = self._create_endpoint_request(
connected_entities, identifiers, protocol, pci_id,
host_reservation_memory_bytes, ip_transport_details, links, oem)
connected_entities,
identifiers,
protocol,
pci_id,
host_reservation_memory_bytes,
ip_transport_details,
links,
oem,
)
resp = self._conn.post(self._path, data=properties)
LOG.info("Endpoint created at %s", resp.headers['Location'])
endpoint_url = resp.headers['Location']
LOG.info("Endpoint created at %s", resp.headers["Location"])
endpoint_url = resp.headers["Location"]
return endpoint_url[endpoint_url.find(self._path):]

View File

@ -13,143 +13,146 @@
# under the License.
identifiers_req_schema = {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'DurableNameFormat': {'type': 'string'},
'DurableName': {'type': 'string'}
"type": "array",
"items": {
"type": "object",
"properties": {
"DurableNameFormat": {"type": "string"},
"DurableName": {"type": "string"},
},
"required": ['DurableNameFormat', 'DurableName']
}
"required": ["DurableNameFormat", "DurableName"],
},
}
connected_entities_req_schema = {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'EntityLink': {
'type': ['object', 'null'],
'properties': {
'@odata.id': {'type': 'string'}
"type": "array",
"items": {
"type": "object",
"properties": {
"EntityLink": {
"type": ["object", "null"],
"properties": {"@odata.id": {"type": "string"}},
"required": ["@odata.id"],
},
"EntityRole": {
"type": "string",
"enum": ["Initiator", "Target", "Both"],
},
"EntityType": {
"type": "string",
"enum": [
"StorageInitiator",
"RootComplex",
"NetworkController",
"Drive",
"StorageExpander",
"DisplayController",
"Bridge",
"Processor",
"Volume",
],
},
"EntityPciId": {
"type": "object",
"properties": {
"DeviceId": {"type": "string"},
"VendorId": {"type": "string"},
"SubsystemId": {"type": "string"},
"SubsystemVendorId": {"type": "string"},
},
"required": ['@odata.id']
},
'EntityRole': {
'type': 'string',
'enum': ['Initiator', 'Target', 'Both']
},
'EntityType': {
'type': 'string',
'enum': [
'StorageInitiator', 'RootComplex', 'NetworkController',
'Drive', 'StorageExpander', 'DisplayController', 'Bridge',
'Processor', 'Volume'
]
},
'EntityPciId': {
'type': 'object',
'properties': {
'DeviceId': {'type': 'string'},
'VendorId': {'type': 'string'},
'SubsystemId': {'type': 'string'},
'SubsystemVendorId': {'type': 'string'}
}
},
'PciFunctionNumber': {'type': 'number'},
'PciClassCode': {'type': 'string'},
'Identifiers': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'DurableNameFormat': {
'type': 'string',
'enum': ['NQN', 'iQN', 'FC_WWN', 'UUID', 'EUI',
'NAA', 'NSID', 'SystemPath', 'LUN']
"PciFunctionNumber": {"type": "number"},
"PciClassCode": {"type": "string"},
"Identifiers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"DurableNameFormat": {
"type": "string",
"enum": [
"NQN",
"iQN",
"FC_WWN",
"UUID",
"EUI",
"NAA",
"NSID",
"SystemPath",
"LUN",
],
},
'DurableName': {'type': 'string'}
"DurableName": {"type": "string"},
},
"required": ['DurableNameFormat', 'DurableName']
}
}
"required": ["DurableNameFormat", "DurableName"],
},
},
},
"required": ['EntityRole']
}
"required": ["EntityRole"],
},
}
protocol_req_schema = {
'type': 'string'
}
protocol_req_schema = {"type": "string"}
pci_id_req_schema = {
'type': 'object',
'properties': {
'DeviceId': {'type': 'string'},
'VendorId': {'type': 'string'},
'SubsystemId': {'type': 'string'},
'SubsystemVendorId': {'type': 'string'}
}
"type": "object",
"properties": {
"DeviceId": {"type": "string"},
"VendorId": {"type": "string"},
"SubsystemId": {"type": "string"},
"SubsystemVendorId": {"type": "string"},
},
}
host_reservation_memory_bytes_req_schema = {
'type': 'number'
}
host_reservation_memory_bytes_req_schema = {"type": "number"}
ip_transport_details_req_schema = {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'TransportProtocol': {'type': 'string'},
'IPv4Address': {
'type': 'object',
'properties': {
'Address': {'type': 'string'}
}
"type": "array",
"items": {
"type": "object",
"properties": {
"TransportProtocol": {"type": "string"},
"IPv4Address": {
"type": "object",
"properties": {"Address": {"type": "string"}},
},
'IPv6Address': {
'type': 'object',
'properties': {
'Address': {'type': 'string'}
}
"IPv6Address": {
"type": "object",
"properties": {"Address": {"type": "string"}},
},
'Port': {'type': 'number'}
}
}
"Port": {"type": "number"},
},
},
}
links_req_schema = {
'type': 'object',
'properties': {
'Ports': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
"type": "object",
"properties": {
"Ports": {
"type": "array",
"items": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
}
}
},
}
oem_req_schema = {
'type': 'object',
'properties': {
'Intel_RackScale': {
'type': 'object',
'properties': {
'EndpointProtocol': {'type': 'string'},
'Authentication': {
'type': 'object',
'properties': {
'Username': {'type': 'string'},
'Password': {'type': 'string'}
}
}
}
"type": "object",
"properties": {
"Intel_RackScale": {
"type": "object",
"properties": {
"EndpointProtocol": {"type": "string"},
"Authentication": {
"type": "object",
"properties": {
"Username": {"type": "string"},
"Password": {"type": "string"},
},
},
},
}
}
},
}

View File

@ -21,10 +21,9 @@ from rsd_lib.resources.v2_4.fabric import endpoint
class Fabric(fabric.Fabric):
def _get_endpoint_collection_path(self):
"""Helper function to find the EndpointCollection path"""
return utils.get_sub_resource_path_by(self, 'Endpoints')
return utils.get_sub_resource_path_by(self, "Endpoints")
@property
@utils.cache_it
@ -35,12 +34,13 @@ class Fabric(fabric.Fabric):
refresh, this property is reset.
"""
return endpoint.EndpointCollection(
self._conn, self._get_endpoint_collection_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_endpoint_collection_path(),
redfish_version=self.redfish_version,
)
class FabricCollection(rsd_lib_base.ResourceCollectionBase):
@property
def _resource_type(self):
return Fabric

View File

@ -25,30 +25,34 @@ from rsd_lib.resources.v2_4.node import schemas as node_schemas
LOG = logging.getLogger(__name__)
PM_OPENATION_ON_DELETE_VALUES = [
'PreserveConfiguration', 'SecureErase', 'OverwritePCD']
"PreserveConfiguration",
"SecureErase",
"OverwritePCD",
]
class AttachEndpointActionField(base.CompositeField):
target_uri = base.Field('target', required=True)
action_info_path = base.Field('@Redfish.ActionInfo')
target_uri = base.Field("target", required=True)
action_info_path = base.Field("@Redfish.ActionInfo")
action_info = None
class DetachEndpointActionField(base.CompositeField):
target_uri = base.Field('target', required=True)
action_info_path = base.Field('@Redfish.ActionInfo')
target_uri = base.Field("target", required=True)
action_info_path = base.Field("@Redfish.ActionInfo")
action_info = None
class NodeActionsField(node.NodeActionsField):
attach_endpoint = AttachEndpointActionField('#ComposedNode.AttachResource')
detach_endpoint = DetachEndpointActionField('#ComposedNode.DetachResource')
attach_endpoint = AttachEndpointActionField("#ComposedNode.AttachResource")
detach_endpoint = DetachEndpointActionField("#ComposedNode.DetachResource")
class Node(node.Node):
persistent_memory_operation_on_delete = base.Field(
'PersistentMemoryOperationOnDelete')
"PersistentMemoryOperationOnDelete"
)
"""This property is used to specify what operation should be performed on
Intel OptaneTM DC Persistent Memory on ComposedNode DELETE Request:
- PreserveConfiguration
@ -56,7 +60,7 @@ class Node(node.Node):
- OverwritePCD
"""
_actions = NodeActionsField('Actions', required=True)
_actions = NodeActionsField("Actions", required=True)
def update(self, clear_tpm_on_delete=None, pm_on_delete=None):
"""Update properties of this composed node
@ -73,94 +77,115 @@ class Node(node.Node):
invalid.
"""
if clear_tpm_on_delete is None and pm_on_delete is None:
raise ValueError('At least "clear_tpm_on_delete" or "pm_on_delete"'
' parameter has to be specified')
raise ValueError(
'At least "clear_tpm_on_delete" or "pm_on_delete"'
" parameter has to be specified"
)
data = {}
if clear_tpm_on_delete is not None:
if not isinstance(clear_tpm_on_delete, bool):
raise exceptions.InvalidParameterValueError(
parameter='clear_tpm_on_delete', value=clear_tpm_on_delete,
valid_values=[True, False])
data['ClearTPMOnDelete'] = clear_tpm_on_delete
parameter="clear_tpm_on_delete",
value=clear_tpm_on_delete,
valid_values=[True, False],
)
data["ClearTPMOnDelete"] = clear_tpm_on_delete
if pm_on_delete is not None:
if pm_on_delete not in PM_OPENATION_ON_DELETE_VALUES:
raise exceptions.InvalidParameterValueError(
parameter='pm_on_delete', value=pm_on_delete,
valid_values=PM_OPENATION_ON_DELETE_VALUES)
data['PersistentMemoryOperationOnDelete'] = pm_on_delete
parameter="pm_on_delete",
value=pm_on_delete,
valid_values=PM_OPENATION_ON_DELETE_VALUES,
)
data["PersistentMemoryOperationOnDelete"] = pm_on_delete
self._conn.patch(self.path, data=data)
class NodeCollection(node.NodeCollection):
@property
def _resource_type(self):
return Node
def _create_compose_request(self, name=None, description=None,
processor_req=None, memory_req=None,
remote_drive_req=None, local_drive_req=None,
ethernet_interface_req=None,
security_req=None, total_system_core_req=None,
total_system_memory_req=None):
def _create_compose_request(
self,
name=None,
description=None,
processor_req=None,
memory_req=None,
remote_drive_req=None,
local_drive_req=None,
ethernet_interface_req=None,
security_req=None,
total_system_core_req=None,
total_system_memory_req=None,
):
request = {}
if name is not None:
request['Name'] = name
request["Name"] = name
if description is not None:
request['Description'] = description
request["Description"] = description
if processor_req is not None:
validate(processor_req,
node_schemas.processor_req_schema)
request['Processors'] = processor_req
validate(processor_req, node_schemas.processor_req_schema)
request["Processors"] = processor_req
if memory_req is not None:
validate(memory_req,
node_schemas.memory_req_schema)
request['Memory'] = memory_req
validate(memory_req, node_schemas.memory_req_schema)
request["Memory"] = memory_req
if remote_drive_req is not None:
validate(remote_drive_req,
node_schemas.remote_drive_req_schema)
request['RemoteDrives'] = remote_drive_req
validate(remote_drive_req, node_schemas.remote_drive_req_schema)
request["RemoteDrives"] = remote_drive_req
if local_drive_req is not None:
validate(local_drive_req,
node_schemas.local_drive_req_schema)
request['LocalDrives'] = local_drive_req
validate(local_drive_req, node_schemas.local_drive_req_schema)
request["LocalDrives"] = local_drive_req
if ethernet_interface_req is not None:
validate(ethernet_interface_req,
node_schemas.ethernet_interface_req_schema)
request['EthernetInterfaces'] = ethernet_interface_req
validate(
ethernet_interface_req,
node_schemas.ethernet_interface_req_schema,
)
request["EthernetInterfaces"] = ethernet_interface_req
if security_req is not None:
validate(security_req,
node_schemas.security_req_schema)
request['Security'] = security_req
validate(security_req, node_schemas.security_req_schema)
request["Security"] = security_req
if total_system_core_req is not None:
validate(total_system_core_req,
node_schemas.total_system_core_req_schema)
request['TotalSystemCoreCount'] = total_system_core_req
validate(
total_system_core_req,
node_schemas.total_system_core_req_schema,
)
request["TotalSystemCoreCount"] = total_system_core_req
if total_system_memory_req is not None:
validate(total_system_memory_req,
node_schemas.total_system_memory_req_schema)
request['TotalSystemMemoryMiB'] = total_system_memory_req
validate(
total_system_memory_req,
node_schemas.total_system_memory_req_schema,
)
request["TotalSystemMemoryMiB"] = total_system_memory_req
return request
def compose_node(self, name=None, description=None,
processor_req=None, memory_req=None,
remote_drive_req=None, local_drive_req=None,
ethernet_interface_req=None, security_req=None,
total_system_core_req=None, total_system_memory_req=None):
def compose_node(
self,
name=None,
description=None,
processor_req=None,
memory_req=None,
remote_drive_req=None,
local_drive_req=None,
ethernet_interface_req=None,
security_req=None,
total_system_core_req=None,
total_system_memory_req=None,
):
"""Compose a node from RackScale hardware
:param name: Name of node
@ -190,7 +215,8 @@ class NodeCollection(node.NodeCollection):
"""
target_uri = self._get_compose_action_element().target_uri
properties = self._create_compose_request(
name=name, description=description,
name=name,
description=description,
processor_req=processor_req,
memory_req=memory_req,
remote_drive_req=remote_drive_req,
@ -198,8 +224,9 @@ class NodeCollection(node.NodeCollection):
ethernet_interface_req=ethernet_interface_req,
security_req=security_req,
total_system_core_req=total_system_core_req,
total_system_memory_req=total_system_memory_req)
total_system_memory_req=total_system_memory_req,
)
resp = self._conn.post(target_uri, data=properties)
LOG.info("Node created at %s", resp.headers['Location'])
node_url = resp.headers['Location']
LOG.info("Node created at %s", resp.headers["Location"])
node_url = resp.headers["Location"]
return node_url[node_url.find(self._path):]

View File

@ -14,235 +14,267 @@
# under the License.
processor_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'@odata.type': {'type': 'string'},
'Model': {'type': 'string'},
'TotalCores': {'type': 'number'},
'AchievableSpeedMHz': {'type': 'number'},
'InstructionSet': {
'type': 'string',
'enum': ['x86', 'x86-64', 'IA-64', 'ARM-A32',
'ARM-A64', 'MIPS32', 'MIPS64', 'OEM']
},
'Oem': {
'type': 'object',
'properties': {
'Intel_RackScale': {
'type': 'object',
'properties': {
'Brand': {
'type': 'string',
'enum': ['E3', 'E5', 'E7', 'X3', 'X5', 'X7',
'I3', 'I5', 'I7', 'Silver', 'Gold',
'Platinum', 'Unknown']
"type": "array",
"items": [
{
"type": "object",
"properties": {
"@odata.type": {"type": "string"},
"Model": {"type": "string"},
"TotalCores": {"type": "number"},
"AchievableSpeedMHz": {"type": "number"},
"InstructionSet": {
"type": "string",
"enum": [
"x86",
"x86-64",
"IA-64",
"ARM-A32",
"ARM-A64",
"MIPS32",
"MIPS64",
"OEM",
],
},
"Oem": {
"type": "object",
"properties": {
"Intel_RackScale": {
"type": "object",
"properties": {
"Brand": {
"type": "string",
"enum": [
"E3",
"E5",
"E7",
"X3",
"X5",
"X7",
"I3",
"I5",
"I7",
"Silver",
"Gold",
"Platinum",
"Unknown",
],
},
"Capabilities": {
"type": "array",
"items": [{"type": "string"}],
},
},
'Capabilities': {
'type': 'array',
'items': [{'type': 'string'}]
}
}
}
}
},
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"Chassis": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"ProcessorType": {
"type": "string",
"enum": [
"CPU",
"FPGA",
"GPU",
"DSP",
"Accelerator",
"OEM",
],
},
"Connectivity": {
"type": "array",
"items": [
{
"type": "string",
"enum": ["Local", "Ethernet", "RemotePCIe"],
}
],
},
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'ProcessorType': {
'type': 'string',
'enum': ['CPU', 'FPGA', 'GPU', 'DSP', 'Accelerator', 'OEM']
},
'Connectivity': {
'type': 'array',
'items': [{
'type': 'string',
'enum': ['Local', 'Ethernet', 'RemotePCIe']
}]
}
},
'additionalProperties': False,
}]
"additionalProperties": False,
}
],
}
memory_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'@odata.type': {'type': 'string'},
'CapacityMiB': {'type': 'number'},
'MemoryType': {
'type': 'string',
'enum': ['DRAM', 'NVDIMM_N', 'NVDIMM_F', 'NVMDIMM_P',
'IntelOptane']
"type": "array",
"items": [
{
"type": "object",
"properties": {
"@odata.type": {"type": "string"},
"CapacityMiB": {"type": "number"},
"MemoryType": {
"type": "string",
"enum": [
"DRAM",
"NVDIMM_N",
"NVDIMM_F",
"NVMDIMM_P",
"IntelOptane",
],
},
"MemoryDeviceType": {
"type": "string",
"enum": [
"DDR",
"DDR2",
"DDR3",
"DDR4",
"DDR4_SDRAM",
"DDR4E_SDRAM",
"LPDDR4_SDRAM",
"DDR3_SDRAM",
"LPDDR3_SDRAM",
"DDR2_SDRAM",
"DDR2_SDRAM_FB_DIMM",
"DDR2_SDRAM_FB_DIMM_PROBE",
"DDR_SGRAM",
"DDR_SDRAM",
"ROM",
"SDRAM",
"EDO",
"FastPageMode",
"PipelinedNibble",
],
},
"SpeedMHz": {"type": "number"},
"Manufacturer": {"type": "string"},
"DataWidthBits": {"type": "number"},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"Chassis": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
},
'MemoryDeviceType': {
'type': 'string',
'enum': ['DDR', 'DDR2', 'DDR3', 'DDR4', 'DDR4_SDRAM',
'DDR4E_SDRAM', 'LPDDR4_SDRAM', 'DDR3_SDRAM',
'LPDDR3_SDRAM', 'DDR2_SDRAM', 'DDR2_SDRAM_FB_DIMM',
'DDR2_SDRAM_FB_DIMM_PROBE', 'DDR_SGRAM',
'DDR_SDRAM', 'ROM', 'SDRAM', 'EDO',
'FastPageMode', 'PipelinedNibble']
},
'SpeedMHz': {'type': 'number'},
'Manufacturer': {'type': 'string'},
'DataWidthBits': {'type': 'number'},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
},
'additionalProperties': False,
}]
"additionalProperties": False,
}
],
}
remote_drive_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'@odata.type': {'type': 'string'},
'CapacityGiB': {'type': 'number'},
'Protocol': {
'type': 'string',
'enum': ['iSCSI', 'NVMeOverFabrics']
},
'Master': {
'type': 'object',
'properties': {
'Type': {
'type': 'string',
'enum': ['Snapshot', 'Clone']
"type": "array",
"items": [
{
"type": "object",
"properties": {
"@odata.type": {"type": "string"},
"CapacityGiB": {"type": "number"},
"Protocol": {
"type": "string",
"enum": ["iSCSI", "NVMeOverFabrics"],
},
"Master": {
"type": "object",
"properties": {
"Type": {
"type": "string",
"enum": ["Snapshot", "Clone"],
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
}
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
},
'additionalProperties': False,
}]
"additionalProperties": False,
}
],
}
local_drive_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'@odata.type': {'type': 'string'},
'CapacityGiB': {'type': 'number'},
'Type': {
'type': 'string',
'enum': ['HDD', 'SSD']
"type": "array",
"items": [
{
"type": "object",
"properties": {
"@odata.type": {"type": "string"},
"CapacityGiB": {"type": "number"},
"Type": {"type": "string", "enum": ["HDD", "SSD"]},
"MinRPM": {"type": "number"},
"SerialNumber": {"type": "string"},
"Interface": {
"type": "string",
"enum": ["SAS", "SATA", "NVMe"],
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"Chassis": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"FabricSwitch": {"type": "boolean"},
},
'MinRPM': {'type': 'number'},
'SerialNumber': {'type': 'string'},
'Interface': {
'type': 'string',
'enum': ['SAS', 'SATA', 'NVMe']
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'FabricSwitch': {'type': 'boolean'}
},
'additionalProperties': False,
}]
"additionalProperties": False,
}
],
}
ethernet_interface_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'@odata.type': {'type': 'string'},
'SpeedMbps': {'type': 'number'},
'PrimaryVLAN': {'type': 'number'},
'VLANs': {
'type': 'array',
'additionalItems': {
'type': 'object',
'properties': {
'VLANId': {'type': 'number'},
'Tagged': {'type': 'boolean'}
}
}
"type": "array",
"items": [
{
"type": "object",
"properties": {
"@odata.type": {"type": "string"},
"SpeedMbps": {"type": "number"},
"PrimaryVLAN": {"type": "number"},
"VLANs": {
"type": "array",
"additionalItems": {
"type": "object",
"properties": {
"VLANId": {"type": "number"},
"Tagged": {"type": "boolean"},
},
},
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"Chassis": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
},
'additionalProperties': False,
}]
"additionalProperties": False,
}
],
}
security_req_schema = {
'type': 'object',
'properties': {
'@odata.type': {'type': 'string'},
'TpmPresent': {'type': 'boolean'},
'TpmInterfaceType': {'type': 'string'},
'TxtEnabled': {'type': 'boolean'},
'ClearTPMOnDelete': {'type': 'boolean'},
'PersistentMemoryOperationOnDelete': {
'type': 'string',
'enum': ['PreserveConfiguration', 'SecureErase', 'OverwritePCD']
}
"type": "object",
"properties": {
"@odata.type": {"type": "string"},
"TpmPresent": {"type": "boolean"},
"TpmInterfaceType": {"type": "string"},
"TxtEnabled": {"type": "boolean"},
"ClearTPMOnDelete": {"type": "boolean"},
"PersistentMemoryOperationOnDelete": {
"type": "string",
"enum": ["PreserveConfiguration", "SecureErase", "OverwritePCD"],
},
},
'additionalProperties': False,
"additionalProperties": False,
}
total_system_core_req_schema = {
'type': 'number'
}
total_system_core_req_schema = {"type": "number"}
total_system_memory_req_schema = {
'type': 'number'
}
total_system_memory_req_schema = {"type": "number"}

View File

@ -21,7 +21,6 @@ from rsd_lib.resources.v2_4.storage_service import volume
class StorageService(storage_service.StorageService):
@property
@utils.cache_it
def volumes(self):
@ -31,12 +30,13 @@ class StorageService(storage_service.StorageService):
refresh, this property is reset.
"""
return volume.VolumeCollection(
self._conn, self._get_volume_collection_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_volume_collection_path(),
redfish_version=self.redfish_version,
)
class StorageServiceCollection(rsd_lib_base.ResourceCollectionBase):
@property
def _resource_type(self):
return StorageService

View File

@ -23,155 +23,166 @@ from rsd_lib import utils as rsd_lib_utils
class OnPackageMemoryField(base.ListField):
memory_type = base.Field('Type')
memory_type = base.Field("Type")
"""Type of memory"""
capacity_mb = base.Field('CapacityMB', adapter=rsd_lib_utils.num_or_none)
capacity_mb = base.Field("CapacityMB", adapter=rsd_lib_utils.num_or_none)
"""Memory capacity"""
speed_mhz = base.Field('SpeedMHz', adapter=rsd_lib_utils.num_or_none)
speed_mhz = base.Field("SpeedMHz", adapter=rsd_lib_utils.num_or_none)
"""Memory speed"""
class ReconfigurationSlotsDetailsField(base.ListField):
slot_id = base.Field('SlotId')
slot_id = base.Field("SlotId")
"""Reconfiguration slot identity"""
uuid = base.Field('UUID')
uuid = base.Field("UUID")
"""Reconfiguration slot uuid"""
programmable_from_host = base.Field('ProgrammableFromHost', adapter=bool)
programmable_from_host = base.Field("ProgrammableFromHost", adapter=bool)
"""Indict whether programmable from host"""
class FpgaField(base.CompositeField):
fpga_type = base.Field('Type')
fpga_type = base.Field("Type")
"""Type of FPGA"""
model = base.Field('Model')
model = base.Field("Model")
"""Model of FPGA"""
fw_id = base.Field('FwId')
fw_id = base.Field("FwId")
"""Firmware identity of FPGA"""
fw_manufacturer = base.Field('FwManufacturer')
fw_manufacturer = base.Field("FwManufacturer")
"""Firmware manufacturer of FPGA"""
fw_version = base.Field('FwVersion')
fw_version = base.Field("FwVersion")
"""Firmware version of FPGA"""
host_interface = base.Field('HostInterface')
host_interface = base.Field("HostInterface")
"""Host interface of FPGA"""
external_interfaces = base.Field('ExternalInterfaces')
external_interfaces = base.Field("ExternalInterfaces")
"""External interfaces of FPGA"""
sideband_interface = base.Field('SidebandInterface')
sideband_interface = base.Field("SidebandInterface")
"""Sideband interface of FPGA"""
pcie_virtual_functions = base.Field(
'PCIeVirtualFunctions', adapter=rsd_lib_utils.num_or_none)
"PCIeVirtualFunctions", adapter=rsd_lib_utils.num_or_none
)
"""PCIe Virtual functions of FPGA"""
programmable_from_host = base.Field('ProgrammableFromHost', adapter=bool)
programmable_from_host = base.Field("ProgrammableFromHost", adapter=bool)
"""Indict whether programmable from host"""
reconfiguration_slots = base.Field(
'ReconfigurationSlots', adapter=rsd_lib_utils.num_or_none)
"ReconfigurationSlots", adapter=rsd_lib_utils.num_or_none
)
"""Number of supported reconfiguration slots"""
reconfiguration_slots_details = ReconfigurationSlotsDetailsField(
'ReconfigurationSlotsDetails')
"ReconfigurationSlotsDetails"
)
"""Details of supported reconfiguration slots"""
# TODO(linyang): might need to return instance instead of URI
acceleration_functions = base.Field(
'AccelerationFunctions', adapter=rsd_lib_utils.get_resource_identity)
"AccelerationFunctions", adapter=rsd_lib_utils.get_resource_identity
)
"""The reference to a resource of type AccelerationFunctions"""
class IntelRackScaleField(processor.IntelRackScaleField):
on_package_memory = OnPackageMemoryField('OnPackageMemory')
on_package_memory = OnPackageMemoryField("OnPackageMemory")
"""An array of references to the endpoints that connect to this processor
"""
thermal_design_power_watt = base.Field(
'ThermalDesignPowerWatt', adapter=rsd_lib_utils.num_or_none)
"ThermalDesignPowerWatt", adapter=rsd_lib_utils.num_or_none
)
"""Thermal Design Power (TDP) of this processor"""
metrics = base.Field(
'Metrics', adapter=rsd_lib_utils.get_resource_identity)
"Metrics", adapter=rsd_lib_utils.get_resource_identity
)
"""A reference to the Metrics associated with this Processor"""
extended_identification_registers = rsd_lib_base.DynamicField(
'ExtendedIdentificationRegisters')
"ExtendedIdentificationRegisters"
)
"""Extended contents of the Identification Registers (CPUID) for this
processor
"""
fpga = FpgaField('FPGA')
fpga = FpgaField("FPGA")
"""FPGA specific properties for FPGA ProcessorType"""
# TODO(linyang): might need to return instance instead of URI
pcie_function = base.Field(
'PCIeFunction', adapter=rsd_lib_utils.get_resource_identity)
"PCIeFunction", adapter=rsd_lib_utils.get_resource_identity
)
"""The reference to a resource of type PCIeFunction"""
class OemField(base.CompositeField):
intel_rackscale = IntelRackScaleField('Intel_RackScale')
intel_rackscale = IntelRackScaleField("Intel_RackScale")
"""Intel Rack Scale Design extensions ('Intel_RackScale' object)"""
class LinksIntelRackScaleField(base.CompositeField):
connected_port = base.Field(
'ConnectedPort', adapter=rsd_lib_utils.get_resource_identity)
"ConnectedPort", adapter=rsd_lib_utils.get_resource_identity
)
"""The reference to a resource of type ConnectedPort"""
endpoints = base.Field('Endpoints', adapter=utils.get_members_identities)
endpoints = base.Field("Endpoints", adapter=utils.get_members_identities)
"""The reference to a list of type Endpoints"""
connected_processors = base.Field(
'ConnectedProcessors', adapter=utils.get_members_identities)
"ConnectedProcessors", adapter=utils.get_members_identities
)
"""The reference to a list of type ConnectedProcessors"""
class LinksOemField(base.CompositeField):
intel_rackscale = LinksIntelRackScaleField('Intel_RackScale')
intel_rackscale = LinksIntelRackScaleField("Intel_RackScale")
"""The Intel Rack Scale specific reference links"""
class LinksField(base.CompositeField):
chassis = base.Field(
'Chassis', adapter=rsd_lib_utils.get_resource_identity)
"Chassis", adapter=rsd_lib_utils.get_resource_identity
)
"""The reference to a resource of type Chassis that represent the physical
container associated with this processor
"""
oem = LinksOemField('Oem')
oem = LinksOemField("Oem")
"""The Oem specific reference links"""
class Processor(processor.Processor):
links = LinksField('Links')
links = LinksField("Links")
"""Contain references to resources that are related to, but not contained
by (subordinate to), this processor
"""
oem = OemField('Oem')
oem = OemField("Oem")
"""Oem extension object"""
def _get_sub_processors_path(self):
"""Helper function to find the System process metrics path"""
return utils.get_sub_resource_path_by(self, 'SubProcessors')
return utils.get_sub_resource_path_by(self, "SubProcessors")
@property
@utils.cache_it
@ -182,12 +193,13 @@ class Processor(processor.Processor):
this property is reset.
"""
return ProcessorCollection(
self._conn, self._get_sub_processors_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_sub_processors_path(),
redfish_version=self.redfish_version,
)
class ProcessorCollection(processor.ProcessorCollection):
@property
def _resource_type(self):
return Processor

View File

@ -20,7 +20,6 @@ from rsd_lib.resources.v2_4.system import processor
class System(system.System):
@property
@utils.cache_it
def processors(self):
@ -37,7 +36,6 @@ class System(system.System):
class SystemCollection(system.SystemCollection):
@property
def _resource_type(self):
return System

View File

@ -15,7 +15,6 @@
def fake_request_get(json_data):
class MockResponse(object):
def __init__(self, json_data):
self.json_data = json_data
@ -27,7 +26,6 @@ def fake_request_get(json_data):
def fake_request_post(json_data, headers=None):
class MockResponse(object):
def __init__(self, json_data, headers):
self.json_data = json_data

View File

@ -359,7 +359,7 @@ class TestChassisCollection(base.TestCase):
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "chassis_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/chassis_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -25,7 +25,7 @@ class PowerZoneTestCase(testtools.TestCase):
super(PowerZoneTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "power_zone.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/power_zone.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -25,7 +25,7 @@ class ThermalTestCase(testtools.TestCase):
super(ThermalTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "thermal.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/thermal.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -25,7 +25,7 @@ class ThermalZoneTestCase(testtools.TestCase):
super(ThermalZoneTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "thermal_zone.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/thermal_zone.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -107,7 +107,7 @@ class EthernetSwtichTestCase(testtools.TestCase):
# On refreshing the port instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "ethernet_switch.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/ethernet_switch.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -166,7 +166,7 @@ class EthernetSwtichTestCase(testtools.TestCase):
# On refreshing...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "ethernet_switch.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/ethernet_switch.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -146,7 +146,7 @@ class EthernetSwitchACLTestCase(testtools.TestCase):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "ethernet_switch_acl.json",
"rsd_lib/tests/unit/json_samples/v2_1/ethernet_switch_acl.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -182,7 +182,7 @@ class EthernetSwitchACLTestCase(testtools.TestCase):
# On refreshing the acl_rule instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "ethernet_switch_acl.json",
"rsd_lib/tests/unit/json_samples/v2_1/ethernet_switch_acl.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -238,11 +238,11 @@ class EthernetSwitchACLRuleCollectionTestCase(testtools.TestCase):
def test__parse_attributes(self):
self.assertEqual("1.0.2", self.acl_rule_col.redfish_version)
self.assertEqual(
"Ethernet Switch Access Control " "List Rules Collection",
"Ethernet Switch Access Control List Rules Collection",
self.acl_rule_col.name,
)
self.assertEqual(
("/redfish/v1/EthernetSwitches/Switch1/ACLs/ACL1/" "Rules/Rule1",),
("/redfish/v1/EthernetSwitches/Switch1/ACLs/ACL1/Rules/Rule1",),
self.acl_rule_col.members_identities,
)
@ -313,7 +313,7 @@ class EthernetSwitchACLRuleCollectionTestCase(testtools.TestCase):
)
self.assertEqual(
result,
"/redfish/v1/EthernetSwitches/Switch1/ACLs/ACL1/" "Rules/Rule1",
"/redfish/v1/EthernetSwitches/Switch1/ACLs/ACL1/Rules/Rule1",
)
def test_add_acl_rule_invalid_reqs(self):

View File

@ -131,7 +131,7 @@ class VLanNetworkInterfaceCollectionTestCase(testtools.TestCase):
)
self.assertEqual(
result,
"/redfish/v1/EthernetSwitches/Switch1/Ports/Port1/" "VLANs/VLAN1",
"/redfish/v1/EthernetSwitches/Switch1/Ports/Port1/VLANs/VLAN1",
)
def test_add_vlan_invalid_reqs(self):

View File

@ -85,7 +85,7 @@ class EventSubscriptionCollectionTestCase(testtools.TestCase):
self.event_subscription_col = event_destination.\
EventDestinationCollection(
self.conn,
"/redfish/v1/EventService/" "Subscriptions",
"/redfish/v1/EventService/Subscriptions",
redfish_version="1.0.2",
)

View File

@ -99,7 +99,7 @@ class EventServiceTestCase(testtools.TestCase):
# On refreshing the event_service instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "event_service.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/event_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -87,7 +87,7 @@ class EndpointCollectionTestCase(testtools.TestCase):
super(EndpointCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "endpoint_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -104,7 +104,7 @@ class EndpointCollectionTestCase(testtools.TestCase):
(
"/redfish/v1/Fabrics/PCIe/Endpoints/NVMeDrivePF1",
"/redfish/v1/Fabrics/PCIe/Endpoints/NVMeDrivePF2",
"/redfish/v1/Fabrics/PCIe/" "Endpoints/HostRootComplex1",
"/redfish/v1/Fabrics/PCIe/Endpoints/HostRootComplex1",
),
self.endpoint_col.members_identities,
)
@ -126,7 +126,7 @@ class EndpointCollectionTestCase(testtools.TestCase):
members = self.endpoint_col.get_members()
mock_endpoint.assert_called_with(
self.endpoint_col._conn,
"/redfish/v1/Fabrics/PCIe/Endpoints" "/HostRootComplex1",
"/redfish/v1/Fabrics/PCIe/Endpoints/HostRootComplex1",
redfish_version=self.endpoint_col.redfish_version,
registries=None,
)

View File

@ -51,7 +51,7 @@ class FabricTestCase(testtools.TestCase):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "endpoint_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -71,7 +71,7 @@ class FabricTestCase(testtools.TestCase):
def test_endpoints_on_refresh(self):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "endpoint_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -82,7 +82,7 @@ class FabricTestCase(testtools.TestCase):
# On refreshing the fabric instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "fabric.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/fabric.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -91,7 +91,7 @@ class FabricTestCase(testtools.TestCase):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "endpoint_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -103,7 +103,7 @@ class FabricTestCase(testtools.TestCase):
def test_switches(self):
self.conn.get.return_value.json.reset_mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "switch_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/switch_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -116,7 +116,7 @@ class FabricTestCase(testtools.TestCase):
def test_switches_on_refresh(self):
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "switch_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/switch_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -124,7 +124,7 @@ class FabricTestCase(testtools.TestCase):
self.fabric_inst.switches, switch.SwitchCollection
)
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "fabric.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/fabric.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -132,7 +132,7 @@ class FabricTestCase(testtools.TestCase):
self.fabric_inst.refresh(force=False)
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "switch_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/switch_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -144,7 +144,7 @@ class FabricTestCase(testtools.TestCase):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "zone_collection.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/zone_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
@ -163,7 +163,7 @@ class FabricTestCase(testtools.TestCase):
def test_zones_on_refresh(self):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "zone_collection.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/zone_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
@ -171,7 +171,7 @@ class FabricTestCase(testtools.TestCase):
# On refreshing the fabric instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "fabric.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/fabric.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -180,7 +180,7 @@ class FabricTestCase(testtools.TestCase):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "zone_collection.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/zone_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
@ -192,7 +192,7 @@ class FabricCollectionTestCase(testtools.TestCase):
super(FabricCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "fabric_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/fabric_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -59,7 +59,7 @@ class PortTestCase(testtools.TestCase):
self.port_inst.actions.reset.allowed_values,
)
self.assertEqual(
("/redfish/v1/Fabrics/PCIe/Endpoints/" "HostRootComplex1",),
("/redfish/v1/Fabrics/PCIe/Endpoints/HostRootComplex1",),
self.port_inst.links.associated_endpoints,
)
self.assertEqual(
@ -163,7 +163,7 @@ class PortCollectionTestCase(testtools.TestCase):
members = self.port_col.get_members()
mock_port.assert_called_with(
self.port_col._conn,
"/redfish/v1/Fabrics/PCIe/Switches/1/" "Ports/Down2",
"/redfish/v1/Fabrics/PCIe/Switches/1/Ports/Down2",
redfish_version="1.0.2",
registries=None,
)

View File

@ -60,7 +60,7 @@ class SwitchTestCase(testtools.TestCase):
"/redfish/v1/Chassis/PCIeSwitch1", self.switch_inst.links.chassis
)
self.assertEqual(
"/redfish/v1/Fabrics/PCIe/Switches/1/Actions/Switch." "Reset",
"/redfish/v1/Fabrics/PCIe/Switches/1/Actions/Switch.Reset",
self.switch_inst.actions.reset.target_uri,
)
self.assertEqual(
@ -78,7 +78,7 @@ class SwitchTestCase(testtools.TestCase):
def test_get__reset_action_element(self):
value = self.switch_inst._get_reset_action_element()
self.assertEqual(
"/redfish/v1/Fabrics/PCIe/Switches/1/Actions/" "Switch.Reset",
"/redfish/v1/Fabrics/PCIe/Switches/1/Actions/Switch.Reset",
value.target_uri,
)
self.assertEqual(["GracefulRestart"], value.allowed_values)
@ -116,7 +116,7 @@ class SwitchTestCase(testtools.TestCase):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "fabrics_port.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/fabrics_port.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
@ -135,7 +135,7 @@ class SwitchTestCase(testtools.TestCase):
def test_ports_on_refresh(self):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "fabrics_port.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/fabrics_port.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
@ -143,7 +143,7 @@ class SwitchTestCase(testtools.TestCase):
# On refreshing the manager instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "switch.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/switch.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -152,7 +152,7 @@ class SwitchTestCase(testtools.TestCase):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "fabrics_port.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/fabrics_port.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
@ -164,7 +164,7 @@ class SwitchCollectionTestCase(testtools.TestCase):
super(SwitchCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "switch_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/switch_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -41,7 +41,7 @@ class ZoneTestCase(testtools.TestCase):
self.assertEqual("PCIe Zone 1", self.zone_inst.name)
self.assertEqual(
(
"/redfish/v1/Fabrics/PCIe/" "Endpoints/HostRootComplex1",
"/redfish/v1/Fabrics/PCIe/Endpoints/HostRootComplex1",
"/redfish/v1/Fabrics/PCIe/Endpoints/NVMeDrivePF2",
),
self.zone_inst.links.endpoints,
@ -98,7 +98,7 @@ class ZoneCollectionTestCase(testtools.TestCase):
super(ZoneCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "zone_collection.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/zone_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.zone_col = zone.ZoneCollection(

View File

@ -137,7 +137,7 @@ class TestManager(base.TestCase):
# On refreshing the manager instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "manager.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/manager.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -200,7 +200,7 @@ class TestManager(base.TestCase):
# On refreshing the manager instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "manager.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/manager.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -227,7 +227,7 @@ class TestManagerCollection(base.TestCase):
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "manager_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/manager_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -104,7 +104,7 @@ class NodeTestCase(testtools.TestCase):
def test_get__reset_action_element(self):
value = self.node_inst._get_reset_action_element()
self.assertEqual(
"/redfish/v1/Nodes/Node1/Actions/" "ComposedNode.Reset",
"/redfish/v1/Nodes/Node1/Actions/ComposedNode.Reset",
value.target_uri,
)
self.assertEqual(

View File

@ -90,7 +90,7 @@ class StorageServiceTestCase(testtools.TestCase):
# On refreshing the storage service instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "storage_service.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/storage_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -150,7 +150,7 @@ class StorageServiceTestCase(testtools.TestCase):
# On refreshing the storage service instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "storage_service.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/storage_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -212,7 +212,7 @@ class StorageServiceTestCase(testtools.TestCase):
# On refreshing the storage service instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "storage_service.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/storage_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -76,7 +76,7 @@ class MemoryCollectionTestCase(testtools.TestCase):
super(MemoryCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "memory_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/memory_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -26,7 +26,7 @@ class NetworkInterface(testtools.TestCase):
super(NetworkInterface, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "network_interface.json",
"rsd_lib/tests/unit/json_samples/v2_1/network_interface.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -97,7 +97,7 @@ class NetworkInterface(testtools.TestCase):
# On refreshing the network_interface instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "network_interface.json",
"rsd_lib/tests/unit/json_samples/v2_1/network_interface.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -25,7 +25,7 @@ class PCIeDeviceTestCase(testtools.TestCase):
super(PCIeDeviceTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "pcie_device.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/pcie_device.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -25,7 +25,7 @@ class PCIeFunctionTestCase(testtools.TestCase):
super(PCIeFunctionTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "pcie_function.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/pcie_function.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -26,7 +26,7 @@ class StorageSubsystemTestCase(testtools.TestCase):
super(StorageSubsystemTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "storage.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/storage.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -155,7 +155,7 @@ class StorageSubsystemCollectionTestCase(testtools.TestCase):
super(StorageSubsystemCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "storage_collection.json",
"rsd_lib/tests/unit/json_samples/v2_1/storage_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -66,7 +66,7 @@ class TaskCollectionTestCase(testtools.TestCase):
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "task_collection.json", "r"
"rsd_lib/tests/unit/json_samples/v2_1/task_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -243,7 +243,7 @@ class RSDLibV2_1TestCase(testtools.TestCase):
exceptions.ConnectionError,
self.rsd._get_resource_class_from_path,
"/redfish/v1/Chassis/1",
RESOURCE_CLASS
RESOURCE_CLASS,
)
self.conn.reset()
@ -255,7 +255,7 @@ class RSDLibV2_1TestCase(testtools.TestCase):
"/redfish/v1/Chassis/1",
self.rsd._get_resource_class_from_path,
"/redfish/v1/Chassis/1",
RESOURCE_CLASS
RESOURCE_CLASS,
)
self.conn.reset()
@ -266,8 +266,8 @@ class RSDLibV2_1TestCase(testtools.TestCase):
self.assertEqual(
chassis.Chassis,
self.rsd._get_resource_class_from_path(
"/redfish/v1/Chassis/1",
RESOURCE_CLASS),
"/redfish/v1/Chassis/1", RESOURCE_CLASS
),
)
self.conn.reset()

View File

@ -28,7 +28,7 @@ class EthernetSwitchTestCase(testtools.TestCase):
super(EthernetSwitchTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "ethernet_switch.json", "r"
"rsd_lib/tests/unit/json_samples/v2_2/ethernet_switch.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -78,7 +78,7 @@ class EthernetSwitchTestCase(testtools.TestCase):
# On refreshing the port instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "ethernet_switch.json", "r"
"rsd_lib/tests/unit/json_samples/v2_2/ethernet_switch.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -138,7 +138,7 @@ class EthernetSwitchTestCase(testtools.TestCase):
# On refreshing the metrics instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "ethernet_switch.json", "r"
"rsd_lib/tests/unit/json_samples/v2_2/ethernet_switch.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -33,7 +33,7 @@ class MetricsTestCase(testtools.TestCase):
self.metrics_inst = ethernet_switch_metrics.EthernetSwitchMetrics(
self.conn,
"/redfish/v1/EthernetSwitches/" "Switch1/Metrics",
"/redfish/v1/EthernetSwitches/Switch1/Metrics",
redfish_version="1.0.2",
)

View File

@ -33,7 +33,7 @@ class NodeCollectionTestCase(testtools.TestCase):
self.conn.post.return_value = request_fakes.fake_request_post(
None,
headers={
"Location": "https://localhost:8443/" "redfish/v1/Nodes/1"
"Location": "https://localhost:8443/redfish/v1/Nodes/1"
},
)

View File

@ -76,7 +76,7 @@ class MemoryTestCase(testtools.TestCase):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "memory_metrics.json", "r"
"rsd_lib/tests/unit/json_samples/v2_2/memory_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
@ -95,7 +95,7 @@ class MemoryTestCase(testtools.TestCase):
def test_metrics_on_refresh(self):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "memory_metrics.json", "r"
"rsd_lib/tests/unit/json_samples/v2_2/memory_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
@ -114,7 +114,7 @@ class MemoryTestCase(testtools.TestCase):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "memory_metrics.json", "r"
"rsd_lib/tests/unit/json_samples/v2_2/memory_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
@ -128,7 +128,7 @@ class MemoryCollectionTestCase(testtools.TestCase):
super(MemoryCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "memory_collection.json",
"rsd_lib/tests/unit/json_samples/v2_2/memory_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -27,7 +27,7 @@ class MemoryMetricsTestCase(testtools.TestCase):
super(MemoryMetricsTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "memory_metrics.json", "r"
"rsd_lib/tests/unit/json_samples/v2_2/memory_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -223,7 +223,7 @@ class ProcessorTestCase(testtools.TestCase):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "processor_metrics.json",
"rsd_lib/tests/unit/json_samples/v2_2/processor_metrics.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -245,7 +245,7 @@ class ProcessorTestCase(testtools.TestCase):
def test_metrics_on_refresh(self):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "processor_metrics.json",
"rsd_lib/tests/unit/json_samples/v2_2/processor_metrics.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -265,7 +265,7 @@ class ProcessorTestCase(testtools.TestCase):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "processor_metrics.json",
"rsd_lib/tests/unit/json_samples/v2_2/processor_metrics.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -26,7 +26,7 @@ class ProcessorMetricsTestCase(testtools.TestCase):
super(ProcessorMetricsTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "processor_metrics.json",
"rsd_lib/tests/unit/json_samples/v2_2/processor_metrics.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -214,7 +214,7 @@ class SystemTestCase(testtools.TestCase):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "memory_collection.json",
"rsd_lib/tests/unit/json_samples/v2_2/memory_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -234,7 +234,7 @@ class SystemTestCase(testtools.TestCase):
def test_memory_on_refresh(self):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "memory_collection.json",
"rsd_lib/tests/unit/json_samples/v2_2/memory_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -252,7 +252,7 @@ class SystemTestCase(testtools.TestCase):
# | GIVEN |
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "memory_collection.json",
"rsd_lib/tests/unit/json_samples/v2_2/memory_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -265,7 +265,7 @@ class SystemCollectionTestCase(testtools.TestCase):
super(SystemCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "system_collection.json",
"rsd_lib/tests/unit/json_samples/v2_2/system_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -25,7 +25,7 @@ class MetricDefinitionTestCase(testtools.TestCase):
super(MetricDefinitionTestCase, self).setUp()
self.conn = mock.Mock()
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "metric_definition.json",
"rsd_lib/tests/unit/json_samples/v2_2/metric_definition.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -151,7 +151,7 @@ class MetricReportTestCase(testtools.TestCase):
# On refreshing the telemetry service instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "metric_report.json", "r"
"rsd_lib/tests/unit/json_samples/v2_2/metric_report.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -276,15 +276,14 @@ class RSDLibV2_2TestCase(testtools.TestCase):
):
with open(
"rsd_lib/tests/unit/json_samples/v2_2/telemetry_service.json",
"r"
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(
f.read()
)
self.assertIsInstance(
self.rsd.get_resource(
"/redfish/v1/TelemetryService"),
v2_2_telemetry_service.TelemetryService
self.rsd.get_resource("/redfish/v1/TelemetryService"),
v2_2_telemetry_service.TelemetryService,
)
def test_get_resource_with_no_class_match(self):

View File

@ -89,7 +89,7 @@ class UpdateServiceTestCase(testtools.TestCase):
# On refreshing the update service instance...
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "update_service.json", "r"
"rsd_lib/tests/unit/json_samples/v2_2/update_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -20,153 +20,192 @@ from rsd_lib.resources.v2_3.ethernet_switch import ethernet_switch
class TestEthernetSwtich(base.TestCase):
def setUp(self):
super(TestEthernetSwtich, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/ethernet_switch.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/ethernet_switch.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.ethernet_switch_inst = ethernet_switch.EthernetSwitch(
self.conn,
'/redfish/v1/EthernetSwitches/Switch1',
redfish_version='1.0.2')
"/redfish/v1/EthernetSwitches/Switch1",
redfish_version="1.0.2",
)
def test_parse_attributes(self):
self.assertEqual('1.0.2', self.ethernet_switch_inst.redfish_version)
self.assertEqual('Switch1', self.ethernet_switch_inst.identity)
self.assertEqual('Switch1', self.ethernet_switch_inst.name)
self.assertEqual('description-as-string',
self.ethernet_switch_inst.description)
self.assertEqual('Quanta', self.ethernet_switch_inst.manufacturer)
self.assertEqual('ly8_rangley', self.ethernet_switch_inst.model)
self.assertEqual('02/21/2015 00:00:00',
self.ethernet_switch_inst.manufacturing_date)
self.assertEqual('2M220100SL', self.ethernet_switch_inst.serial_number)
self.assertEqual('1LY8UZZ0007', self.ethernet_switch_inst.part_number)
self.assertEqual('ONIE', self.ethernet_switch_inst.firmware_name)
self.assertEqual('1.1', self.ethernet_switch_inst.firmware_version)
self.assertEqual('TOR', self.ethernet_switch_inst.role)
self.assertEqual('Enabled', self.ethernet_switch_inst.status.state)
self.assertEqual('OK', self.ethernet_switch_inst.status.health)
self.assertEqual('/redfish/v1/Chassis/FabricModule1',
self.ethernet_switch_inst.links.chassis)
self.assertEqual(('/redfish/v1/Managers/PSME',),
self.ethernet_switch_inst.links.managed_by)
self.assertEqual(5,
self.ethernet_switch_inst.
class_to_priority_mapping[0].priority)
self.assertEqual(1,
self.ethernet_switch_inst.
class_to_priority_mapping[0].traffic_class)
self.assertEqual(5,
self.ethernet_switch_inst.
class_to_priority_mapping[1].priority)
self.assertEqual(2,
self.ethernet_switch_inst.
class_to_priority_mapping[1].traffic_class)
self.assertEqual("1.0.2", self.ethernet_switch_inst.redfish_version)
self.assertEqual("Switch1", self.ethernet_switch_inst.identity)
self.assertEqual("Switch1", self.ethernet_switch_inst.name)
self.assertEqual(
"description-as-string", self.ethernet_switch_inst.description
)
self.assertEqual("Quanta", self.ethernet_switch_inst.manufacturer)
self.assertEqual("ly8_rangley", self.ethernet_switch_inst.model)
self.assertEqual(
"02/21/2015 00:00:00", self.ethernet_switch_inst.manufacturing_date
)
self.assertEqual("2M220100SL", self.ethernet_switch_inst.serial_number)
self.assertEqual("1LY8UZZ0007", self.ethernet_switch_inst.part_number)
self.assertEqual("ONIE", self.ethernet_switch_inst.firmware_name)
self.assertEqual("1.1", self.ethernet_switch_inst.firmware_version)
self.assertEqual("TOR", self.ethernet_switch_inst.role)
self.assertEqual("Enabled", self.ethernet_switch_inst.status.state)
self.assertEqual("OK", self.ethernet_switch_inst.status.health)
self.assertEqual(
"/redfish/v1/Chassis/FabricModule1",
self.ethernet_switch_inst.links.chassis,
)
self.assertEqual(
("/redfish/v1/Managers/PSME",),
self.ethernet_switch_inst.links.managed_by,
)
self.assertEqual(
5, self.ethernet_switch_inst.class_to_priority_mapping[0].priority
)
self.assertEqual(
1,
self.ethernet_switch_inst.class_to_priority_mapping[
0
].traffic_class,
)
self.assertEqual(
5, self.ethernet_switch_inst.class_to_priority_mapping[1].priority
)
self.assertEqual(
2,
self.ethernet_switch_inst.class_to_priority_mapping[
1
].traffic_class,
)
self.assertEqual(True, self.ethernet_switch_inst.dcbx_enabled)
self.assertEqual(True, self.ethernet_switch_inst.ets_enabled)
self.assertEqual(True, self.ethernet_switch_inst.lldp_enabled)
self.assertEqual(4, self.ethernet_switch_inst.max_acl_number)
self.assertEqual('/redfish/v1/EthernetSwitches/Switch1/Metrics',
self.ethernet_switch_inst.metrics)
self.assertEqual(True,
self.ethernet_switch_inst.
priority_flow_control.enabled)
self.assertEqual([0, 1, 6, 7],
self.ethernet_switch_inst.
priority_flow_control.lossless_priorities)
self.assertEqual(5,
self.ethernet_switch_inst.
priority_to_class_mapping[0].priority)
self.assertEqual(1,
self.ethernet_switch_inst.
priority_to_class_mapping[0].traffic_class)
self.assertEqual(6,
self.ethernet_switch_inst.
priority_to_class_mapping[1].priority)
self.assertEqual(2,
self.ethernet_switch_inst.
priority_to_class_mapping[1].traffic_class)
self.assertEqual(4791,
self.ethernet_switch_inst.
traffic_classification[0].port)
self.assertEqual('UDP',
self.ethernet_switch_inst.
traffic_classification[0].protocol)
self.assertEqual(1,
self.ethernet_switch_inst.
traffic_classification[0].traffic_class)
self.assertEqual(860,
self.ethernet_switch_inst.
traffic_classification[1].port)
self.assertEqual('TCP',
self.ethernet_switch_inst.
traffic_classification[1].protocol)
self.assertEqual(2,
self.ethernet_switch_inst.
traffic_classification[1].traffic_class)
self.assertEqual(3260,
self.ethernet_switch_inst.
traffic_classification[2].port)
self.assertEqual('TCP',
self.ethernet_switch_inst.
traffic_classification[2].protocol)
self.assertEqual(2,
self.ethernet_switch_inst.
traffic_classification[2].traffic_class)
self.assertEqual(60,
self.ethernet_switch_inst.
transmission_selection[0].bandwidth_percent)
self.assertEqual(1,
self.ethernet_switch_inst.
transmission_selection[0].traffic_class)
self.assertEqual(30,
self.ethernet_switch_inst.
transmission_selection[1].bandwidth_percent)
self.assertEqual(2,
self.ethernet_switch_inst.
transmission_selection[1].traffic_class)
self.assertEqual(
"/redfish/v1/EthernetSwitches/Switch1/Metrics",
self.ethernet_switch_inst.metrics,
)
self.assertEqual(
True, self.ethernet_switch_inst.priority_flow_control.enabled
)
self.assertEqual(
[0, 1, 6, 7],
self.ethernet_switch_inst.priority_flow_control.
lossless_priorities,
)
self.assertEqual(
5, self.ethernet_switch_inst.priority_to_class_mapping[0].priority
)
self.assertEqual(
1,
self.ethernet_switch_inst.priority_to_class_mapping[
0
].traffic_class,
)
self.assertEqual(
6, self.ethernet_switch_inst.priority_to_class_mapping[1].priority
)
self.assertEqual(
2,
self.ethernet_switch_inst.priority_to_class_mapping[
1
].traffic_class,
)
self.assertEqual(
4791, self.ethernet_switch_inst.traffic_classification[0].port
)
self.assertEqual(
"UDP", self.ethernet_switch_inst.traffic_classification[0].protocol
)
self.assertEqual(
1,
self.ethernet_switch_inst.traffic_classification[0].traffic_class,
)
self.assertEqual(
860, self.ethernet_switch_inst.traffic_classification[1].port
)
self.assertEqual(
"TCP", self.ethernet_switch_inst.traffic_classification[1].protocol
)
self.assertEqual(
2,
self.ethernet_switch_inst.traffic_classification[1].traffic_class,
)
self.assertEqual(
3260, self.ethernet_switch_inst.traffic_classification[2].port
)
self.assertEqual(
"TCP", self.ethernet_switch_inst.traffic_classification[2].protocol
)
self.assertEqual(
2,
self.ethernet_switch_inst.traffic_classification[2].traffic_class,
)
self.assertEqual(
60,
self.ethernet_switch_inst.transmission_selection[
0
].bandwidth_percent,
)
self.assertEqual(
1,
self.ethernet_switch_inst.transmission_selection[0].traffic_class,
)
self.assertEqual(
30,
self.ethernet_switch_inst.transmission_selection[
1
].bandwidth_percent,
)
self.assertEqual(
2,
self.ethernet_switch_inst.transmission_selection[1].traffic_class,
)
class EthernetSwitchCollectionTestCase(testtools.TestCase):
def setUp(self):
super(EthernetSwitchCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'ethernet_switch_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"ethernet_switch_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.ethernet_switch_col = ethernet_switch.EthernetSwitchCollection(
self.conn,
'redfish/v1/EthernetSwitches',
redfish_version='1.0.2')
self.conn, "redfish/v1/EthernetSwitches", redfish_version="1.0.2"
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.ethernet_switch_col.redfish_version)
self.assertEqual('Ethernet Switches Collection',
self.ethernet_switch_col.name)
self.assertEqual(('/redfish/v1/EthernetSwitches/Switch1',),
self.ethernet_switch_col.members_identities)
self.assertEqual("1.0.2", self.ethernet_switch_col.redfish_version)
self.assertEqual(
"Ethernet Switches Collection", self.ethernet_switch_col.name
)
self.assertEqual(
("/redfish/v1/EthernetSwitches/Switch1",),
self.ethernet_switch_col.members_identities,
)
@mock.patch.object(ethernet_switch, 'EthernetSwitch', autospec=True)
@mock.patch.object(ethernet_switch, "EthernetSwitch", autospec=True)
def test_get_member(self, mock_ethernet_switch):
self.ethernet_switch_col.get_member(
'/redfish/v1/EthernetSwitches/Switch1')
"/redfish/v1/EthernetSwitches/Switch1"
)
mock_ethernet_switch.assert_called_once_with(
self.ethernet_switch_col._conn,
'/redfish/v1/EthernetSwitches/Switch1',
"/redfish/v1/EthernetSwitches/Switch1",
redfish_version=self.ethernet_switch_col.redfish_version,
registries=None,
)
@mock.patch.object(ethernet_switch, 'EthernetSwitch', autospec=True)
@mock.patch.object(ethernet_switch, "EthernetSwitch", autospec=True)
def test_get_members(self, mock_ethernet_switch):
members = self.ethernet_switch_col.get_members()
self.assertEqual(mock_ethernet_switch.call_count, 1)

View File

@ -24,208 +24,247 @@ from rsd_lib.tests.unit.fakes import request_fakes
class EndpointTestCase(testtools.TestCase):
def setUp(self):
super(EndpointTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/endpoint_1.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/endpoint_1.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.endpoint_inst = endpoint.Endpoint(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.endpoint_inst.redfish_version)
self.assertEqual('Fabric Endpoint',
self.endpoint_inst.description)
self.assertEqual('1', self.endpoint_inst.identity)
self.assertEqual('Fabric Endpoint', self.endpoint_inst.name)
self.assertEqual('Target',
self.endpoint_inst.connected_entities[0].entity_role)
self.assertEqual('/redfish/v1/StorageServices/1/Volumes/1',
self.endpoint_inst.connected_entities[0].entity_link)
self.assertEqual('Enabled', self.endpoint_inst.status.state)
self.assertEqual('OK', self.endpoint_inst.status.health)
self.assertEqual('OK', self.endpoint_inst.status.health_rollup)
self.assertEqual('NVMeOverFabrics', self.endpoint_inst.protocol)
self.assertEqual('NQN',
self.endpoint_inst.identifiers[0].name_format)
self.assertEqual('nqn.2014-08.org.nvmexpress:NVMf:uuid:'
'397f9b78-7e94-11e7-9ea4-001e67dfa170',
self.endpoint_inst.identifiers[0].name)
self.assertEqual('UUID',
self.endpoint_inst.identifiers[1].name_format)
self.assertEqual('397f9b78-7e94-11e7-9ea4-001e67dfa170',
self.endpoint_inst.identifiers[1].name)
self.assertEqual("1.0.2", self.endpoint_inst.redfish_version)
self.assertEqual("Fabric Endpoint", self.endpoint_inst.description)
self.assertEqual("1", self.endpoint_inst.identity)
self.assertEqual("Fabric Endpoint", self.endpoint_inst.name)
self.assertEqual(
"Target", self.endpoint_inst.connected_entities[0].entity_role
)
self.assertEqual(
"/redfish/v1/StorageServices/1/Volumes/1",
self.endpoint_inst.connected_entities[0].entity_link,
)
self.assertEqual("Enabled", self.endpoint_inst.status.state)
self.assertEqual("OK", self.endpoint_inst.status.health)
self.assertEqual("OK", self.endpoint_inst.status.health_rollup)
self.assertEqual("NVMeOverFabrics", self.endpoint_inst.protocol)
self.assertEqual("NQN", self.endpoint_inst.identifiers[0].name_format)
self.assertEqual(
"nqn.2014-08.org.nvmexpress:NVMf:uuid:"
"397f9b78-7e94-11e7-9ea4-001e67dfa170",
self.endpoint_inst.identifiers[0].name,
)
self.assertEqual("UUID", self.endpoint_inst.identifiers[1].name_format)
self.assertEqual(
"397f9b78-7e94-11e7-9ea4-001e67dfa170",
self.endpoint_inst.identifiers[1].name,
)
self.assertEqual((), self.endpoint_inst.links.ports)
self.assertEqual((), self.endpoint_inst.links.endpoints)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Zones/1',),
self.endpoint_inst.links.zones)
self.assertEqual('/redfish/v1/Systems/Target/EthernetInterfaces/1',
self.endpoint_inst.links.interface)
self.assertEqual(
'RoCEv2',
self.endpoint_inst.ip_transport_details[0].transport_protocol)
("/redfish/v1/Fabrics/NVMeoE/Zones/1",),
self.endpoint_inst.links.zones,
)
self.assertEqual(
'192.168.0.10',
self.endpoint_inst.ip_transport_details[0].ipv4_address)
"/redfish/v1/Systems/Target/EthernetInterfaces/1",
self.endpoint_inst.links.interface,
)
self.assertEqual(
None, self.endpoint_inst.ip_transport_details[0].ipv6_address)
"RoCEv2",
self.endpoint_inst.ip_transport_details[0].transport_protocol,
)
self.assertEqual(
"192.168.0.10",
self.endpoint_inst.ip_transport_details[0].ipv4_address,
)
self.assertEqual(
None, self.endpoint_inst.ip_transport_details[0].ipv6_address
)
self.assertEqual(1023, self.endpoint_inst.ip_transport_details[0].port)
self.assertEqual(None, self.endpoint_inst.oem.authentication)
with open('rsd_lib/tests/unit/json_samples/v2_3/endpoint_2.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/endpoint_2.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.endpoint_inst.refresh()
self.assertEqual('1.0.2', self.endpoint_inst.redfish_version)
self.assertEqual('Fabric Initiator Endpoint',
self.endpoint_inst.description)
self.assertEqual('1', self.endpoint_inst.identity)
self.assertEqual('Fabric Endpoint', self.endpoint_inst.name)
self.assertEqual('Initiator',
self.endpoint_inst.connected_entities[0].entity_role)
self.assertEqual(None,
self.endpoint_inst.connected_entities[0].entity_link)
self.assertEqual("1.0.2", self.endpoint_inst.redfish_version)
self.assertEqual(
"Fabric Initiator Endpoint", self.endpoint_inst.description
)
self.assertEqual("1", self.endpoint_inst.identity)
self.assertEqual("Fabric Endpoint", self.endpoint_inst.name)
self.assertEqual(
"Initiator", self.endpoint_inst.connected_entities[0].entity_role
)
self.assertEqual(
None, self.endpoint_inst.connected_entities[0].entity_link
)
self.assertEqual(None, self.endpoint_inst.status.state)
self.assertEqual(None, self.endpoint_inst.status.health)
self.assertEqual(None, self.endpoint_inst.status.health_rollup)
self.assertEqual('NVMeOverFabrics', self.endpoint_inst.protocol)
self.assertEqual('NQN',
self.endpoint_inst.identifiers[0].name_format)
self.assertEqual('nqn.2014-08.org.nvmexpress:NVMf:uuid:'
'12345678-90ab-cdef-0000-000000000000',
self.endpoint_inst.identifiers[0].name)
self.assertEqual('UUID',
self.endpoint_inst.identifiers[1].name_format)
self.assertEqual('12345678-90ab-cdef-0000-000000000000',
self.endpoint_inst.identifiers[1].name)
self.assertEqual("NVMeOverFabrics", self.endpoint_inst.protocol)
self.assertEqual("NQN", self.endpoint_inst.identifiers[0].name_format)
self.assertEqual(
"nqn.2014-08.org.nvmexpress:NVMf:uuid:"
"12345678-90ab-cdef-0000-000000000000",
self.endpoint_inst.identifiers[0].name,
)
self.assertEqual("UUID", self.endpoint_inst.identifiers[1].name_format)
self.assertEqual(
"12345678-90ab-cdef-0000-000000000000",
self.endpoint_inst.identifiers[1].name,
)
self.assertEqual((), self.endpoint_inst.links.ports)
self.assertEqual((), self.endpoint_inst.links.endpoints)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Zones/1',),
self.endpoint_inst.links.zones)
self.assertEqual(
("/redfish/v1/Fabrics/NVMeoE/Zones/1",),
self.endpoint_inst.links.zones,
)
self.assertEqual(None, self.endpoint_inst.links.interface)
self.assertEqual(
'RoCEv2',
self.endpoint_inst.ip_transport_details[0].transport_protocol)
"RoCEv2",
self.endpoint_inst.ip_transport_details[0].transport_protocol,
)
self.assertEqual(
'192.168.0.10',
self.endpoint_inst.ip_transport_details[0].ipv4_address)
"192.168.0.10",
self.endpoint_inst.ip_transport_details[0].ipv4_address,
)
self.assertEqual(
None, self.endpoint_inst.ip_transport_details[0].ipv6_address)
None, self.endpoint_inst.ip_transport_details[0].ipv6_address
)
self.assertEqual(4791, self.endpoint_inst.ip_transport_details[0].port)
self.assertEqual(None, self.endpoint_inst.oem.authentication)
def test_update_authentication(self):
self.endpoint_inst.update_authentication(username='fake-username')
self.endpoint_inst.update_authentication(username="fake-username")
self.endpoint_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
data={
"Oem": {
"Intel_RackScale": {
"@odata.type": "#Intel.Oem.Endpoint",
"Authentication": {"Username": "fake-username"}
"Authentication": {"Username": "fake-username"},
}
}
})
},
)
self.endpoint_inst._conn.patch.reset_mock()
self.endpoint_inst.update_authentication(password='fake-password')
self.endpoint_inst.update_authentication(password="fake-password")
self.endpoint_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
data={
"Oem": {
"Intel_RackScale": {
"@odata.type": "#Intel.Oem.Endpoint",
"Authentication": {"Password": "fake-password"}
"Authentication": {"Password": "fake-password"},
}
}
})
},
)
self.endpoint_inst._conn.patch.reset_mock()
self.endpoint_inst.update_authentication(username='fake-username',
password='fake-password')
self.endpoint_inst.update_authentication(
username="fake-username", password="fake-password"
)
self.endpoint_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
data={
"Oem": {
"Intel_RackScale": {
"@odata.type": "#Intel.Oem.Endpoint",
"Authentication": {
"Username": "fake-username",
"Password": "fake-password"
}
"Password": "fake-password",
},
}
}
})
},
)
def test_update_authentication_with_invalid_parameter(self):
with self.assertRaisesRegex(
ValueError,
'At least "username" or "password" parameter has to be specified'):
'At least "username" or "password" parameter has to be specified',
):
self.endpoint_inst.update_authentication()
def test_delete(self):
self.endpoint_inst.delete()
self.endpoint_inst._conn.delete.assert_called_once_with(
self.endpoint_inst.path)
self.endpoint_inst.path
)
class EndpointCollectionTestCase(testtools.TestCase):
def setUp(self):
super(EndpointCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'endpoint_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.conn.post.return_value = request_fakes.fake_request_post(
None, headers={"Location": "https://localhost:8443/redfish/v1/"
"Fabrics/NVMeoE/Endpoints/3"})
None,
headers={
"Location": "https://localhost:8443/redfish/v1/"
"Fabrics/NVMeoE/Endpoints/3"
},
)
self.endpoint_col = endpoint.EndpointCollection(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Endpoints',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/Fabrics/NVMeoE/Endpoints",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.endpoint_col.redfish_version)
self.assertEqual('Endpoint Collection',
self.endpoint_col.name)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
'/redfish/v1/Fabrics/NVMeoE/Endpoints/2'),
self.endpoint_col.members_identities)
self.assertEqual("1.0.2", self.endpoint_col.redfish_version)
self.assertEqual("Endpoint Collection", self.endpoint_col.name)
self.assertEqual(
(
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
"/redfish/v1/Fabrics/NVMeoE/Endpoints/2",
),
self.endpoint_col.members_identities,
)
@mock.patch.object(endpoint, 'Endpoint', autospec=True)
@mock.patch.object(endpoint, "Endpoint", autospec=True)
def test_get_member(self, mock_endpoint):
self.endpoint_col.get_member(
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1')
self.endpoint_col.get_member("/redfish/v1/Fabrics/NVMeoE/Endpoints/1")
mock_endpoint.assert_called_once_with(
self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version=self.endpoint_col.redfish_version,
registries=None,
)
@mock.patch.object(endpoint, 'Endpoint', autospec=True)
@mock.patch.object(endpoint, "Endpoint", autospec=True)
def test_get_members(self, mock_endpoint):
members = self.endpoint_col.get_members()
calls = [
mock.call(
self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version=self.endpoint_col.redfish_version,
registries=None,
),
mock.call(
self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/2',
"/redfish/v1/Fabrics/NVMeoE/Endpoints/2",
redfish_version=self.endpoint_col.redfish_version,
registries=None,
)
),
]
mock_endpoint.assert_has_calls(calls)
self.assertIsInstance(members, list)
@ -238,7 +277,7 @@ class EndpointCollectionTestCase(testtools.TestCase):
{
"DurableNameFormat": "NQN",
"DurableName": "nqn.2014-08.org.nvmexpress:NVMf:"
"uuid:397f9b78-7e94-11e7-9ea4-001e67dfa170"
"uuid:397f9b78-7e94-11e7-9ea4-001e67dfa170",
}
],
"ConnectedEntities": [
@ -246,7 +285,7 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityLink": {
"@odata.id": "/redfish/v1/StorageServices/1/Volumes/1"
},
"EntityRole": "Target"
"EntityRole": "Target",
}
],
"Links": {
@ -255,19 +294,19 @@ class EndpointCollectionTestCase(testtools.TestCase):
"Interfaces": [
{
"@odata.id": "/redfish/v1/Systems/Target/"
"EthernetInterfaces/1"
"EthernetInterfaces/1"
}
]
}
}
}
},
}
result = self.endpoint_col.create_endpoint(
identifiers=[
{
"DurableNameFormat": "NQN",
"DurableName": "nqn.2014-08.org.nvmexpress:NVMf:"
"uuid:397f9b78-7e94-11e7-9ea4-001e67dfa170"
"uuid:397f9b78-7e94-11e7-9ea4-001e67dfa170",
}
],
connected_entities=[
@ -275,15 +314,16 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityLink": {
"@odata.id": "/redfish/v1/StorageServices/1/Volumes/1"
},
"EntityRole": "Target"
"EntityRole": "Target",
}
],
protocol="NVMeOverFabrics",
interface="/redfish/v1/Systems/Target/EthernetInterfaces/1")
interface="/redfish/v1/Systems/Target/EthernetInterfaces/1",
)
self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs)
self.assertEqual(result,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3')
"/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
)
self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
self.endpoint_col._conn.post.reset_mock()
reqs = {
@ -292,7 +332,7 @@ class EndpointCollectionTestCase(testtools.TestCase):
{
"DurableNameFormat": "iQN",
"DurableName": "iqn.1986-03.com.intel:my_storage-uuid:"
"397f9b78-7e94-11e7-9ea4-001e67dfa170"
"397f9b78-7e94-11e7-9ea4-001e67dfa170",
}
],
"ConnectedEntities": [
@ -302,28 +342,25 @@ class EndpointCollectionTestCase(testtools.TestCase):
},
"EntityRole": "Target",
"Identifiers": [
{
"DurableNameFormat": "LUN",
"DurableName": "1"
}
]
{"DurableNameFormat": "LUN", "DurableName": "1"}
],
}
],
"Oem": {
"Intel_RackScale": {
"Authentication": {
"Username": "userA",
"Password": "passB"
"Password": "passB",
}
}
}
},
}
result = self.endpoint_col.create_endpoint(
identifiers=[
{
"DurableNameFormat": "iQN",
"DurableName": "iqn.1986-03.com.intel:my_storage-uuid:"
"397f9b78-7e94-11e7-9ea4-001e67dfa170"
"397f9b78-7e94-11e7-9ea4-001e67dfa170",
}
],
connected_entities=[
@ -333,29 +370,24 @@ class EndpointCollectionTestCase(testtools.TestCase):
},
"EntityRole": "Target",
"Identifiers": [
{
"DurableNameFormat": "LUN",
"DurableName": "1"
}
]
{"DurableNameFormat": "LUN", "DurableName": "1"}
],
}
],
protocol="iSCSI",
authentication={
"Username": "userA",
"Password": "passB"
})
authentication={"Username": "userA", "Password": "passB"},
)
self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs)
self.assertEqual(result,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3')
"/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
)
self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
def test_create_endpoint_with_invalid_reqs(self):
identifiers = [
{
"DurableNameFormat": "iQN",
"DurableName": "iqn.1986-03.com.intel:my_storage-uuid:"
"397f9b78-7e94-11e7-9ea4-001e67dfa170"
"397f9b78-7e94-11e7-9ea4-001e67dfa170",
}
]
connected_entities = [
@ -365,87 +397,104 @@ class EndpointCollectionTestCase(testtools.TestCase):
},
"EntityRole": "Target",
"Identifiers": [
{
"DurableNameFormat": "LUN",
"DurableName": "1"
}
]
{"DurableNameFormat": "LUN", "DurableName": "1"}
],
}
]
result = self.endpoint_col.create_endpoint(
identifiers=identifiers, connected_entities=connected_entities)
self.assertEqual(result,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3')
identifiers=identifiers, connected_entities=connected_entities
)
self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
# Test invalid identifiers argument
invalid_identifiers = copy.deepcopy(identifiers)
invalid_identifiers[0]['DurableNameFormat'] = 'fake-format'
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=invalid_identifiers,
connected_entities=connected_entities)
invalid_identifiers[0]["DurableNameFormat"] = "fake-format"
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=invalid_identifiers,
connected_entities=connected_entities,
)
invalid_identifiers = copy.deepcopy(identifiers)
invalid_identifiers[0].pop('DurableNameFormat')
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=invalid_identifiers,
connected_entities=connected_entities)
invalid_identifiers[0].pop("DurableNameFormat")
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=invalid_identifiers,
connected_entities=connected_entities,
)
invalid_identifiers = copy.deepcopy(identifiers)
invalid_identifiers[0].pop('DurableName')
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=invalid_identifiers,
connected_entities=connected_entities)
invalid_identifiers[0].pop("DurableName")
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=invalid_identifiers,
connected_entities=connected_entities,
)
# Test invalid connected_entities argument
invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0]['EntityRole'] = 'fake-format'
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities)
invalid_connected_entities[0]["EntityRole"] = "fake-format"
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0]['EntityLink'].pop('@odata.id')
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities)
invalid_connected_entities[0]["EntityLink"].pop("@odata.id")
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0].pop('EntityLink')
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities)
invalid_connected_entities[0].pop("EntityLink")
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0].pop('EntityRole')
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities)
invalid_connected_entities[0].pop("EntityRole")
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
# Test invalid protocol argument
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=connected_entities,
protocol=1)
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=connected_entities,
protocol=1,
)
# Test invalid interface argument
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=connected_entities,
interface=1)
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=connected_entities,
interface=1,
)
# Test invalid authentication argument
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=connected_entities,
authentication={'Username': 1})
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=connected_entities,
authentication={"Username": 1},
)

View File

@ -25,175 +25,190 @@ from rsd_lib.resources.v2_3.fabric import zone
class FabricTestCase(testtools.TestCase):
def setUp(self):
super(FabricTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/fabric.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/fabric.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst = fabric.Fabric(
self.conn, '/redfish/v1/Fabrics/NVMeoE',
redfish_version='1.0.2')
self.conn, "/redfish/v1/Fabrics/NVMeoE", redfish_version="1.0.2"
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.fabric_inst.redfish_version)
self.assertEqual('NVMeoE', self.fabric_inst.identity)
self.assertEqual("1.0.2", self.fabric_inst.redfish_version)
self.assertEqual("NVMeoE", self.fabric_inst.identity)
self.assertEqual(None, self.fabric_inst.name)
self.assertEqual('NVMeOverFabrics', self.fabric_inst.fabric_type)
self.assertEqual("NVMeOverFabrics", self.fabric_inst.fabric_type)
self.assertEqual(None, self.fabric_inst.max_zones)
self.assertEqual('Enabled', self.fabric_inst.status.state)
self.assertEqual('OK', self.fabric_inst.status.health)
self.assertEqual('OK', self.fabric_inst.status.health_rollup)
self.assertEqual("Enabled", self.fabric_inst.status.state)
self.assertEqual("OK", self.fabric_inst.status.health)
self.assertEqual("OK", self.fabric_inst.status.health_rollup)
def test__get_endpoint_collection_path(self):
expected = '/redfish/v1/Fabrics/NVMeoE/Endpoints'
expected = "/redfish/v1/Fabrics/NVMeoE/Endpoints"
result = self.fabric_inst._get_endpoint_collection_path()
self.assertEqual(expected, result)
def test__get_endpoint_collection_path_missing_attr(self):
self.fabric_inst._json.pop('Endpoints')
self.fabric_inst._json.pop("Endpoints")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Endpoints',
self.fabric_inst._get_endpoint_collection_path)
exceptions.MissingAttributeError,
"attribute Endpoints",
self.fabric_inst._get_endpoint_collection_path,
)
def test_endpoints(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'endpoint_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_endpoints = self.fabric_inst.endpoints
# | THEN |
self.assertIsInstance(actual_endpoints,
endpoint.EndpointCollection)
self.assertIsInstance(actual_endpoints, endpoint.EndpointCollection)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_endpoints,
self.fabric_inst.endpoints)
self.assertIs(actual_endpoints, self.fabric_inst.endpoints)
self.conn.get.return_value.json.assert_not_called()
def test_endpoints_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'endpoint_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.endpoints,
endpoint.EndpointCollection)
self.assertIsInstance(
self.fabric_inst.endpoints, endpoint.EndpointCollection
)
# On refreshing the fabric instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'fabric.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/fabric.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst.invalidate()
self.fabric_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'endpoint_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.endpoints,
endpoint.EndpointCollection)
self.assertIsInstance(
self.fabric_inst.endpoints, endpoint.EndpointCollection
)
def test__get_zone_collection_path(self):
expected = '/redfish/v1/Fabrics/NVMeoE/Zones'
expected = "/redfish/v1/Fabrics/NVMeoE/Zones"
result = self.fabric_inst._get_zone_collection_path()
self.assertEqual(expected, result)
def test__get_zone_collection_path_missing_attr(self):
self.fabric_inst._json.pop('Zones')
self.fabric_inst._json.pop("Zones")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Zones',
self.fabric_inst._get_zone_collection_path)
exceptions.MissingAttributeError,
"attribute Zones",
self.fabric_inst._get_zone_collection_path,
)
def test_zones(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'zone_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/zone_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_zones = self.fabric_inst.zones
# | THEN |
self.assertIsInstance(actual_zones,
zone.ZoneCollection)
self.assertIsInstance(actual_zones, zone.ZoneCollection)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_zones,
self.fabric_inst.zones)
self.assertIs(actual_zones, self.fabric_inst.zones)
self.conn.get.return_value.json.assert_not_called()
def test_zones_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'zone_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/zone_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.zones,
zone.ZoneCollection)
self.assertIsInstance(self.fabric_inst.zones, zone.ZoneCollection)
# On refreshing the fabric instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'fabric.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/fabric.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst.invalidate()
self.fabric_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'zone_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/zone_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.zones,
zone.ZoneCollection)
self.assertIsInstance(self.fabric_inst.zones, zone.ZoneCollection)
class FabricCollectionTestCase(testtools.TestCase):
def setUp(self):
super(FabricCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'fabric_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/fabric_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_col = fabric.FabricCollection(
self.conn, '/redfish/v1/Fabrics', redfish_version='1.0.2')
self.conn, "/redfish/v1/Fabrics", redfish_version="1.0.2"
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.fabric_col.redfish_version)
self.assertEqual('Fabric Collection',
self.fabric_col.name)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE',),
self.fabric_col.members_identities)
self.assertEqual("1.0.2", self.fabric_col.redfish_version)
self.assertEqual("Fabric Collection", self.fabric_col.name)
self.assertEqual(
("/redfish/v1/Fabrics/NVMeoE",), self.fabric_col.members_identities
)
@mock.patch.object(fabric, 'Fabric', autospec=True)
@mock.patch.object(fabric, "Fabric", autospec=True)
def test_get_member(self, mock_fabric):
self.fabric_col.get_member('/redfish/v1/Fabrics/NVMeoE')
self.fabric_col.get_member("/redfish/v1/Fabrics/NVMeoE")
mock_fabric.assert_called_once_with(
self.fabric_col._conn, '/redfish/v1/Fabrics/NVMeoE',
self.fabric_col._conn,
"/redfish/v1/Fabrics/NVMeoE",
redfish_version=self.fabric_col.redfish_version,
registries=None,
)
@mock.patch.object(fabric, 'Fabric', autospec=True)
@mock.patch.object(fabric, "Fabric", autospec=True)
def test_get_members(self, mock_fabric):
members = self.fabric_col.get_members()
mock_fabric.assert_called_once_with(
self.fabric_col._conn, '/redfish/v1/Fabrics/NVMeoE',
self.fabric_col._conn,
"/redfish/v1/Fabrics/NVMeoE",
redfish_version=self.fabric_col.redfish_version,
registries=None,
)

View File

@ -23,91 +23,124 @@ from rsd_lib.tests.unit.fakes import request_fakes
class ZoneTestCase(testtools.TestCase):
def setUp(self):
super(ZoneTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/zone.json',
'r') as f:
with open("rsd_lib/tests/unit/json_samples/v2_3/zone.json", "r") as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.zone_inst = zone.Zone(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Zones/1',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/Fabrics/NVMeoE/Zones/1",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.zone_inst.redfish_version)
self.assertEqual('Zone 1',
self.zone_inst.description)
self.assertEqual('1', self.zone_inst.identity)
self.assertEqual('Zone 1', self.zone_inst.name)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
'/redfish/v1/Fabrics/NVMeoE/Endpoints/2'),
self.zone_inst.links.endpoints)
self.assertEqual('Enabled', self.zone_inst.status.state)
self.assertEqual('OK', self.zone_inst.status.health)
self.assertEqual("1.0.2", self.zone_inst.redfish_version)
self.assertEqual("Zone 1", self.zone_inst.description)
self.assertEqual("1", self.zone_inst.identity)
self.assertEqual("Zone 1", self.zone_inst.name)
self.assertEqual(
(
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
"/redfish/v1/Fabrics/NVMeoE/Endpoints/2",
),
self.zone_inst.links.endpoints,
)
self.assertEqual("Enabled", self.zone_inst.status.state)
self.assertEqual("OK", self.zone_inst.status.health)
def test_update(self):
self.zone_inst.update(
['/redfish/v1/Fabrics/NVMeoE/Endpoints/1'])
self.zone_inst.update(["/redfish/v1/Fabrics/NVMeoE/Endpoints/1"])
self.zone_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Zones/1',
data={"Links": {"Endpoints":
[{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/1"}]}})
"/redfish/v1/Fabrics/NVMeoE/Zones/1",
data={
"Links": {
"Endpoints": [
{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/1"}
]
}
},
)
self.zone_inst._conn.patch.reset_mock()
self.zone_inst.update(
['/redfish/v1/Fabrics/NVMeoE/Endpoints/2',
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3'])
[
"/redfish/v1/Fabrics/NVMeoE/Endpoints/2",
"/redfish/v1/Fabrics/NVMeoE/Endpoints/3",
]
)
self.zone_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Zones/1',
data={"Links": {"Endpoints":
[{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/2"},
{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/3"}]}})
"/redfish/v1/Fabrics/NVMeoE/Zones/1",
data={
"Links": {
"Endpoints": [
{
"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints"
"/2"
},
{
"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints"
"/3"
},
]
}
},
)
def test_delete(self):
self.zone_inst.delete()
self.zone_inst._conn.delete.assert_called_once_with(
self.zone_inst.path)
self.zone_inst.path
)
class ZoneCollectionTestCase(testtools.TestCase):
def setUp(self):
super(ZoneCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'zone_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/zone_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.conn.post.return_value = request_fakes.fake_request_post(
None, headers={"Location": "https://localhost:8443/redfish/v1/"
"Fabrics/NVMeoE/Zones/2"})
None,
headers={
"Location": "https://localhost:8443/redfish/v1/"
"Fabrics/NVMeoE/Zones/2"
},
)
self.zone_col = zone.ZoneCollection(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Zones',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/Fabrics/NVMeoE/Zones",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.zone_col.redfish_version)
self.assertEqual('Zone Collection',
self.zone_col.name)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Zones/1',),
self.zone_col.members_identities)
self.assertEqual("1.0.2", self.zone_col.redfish_version)
self.assertEqual("Zone Collection", self.zone_col.name)
self.assertEqual(
("/redfish/v1/Fabrics/NVMeoE/Zones/1",),
self.zone_col.members_identities,
)
@mock.patch.object(zone, 'Zone', autospec=True)
@mock.patch.object(zone, "Zone", autospec=True)
def test_get_member(self, mock_zone):
self.zone_col.get_member('/redfish/v1/Fabrics/NVMeoE/Zones/1')
self.zone_col.get_member("/redfish/v1/Fabrics/NVMeoE/Zones/1")
mock_zone.assert_called_once_with(
self.zone_col._conn, '/redfish/v1/Fabrics/NVMeoE/Zones/1',
self.zone_col._conn,
"/redfish/v1/Fabrics/NVMeoE/Zones/1",
redfish_version=self.zone_col.redfish_version,
registries=None,
)
@mock.patch.object(zone, 'Zone', autospec=True)
@mock.patch.object(zone, "Zone", autospec=True)
def test_get_members(self, mock_zone):
members = self.zone_col.get_members()
mock_zone.assert_called_with(
self.zone_col._conn, '/redfish/v1/Fabrics/NVMeoE/Zones/1',
self.zone_col._conn,
"/redfish/v1/Fabrics/NVMeoE/Zones/1",
redfish_version=self.zone_col.redfish_version,
registries=None,
)
@ -116,12 +149,26 @@ class ZoneCollectionTestCase(testtools.TestCase):
def test_create_zone(self):
result = self.zone_col.create_zone(
['/redfish/v1/Fabrics/NVMeoE/Endpoints/2',
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3'])
[
"/redfish/v1/Fabrics/NVMeoE/Endpoints/2",
"/redfish/v1/Fabrics/NVMeoE/Endpoints/3",
]
)
self.zone_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Zones',
data={"Links": {"Endpoints":
[{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/2"},
{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/3"}]}})
self.assertEqual(result,
'/redfish/v1/Fabrics/NVMeoE/Zones/2')
"/redfish/v1/Fabrics/NVMeoE/Zones",
data={
"Links": {
"Endpoints": [
{
"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints"
"/2"
},
{
"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints"
"/3"
},
]
}
},
)
self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Zones/2")

View File

@ -20,100 +20,122 @@ from rsd_lib.resources.v2_3.system import ethernet_interface
class TestManager(base.TestCase):
def setUp(self):
super(TestManager, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/manager.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/manager.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.manager_inst = manager.Manager(self.conn,
'/redfish/v1/Manager/PSME',
redfish_version='1.0.2')
self.manager_inst = manager.Manager(
self.conn, "/redfish/v1/Manager/PSME", redfish_version="1.0.2"
)
def test_ethernet_interfaces(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'manager_ethernet_interface_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"manager_ethernet_interface_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_ethernet_interfaces = self.manager_inst.ethernet_interfaces
# | THEN |
self.assertIsInstance(actual_ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection)
self.assertIsInstance(
actual_ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection,
)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_ethernet_interfaces,
self.manager_inst.ethernet_interfaces)
self.assertIs(
actual_ethernet_interfaces, self.manager_inst.ethernet_interfaces
)
self.conn.get.return_value.json.assert_not_called()
def test_ethernet_interfaces_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'manager_ethernet_interface_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"manager_ethernet_interface_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.manager_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection)
self.assertIsInstance(
self.manager_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection,
)
# On refreshing the manager instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'manager.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/manager.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.manager_inst.invalidate()
self.manager_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'manager_ethernet_interface_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"manager_ethernet_interface_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.manager_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection)
self.assertIsInstance(
self.manager_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection,
)
class TestManagerCollection(base.TestCase):
def setUp(self):
super(TestManagerCollection, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'manager_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/manager_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.manager_col = manager.ManagerCollection(self.conn,
'redfish/v1/Managers',
redfish_version='1.0.2')
self.manager_col = manager.ManagerCollection(
self.conn, "redfish/v1/Managers", redfish_version="1.0.2"
)
def test_parse_attributes(self):
self.assertEqual('1.0.2', self.manager_col.redfish_version)
self.assertEqual('Manager Collection', self.manager_col.name)
self.assertEqual(('/redfish/v1/Managers/BMC1',
'/redfish/v1/Managers/BMC2',
'/redfish/v1/Managers/PSME',),
self.manager_col.members_identities)
self.assertEqual("1.0.2", self.manager_col.redfish_version)
self.assertEqual("Manager Collection", self.manager_col.name)
self.assertEqual(
(
"/redfish/v1/Managers/BMC1",
"/redfish/v1/Managers/BMC2",
"/redfish/v1/Managers/PSME",
),
self.manager_col.members_identities,
)
@mock.patch.object(manager, 'Manager', autospec=True)
@mock.patch.object(manager, "Manager", autospec=True)
def test_get_member(self, mock_manager):
self.manager_col.get_member('/redfish/v1/Managers/BMC1')
self.manager_col.get_member("/redfish/v1/Managers/BMC1")
mock_manager.assert_called_once_with(
self.manager_col._conn,
'/redfish/v1/Managers/BMC1',
"/redfish/v1/Managers/BMC1",
redfish_version=self.manager_col.redfish_version,
registries=None,
)
@mock.patch.object(manager, 'Manager', autospec=True)
@mock.patch.object(manager, "Manager", autospec=True)
def test_get_members(self, mock_manager):
members = self.manager_col.get_members()
self.assertEqual(mock_manager.call_count, 3)

View File

@ -21,25 +21,30 @@ from rsd_lib.resources.v2_3.node import attach_action_info
class AttachResourceActionInfoTestCase(testtools.TestCase):
def setUp(self):
super(AttachResourceActionInfoTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/attach_action_info.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.attach_action_info = attach_action_info.AttachResourceActionInfo(
self.conn, '/redfish/v1/Nodes/2/Actions/AttachResourceActionInfo',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/Nodes/2/Actions/AttachResourceActionInfo",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.attach_action_info.redfish_version)
self.assertEqual("1.0.2", self.attach_action_info.redfish_version)
self.assertEqual(None, self.attach_action_info.description)
self.assertEqual('AttachResourceActionInfo',
self.attach_action_info.identity)
self.assertEqual('Attach Resource ActionInfo',
self.attach_action_info.name)
self.assertEqual(
"AttachResourceActionInfo", self.attach_action_info.identity
)
self.assertEqual(
"Attach Resource ActionInfo", self.attach_action_info.name
)
def test_parameters(self):
# | WHEN |
@ -53,21 +58,20 @@ class AttachResourceActionInfoTestCase(testtools.TestCase):
"object_data_type": "#Resource.Resource",
"allowable_values": (
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1",
)
),
},
{
"name": "Protocol",
"required": False,
"data_type": "String",
"object_data_type": None,
"allowable_values": ["NVMeOverFabrics"]
}
"allowable_values": ["NVMeOverFabrics"],
},
]
self.assertEqual(expected, actual_parameters)
# tests for same object on invoking subsequently
self.assertIs(actual_parameters,
self.attach_action_info.parameters)
self.assertIs(actual_parameters, self.attach_action_info.parameters)
def test_parameters_on_refresh(self):
expected = [
@ -78,15 +82,15 @@ class AttachResourceActionInfoTestCase(testtools.TestCase):
"object_data_type": "#Resource.Resource",
"allowable_values": (
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1",
)
),
},
{
"name": "Protocol",
"required": False,
"data_type": "String",
"object_data_type": None,
"allowable_values": ["NVMeOverFabrics"]
}
"allowable_values": ["NVMeOverFabrics"],
},
]
self.assertEqual(expected, self.attach_action_info.parameters)
@ -94,8 +98,11 @@ class AttachResourceActionInfoTestCase(testtools.TestCase):
self.attach_action_info.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_pool_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"storage_pool_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertEqual(expected, self.attach_action_info.parameters)

View File

@ -25,16 +25,15 @@ from rsd_lib.tests.unit.fakes import request_fakes
class NodeTestCase(testtools.TestCase):
def setUp(self):
super(NodeTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/node.json', 'r') as f:
with open("rsd_lib/tests/unit/json_samples/v2_3/node.json", "r") as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst = node.Node(
self.conn, '/redfish/v1/Nodes/Node1',
redfish_version='1.0.2')
self.conn, "/redfish/v1/Nodes/Node1", redfish_version="1.0.2"
)
def test__parse_attributes(self):
self.assertEqual(True, self.node_inst.clear_tpm_on_delete)
@ -42,26 +41,32 @@ class NodeTestCase(testtools.TestCase):
def test_update_node(self):
self.node_inst.update(clear_tpm_on_delete=True)
self.node_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Nodes/Node1', data={'ClearTPMOnDelete': True})
"/redfish/v1/Nodes/Node1", data={"ClearTPMOnDelete": True}
)
def test_update_node_with_invalid_parameter(self):
with self.assertRaisesRegex(
exceptions.InvalidParameterValueError,
'The parameter "clear_tpm_on_delete" value "fake-value" is'):
self.node_inst.update(clear_tpm_on_delete='fake-value')
'The parameter "clear_tpm_on_delete" value "fake-value" is',
):
self.node_inst.update(clear_tpm_on_delete="fake-value")
def test__get_attach_endpoint_action_element(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/attach_action_info.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
value = self.node_inst._get_attach_endpoint_action_element()
self.assertEqual('/redfish/v1/Nodes/Node1/Actions/'
'ComposedNode.AttachResource',
value.target_uri)
self.assertEqual('/redfish/v1/Nodes/Node1/Actions/'
'AttachResourceActionInfo',
value.action_info_path)
self.assertEqual(
"/redfish/v1/Nodes/Node1/Actions/ComposedNode.AttachResource",
value.target_uri,
)
self.assertEqual(
"/redfish/v1/Nodes/Node1/Actions/AttachResourceActionInfo",
value.action_info_path,
)
expected = [
{
"name": "Resource",
@ -70,21 +75,23 @@ class NodeTestCase(testtools.TestCase):
"object_data_type": "#Resource.Resource",
"allowable_values": (
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1",
)
),
},
{
"name": "Protocol",
"required": False,
"data_type": "String",
"object_data_type": None,
"allowable_values": ["NVMeOverFabrics"]
}
"allowable_values": ["NVMeOverFabrics"],
},
]
self.assertEqual(expected, value.action_info.parameters)
def test_get_allowed_attach_endpoints(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/attach_action_info.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
expected = self.node_inst.get_allowed_attach_endpoints()
@ -92,55 +99,79 @@ class NodeTestCase(testtools.TestCase):
self.assertEqual(expected, result)
def test_attach_endpoint(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/attach_action_info.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst.attach_endpoint(
resource='/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1',
protocol='NVMeOverFabrics')
resource="/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1",
protocol="NVMeOverFabrics",
)
self.node_inst._conn.post.assert_called_once_with(
'/redfish/v1/Nodes/Node1/Actions/ComposedNode.AttachResource',
data={'Resource': {'@odata.id': '/redfish/v1/StorageServices'
'/1-sv-1/Volumes/1-sv-1-vl-1'},
'Protocol': 'NVMeOverFabrics'})
"/redfish/v1/Nodes/Node1/Actions/ComposedNode.AttachResource",
data={
"Resource": {
"@odata.id": "/redfish/v1/StorageServices"
"/1-sv-1/Volumes/1-sv-1-vl-1"
},
"Protocol": "NVMeOverFabrics",
},
)
def test_attach_endpoint_only_with_resource_uri(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/attach_action_info.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst.attach_endpoint(
resource='/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1')
resource="/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1"
)
self.node_inst._conn.post.assert_called_once_with(
'/redfish/v1/Nodes/Node1/Actions/ComposedNode.AttachResource',
data={'Resource': {'@odata.id': '/redfish/v1/StorageServices'
'/1-sv-1/Volumes/1-sv-1-vl-1'}})
"/redfish/v1/Nodes/Node1/Actions/ComposedNode.AttachResource",
data={
"Resource": {
"@odata.id": "/redfish/v1/StorageServices"
"/1-sv-1/Volumes/1-sv-1-vl-1"
}
},
)
def test_attach_endpoint_invalid_parameter(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/attach_action_info.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
with self.assertRaisesRegex(
exceptions.InvalidParameterValueError,
'"resource" value.*{0}'.format(
'/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1')):
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1"
),
):
self.node_inst.attach_endpoint(resource='invalid-resource')
self.node_inst.attach_endpoint(resource="invalid-resource")
def test__get_detach_endpoint_action_element(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/attach_action_info.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
value = self.node_inst._get_detach_endpoint_action_element()
self.assertEqual('/redfish/v1/Nodes/Node1/Actions/'
'ComposedNode.DetachResource',
value.target_uri)
self.assertEqual('/redfish/v1/Nodes/Node1/Actions/'
'DetachResourceActionInfo',
value.action_info_path)
self.assertEqual(
"/redfish/v1/Nodes/Node1/Actions/ComposedNode.DetachResource",
value.target_uri,
)
self.assertEqual(
"/redfish/v1/Nodes/Node1/Actions/DetachResourceActionInfo",
value.action_info_path,
)
expected = [
{
"name": "Resource",
@ -149,21 +180,23 @@ class NodeTestCase(testtools.TestCase):
"object_data_type": "#Resource.Resource",
"allowable_values": (
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1",
)
),
},
{
"name": "Protocol",
"required": False,
"data_type": "String",
"object_data_type": None,
"allowable_values": ["NVMeOverFabrics"]
}
"allowable_values": ["NVMeOverFabrics"],
},
]
self.assertEqual(expected, value.action_info.parameters)
def test_get_allowed_detach_endpoints(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/attach_action_info.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
expected = self.node_inst.get_allowed_detach_endpoints()
@ -171,46 +204,62 @@ class NodeTestCase(testtools.TestCase):
self.assertEqual(expected, result)
def test_detach_endpoint(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/attach_action_info.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst.detach_endpoint(
resource='/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1')
resource="/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1"
)
self.node_inst._conn.post.assert_called_once_with(
'/redfish/v1/Nodes/Node1/Actions/ComposedNode.DetachResource',
data={'Resource': {'@odata.id': '/redfish/v1/StorageServices'
'/1-sv-1/Volumes/1-sv-1-vl-1'}})
"/redfish/v1/Nodes/Node1/Actions/ComposedNode.DetachResource",
data={
"Resource": {
"@odata.id": "/redfish/v1/StorageServices"
"/1-sv-1/Volumes/1-sv-1-vl-1"
}
},
)
def test_detach_endpoint_invalid_parameter(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/attach_action_info.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
with self.assertRaisesRegex(
exceptions.InvalidParameterValueError,
'"resource" value.*{0}'.format(
'/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1')):
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1"
),
):
self.node_inst.detach_endpoint(resource='invalid-resource')
self.node_inst.detach_endpoint(resource="invalid-resource")
def test_refresh(self):
self.assertIsNone(self.node_inst._actions.attach_endpoint.action_info)
self.assertIsNone(self.node_inst._actions.detach_endpoint.action_info)
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/attach_action_info.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst._get_attach_endpoint_action_element()
self.node_inst._get_detach_endpoint_action_element()
self.assertIsNotNone(
self.node_inst._actions.attach_endpoint.action_info)
self.node_inst._actions.attach_endpoint.action_info
)
self.assertIsNotNone(
self.node_inst._actions.detach_endpoint.action_info)
self.node_inst._actions.detach_endpoint.action_info
)
with open('rsd_lib/tests/unit/json_samples/v2_3/node.json', 'r') as f:
with open("rsd_lib/tests/unit/json_samples/v2_3/node.json", "r") as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst.refresh()
@ -219,40 +268,48 @@ class NodeTestCase(testtools.TestCase):
class NodeCollectionTestCase(testtools.TestCase):
def setUp(self):
super(NodeCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/node_collection.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/node_collection.json", "r"
) as f:
self.conn.get.return_value = request_fakes.fake_request_get(
json.loads(f.read()))
json.loads(f.read())
)
self.conn.post.return_value = request_fakes.fake_request_post(
None, headers={"Location": "https://localhost:8443/"
"redfish/v1/Nodes/1"})
None,
headers={
"Location": "https://localhost:8443/redfish/v1/Nodes/1"
},
)
self.node_col = node.NodeCollection(
self.conn, '/redfish/v1/Nodes', redfish_version='1.0.2')
self.conn, "/redfish/v1/Nodes", redfish_version="1.0.2"
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.node_col.redfish_version)
self.assertEqual('Composed Node Collection', self.node_col.name)
self.assertEqual(('/redfish/v1/Nodes/1',),
self.node_col.members_identities)
self.assertEqual("1.0.2", self.node_col.redfish_version)
self.assertEqual("Composed Node Collection", self.node_col.name)
self.assertEqual(
("/redfish/v1/Nodes/1",), self.node_col.members_identities
)
@mock.patch.object(node, 'Node', autospec=True)
@mock.patch.object(node, "Node", autospec=True)
def test_get_member(self, mock_node):
self.node_col.get_member('/redfish/v1/Nodes/1')
self.node_col.get_member("/redfish/v1/Nodes/1")
mock_node.assert_called_once_with(
self.node_col._conn, '/redfish/v1/Nodes/1',
self.node_col._conn,
"/redfish/v1/Nodes/1",
redfish_version=self.node_col.redfish_version,
registries=None,
)
@mock.patch.object(node, 'Node', autospec=True)
@mock.patch.object(node, "Node", autospec=True)
def test_get_members(self, mock_node):
members = self.node_col.get_members()
mock_node.assert_called_once_with(
self.node_col._conn, '/redfish/v1/Nodes/1',
self.node_col._conn,
"/redfish/v1/Nodes/1",
redfish_version=self.node_col.redfish_version,
registries=None,
)
@ -261,284 +318,330 @@ class NodeCollectionTestCase(testtools.TestCase):
def test__get_compose_action_element(self):
value = self.node_col._get_compose_action_element()
self.assertEqual('/redfish/v1/Nodes/Actions/Allocate',
value.target_uri)
self.assertEqual(
"/redfish/v1/Nodes/Actions/Allocate", value.target_uri
)
def test_compose_node_no_reqs(self):
result = self.node_col.compose_node()
self.node_col._conn.post.assert_called_once_with(
'/redfish/v1/Nodes/Actions/Allocate', data={})
self.assertEqual(result, '/redfish/v1/Nodes/1')
"/redfish/v1/Nodes/Actions/Allocate", data={}
)
self.assertEqual(result, "/redfish/v1/Nodes/1")
def test_compose_node(self):
reqs = {
'Name': 'test',
'Description': 'this is a test node',
'Processors': [{
'TotalCores': 4,
'ProcessorType': 'FPGA',
'Oem': {
'Brand': 'Platinum',
'Capabilities': ['sse']
"Name": "test",
"Description": "this is a test node",
"Processors": [
{
"TotalCores": 4,
"ProcessorType": "FPGA",
"Oem": {"Brand": "Platinum", "Capabilities": ["sse"]},
}
}],
'Memory': [{
'CapacityMiB': 8000
}],
'RemoteDrives': [{
'CapacityGiB': 80,
'Protocol': 'NVMeOverFabrics',
'Master': {
'Type': 'Snapshot',
'Resource': {
'@odata.id':
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102'
}
},
'Resource': {
'@odata.id':
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102'
],
"Memory": [{"CapacityMiB": 8000}],
"RemoteDrives": [
{
"CapacityGiB": 80,
"Protocol": "NVMeOverFabrics",
"Master": {
"Type": "Snapshot",
"Resource": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/102"
},
},
"Resource": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/102"
},
}
}],
'Security': {
'TpmPresent': True,
'TpmInterfaceType': 'TPM2_0',
'TxtEnabled': True,
'ClearTPMOnDelete': True
],
"Security": {
"TpmPresent": True,
"TpmInterfaceType": "TPM2_0",
"TxtEnabled": True,
"ClearTPMOnDelete": True,
},
'TotalSystemCoreCount': 8,
'TotalSystemMemoryMiB': 16000
"TotalSystemCoreCount": 8,
"TotalSystemMemoryMiB": 16000,
}
result = self.node_col.compose_node(
name='test', description='this is a test node',
processor_req=[{
'TotalCores': 4,
'ProcessorType': 'FPGA',
'Oem': {
'Brand': 'Platinum',
'Capabilities': ['sse']
name="test",
description="this is a test node",
processor_req=[
{
"TotalCores": 4,
"ProcessorType": "FPGA",
"Oem": {"Brand": "Platinum", "Capabilities": ["sse"]},
}
}],
memory_req=[{'CapacityMiB': 8000}],
remote_drive_req=[{
'CapacityGiB': 80,
'Protocol': 'NVMeOverFabrics',
'Master': {
'Type': 'Snapshot',
'Resource': {
'@odata.id':
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102'
}
},
'Resource': {
'@odata.id':
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102'
],
memory_req=[{"CapacityMiB": 8000}],
remote_drive_req=[
{
"CapacityGiB": 80,
"Protocol": "NVMeOverFabrics",
"Master": {
"Type": "Snapshot",
"Resource": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/102"
},
},
"Resource": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/102"
},
}
}],
],
security_req={
'TpmPresent': True,
'TpmInterfaceType': 'TPM2_0',
'TxtEnabled': True,
'ClearTPMOnDelete': True
"TpmPresent": True,
"TpmInterfaceType": "TPM2_0",
"TxtEnabled": True,
"ClearTPMOnDelete": True,
},
total_system_core_req=8,
total_system_memory_req=16000)
total_system_memory_req=16000,
)
self.node_col._conn.post.assert_called_once_with(
'/redfish/v1/Nodes/Actions/Allocate', data=reqs)
self.assertEqual(result, '/redfish/v1/Nodes/1')
"/redfish/v1/Nodes/Actions/Allocate", data=reqs
)
self.assertEqual(result, "/redfish/v1/Nodes/1")
def test_compose_node_with_invalid_reqs(self):
# Wrong processor type
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
("'invalid' is not one of \['CPU', 'FPGA', 'GPU', 'DSP', "
"'Accelerator', 'OEM'\]")):
(
"'invalid' is not one of \['CPU', 'FPGA', 'GPU', 'DSP', "
"'Accelerator', 'OEM'\]"
),
):
self.node_col.compose_node(
name='test', description='this is a test node',
processor_req=[{
'TotalCores': 4,
'ProcessorType': 'invalid'}])
name="test",
description="this is a test node",
processor_req=[{"TotalCores": 4, "ProcessorType": "invalid"}],
)
# Wrong processor Oem Brand
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
("'invalid' is not one of \['E3', 'E5'")):
("'invalid' is not one of \['E3', 'E5'"),
):
self.node_col.compose_node(
name='test', description='this is a test node',
processor_req=[{
'TotalCores': 4,
'Oem': {
'Brand': 'invalid',
'Capabilities': ['sse']
name="test",
description="this is a test node",
processor_req=[
{
"TotalCores": 4,
"Oem": {"Brand": "invalid", "Capabilities": ["sse"]},
}
}])
],
)
# Wrong processor Oem Capabilities
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
("'sse' is not of type 'array'")):
("'sse' is not of type 'array'"),
):
self.node_col.compose_node(
name='test', description='this is a test node',
processor_req=[{
'TotalCores': 4,
'Oem': {
'Brand': 'E3',
'Capabilities': 'sse'
name="test",
description="this is a test node",
processor_req=[
{
"TotalCores": 4,
"Oem": {"Brand": "E3", "Capabilities": "sse"},
}
}])
],
)
# Wrong processor Oem Capabilities
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
("0 is not of type 'string'")):
("0 is not of type 'string'"),
):
self.node_col.compose_node(
name='test', description='this is a test node',
processor_req=[{
'TotalCores': 4,
'Oem': {
'Brand': 'E3',
'Capabilities': [0]
name="test",
description="this is a test node",
processor_req=[
{
"TotalCores": 4,
"Oem": {"Brand": "E3", "Capabilities": [0]},
}
}])
],
)
# Wrong remote drive CapacityGiB
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
("'invalid' is not of type 'number'")):
("'invalid' is not of type 'number'"),
):
self.node_col.compose_node(
name='test', description='this is a test node',
remote_drive_req=[{
'CapacityGiB': 'invalid',
'Protocol': 'NVMeOverFabrics',
'Master': {
'Type': 'Snapshot',
'Resource': {
'@odata.id':
'/redfish/v1/StorageServices/NVMeoE1/Volumes/'
'102'
}
},
'Resource': {
'@odata.id':
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102'
}
}])
name="test",
description="this is a test node",
remote_drive_req=[
{
"CapacityGiB": "invalid",
"Protocol": "NVMeOverFabrics",
"Master": {
"Type": "Snapshot",
"Resource": {
"@odata.id": "/redfish/v1/StorageServices/"
"NVMeoE1/Volumes/"
"102"
},
},
"Resource": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/102"
},
}
],
)
# Wrong remote drive Protocol
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
("'invalid' is not one of \['iSCSI', 'NVMeOverFabrics'\]")):
("'invalid' is not one of \['iSCSI', 'NVMeOverFabrics'\]"),
):
self.node_col.compose_node(
name='test', description='this is a test node',
remote_drive_req=[{
'CapacityGiB': 80,
'Protocol': 'invalid',
'Master': {
'Type': 'Snapshot',
'Resource': {
'@odata.id':
'/redfish/v1/StorageServices/NVMeoE1/Volumes/'
'102'
}
},
'Resource': {
'@odata.id':
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102'
}
}])
name="test",
description="this is a test node",
remote_drive_req=[
{
"CapacityGiB": 80,
"Protocol": "invalid",
"Master": {
"Type": "Snapshot",
"Resource": {
"@odata.id": "/redfish/v1/StorageServices/"
"NVMeoE1/Volumes/"
"102"
},
},
"Resource": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/102"
},
}
],
)
# Wrong remote drive Master Type
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
("'invalid' is not one of \['Snapshot', 'Clone'\]")):
("'invalid' is not one of \['Snapshot', 'Clone'\]"),
):
self.node_col.compose_node(
name='test', description='this is a test node',
remote_drive_req=[{
'CapacityGiB': 80,
'Protocol': 'iSCSI',
'Master': {
'Type': 'invalid',
'Resource': {
'@odata.id':
'/redfish/v1/StorageServices/NVMeoE1/Volumes/'
'102'
}
},
'Resource': {
'@odata.id':
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102'
}
}])
name="test",
description="this is a test node",
remote_drive_req=[
{
"CapacityGiB": 80,
"Protocol": "iSCSI",
"Master": {
"Type": "invalid",
"Resource": {
"@odata.id": "/redfish/v1/StorageServices/"
"NVMeoE1/Volumes/"
"102"
},
},
"Resource": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/102"
},
}
],
)
# Wrong security parameter "TpmPresent"
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
"'invalid' is not of type 'boolean'"):
"'invalid' is not of type 'boolean'",
):
self.node_col.compose_node(
name='test', description='this is a test node',
name="test",
description="this is a test node",
security_req={
'TpmPresent': 'invalid',
'TpmInterfaceType': 'TPM2_0',
'TxtEnabled': True,
'ClearTPMOnDelete': True
})
"TpmPresent": "invalid",
"TpmInterfaceType": "TPM2_0",
"TxtEnabled": True,
"ClearTPMOnDelete": True,
},
)
# Wrong security parameter "TpmInterfaceType"
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
"True is not of type 'string'"):
"True is not of type 'string'",
):
self.node_col.compose_node(
name='test', description='this is a test node',
name="test",
description="this is a test node",
security_req={
'TpmPresent': False,
'TpmInterfaceType': True,
'TxtEnabled': True,
'ClearTPMOnDelete': True
})
"TpmPresent": False,
"TpmInterfaceType": True,
"TxtEnabled": True,
"ClearTPMOnDelete": True,
},
)
# Wrong security parameter "TxtEnabled"
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
"'invalid' is not of type 'boolean'"):
"'invalid' is not of type 'boolean'",
):
self.node_col.compose_node(
name='test', description='this is a test node',
name="test",
description="this is a test node",
security_req={
'TpmPresent': True,
'TpmInterfaceType': 'TPM2_0',
'TxtEnabled': 'invalid',
'ClearTPMOnDelete': True
})
"TpmPresent": True,
"TpmInterfaceType": "TPM2_0",
"TxtEnabled": "invalid",
"ClearTPMOnDelete": True,
},
)
# Wrong security parameter "ClearTPMOnDelete"
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
"'invalid' is not of type 'boolean'"):
"'invalid' is not of type 'boolean'",
):
self.node_col.compose_node(
name='test', description='this is a test node',
name="test",
description="this is a test node",
security_req={
'TpmPresent': True,
'TpmInterfaceType': 'TPM2_0',
'TxtEnabled': True,
'ClearTPMOnDelete': 'invalid'
})
"TpmPresent": True,
"TpmInterfaceType": "TPM2_0",
"TxtEnabled": True,
"ClearTPMOnDelete": "invalid",
},
)
# Wrong additional security parameter
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
("Additional properties are not allowed \('invalid-key' was "
"unexpected\)")):
(
"Additional properties are not allowed \('invalid-key' was "
"unexpected\)"
),
):
self.node_col.compose_node(
name='test', description='this is a test node',
name="test",
description="this is a test node",
security_req={
'TpmPresent': True,
'TpmInterfaceType': 'TPM2_0',
'TxtEnabled': False,
'invalid-key': 'invalid-value'
})
"TpmPresent": True,
"TpmInterfaceType": "TPM2_0",
"TxtEnabled": False,
"invalid-key": "invalid-value",
},
)

View File

@ -22,49 +22,54 @@ from rsd_lib.resources.v2_3.storage_service import drive_metrics
class DriveTestCase(testtools.TestCase):
def setUp(self):
super(DriveTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/drive.json',
'r') as f:
with open("rsd_lib/tests/unit/json_samples/v2_3/drive.json", "r") as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.drive_inst = drive.Drive(
self.conn, '/redfish/v1/Chassis/1/Drives/1',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/Chassis/1/Drives/1",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.drive_inst.redfish_version)
self.assertEqual('2', self.drive_inst.identity)
self.assertEqual('Physical Drive', self.drive_inst.name)
self.assertEqual('2', self.drive_inst.identity)
self.assertEqual('NVMe', self.drive_inst.protocol)
self.assertEqual('NVMe', self.drive_inst.drive_type)
self.assertEqual('SSD', self.drive_inst.media_type)
self.assertEqual("1.0.2", self.drive_inst.redfish_version)
self.assertEqual("2", self.drive_inst.identity)
self.assertEqual("Physical Drive", self.drive_inst.name)
self.assertEqual("2", self.drive_inst.identity)
self.assertEqual("NVMe", self.drive_inst.protocol)
self.assertEqual("NVMe", self.drive_inst.drive_type)
self.assertEqual("SSD", self.drive_inst.media_type)
self.assertEqual(2442408680913, self.drive_inst.capacity_bytes)
self.assertEqual('Intel Corporation', self.drive_inst.manufacturer)
self.assertEqual('E323', self.drive_inst.model)
self.assertEqual("Intel Corporation", self.drive_inst.manufacturer)
self.assertEqual("E323", self.drive_inst.model)
self.assertEqual(None, self.drive_inst.revision)
self.assertEqual(None, self.drive_inst.sku)
self.assertEqual('123fed3029c-b23394-121',
self.drive_inst.serial_number)
self.assertEqual(
"123fed3029c-b23394-121", self.drive_inst.serial_number
)
self.assertEqual(None, self.drive_inst.part_number)
self.assertEqual(None, self.drive_inst.asset_tag)
self.assertEqual(None, self.drive_inst.rotation_speed_rpm)
self.assertEqual('397f9b78-7e94-11e7-9ea4-001e67dfa170',
self.drive_inst.identifiers[0].durable_name)
self.assertEqual('UUID',
self.drive_inst.identifiers[0].durable_name_format)
self.assertEqual('3', self.drive_inst.location[0].info)
self.assertEqual('DriveBay number',
self.drive_inst.location[0].info_format)
self.assertEqual('Enabled', self.drive_inst.status.state)
self.assertEqual('OK', self.drive_inst.status.health)
self.assertEqual('OK', self.drive_inst.status.health_rollup)
self.assertEqual(
"397f9b78-7e94-11e7-9ea4-001e67dfa170",
self.drive_inst.identifiers[0].durable_name,
)
self.assertEqual(
"UUID", self.drive_inst.identifiers[0].durable_name_format
)
self.assertEqual("3", self.drive_inst.location[0].info)
self.assertEqual(
"DriveBay number", self.drive_inst.location[0].info_format
)
self.assertEqual("Enabled", self.drive_inst.status.state)
self.assertEqual("OK", self.drive_inst.status.health)
self.assertEqual("OK", self.drive_inst.status.health_rollup)
self.assertEqual(False, self.drive_inst.oem.erased)
self.assertEqual(True, self.drive_inst.oem.erase_on_detach)
self.assertEqual('1.0', self.drive_inst.oem.firmware_version)
self.assertEqual("1.0", self.drive_inst.oem.firmware_version)
self.assertEqual(None, self.drive_inst.oem.storage)
self.assertEqual(None, self.drive_inst.oem.pcie_function)
self.assertEqual(None, self.drive_inst.status_indicator)
@ -72,111 +77,120 @@ class DriveTestCase(testtools.TestCase):
self.assertEqual(None, self.drive_inst.capable_speed_gbs)
self.assertEqual(None, self.drive_inst.negotiated_speed_gbs)
self.assertEqual(95, self.drive_inst.predicted_media_life_left_percent)
self.assertEqual('/redfish/v1/Chassis/1',
self.drive_inst.links.chassis)
self.assertEqual(
"/redfish/v1/Chassis/1", self.drive_inst.links.chassis
)
self.assertEqual((), self.drive_inst.links.volumes)
self.assertEqual((), self.drive_inst.links.endpoints)
def test_get_metrics_path(self):
expected = '/redfish/v1/Chassis/1/Drives/1/Metrics'
expected = "/redfish/v1/Chassis/1/Drives/1/Metrics"
result = self.drive_inst._get_metrics_path()
self.assertEqual(expected, result)
def test_drive_metrics(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'drive_metrics.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/drive_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_drive_metrics = self.drive_inst.metrics
# | THEN |
self.assertIsInstance(actual_drive_metrics,
drive_metrics.DriveMetrics)
self.assertIsInstance(actual_drive_metrics, drive_metrics.DriveMetrics)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_drive_metrics,
self.drive_inst.metrics)
self.assertIs(actual_drive_metrics, self.drive_inst.metrics)
self.conn.get.return_value.json.assert_not_called()
def test_drive_metrics_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'drive_metrics.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/drive_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.drive_inst.metrics,
drive_metrics.DriveMetrics)
self.assertIsInstance(
self.drive_inst.metrics, drive_metrics.DriveMetrics
)
# On refreshing the chassis instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'drive.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/drive.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.drive_inst.invalidate()
self.drive_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'drive_metrics.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/drive_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.drive_inst.metrics,
drive_metrics.DriveMetrics)
self.assertIsInstance(
self.drive_inst.metrics, drive_metrics.DriveMetrics
)
class DriveCollectionTestCase(testtools.TestCase):
def setUp(self):
super(DriveCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'drive_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/drive_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.drive_col = drive.DriveCollection(
self.conn, '/redfish/v1/StorageServices/NVMeoE1/Drives',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/StorageServices/NVMeoE1/Drives",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.drive_col.redfish_version)
self.assertEqual('Drives',
self.drive_col.name)
self.assertEqual("1.0.2", self.drive_col.redfish_version)
self.assertEqual("Drives", self.drive_col.name)
self.assertEqual(
('/redfish/v1/Chassis/1/Drives/1',
'/redfish/v1/Chassis/1/Drives/2'),
self.drive_col.members_identities)
(
"/redfish/v1/Chassis/1/Drives/1",
"/redfish/v1/Chassis/1/Drives/2",
),
self.drive_col.members_identities,
)
@mock.patch.object(drive, 'Drive', autospec=True)
@mock.patch.object(drive, "Drive", autospec=True)
def test_get_member(self, mock_drive):
self.drive_col.get_member(
'/redfish/v1/Chassis/1/Drives/1')
self.drive_col.get_member("/redfish/v1/Chassis/1/Drives/1")
mock_drive.assert_called_once_with(
self.drive_col._conn,
'/redfish/v1/Chassis/1/Drives/1',
"/redfish/v1/Chassis/1/Drives/1",
redfish_version=self.drive_col.redfish_version,
registries=None,
)
@mock.patch.object(drive, 'Drive', autospec=True)
@mock.patch.object(drive, "Drive", autospec=True)
def test_get_members(self, mock_drive):
members = self.drive_col.get_members()
calls = [
mock.call(
self.drive_col._conn,
'/redfish/v1/Chassis/1/Drives/1',
"/redfish/v1/Chassis/1/Drives/1",
redfish_version=self.drive_col.redfish_version,
registries=None,
),
mock.call(
self.drive_col._conn,
'/redfish/v1/Chassis/1/Drives/2',
"/redfish/v1/Chassis/1/Drives/2",
redfish_version=self.drive_col.redfish_version,
registries=None,
)
),
]
mock_drive.assert_has_calls(calls)
self.assertIsInstance(members, list)

View File

@ -21,24 +21,28 @@ from rsd_lib.resources.v2_3.storage_service import drive_metrics
class DriveMetricsTestCase(testtools.TestCase):
def setUp(self):
super(DriveMetricsTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/drive_metrics.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/drive_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.drive_metrics_inst = drive_metrics.DriveMetrics(
self.conn, '/redfish/v1/Chassis/1/Drives/1/Metrics',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/Chassis/1/Drives/1/Metrics",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('Drive Metrics for Drive',
self.drive_metrics_inst.name)
self.assertEqual('Metrics for Drive 1',
self.drive_metrics_inst.description)
self.assertEqual('Metrics', self.drive_metrics_inst.identity)
self.assertEqual(
"Drive Metrics for Drive", self.drive_metrics_inst.name
)
self.assertEqual(
"Metrics for Drive 1", self.drive_metrics_inst.description
)
self.assertEqual("Metrics", self.drive_metrics_inst.identity)
self.assertEqual(318, self.drive_metrics_inst.temperature_kelvin)
life_time = self.drive_metrics_inst.life_time

View File

@ -24,226 +24,281 @@ from rsd_lib.resources.v2_3.storage_service import volume
class StoragePoolTestCase(testtools.TestCase):
def setUp(self):
super(StoragePoolTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/storage_pool.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/storage_pool.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_pool_inst = storage_pool.StoragePool(
self.conn, '/redfish/v1/StorageServices/NVMeoE1/StoragePool/2',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/StorageServices/NVMeoE1/StoragePool/2",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.storage_pool_inst.redfish_version)
self.assertEqual('Base storage pool',
self.storage_pool_inst.description)
self.assertEqual('2', self.storage_pool_inst.identity)
self.assertEqual('BasePool', self.storage_pool_inst.name)
self.assertEqual('Enabled', self.storage_pool_inst.status.state)
self.assertEqual('OK', self.storage_pool_inst.status.health)
self.assertEqual('OK', self.storage_pool_inst.status.health_rollup)
self.assertEqual("1.0.2", self.storage_pool_inst.redfish_version)
self.assertEqual(
'/dev/nvme5', self.storage_pool_inst.identifier.durable_name)
"Base storage pool", self.storage_pool_inst.description
)
self.assertEqual("2", self.storage_pool_inst.identity)
self.assertEqual("BasePool", self.storage_pool_inst.name)
self.assertEqual("Enabled", self.storage_pool_inst.status.state)
self.assertEqual("OK", self.storage_pool_inst.status.health)
self.assertEqual("OK", self.storage_pool_inst.status.health_rollup)
self.assertEqual(
'SystemPath',
self.storage_pool_inst.identifier.durable_name_format)
self.assertEqual(512174850048,
self.storage_pool_inst.capacity.allocated_bytes)
self.assertEqual(3071983104,
self.storage_pool_inst.capacity.consumed_bytes)
self.assertEqual(None,
self.storage_pool_inst.capacity.guaranteed_bytes)
self.assertEqual(None,
self.storage_pool_inst.capacity.provisioned_bytes)
"/dev/nvme5", self.storage_pool_inst.identifier.durable_name
)
self.assertEqual(
('/redfish/v1/Chassis/1/Drives/2',),
self.storage_pool_inst.capacity_sources[0].providing_drives)
"SystemPath", self.storage_pool_inst.identifier.durable_name_format
)
self.assertEqual(
512174850048, self.storage_pool_inst.capacity.allocated_bytes
)
self.assertEqual(
3071983104, self.storage_pool_inst.capacity.consumed_bytes
)
self.assertEqual(
None, self.storage_pool_inst.capacity.guaranteed_bytes
)
self.assertEqual(
None, self.storage_pool_inst.capacity.provisioned_bytes
)
self.assertEqual(
("/redfish/v1/Chassis/1/Drives/2",),
self.storage_pool_inst.capacity_sources[0].providing_drives,
)
self.assertEqual(
512174850048,
self.storage_pool_inst.capacity_sources[0].
provided_capacity.allocated_bytes)
self.storage_pool_inst.capacity_sources[
0
].provided_capacity.allocated_bytes,
)
self.assertEqual(
3071983104,
self.storage_pool_inst.capacity_sources[0].
provided_capacity.consumed_bytes)
self.storage_pool_inst.capacity_sources[
0
].provided_capacity.consumed_bytes,
)
self.assertEqual(
None,
self.storage_pool_inst.capacity_sources[0].
provided_capacity.guaranteed_bytes)
self.storage_pool_inst.capacity_sources[
0
].provided_capacity.guaranteed_bytes,
)
self.assertEqual(
None,
self.storage_pool_inst.capacity_sources[0].
provided_capacity.provisioned_bytes)
self.storage_pool_inst.capacity_sources[
0
].provided_capacity.provisioned_bytes,
)
def test__get_allocated_volumes_path(self):
expected = '/redfish/v1/StorageServices/NVMeoE1/StoragePools/'\
'2/AllocatedVolumes'
expected = (
"/redfish/v1/StorageServices/NVMeoE1/StoragePools/"
"2/AllocatedVolumes"
)
result = self.storage_pool_inst._get_allocated_volumes_path()
self.assertEqual(expected, result)
def test__get_allocated_volumes_path_missing_processors_attr(self):
self.storage_pool_inst._json.pop('AllocatedVolumes')
self.storage_pool_inst._json.pop("AllocatedVolumes")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute AllocatedVolumes',
self.storage_pool_inst._get_allocated_volumes_path)
exceptions.MissingAttributeError,
"attribute AllocatedVolumes",
self.storage_pool_inst._get_allocated_volumes_path,
)
def test_allocated_volumes(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'volume_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_volumes = self.storage_pool_inst.allocated_volumes
# | THEN |
self.assertIsInstance(actual_volumes,
volume.VolumeCollection)
self.assertIsInstance(actual_volumes, volume.VolumeCollection)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_volumes,
self.storage_pool_inst.allocated_volumes)
self.assertIs(actual_volumes, self.storage_pool_inst.allocated_volumes)
self.conn.get.return_value.json.assert_not_called()
def test_allocated_volumes_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'volume_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_pool_inst.allocated_volumes,
volume.VolumeCollection)
self.assertIsInstance(
self.storage_pool_inst.allocated_volumes, volume.VolumeCollection
)
# On refreshing the storage service instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_pool.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/storage_pool.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_pool_inst.invalidate()
self.storage_pool_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'volume_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_pool_inst.allocated_volumes,
volume.VolumeCollection)
self.assertIsInstance(
self.storage_pool_inst.allocated_volumes, volume.VolumeCollection
)
def test__get_allocated_pools_path(self):
expected = '/redfish/v1/StorageServices/NVMeoE1/StoragePools/'\
'2/AllocatedPools'
expected = (
"/redfish/v1/StorageServices/NVMeoE1/StoragePools/"
"2/AllocatedPools"
)
result = self.storage_pool_inst._get_allocated_pools_path()
self.assertEqual(expected, result)
def test__get_allocated_pools_path_missing_processors_attr(self):
self.storage_pool_inst._json.pop('AllocatedPools')
self.storage_pool_inst._json.pop("AllocatedPools")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute AllocatedPools',
self.storage_pool_inst._get_allocated_pools_path)
exceptions.MissingAttributeError,
"attribute AllocatedPools",
self.storage_pool_inst._get_allocated_pools_path,
)
def test_allocated_pools(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_pool_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"storage_pool_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_storage_pools = self.storage_pool_inst.allocated_pools
# | THEN |
self.assertIsInstance(actual_storage_pools,
storage_pool.StoragePoolCollection)
self.assertIsInstance(
actual_storage_pools, storage_pool.StoragePoolCollection
)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_storage_pools,
self.storage_pool_inst.allocated_pools)
self.assertIs(
actual_storage_pools, self.storage_pool_inst.allocated_pools
)
self.conn.get.return_value.json.assert_not_called()
def test_allocated_pools_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_pool_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"storage_pool_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_pool_inst.allocated_pools,
storage_pool.StoragePoolCollection)
self.assertIsInstance(
self.storage_pool_inst.allocated_pools,
storage_pool.StoragePoolCollection,
)
# On refreshing the storage service instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_pool.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/storage_pool.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_pool_inst.invalidate()
self.storage_pool_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_pool_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"storage_pool_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_pool_inst.allocated_pools,
storage_pool.StoragePoolCollection)
self.assertIsInstance(
self.storage_pool_inst.allocated_pools,
storage_pool.StoragePoolCollection,
)
class StoragePoolCollectionTestCase(testtools.TestCase):
def setUp(self):
super(StoragePoolCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_pool_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"storage_pool_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_pool_col = storage_pool.StoragePoolCollection(
self.conn, '/redfish/v1/StorageServices/NVMeoE1/StoragePools',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/StorageServices/NVMeoE1/StoragePools",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.storage_pool_col.redfish_version)
self.assertEqual('StoragePools Collection',
self.storage_pool_col.name)
self.assertEqual("1.0.2", self.storage_pool_col.redfish_version)
self.assertEqual("StoragePools Collection", self.storage_pool_col.name)
self.assertEqual(
('/redfish/v1/StorageServices/NVMeoE1/StoragePools/1',
'/redfish/v1/StorageServices/NVMeoE1/StoragePools/2'),
self.storage_pool_col.members_identities)
(
"/redfish/v1/StorageServices/NVMeoE1/StoragePools/1",
"/redfish/v1/StorageServices/NVMeoE1/StoragePools/2",
),
self.storage_pool_col.members_identities,
)
@mock.patch.object(storage_pool, 'StoragePool', autospec=True)
@mock.patch.object(storage_pool, "StoragePool", autospec=True)
def test_get_member(self, mock_storage_pool):
self.storage_pool_col.get_member(
'/redfish/v1/StorageServices/NVMeoE1/StoragePools/1')
"/redfish/v1/StorageServices/NVMeoE1/StoragePools/1"
)
mock_storage_pool.assert_called_once_with(
self.storage_pool_col._conn,
'/redfish/v1/StorageServices/NVMeoE1/StoragePools/1',
"/redfish/v1/StorageServices/NVMeoE1/StoragePools/1",
redfish_version=self.storage_pool_col.redfish_version,
registries=None,
)
@mock.patch.object(storage_pool, 'StoragePool', autospec=True)
@mock.patch.object(storage_pool, "StoragePool", autospec=True)
def test_get_members(self, mock_storage_pool):
members = self.storage_pool_col.get_members()
calls = [
mock.call(
self.storage_pool_col._conn,
'/redfish/v1/StorageServices/NVMeoE1/StoragePools/1',
"/redfish/v1/StorageServices/NVMeoE1/StoragePools/1",
redfish_version=self.storage_pool_col.redfish_version,
registries=None,
),
mock.call(
self.storage_pool_col._conn,
'/redfish/v1/StorageServices/NVMeoE1/StoragePools/2',
"/redfish/v1/StorageServices/NVMeoE1/StoragePools/2",
redfish_version=self.storage_pool_col.redfish_version,
registries=None,
)
),
]
mock_storage_pool.assert_has_calls(calls)
self.assertIsInstance(members, list)

View File

@ -27,292 +27,348 @@ from rsd_lib.resources.v2_3.storage_service import volume
class StorageServiceTestCase(testtools.TestCase):
def setUp(self):
super(StorageServiceTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/storage_service.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/storage_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_inst = storage_service.StorageService(
self.conn, '/redfish/v1/StorageServices/NVMeoE1',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/StorageServices/NVMeoE1",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.storage_service_inst.redfish_version)
self.assertEqual('Storage Service description',
self.storage_service_inst.description)
self.assertEqual('NVMeoE1', self.storage_service_inst.identity)
self.assertEqual('Storage Service', self.storage_service_inst.name)
self.assertEqual('Enabled', self.storage_service_inst.status.state)
self.assertEqual('OK', self.storage_service_inst.status.health)
self.assertEqual('OK', self.storage_service_inst.status.health_rollup)
self.assertEqual("1.0.2", self.storage_service_inst.redfish_version)
self.assertEqual(
"Storage Service description",
self.storage_service_inst.description,
)
self.assertEqual("NVMeoE1", self.storage_service_inst.identity)
self.assertEqual("Storage Service", self.storage_service_inst.name)
self.assertEqual("Enabled", self.storage_service_inst.status.state)
self.assertEqual("OK", self.storage_service_inst.status.health)
self.assertEqual("OK", self.storage_service_inst.status.health_rollup)
def test__get_volume_collection_path(self):
expected = '/redfish/v1/StorageServices/1/Volumes'
expected = "/redfish/v1/StorageServices/1/Volumes"
result = self.storage_service_inst._get_volume_collection_path()
self.assertEqual(expected, result)
def test__get_volume_collection_path_missing_processors_attr(self):
self.storage_service_inst._json.pop('Volumes')
self.storage_service_inst._json.pop("Volumes")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Volumes',
self.storage_service_inst._get_volume_collection_path)
exceptions.MissingAttributeError,
"attribute Volumes",
self.storage_service_inst._get_volume_collection_path,
)
def test_volumes(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'volume_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_volumes = self.storage_service_inst.volumes
# | THEN |
self.assertIsInstance(actual_volumes,
volume.VolumeCollection)
self.assertIsInstance(actual_volumes, volume.VolumeCollection)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_volumes,
self.storage_service_inst.volumes)
self.assertIs(actual_volumes, self.storage_service_inst.volumes)
self.conn.get.return_value.json.assert_not_called()
def test_volumes_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'volume_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.volumes,
volume.VolumeCollection)
self.assertIsInstance(
self.storage_service_inst.volumes, volume.VolumeCollection
)
# On refreshing the storage service instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_service.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/storage_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_inst.invalidate()
self.storage_service_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'volume_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.volumes,
volume.VolumeCollection)
self.assertIsInstance(
self.storage_service_inst.volumes, volume.VolumeCollection
)
def test__get_storage_pool_collection_path(self):
expected = '/redfish/v1/StorageServices/1/StoragePools'
expected = "/redfish/v1/StorageServices/1/StoragePools"
result = self.storage_service_inst._get_storage_pool_collection_path()
self.assertEqual(expected, result)
def test__get_storage_pool_collection_path_missing_processors_attr(self):
self.storage_service_inst._json.pop('StoragePools')
self.storage_service_inst._json.pop("StoragePools")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute StoragePools',
self.storage_service_inst._get_storage_pool_collection_path)
exceptions.MissingAttributeError,
"attribute StoragePools",
self.storage_service_inst._get_storage_pool_collection_path,
)
def test_storage_pools(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_pool_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"storage_pool_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_storage_pools = self.storage_service_inst.storage_pools
# | THEN |
self.assertIsInstance(actual_storage_pools,
storage_pool.StoragePoolCollection)
self.assertIsInstance(
actual_storage_pools, storage_pool.StoragePoolCollection
)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_storage_pools,
self.storage_service_inst.storage_pools)
self.assertIs(
actual_storage_pools, self.storage_service_inst.storage_pools
)
self.conn.get.return_value.json.assert_not_called()
def test_storage_pools_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_pool_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"storage_pool_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.storage_pools,
storage_pool.StoragePoolCollection)
self.assertIsInstance(
self.storage_service_inst.storage_pools,
storage_pool.StoragePoolCollection,
)
# On refreshing the storage service instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_service.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/storage_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_inst.invalidate()
self.storage_service_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_pool_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"storage_pool_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.storage_pools,
storage_pool.StoragePoolCollection)
self.assertIsInstance(
self.storage_service_inst.storage_pools,
storage_pool.StoragePoolCollection,
)
def test__get_drive_collection_path(self):
expected = '/redfish/v1/StorageServices/NVMeoE1/Drives'
expected = "/redfish/v1/StorageServices/NVMeoE1/Drives"
result = self.storage_service_inst._get_drive_collection_path()
self.assertEqual(expected, result)
def test__get_drive_collection_path_missing_processors_attr(self):
self.storage_service_inst._json.pop('Drives')
self.storage_service_inst._json.pop("Drives")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Drives',
self.storage_service_inst._get_drive_collection_path)
exceptions.MissingAttributeError,
"attribute Drives",
self.storage_service_inst._get_drive_collection_path,
)
def test_drives(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'drive_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/drive_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_drives = self.storage_service_inst.drives
# | THEN |
self.assertIsInstance(actual_drives,
drive.DriveCollection)
self.assertIsInstance(actual_drives, drive.DriveCollection)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_drives,
self.storage_service_inst.drives)
self.assertIs(actual_drives, self.storage_service_inst.drives)
self.conn.get.return_value.json.assert_not_called()
def test_drives_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'drive_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/drive_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.drives,
drive.DriveCollection)
self.assertIsInstance(
self.storage_service_inst.drives, drive.DriveCollection
)
# On refreshing the storage service instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_service.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/storage_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_inst.invalidate()
self.storage_service_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'drive_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/drive_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.drives,
drive.DriveCollection)
self.assertIsInstance(
self.storage_service_inst.drives, drive.DriveCollection
)
def test__get_endpoint_collection_path(self):
expected = '/redfish/v1/Fabrics/1/Endpoints'
expected = "/redfish/v1/Fabrics/1/Endpoints"
result = self.storage_service_inst._get_endpoint_collection_path()
self.assertEqual(expected, result)
def test__get_endpoint_collection_path_missing_attr(self):
self.storage_service_inst._json.pop('Endpoints')
self.storage_service_inst._json.pop("Endpoints")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Endpoints',
self.storage_service_inst._get_endpoint_collection_path)
exceptions.MissingAttributeError,
"attribute Endpoints",
self.storage_service_inst._get_endpoint_collection_path,
)
def test_endpoints(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'endpoint_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_1/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_endpoints = self.storage_service_inst.endpoints
# | THEN |
self.assertIsInstance(actual_endpoints,
endpoint.EndpointCollection)
self.assertIsInstance(actual_endpoints, endpoint.EndpointCollection)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_endpoints,
self.storage_service_inst.endpoints)
self.assertIs(actual_endpoints, self.storage_service_inst.endpoints)
self.conn.get.return_value.json.assert_not_called()
def test_endpoints_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'endpoint_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_1/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.endpoints,
endpoint.EndpointCollection)
self.assertIsInstance(
self.storage_service_inst.endpoints, endpoint.EndpointCollection
)
# On refreshing the fabric instance...
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'fabric.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_1/fabric.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_inst.invalidate()
self.storage_service_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'endpoint_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_1/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.endpoints,
endpoint.EndpointCollection)
self.assertIsInstance(
self.storage_service_inst.endpoints, endpoint.EndpointCollection
)
class StorageServiceCollectionTestCase(testtools.TestCase):
def setUp(self):
super(StorageServiceCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_service_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"storage_service_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_col = storage_service.StorageServiceCollection(
self.conn, '/redfish/v1/StorageServices', redfish_version='1.0.2')
self.conn, "/redfish/v1/StorageServices", redfish_version="1.0.2"
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.storage_service_col.redfish_version)
self.assertEqual('Storage Services Collection',
self.storage_service_col.name)
self.assertEqual(('/redfish/v1/StorageServices/NVMeoE1',),
self.storage_service_col.members_identities)
self.assertEqual("1.0.2", self.storage_service_col.redfish_version)
self.assertEqual(
"Storage Services Collection", self.storage_service_col.name
)
self.assertEqual(
("/redfish/v1/StorageServices/NVMeoE1",),
self.storage_service_col.members_identities,
)
@mock.patch.object(storage_service, 'StorageService', autospec=True)
@mock.patch.object(storage_service, "StorageService", autospec=True)
def test_get_member(self, mock_storage_service):
self.storage_service_col.get_member(
'/redfish/v1/StorageServices/NVMeoE1')
"/redfish/v1/StorageServices/NVMeoE1"
)
mock_storage_service.assert_called_once_with(
self.storage_service_col._conn,
'/redfish/v1/StorageServices/NVMeoE1',
"/redfish/v1/StorageServices/NVMeoE1",
redfish_version=self.storage_service_col.redfish_version,
registries=None,
)
@mock.patch.object(storage_service, 'StorageService', autospec=True)
@mock.patch.object(storage_service, "StorageService", autospec=True)
def test_get_members(self, mock_storage_service):
members = self.storage_service_col.get_members()
mock_storage_service.assert_called_once_with(
self.storage_service_col._conn,
'/redfish/v1/StorageServices/NVMeoE1',
"/redfish/v1/StorageServices/NVMeoE1",
redfish_version=self.storage_service_col.redfish_version,
registries=None,
)

View File

@ -26,230 +26,275 @@ from rsd_lib.tests.unit.fakes import request_fakes
class StorageServiceTestCase(testtools.TestCase):
def setUp(self):
super(StorageServiceTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/volume.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.volume_inst = volume.Volume(
self.conn, '/redfish/v1/StorageServices/NVMeoE1/Volumes/1',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.volume_inst.redfish_version)
self.assertEqual('Volume description', self.volume_inst.description)
self.assertEqual('1', self.volume_inst.identity)
self.assertEqual('NVMe remote storage', self.volume_inst.name)
self.assertEqual('Enabled', self.volume_inst.status.state)
self.assertEqual('OK', self.volume_inst.status.health)
self.assertEqual('OK', self.volume_inst.status.health_rollup)
self.assertEqual("1.0.2", self.volume_inst.redfish_version)
self.assertEqual("Volume description", self.volume_inst.description)
self.assertEqual("1", self.volume_inst.identity)
self.assertEqual("NVMe remote storage", self.volume_inst.name)
self.assertEqual("Enabled", self.volume_inst.status.state)
self.assertEqual("OK", self.volume_inst.status.health)
self.assertEqual("OK", self.volume_inst.status.health_rollup)
self.assertIsNone(self.volume_inst.model)
self.assertIsNone(self.volume_inst.manufacturer)
self.assertEqual(['Read', 'Write'],
self.volume_inst.access_capabilities)
self.assertEqual(
["Read", "Write"], self.volume_inst.access_capabilities
)
self.assertEqual(3071983104, self.volume_inst.capacity_bytes)
self.assertEqual(3071983104, self.volume_inst.allocated_Bytes)
self.assertEqual(('/redfish/v1/StorageServices/1/StoragePools/2',),
self.volume_inst.capacity_sources[0].providing_pools)
self.assertEqual(3071983104,
self.volume_inst.capacity_sources[0].allocated_Bytes)
self.assertEqual(
'/dev/nvme1n1p1',
self.volume_inst.identifiers[0].durable_name)
("/redfish/v1/StorageServices/1/StoragePools/2",),
self.volume_inst.capacity_sources[0].providing_pools,
)
self.assertEqual(
'SystemPath',
self.volume_inst.identifiers[0].durable_name_format)
3071983104, self.volume_inst.capacity_sources[0].allocated_Bytes
)
self.assertEqual(
'iqn.2001-04.com.example:diskarrays-sn-a8675309',
self.volume_inst.identifiers[1].durable_name)
"/dev/nvme1n1p1", self.volume_inst.identifiers[0].durable_name
)
self.assertEqual(
'iQN',
self.volume_inst.identifiers[1].durable_name_format)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Endpoints/1',),
self.volume_inst.links.endpoints)
"SystemPath", self.volume_inst.identifiers[0].durable_name_format
)
self.assertEqual(
'/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Metrics',
self.volume_inst.links.metrics)
"iqn.2001-04.com.example:diskarrays-sn-a8675309",
self.volume_inst.identifiers[1].durable_name,
)
self.assertEqual(
'SourceElement',
self.volume_inst.replica_infos[0].replica_readonly_access)
self.assertEqual('Snapshot',
self.volume_inst.replica_infos[0].replica_type)
self.assertEqual('Target',
self.volume_inst.replica_infos[0].replica_role)
self.assertEqual('/redfish/v1/StorageServices/NVMeoE1/Volumes/2',
self.volume_inst.replica_infos[0].replica)
"iQN", self.volume_inst.identifiers[1].durable_name_format
)
self.assertEqual(
("/redfish/v1/Fabrics/NVMeoE/Endpoints/1",),
self.volume_inst.links.endpoints,
)
self.assertEqual(
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Metrics",
self.volume_inst.links.metrics,
)
self.assertEqual(
"SourceElement",
self.volume_inst.replica_infos[0].replica_readonly_access,
)
self.assertEqual(
"Snapshot", self.volume_inst.replica_infos[0].replica_type
)
self.assertEqual(
"Target", self.volume_inst.replica_infos[0].replica_role
)
self.assertEqual(
"/redfish/v1/StorageServices/NVMeoE1/Volumes/2",
self.volume_inst.replica_infos[0].replica,
)
self.assertEqual(False, self.volume_inst.bootable)
self.assertIsNone(self.volume_inst.erased)
self.assertEqual(True, self.volume_inst.erase_on_detach)
def test__parse_attributes_missing_actions(self):
self.volume_inst.json.pop('Actions')
self.volume_inst.json.pop("Actions")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Actions',
self.volume_inst.refresh)
exceptions.MissingAttributeError,
"attribute Actions",
self.volume_inst.refresh,
)
def test_update_volume(self):
self.volume_inst.update(bootable=True)
self.volume_inst._conn.patch.assert_called_once_with(
'/redfish/v1/StorageServices/NVMeoE1/Volumes/1',
data={'Oem': {'Intel_RackScale': {"Bootable": True}}})
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1",
data={"Oem": {"Intel_RackScale": {"Bootable": True}}},
)
self.volume_inst._conn.patch.reset_mock()
self.volume_inst.update(erased=False)
self.volume_inst._conn.patch.assert_called_once_with(
'/redfish/v1/StorageServices/NVMeoE1/Volumes/1',
data={'Oem': {'Intel_RackScale': {"Erased": False}}})
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1",
data={"Oem": {"Intel_RackScale": {"Erased": False}}},
)
self.volume_inst._conn.patch.reset_mock()
self.volume_inst.update(bootable=False, erased=True)
self.volume_inst._conn.patch.assert_called_once_with(
'/redfish/v1/StorageServices/NVMeoE1/Volumes/1',
data={'Oem': {'Intel_RackScale': {"Bootable": False,
"Erased": True}}})
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1",
data={
"Oem": {"Intel_RackScale": {"Bootable": False, "Erased": True}}
},
)
def test_update_volume_with_invalid_parameter(self):
with self.assertRaisesRegex(
ValueError,
'At least "bootable" or "erased" parameter has to be specified'):
'At least "bootable" or "erased" parameter has to be specified',
):
self.volume_inst.update()
with self.assertRaisesRegex(
exceptions.InvalidParameterValueError,
'The parameter "bootable" value "fake-value" is invalid'):
self.volume_inst.update(bootable='fake-value')
'The parameter "bootable" value "fake-value" is invalid',
):
self.volume_inst.update(bootable="fake-value")
with self.assertRaisesRegex(
exceptions.InvalidParameterValueError,
'The parameter "erased" value "fake-value" is invalid'):
self.volume_inst.update(bootable=True, erased='fake-value')
'The parameter "erased" value "fake-value" is invalid',
):
self.volume_inst.update(bootable=True, erased="fake-value")
def test__get_initialize_action_element(self):
value = self.volume_inst._get_initialize_action_element()
self.assertEqual("/redfish/v1/StorageServices/NVMeoE1/Volumes/1/"
"Actions/Volume.Initialize",
value.target_uri)
self.assertEqual(
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1/"
"Actions/Volume.Initialize",
value.target_uri,
)
def test_initialize(self):
self.volume_inst.initialize(init_type="Fast")
self.volume_inst._conn.post.assert_called_once_with(
'/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Actions/'
'Volume.Initialize',
data={"InitializeType": "Fast"})
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Actions/"
"Volume.Initialize",
data={"InitializeType": "Fast"},
)
self.volume_inst._conn.post.reset_mock()
self.volume_inst.initialize(init_type="Slow")
self.volume_inst._conn.post.assert_called_once_with(
'/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Actions/'
'Volume.Initialize',
data={"InitializeType": "Slow"})
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Actions/"
"Volume.Initialize",
data={"InitializeType": "Slow"},
)
def test_initialize_with_invalid_parameter(self):
with self.assertRaisesRegex(
exceptions.InvalidParameterValueError,
'The parameter "init_type" value "fake-value" is invalid'
'.*[\'Fast\', \'Slow\']'):
".*['Fast', 'Slow']",
):
self.volume_inst.initialize(init_type="fake-value")
def test_delete(self):
self.volume_inst.delete()
self.volume_inst._conn.delete.assert_called_once_with(
self.volume_inst.path)
self.volume_inst.path
)
def test_get_metrics_path(self):
expected = '/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Metrics'
expected = "/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Metrics"
result = self.volume_inst._get_metrics_path()
self.assertEqual(expected, result)
def test_volume_metrics(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'volume_metrics.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_volume_metrics = self.volume_inst.metrics
# | THEN |
self.assertIsInstance(actual_volume_metrics,
volume_metrics.VolumeMetrics)
self.assertIsInstance(
actual_volume_metrics, volume_metrics.VolumeMetrics
)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_volume_metrics,
self.volume_inst.metrics)
self.assertIs(actual_volume_metrics, self.volume_inst.metrics)
self.conn.get.return_value.json.assert_not_called()
def test_volume_metrics_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'volume_metrics.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.volume_inst.metrics,
volume_metrics.VolumeMetrics)
self.assertIsInstance(
self.volume_inst.metrics, volume_metrics.VolumeMetrics
)
# On refreshing the volume instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'volume.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.volume_inst.invalidate()
self.volume_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'volume.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.volume_inst.metrics,
volume_metrics.VolumeMetrics)
self.assertIsInstance(
self.volume_inst.metrics, volume_metrics.VolumeMetrics
)
class VolumeCollectionTestCase(testtools.TestCase):
def setUp(self):
super(VolumeCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'volume_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.conn.post.return_value = request_fakes.fake_request_post(
None, headers={"Location": "https://localhost:8443/redfish/v1/"
"StorageServices/NVMeoE1/Volumes/2"})
None,
headers={
"Location": "https://localhost:8443/redfish/v1/"
"StorageServices/NVMeoE1/Volumes/2"
},
)
self.volume_col = volume.VolumeCollection(
self.conn, '/redfish/v1/StorageServices/NVMeoE1/Volumes',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/StorageServices/NVMeoE1/Volumes",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.volume_col.redfish_version)
self.assertEqual('Volume Collection',
self.volume_col.name)
self.assertEqual(('/redfish/v1/StorageServices/NVMeoE1/Volumes/1',),
self.volume_col.members_identities)
self.assertEqual("1.0.2", self.volume_col.redfish_version)
self.assertEqual("Volume Collection", self.volume_col.name)
self.assertEqual(
("/redfish/v1/StorageServices/NVMeoE1/Volumes/1",),
self.volume_col.members_identities,
)
@mock.patch.object(volume, 'Volume', autospec=True)
@mock.patch.object(volume, "Volume", autospec=True)
def test_get_member(self, mock_volume):
self.volume_col.get_member(
'/redfish/v1/StorageServices/NVMeoE1/Volumes/1')
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1"
)
mock_volume.assert_called_once_with(
self.volume_col._conn,
'/redfish/v1/StorageServices/NVMeoE1/Volumes/1',
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1",
redfish_version=self.volume_col.redfish_version,
registries=None,
)
@mock.patch.object(volume, 'Volume', autospec=True)
@mock.patch.object(volume, "Volume", autospec=True)
def test_get_members(self, mock_volume):
members = self.volume_col.get_members()
mock_volume.assert_called_once_with(
self.volume_col._conn,
'/redfish/v1/StorageServices/NVMeoE1/Volumes/1',
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1",
redfish_version=self.volume_col.redfish_version,
registries=None,
)
@ -258,17 +303,14 @@ class VolumeCollectionTestCase(testtools.TestCase):
def test_create_volume(self):
reqs = {
"AccessCapabilities": [
"Read",
"Write"
],
"AccessCapabilities": ["Read", "Write"],
"CapacityBytes": 10737418240,
"CapacitySources": [
{
"ProvidingPools": [
{
"@odata.id": "/redfish/v1/StorageServices/1/"
"StoragePools/2"
"StoragePools/2"
}
]
}
@ -278,75 +320,96 @@ class VolumeCollectionTestCase(testtools.TestCase):
"ReplicaType": "Clone",
"Replica": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/1"
}
"Volumes/1"
},
}
],
"Oem": {
"Intel_RackScale": {
"Bootable": True
}
}
"Oem": {"Intel_RackScale": {"Bootable": True}},
}
result = self.volume_col.create_volume(
capacity=10737418240,
access_capabilities=["Read", "Write"],
capacity_sources=[{
"ProvidingPools": [{
"@odata.id": "/redfish/v1/StorageServices/1/StoragePools/2"
}]
}],
replica_infos=[{
"ReplicaType": "Clone",
"Replica": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/1"
}
}],
bootable=True)
capacity_sources=[
{
"ProvidingPools": [
{
"@odata.id": "/redfish/v1/StorageServices/1/"
"StoragePools/2"
}
]
}
],
replica_infos=[
{
"ReplicaType": "Clone",
"Replica": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/1"
},
}
],
bootable=True,
)
self.volume_col._conn.post.assert_called_once_with(
'/redfish/v1/StorageServices/NVMeoE1/Volumes', data=reqs)
self.assertEqual(result,
'/redfish/v1/StorageServices/NVMeoE1/Volumes/2')
"/redfish/v1/StorageServices/NVMeoE1/Volumes", data=reqs
)
self.assertEqual(
result, "/redfish/v1/StorageServices/NVMeoE1/Volumes/2"
)
def test_create_volume_with_invalid_reqs(self):
self.assertRaises(jsonschema.exceptions.ValidationError,
self.volume_col.create_volume,
capacity='invalid_capacity')
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.volume_col.create_volume,
capacity="invalid_capacity",
)
result = self.volume_col.create_volume(capacity=1024)
self.assertEqual(result,
'/redfish/v1/StorageServices/NVMeoE1/Volumes/2')
self.assertEqual(
result, "/redfish/v1/StorageServices/NVMeoE1/Volumes/2"
)
invalid_access_capabilities = ["Write", "invalid"]
self.assertRaises(jsonschema.exceptions.ValidationError,
self.volume_col.create_volume,
capacity=1024,
access_capabilities=invalid_access_capabilities)
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.volume_col.create_volume,
capacity=1024,
access_capabilities=invalid_access_capabilities,
)
invalid_capacity_sources = [{
"ProvidingPools": {
"@odata.id": "/redfish/v1/StorageServices/1/StoragePools/2"
invalid_capacity_sources = [
{
"ProvidingPools": {
"@odata.id": "/redfish/v1/StorageServices/1/StoragePools/2"
}
}
}]
self.assertRaises(jsonschema.exceptions.ValidationError,
self.volume_col.create_volume,
capacity=1024,
capacity_sources=invalid_capacity_sources)
]
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.volume_col.create_volume,
capacity=1024,
capacity_sources=invalid_capacity_sources,
)
invalid_replica_infos = [{
"Invalid": "Clone",
"Replica": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/1"
invalid_replica_infos = [
{
"Invalid": "Clone",
"Replica": {
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/1"
},
}
}]
self.assertRaises(jsonschema.exceptions.ValidationError,
self.volume_col.create_volume,
capacity=1024,
replica_infos=invalid_replica_infos)
]
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.volume_col.create_volume,
capacity=1024,
replica_infos=invalid_replica_infos,
)
self.assertRaises(jsonschema.exceptions.ValidationError,
self.volume_col.create_volume,
capacity=1024,
bootable="True")
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.volume_col.create_volume,
capacity=1024,
bootable="True",
)

View File

@ -21,22 +21,26 @@ from rsd_lib.resources.v2_3.storage_service import volume_metrics
class VolumeMetricsTestCase(testtools.TestCase):
def setUp(self):
super(VolumeMetricsTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/volume_metrics.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/volume_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.volume_metrics_inst = volume_metrics.VolumeMetrics(
self.conn, '/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Metrics',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Metrics",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('Volume Metrics', self.volume_metrics_inst.name)
self.assertEqual('Metrics', self.volume_metrics_inst.identity)
self.assertEqual('Metrics for Volume 1',
self.volume_metrics_inst.description)
self.assertEqual(6799708160,
self.volume_metrics_inst.capacity_used_bytes)
self.assertEqual("Volume Metrics", self.volume_metrics_inst.name)
self.assertEqual("Metrics", self.volume_metrics_inst.identity)
self.assertEqual(
"Metrics for Volume 1", self.volume_metrics_inst.description
)
self.assertEqual(
6799708160, self.volume_metrics_inst.capacity_used_bytes
)

View File

@ -24,128 +24,160 @@ class EthernetInterface(testtools.TestCase):
def setUp(self):
super(EthernetInterface, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'system_ethernet_interface.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"system_ethernet_interface.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.ethernet_interface_inst = ethernet_interface.EthernetInterface(
self.conn,
'/redfish/v1/Managers/1/EthernetInterfaces/1',
redfish_version='1.0.2')
"/redfish/v1/Managers/1/EthernetInterfaces/1",
redfish_version="1.0.2",
)
def test_parse_attributes(self):
self.assertEqual("LAN1", self.ethernet_interface_inst.identity)
self.assertEqual("Ethernet Interface",
self.ethernet_interface_inst.name)
self.assertEqual("System NIC 1",
self.ethernet_interface_inst.description)
self.assertEqual("Enabled",
self.ethernet_interface_inst.status.state)
self.assertEqual(
"Ethernet Interface", self.ethernet_interface_inst.name
)
self.assertEqual(
"System NIC 1", self.ethernet_interface_inst.description
)
self.assertEqual("Enabled", self.ethernet_interface_inst.status.state)
self.assertEqual("OK", self.ethernet_interface_inst.status.health)
self.assertEqual(None,
self.ethernet_interface_inst.status.health_rollup)
self.assertEqual(True,
self.ethernet_interface_inst.interface_enabled)
self.assertEqual("AA:BB:CC:DD:EE:FF",
self.ethernet_interface_inst.permanent_mac_address)
self.assertEqual("AA:BB:CC:DD:EE:FF",
self.ethernet_interface_inst.mac_address)
self.assertEqual(
None, self.ethernet_interface_inst.status.health_rollup
)
self.assertEqual(True, self.ethernet_interface_inst.interface_enabled)
self.assertEqual(
"AA:BB:CC:DD:EE:FF",
self.ethernet_interface_inst.permanent_mac_address,
)
self.assertEqual(
"AA:BB:CC:DD:EE:FF", self.ethernet_interface_inst.mac_address
)
self.assertEqual(100, self.ethernet_interface_inst.speed_mbps)
self.assertEqual(True, self.ethernet_interface_inst.auto_neg)
self.assertEqual(True, self.ethernet_interface_inst.full_duplex)
self.assertEqual(1500, self.ethernet_interface_inst.mtu_size)
self.assertEqual("web483", self.ethernet_interface_inst.host_name)
self.assertEqual("web483.redfishspecification.org",
self.ethernet_interface_inst.fqdn)
self.assertEqual("fe80::3ed9:2bff:fe34:600",
self.ethernet_interface_inst.ipv6_default_gateway)
self.assertEqual(
None, self.ethernet_interface_inst.max_ipv6_static_addresses)
self.assertEqual((['names.redfishspecification.org']),
self.ethernet_interface_inst.name_servers)
"web483.redfishspecification.org",
self.ethernet_interface_inst.fqdn,
)
self.assertEqual(
"fe80::3ed9:2bff:fe34:600",
self.ethernet_interface_inst.ipv6_default_gateway,
)
self.assertEqual(
None, self.ethernet_interface_inst.max_ipv6_static_addresses
)
self.assertEqual(
(["names.redfishspecification.org"]),
self.ethernet_interface_inst.name_servers,
)
self.assertEqual(
"192.168.0.10",
self.ethernet_interface_inst.ipv4_addresses[0].address)
self.ethernet_interface_inst.ipv4_addresses[0].address,
)
self.assertEqual(
"255.255.252.0",
self.ethernet_interface_inst.ipv4_addresses[0].subnet_mask)
self.ethernet_interface_inst.ipv4_addresses[0].subnet_mask,
)
self.assertEqual(
"Static",
self.ethernet_interface_inst.ipv4_addresses[0].address_origin)
self.ethernet_interface_inst.ipv4_addresses[0].address_origin,
)
self.assertEqual(
"192.168.0.1",
self.ethernet_interface_inst.ipv4_addresses[0].gateway)
self.ethernet_interface_inst.ipv4_addresses[0].gateway,
)
self.assertEqual(
"fe80::1ec1:deff:fe6f:1e24",
self.ethernet_interface_inst.ipv6_addresses[0].address)
self.ethernet_interface_inst.ipv6_addresses[0].address,
)
self.assertEqual(
64, self.ethernet_interface_inst.ipv6_addresses[0].prefix_length)
64, self.ethernet_interface_inst.ipv6_addresses[0].prefix_length
)
self.assertEqual(
"Static",
self.ethernet_interface_inst.ipv6_addresses[0].address_origin)
self.ethernet_interface_inst.ipv6_addresses[0].address_origin,
)
self.assertEqual(
"Preferred",
self.ethernet_interface_inst.ipv6_addresses[0].address_state)
self.ethernet_interface_inst.ipv6_addresses[0].address_state,
)
self.assertEqual(None, self.ethernet_interface_inst.vlan)
self.assertEqual([],
self.ethernet_interface_inst.ipv6_static_addresses)
self.assertEqual(None,
self.ethernet_interface_inst.
ipv6_address_policy_table)
self.assertEqual(
[], self.ethernet_interface_inst.ipv6_static_addresses
)
self.assertEqual(
None, self.ethernet_interface_inst.ipv6_address_policy_table
)
self.assertEqual(
"/redfish/v1/EthernetSwitches/1/Ports/1",
self.ethernet_interface_inst.links.oem.intel_rackscale.
neighbor_port)
neighbor_port,
)
# New attributes in RSD 2.3
self.assertEqual(
"UefiDevicePath string",
self.ethernet_interface_inst.uefi_device_path)
self.ethernet_interface_inst.uefi_device_path,
)
self.assertEqual(
["RoCEv2", "iWARP", "iSCSI"],
self.ethernet_interface_inst.oem.intel_rackscale.
supported_protocols)
self.assertEqual(
None, self.ethernet_interface_inst.links.endpoints)
supported_protocols,
)
self.assertEqual(None, self.ethernet_interface_inst.links.endpoints)
class EthernetInterfaceCollectionTestCase(testtools.TestCase):
def setUp(self):
super(EthernetInterfaceCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'system_ethernet_interface_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"system_ethernet_interface_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.ethernet_interface_col = ethernet_interface.\
EthernetInterfaceCollection(
self.conn,
'/redfish/v1/Systems/System1/EthernetInterfaces',
redfish_version='1.0.2')
"/redfish/v1/Systems/System1/EthernetInterfaces",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.ethernet_interface_col.redfish_version)
self.assertEqual("1.0.2", self.ethernet_interface_col.redfish_version)
self.assertEqual(
('/redfish/v1/Systems/System1/EthernetInterfaces/LAN1',),
self.ethernet_interface_col.members_identities)
("/redfish/v1/Systems/System1/EthernetInterfaces/LAN1",),
self.ethernet_interface_col.members_identities,
)
@mock.patch.object(ethernet_interface, 'EthernetInterface', autospec=True)
@mock.patch.object(ethernet_interface, "EthernetInterface", autospec=True)
def test_get_member(self, mock_ethernet_interface):
self.ethernet_interface_col.get_member(
'/redfish/v1/Systems/System1/EthernetInterfaces/LAN1')
"/redfish/v1/Systems/System1/EthernetInterfaces/LAN1"
)
mock_ethernet_interface.assert_called_once_with(
self.ethernet_interface_col._conn,
'/redfish/v1/Systems/System1/EthernetInterfaces/LAN1',
"/redfish/v1/Systems/System1/EthernetInterfaces/LAN1",
redfish_version=self.ethernet_interface_col.redfish_version,
registries=None,
)
@mock.patch.object(ethernet_interface, 'EthernetInterface', autospec=True)
@mock.patch.object(ethernet_interface, "EthernetInterface", autospec=True)
def test_get_members(self, mock_ethernet_interface):
members = self.ethernet_interface_col.get_members()
calls = [
mock.call(
self.ethernet_interface_col._conn,
'/redfish/v1/Systems/System1/EthernetInterfaces/LAN1',
"/redfish/v1/Systems/System1/EthernetInterfaces/LAN1",
redfish_version=self.ethernet_interface_col.redfish_version,
registries=None,
)

View File

@ -23,17 +23,19 @@ from rsd_lib.resources.v2_3.system import system
class SystemTestCase(testtools.TestCase):
def setUp(self):
super(SystemTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/system.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/system.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_inst = system.System(
self.conn, '/redfish/v1/Systems/437XR1138R2',
redfish_version='1.1.0')
self.conn,
"/redfish/v1/Systems/437XR1138R2",
redfish_version="1.1.0",
)
def test_class_inherit(self):
self.assertIsInstance(self.system_inst, system.System)
@ -42,95 +44,113 @@ class SystemTestCase(testtools.TestCase):
def test_ethernet_interfaces(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'system_ethernet_interface_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"system_ethernet_interface_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_ethernet_interface_col = self.system_inst.ethernet_interfaces
# | THEN |
self.assertIsInstance(actual_ethernet_interface_col,
ethernet_interface.EthernetInterfaceCollection)
self.assertIsInstance(
actual_ethernet_interface_col,
ethernet_interface.EthernetInterfaceCollection,
)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_ethernet_interface_col,
self.system_inst.ethernet_interfaces)
self.assertIs(
actual_ethernet_interface_col, self.system_inst.ethernet_interfaces
)
self.conn.get.return_value.json.assert_not_called()
def test_ethernet_interfaces_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'system_ethernet_interface_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"system_ethernet_interface_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection)
self.assertIsInstance(
self.system_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection,
)
# on refreshing the system instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/system.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/system.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_inst.invalidate()
self.system_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'system_ethernet_interface_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/"
"system_ethernet_interface_collection.json",
"r",
) as f:
self.conn.get.return_value.son.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection)
self.assertIsInstance(
self.system_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection,
)
class SystemCollectionTestCase(testtools.TestCase):
def setUp(self):
super(SystemCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'system_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_3/system_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_col = system.SystemCollection(
self.conn, '/redfish/v1/Systems',
redfish_version='1.1.0')
self.conn, "/redfish/v1/Systems", redfish_version="1.1.0"
)
def test__parse_attributes(self):
self.assertEqual('1.1.0', self.system_col.redfish_version)
self.assertEqual(('/redfish/v1/Systems/System1',
'/redfish/v1/Systems/System2'),
self.system_col.members_identities)
self.assertEqual("1.1.0", self.system_col.redfish_version)
self.assertEqual(
("/redfish/v1/Systems/System1", "/redfish/v1/Systems/System2"),
self.system_col.members_identities,
)
@mock.patch.object(system, 'System', autospec=True)
@mock.patch.object(system, "System", autospec=True)
def test_get_member(self, mock_system):
self.system_col.get_member(
'/redfish/v1/Systems/System1')
self.system_col.get_member("/redfish/v1/Systems/System1")
mock_system.assert_called_once_with(
self.system_col._conn,
'/redfish/v1/Systems/System1',
"/redfish/v1/Systems/System1",
redfish_version=self.system_col.redfish_version,
registries=None,
)
@mock.patch.object(system, 'System', autospec=True)
@mock.patch.object(system, "System", autospec=True)
def test_get_members(self, mock_system):
members = self.system_col.get_members()
calls = [
mock.call(
self.system_col._conn,
'/redfish/v1/Systems/System1',
"/redfish/v1/Systems/System1",
redfish_version=self.system_col.redfish_version,
registries=None,
),
mock.call(
self.system_col._conn,
'/redfish/v1/Systems/System2',
"/redfish/v1/Systems/System2",
redfish_version=self.system_col.redfish_version,
registries=None,
)
),
]
mock_system.assert_has_calls(calls)
self.assertIsInstance(members, list)

View File

@ -38,11 +38,10 @@ from rsd_lib.resources.v2_3.system import system as v2_3_system
class RSDLibV2_3TestCase(testtools.TestCase):
def setUp(self):
super(RSDLibV2_3TestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/root.json', 'r') as f:
with open("rsd_lib/tests/unit/json_samples/v2_3/root.json", "r") as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.rsd = v2_3.RSDLibV2_3(self.conn)
@ -53,165 +52,207 @@ class RSDLibV2_3TestCase(testtools.TestCase):
self.assertEqual("/redfish/v1/Nodes", self.rsd._nodes_path)
self.assertEqual("/redfish/v1/Chassis", self.rsd._chassis_path)
self.assertEqual("/redfish/v1/Fabrics", self.rsd._fabrics_path)
self.assertEqual("/redfish/v1/StorageServices",
self.rsd._storage_service_path)
self.assertEqual(
"/redfish/v1/StorageServices", self.rsd._storage_service_path
)
self.assertEqual("/redfish/v1/Managers", self.rsd._managers_path)
self.assertEqual("/redfish/v1/EthernetSwitches",
self.rsd._ethernet_switches_path)
self.assertEqual("/redfish/v1/TelemetryService",
self.rsd._telemetry_service_path)
self.assertEqual("/redfish/v1/TaskService",
self.rsd._task_service_path)
self.assertEqual("/redfish/v1/Registries",
self.rsd._registries_path)
self.assertEqual("/redfish/v1/UpdateService",
self.rsd._update_service_path)
self.assertEqual("/redfish/v1/EventService",
self.rsd._event_service_path)
self.assertEqual(
"/redfish/v1/EthernetSwitches", self.rsd._ethernet_switches_path
)
self.assertEqual(
"/redfish/v1/TelemetryService", self.rsd._telemetry_service_path
)
self.assertEqual(
"/redfish/v1/TaskService", self.rsd._task_service_path
)
self.assertEqual("/redfish/v1/Registries", self.rsd._registries_path)
self.assertEqual(
"/redfish/v1/UpdateService", self.rsd._update_service_path
)
self.assertEqual(
"/redfish/v1/EventService", self.rsd._event_service_path
)
@mock.patch.object(v2_3_system, 'SystemCollection', autospec=True)
@mock.patch.object(v2_3_system, "SystemCollection", autospec=True)
def test_get_system_collection(self, mock_system_collection):
self.rsd.get_system_collection()
mock_system_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Systems',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/Systems",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_system, 'System', autospec=True)
@mock.patch.object(v2_3_system, "System", autospec=True)
def test_get_system(self, mock_system):
self.rsd.get_system('fake-system-id')
self.rsd.get_system("fake-system-id")
mock_system.assert_called_once_with(
self.rsd._conn, 'fake-system-id',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"fake-system-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_node, 'NodeCollection', autospec=True)
@mock.patch.object(v2_3_node, "NodeCollection", autospec=True)
def test_get_node_collection(self, mock_node_collection):
self.rsd.get_node_collection()
mock_node_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Nodes',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/Nodes",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_node, 'Node', autospec=True)
@mock.patch.object(v2_3_node, "Node", autospec=True)
def test_get_node(self, mock_node):
self.rsd.get_node('fake-node-id')
self.rsd.get_node("fake-node-id")
mock_node.assert_called_once_with(
self.rsd._conn, 'fake-node-id',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"fake-node-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_fabric, 'FabricCollection', autospec=True)
@mock.patch.object(v2_3_fabric, "FabricCollection", autospec=True)
def test_get_fabric_collection(self, mock_fabric_collection):
self.rsd.get_fabric_collection()
mock_fabric_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Fabrics',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/Fabrics",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_fabric, 'Fabric', autospec=True)
@mock.patch.object(v2_3_fabric, "Fabric", autospec=True)
def test_get_fabric(self, mock_fabric):
self.rsd.get_fabric('fake-fabric-id')
self.rsd.get_fabric("fake-fabric-id")
mock_fabric.assert_called_once_with(
self.rsd._conn, 'fake-fabric-id',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"fake-fabric-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_chassis, 'ChassisCollection', autospec=True)
@mock.patch.object(v2_3_chassis, "ChassisCollection", autospec=True)
def test_get_chassis_collection(self, mock_chassis_collection):
self.rsd.get_chassis_collection()
mock_chassis_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Chassis',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/Chassis",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_chassis, 'Chassis', autospec=True)
@mock.patch.object(v2_3_chassis, "Chassis", autospec=True)
def test_get_chassis(self, mock_chassis):
self.rsd.get_chassis('fake-chassis-id')
self.rsd.get_chassis("fake-chassis-id")
mock_chassis.assert_called_once_with(
self.rsd._conn, 'fake-chassis-id',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"fake-chassis-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_storage_service, 'StorageServiceCollection',
autospec=True)
def test_get_storage_service_collection(self,
mock_storage_service_collection):
@mock.patch.object(
v2_3_storage_service, "StorageServiceCollection", autospec=True
)
def test_get_storage_service_collection(
self, mock_storage_service_collection
):
self.rsd.get_storage_service_collection()
mock_storage_service_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/StorageServices',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/StorageServices",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_storage_service, 'StorageService', autospec=True)
@mock.patch.object(v2_3_storage_service, "StorageService", autospec=True)
def test_get_storage_service(self, mock_storage_service):
self.rsd.get_storage_service('fake-storage-service-id')
self.rsd.get_storage_service("fake-storage-service-id")
mock_storage_service.assert_called_once_with(
self.rsd._conn, 'fake-storage-service-id',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"fake-storage-service-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_manager, 'ManagerCollection', autospec=True)
@mock.patch.object(v2_3_manager, "ManagerCollection", autospec=True)
def test_get_manager_collection(self, mock_manager_collection):
self.rsd.get_manager_collection()
mock_manager_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Managers',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/Managers",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_manager, 'Manager', autospec=True)
@mock.patch.object(v2_3_manager, "Manager", autospec=True)
def test_get_manager(self, mock_manager_service):
self.rsd.get_manager('fake-manager-id')
self.rsd.get_manager("fake-manager-id")
mock_manager_service.assert_called_once_with(
self.rsd._conn, 'fake-manager-id',
redfish_version=self.rsd.redfish_version
self.rsd._conn,
"fake-manager-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_ethernet_switch,
'EthernetSwitchCollection',
autospec=True)
def test_get_ethernet_switch_collection(self,
mock_ethernet_switch_collection):
self.rsd.get_ethernet_switch_collection()
mock_ethernet_switch_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/EthernetSwitches',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_3_ethernet_switch, 'EthernetSwitch', autospec=True)
def test_get_ethernet_switch(self, mock_ethernet_switch_service):
self.rsd.get_ethernet_switch('fake-ethernet-switch-id')
mock_ethernet_switch_service.assert_called_once_with(
self.rsd._conn, 'fake-ethernet-switch-id',
redfish_version=self.rsd.redfish_version
)
@mock.patch.object(v2_1_task_service, 'TaskService', autospec=True)
def test_get_task_service(
self, mock_task_service):
self.rsd.get_task_service()
mock_task_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/TaskService',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(
v2_1_registries, 'MessageRegistryFileCollection', autospec=True)
v2_3_ethernet_switch, "EthernetSwitchCollection", autospec=True
)
def test_get_ethernet_switch_collection(
self, mock_ethernet_switch_collection
):
self.rsd.get_ethernet_switch_collection()
mock_ethernet_switch_collection.assert_called_once_with(
self.rsd._conn,
"/redfish/v1/EthernetSwitches",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_ethernet_switch, "EthernetSwitch", autospec=True)
def test_get_ethernet_switch(self, mock_ethernet_switch_service):
self.rsd.get_ethernet_switch("fake-ethernet-switch-id")
mock_ethernet_switch_service.assert_called_once_with(
self.rsd._conn,
"fake-ethernet-switch-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_1_task_service, "TaskService", autospec=True)
def test_get_task_service(self, mock_task_service):
self.rsd.get_task_service()
mock_task_service.assert_called_once_with(
self.rsd._conn,
"/redfish/v1/TaskService",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(
v2_1_registries, "MessageRegistryFileCollection", autospec=True
)
def test_get_registries_collection(self, mock_registries_collection):
self.rsd.get_registries_collection()
mock_registries_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Registries',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_registries, 'MessageRegistryFile', autospec=True)
def test_get_registries(self, mock_registries_service):
self.rsd.get_registries('fake-registries-id')
mock_registries_service.assert_called_once_with(
self.rsd._conn, 'fake-registries-id',
redfish_version=self.rsd.redfish_version
self.rsd._conn,
"/redfish/v1/Registries",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_2_update_service, 'UpdateService', autospec=True)
def test_get_update_service(
self, mock_update_service):
@mock.patch.object(v2_1_registries, "MessageRegistryFile", autospec=True)
def test_get_registries(self, mock_registries_service):
self.rsd.get_registries("fake-registries-id")
mock_registries_service.assert_called_once_with(
self.rsd._conn,
"fake-registries-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_2_update_service, "UpdateService", autospec=True)
def test_get_update_service(self, mock_update_service):
self.rsd.get_update_service()
mock_update_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/UpdateService',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/UpdateService",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_1_event_service, 'EventService', autospec=True)
@mock.patch.object(v2_1_event_service, "EventService", autospec=True)
def test_get_event_service(self, mock_event_service):
self.rsd.get_event_service()
mock_event_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/EventService',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/EventService",
redfish_version=self.rsd.redfish_version,
)
# @mock.patch.object(v2_2_telemetry, 'Telemetry', autospec=True)
# def test_get_telemetry_service(self, mock_telemetry_service):
@ -227,16 +268,14 @@ class RSDLibV2_3TestCase(testtools.TestCase):
return_value=v2_3_storage_service.storage_pool.StoragePool,
):
with open(
"rsd_lib/tests/unit/json_samples/v2_3/storage_pool.json",
"r"
"rsd_lib/tests/unit/json_samples/v2_3/storage_pool.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(
f.read()
)
self.assertIsInstance(
self.rsd.get_resource(
"/redfish/v1/TelemetryService"),
v2_3_storage_service.storage_pool.StoragePool
self.rsd.get_resource("/redfish/v1/TelemetryService"),
v2_3_storage_service.storage_pool.StoragePool,
)
def test_get_resource_with_no_class_match(self):

View File

@ -24,131 +24,160 @@ from rsd_lib.tests.unit.fakes import request_fakes
class EndpointTestCase(testtools.TestCase):
def setUp(self):
super(EndpointTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/endpoint.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/endpoint.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.endpoint_inst = endpoint.Endpoint(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.endpoint_inst.redfish_version)
self.assertEqual('Fabric Endpoint',
self.endpoint_inst.description)
self.assertEqual('1', self.endpoint_inst.identity)
self.assertEqual('Fabric Endpoint', self.endpoint_inst.name)
self.assertEqual('Target',
self.endpoint_inst.connected_entities[0].entity_role)
self.assertEqual('/redfish/v1/Chassis/PCIeSwitch1/Drives/Disk.Bay.0',
self.endpoint_inst.connected_entities[0].entity_link)
self.assertEqual("1.0.2", self.endpoint_inst.redfish_version)
self.assertEqual("Fabric Endpoint", self.endpoint_inst.description)
self.assertEqual("1", self.endpoint_inst.identity)
self.assertEqual("Fabric Endpoint", self.endpoint_inst.name)
self.assertEqual(
'Drive', self.endpoint_inst.connected_entities[0].entity_type)
"Target", self.endpoint_inst.connected_entities[0].entity_role
)
self.assertEqual(
'UUID',
self.endpoint_inst.connected_entities[0].identifiers[0].
name_format)
"/redfish/v1/Chassis/PCIeSwitch1/Drives/Disk.Bay.0",
self.endpoint_inst.connected_entities[0].entity_link,
)
self.assertEqual(
'00000000-0000-0000-0000-000000000000',
self.endpoint_inst.connected_entities[0].identifiers[0].name)
self.assertEqual('Enabled', self.endpoint_inst.status.state)
self.assertEqual('OK', self.endpoint_inst.status.health)
self.assertEqual('OK', self.endpoint_inst.status.health_rollup)
"Drive", self.endpoint_inst.connected_entities[0].entity_type
)
self.assertEqual(
'NVMeOverFabrics', self.endpoint_inst.endpoint_protocol)
self.assertEqual('NQN',
self.endpoint_inst.identifiers[0].name_format)
self.assertEqual('nqn.2014-08.org.nvmexpress:NVMf:uuid:'
'397f9b78-7e94-11e7-9ea4-001e67dfa170',
self.endpoint_inst.identifiers[0].name)
self.assertEqual('UUID',
self.endpoint_inst.identifiers[1].name_format)
self.assertEqual('397f9b78-7e94-11e7-9ea4-001e67dfa170',
self.endpoint_inst.identifiers[1].name)
"UUID",
self.endpoint_inst.connected_entities[0]
.identifiers[0]
.name_format,
)
self.assertEqual(
"00000000-0000-0000-0000-000000000000",
self.endpoint_inst.connected_entities[0].identifiers[0].name,
)
self.assertEqual("Enabled", self.endpoint_inst.status.state)
self.assertEqual("OK", self.endpoint_inst.status.health)
self.assertEqual("OK", self.endpoint_inst.status.health_rollup)
self.assertEqual(
"NVMeOverFabrics", self.endpoint_inst.endpoint_protocol
)
self.assertEqual("NQN", self.endpoint_inst.identifiers[0].name_format)
self.assertEqual(
"nqn.2014-08.org.nvmexpress:NVMf:uuid:"
"397f9b78-7e94-11e7-9ea4-001e67dfa170",
self.endpoint_inst.identifiers[0].name,
)
self.assertEqual("UUID", self.endpoint_inst.identifiers[1].name_format)
self.assertEqual(
"397f9b78-7e94-11e7-9ea4-001e67dfa170",
self.endpoint_inst.identifiers[1].name,
)
self.assertEqual(
('/redfish/v1/Fabrics/PCIe/Switches/1/Ports/Down1',),
self.endpoint_inst.links.ports)
("/redfish/v1/Fabrics/PCIe/Switches/1/Ports/Down1",),
self.endpoint_inst.links.ports,
)
self.assertEqual(
('/redfish/v1/Fabrics/PCIe/Endpoints',),
self.endpoint_inst.links.endpoints)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Zones/1',),
self.endpoint_inst.links.oem.intel_rackscale.zones)
("/redfish/v1/Fabrics/PCIe/Endpoints",),
self.endpoint_inst.links.endpoints,
)
self.assertEqual(
('/redfish/v1/Systems/Target/EthernetInterfaces/1',),
self.endpoint_inst.links.oem.intel_rackscale.interfaces)
("/redfish/v1/Fabrics/NVMeoE/Zones/1",),
self.endpoint_inst.links.oem.intel_rackscale.zones,
)
self.assertEqual(
'RoCEv2',
self.endpoint_inst.ip_transport_details[0].transport_protocol)
("/redfish/v1/Systems/Target/EthernetInterfaces/1",),
self.endpoint_inst.links.oem.intel_rackscale.interfaces,
)
self.assertEqual(
'192.168.0.10',
self.endpoint_inst.ip_transport_details[0].ipv4_address)
"RoCEv2",
self.endpoint_inst.ip_transport_details[0].transport_protocol,
)
self.assertEqual(
None, self.endpoint_inst.ip_transport_details[0].ipv6_address)
"192.168.0.10",
self.endpoint_inst.ip_transport_details[0].ipv4_address,
)
self.assertEqual(
None, self.endpoint_inst.ip_transport_details[0].ipv6_address
)
self.assertEqual(1023, self.endpoint_inst.ip_transport_details[0].port)
self.assertEqual(
None, self.endpoint_inst.oem.intel_rackscale.authentication)
None, self.endpoint_inst.oem.intel_rackscale.authentication
)
self.assertEqual(
'FPGA-oF',
self.endpoint_inst.oem.intel_rackscale.endpoint_protocol)
"FPGA-oF", self.endpoint_inst.oem.intel_rackscale.endpoint_protocol
)
class EndpointCollectionTestCase(testtools.TestCase):
def setUp(self):
super(EndpointCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'endpoint_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.conn.post.return_value = request_fakes.fake_request_post(
None, headers={"Location": "https://localhost:8443/redfish/v1/"
"Fabrics/NVMeoE/Endpoints/3"})
None,
headers={
"Location": "https://localhost:8443/redfish/v1/"
"Fabrics/NVMeoE/Endpoints/3"
},
)
self.endpoint_col = endpoint.EndpointCollection(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Endpoints',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/Fabrics/NVMeoE/Endpoints",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.endpoint_col.redfish_version)
self.assertEqual('Endpoint Collection',
self.endpoint_col.name)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
'/redfish/v1/Fabrics/NVMeoE/Endpoints/2'),
self.endpoint_col.members_identities)
self.assertEqual("1.0.2", self.endpoint_col.redfish_version)
self.assertEqual("Endpoint Collection", self.endpoint_col.name)
self.assertEqual(
(
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
"/redfish/v1/Fabrics/NVMeoE/Endpoints/2",
),
self.endpoint_col.members_identities,
)
@mock.patch.object(endpoint, 'Endpoint', autospec=True)
@mock.patch.object(endpoint, "Endpoint", autospec=True)
def test_get_member(self, mock_endpoint):
self.endpoint_col.get_member(
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1')
self.endpoint_col.get_member("/redfish/v1/Fabrics/NVMeoE/Endpoints/1")
mock_endpoint.assert_called_once_with(
self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version=self.endpoint_col.redfish_version,
registries=None,
)
@mock.patch.object(endpoint, 'Endpoint', autospec=True)
@mock.patch.object(endpoint, "Endpoint", autospec=True)
def test_get_members(self, mock_endpoint):
members = self.endpoint_col.get_members()
calls = [
mock.call(
self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1',
"/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version=self.endpoint_col.redfish_version,
registries=None,
),
mock.call(
self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/2',
"/redfish/v1/Fabrics/NVMeoE/Endpoints/2",
redfish_version=self.endpoint_col.redfish_version,
registries=None,
)
),
]
mock_endpoint.assert_has_calls(calls)
self.assertIsInstance(members, list)
@ -158,40 +187,35 @@ class EndpointCollectionTestCase(testtools.TestCase):
reqs = {
"EndpointProtocol": "PCIe",
"ConnectedEntities": [
{
"EntityRole": "Initiator",
"EntityLink": None
}
{"EntityRole": "Initiator", "EntityLink": None}
],
"Links": {
"Ports": [
{
"@odata.id": "/redfish/v1/Fabrics/PCIe/Switches/1/"
"Ports/Up1"
"Ports/Up1"
}
]
}
},
}
result = self.endpoint_col.create_endpoint(
links={
"Ports": [
{
"@odata.id": "/redfish/v1/Fabrics/PCIe/Switches/1/"
"Ports/Up1"
"Ports/Up1"
}
]
},
connected_entities=[
{
"EntityRole": "Initiator",
"EntityLink": None
}
{"EntityRole": "Initiator", "EntityLink": None}
],
protocol="PCIe")
protocol="PCIe",
)
self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs)
self.assertEqual(result,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3')
"/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
)
self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
self.endpoint_col._conn.post.reset_mock()
reqs = {
@ -201,10 +225,10 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityRole": "Target",
"EntityLink": {
"@odata.id": "/redfish/v1/Systems/System1/Processors/"
"FPGA1"
}
"FPGA1"
},
}
]
],
}
result = self.endpoint_col.create_endpoint(
connected_entities=[
@ -212,60 +236,48 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityRole": "Target",
"EntityLink": {
"@odata.id": "/redfish/v1/Systems/System1/Processors/"
"FPGA1"
}
"FPGA1"
},
}
],
protocol="PCIe")
protocol="PCIe",
)
self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs)
self.assertEqual(result,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3')
"/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
)
self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
self.endpoint_col._conn.post.reset_mock()
reqs = {
"EndpointProtocol": "OEM",
"ConnectedEntities": [
{
"EntityRole": "Initiator",
"EntityLink": None
}
{"EntityRole": "Initiator", "EntityLink": None}
],
"Identifiers": [
{
"DurableName": "12345678-90ab-cdef-0000-000000000000",
"DurableNameFormat": "UUID"
"DurableNameFormat": "UUID",
}
],
"Oem": {
"Intel_RackScale": {
"EndpointProtocol": "FPGA-oF"
}
}
"Oem": {"Intel_RackScale": {"EndpointProtocol": "FPGA-oF"}},
}
result = self.endpoint_col.create_endpoint(
connected_entities=[
{
"EntityRole": "Initiator",
"EntityLink": None
}
{"EntityRole": "Initiator", "EntityLink": None}
],
protocol="OEM",
identifiers=[
{
"DurableName": "12345678-90ab-cdef-0000-000000000000",
"DurableNameFormat": "UUID"
"DurableNameFormat": "UUID",
}
],
oem={
"Intel_RackScale": {
"EndpointProtocol": "FPGA-oF"
}
})
oem={"Intel_RackScale": {"EndpointProtocol": "FPGA-oF"}},
)
self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs)
self.assertEqual(result,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3')
"/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
)
self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
self.endpoint_col._conn.post.reset_mock()
reqs = {
@ -274,32 +286,26 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityRole": "Target",
"EntityLink": {
"@odata.id": "/redfish/v1/Systems/System1/Processors/"
"FPGA1"
}
"FPGA1"
},
}
],
"Identifiers": [
{
"DurableName": "123e4567-e89b-12d3-a456-426655440000",
"DurableNameFormat": "UUID"
"DurableNameFormat": "UUID",
}
],
"IPTransportDetails": [
{
"TransportProtocol": "RoCEv2",
"IPv4Address": {
"Address": "192.168.0.10"
},
"IPv4Address": {"Address": "192.168.0.10"},
"IPv6Address": {},
"Port": 4424
"Port": 4424,
}
],
"EndpointProtocol": "OEM",
"Oem": {
"Intel_RackScale": {
"EndpointProtocol": "FPGA-oF"
}
}
"Oem": {"Intel_RackScale": {"EndpointProtocol": "FPGA-oF"}},
}
result = self.endpoint_col.create_endpoint(
connected_entities=[
@ -307,43 +313,38 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityRole": "Target",
"EntityLink": {
"@odata.id": "/redfish/v1/Systems/System1/Processors/"
"FPGA1"
}
"FPGA1"
},
}
],
identifiers=[
{
"DurableName": "123e4567-e89b-12d3-a456-426655440000",
"DurableNameFormat": "UUID"
"DurableNameFormat": "UUID",
}
],
ip_transport_details=[
{
"TransportProtocol": "RoCEv2",
"IPv4Address": {
"Address": "192.168.0.10"
},
"IPv4Address": {"Address": "192.168.0.10"},
"IPv6Address": {},
"Port": 4424
"Port": 4424,
}
],
protocol="OEM",
oem={
"Intel_RackScale": {
"EndpointProtocol": "FPGA-oF"
}
})
oem={"Intel_RackScale": {"EndpointProtocol": "FPGA-oF"}},
)
self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs)
self.assertEqual(result,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3')
"/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
)
self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
def test_create_endpoint_with_invalid_reqs(self):
identifiers = [
{
"DurableNameFormat": "iQN",
"DurableName": "iqn.1986-03.com.intel:my_storage-uuid:"
"397f9b78-7e94-11e7-9ea4-001e67dfa170"
"397f9b78-7e94-11e7-9ea4-001e67dfa170",
}
]
connected_entities = [
@ -353,59 +354,68 @@ class EndpointCollectionTestCase(testtools.TestCase):
},
"EntityRole": "Target",
"Identifiers": [
{
"DurableNameFormat": "LUN",
"DurableName": "1"
}
]
{"DurableNameFormat": "LUN", "DurableName": "1"}
],
}
]
result = self.endpoint_col.create_endpoint(
identifiers=identifiers, connected_entities=connected_entities)
self.assertEqual(result,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3')
identifiers=identifiers, connected_entities=connected_entities
)
self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
# Test invalid identifiers argument
invalid_identifiers = copy.deepcopy(identifiers)
invalid_identifiers[0].pop('DurableNameFormat')
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=invalid_identifiers,
connected_entities=connected_entities)
invalid_identifiers[0].pop("DurableNameFormat")
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=invalid_identifiers,
connected_entities=connected_entities,
)
invalid_identifiers = copy.deepcopy(identifiers)
invalid_identifiers[0].pop('DurableName')
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=invalid_identifiers,
connected_entities=connected_entities)
invalid_identifiers[0].pop("DurableName")
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=invalid_identifiers,
connected_entities=connected_entities,
)
# Test invalid connected_entities argument
invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0]['EntityRole'] = 'fake-format'
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities)
invalid_connected_entities[0]["EntityRole"] = "fake-format"
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0]['EntityLink'].pop('@odata.id')
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities)
invalid_connected_entities[0]["EntityLink"].pop("@odata.id")
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0].pop('EntityRole')
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities)
invalid_connected_entities[0].pop("EntityRole")
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
# Test invalid protocol argument
self.assertRaises(jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=connected_entities,
protocol=1)
self.assertRaises(
jsonschema.exceptions.ValidationError,
self.endpoint_col.create_endpoint,
identifiers=identifiers,
connected_entities=connected_entities,
protocol=1,
)

View File

@ -25,175 +25,190 @@ from rsd_lib.resources.v2_4.fabric import fabric
class FabricTestCase(testtools.TestCase):
def setUp(self):
super(FabricTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/fabric.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/fabric.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst = fabric.Fabric(
self.conn, '/redfish/v1/Fabrics/NVMeoE',
redfish_version='1.0.2')
self.conn, "/redfish/v1/Fabrics/NVMeoE", redfish_version="1.0.2"
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.fabric_inst.redfish_version)
self.assertEqual('NVMeoE', self.fabric_inst.identity)
self.assertEqual("1.0.2", self.fabric_inst.redfish_version)
self.assertEqual("NVMeoE", self.fabric_inst.identity)
self.assertEqual(None, self.fabric_inst.name)
self.assertEqual('NVMeOverFabrics', self.fabric_inst.fabric_type)
self.assertEqual("NVMeOverFabrics", self.fabric_inst.fabric_type)
self.assertEqual(None, self.fabric_inst.max_zones)
self.assertEqual('Enabled', self.fabric_inst.status.state)
self.assertEqual('OK', self.fabric_inst.status.health)
self.assertEqual('OK', self.fabric_inst.status.health_rollup)
self.assertEqual("Enabled", self.fabric_inst.status.state)
self.assertEqual("OK", self.fabric_inst.status.health)
self.assertEqual("OK", self.fabric_inst.status.health_rollup)
def test__get_endpoint_collection_path(self):
expected = '/redfish/v1/Fabrics/NVMeoE/Endpoints'
expected = "/redfish/v1/Fabrics/NVMeoE/Endpoints"
result = self.fabric_inst._get_endpoint_collection_path()
self.assertEqual(expected, result)
def test__get_endpoint_collection_path_missing_attr(self):
self.fabric_inst._json.pop('Endpoints')
self.fabric_inst._json.pop("Endpoints")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Endpoints',
self.fabric_inst._get_endpoint_collection_path)
exceptions.MissingAttributeError,
"attribute Endpoints",
self.fabric_inst._get_endpoint_collection_path,
)
def test_endpoints(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'endpoint_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_endpoints = self.fabric_inst.endpoints
# | THEN |
self.assertIsInstance(actual_endpoints,
endpoint.EndpointCollection)
self.assertIsInstance(actual_endpoints, endpoint.EndpointCollection)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_endpoints,
self.fabric_inst.endpoints)
self.assertIs(actual_endpoints, self.fabric_inst.endpoints)
self.conn.get.return_value.json.assert_not_called()
def test_endpoints_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'endpoint_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.endpoints,
endpoint.EndpointCollection)
self.assertIsInstance(
self.fabric_inst.endpoints, endpoint.EndpointCollection
)
# On refreshing the fabric instance...
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'fabric.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/fabric.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst.invalidate()
self.fabric_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'endpoint_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/endpoint_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.endpoints,
endpoint.EndpointCollection)
self.assertIsInstance(
self.fabric_inst.endpoints, endpoint.EndpointCollection
)
def test__get_zone_collection_path(self):
expected = '/redfish/v1/Fabrics/NVMeoE/Zones'
expected = "/redfish/v1/Fabrics/NVMeoE/Zones"
result = self.fabric_inst._get_zone_collection_path()
self.assertEqual(expected, result)
def test__get_zone_collection_path_missing_attr(self):
self.fabric_inst._json.pop('Zones')
self.fabric_inst._json.pop("Zones")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Zones',
self.fabric_inst._get_zone_collection_path)
exceptions.MissingAttributeError,
"attribute Zones",
self.fabric_inst._get_zone_collection_path,
)
def test_zones(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'zone_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/zone_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_zones = self.fabric_inst.zones
# | THEN |
self.assertIsInstance(actual_zones,
zone.ZoneCollection)
self.assertIsInstance(actual_zones, zone.ZoneCollection)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_zones,
self.fabric_inst.zones)
self.assertIs(actual_zones, self.fabric_inst.zones)
self.conn.get.return_value.json.assert_not_called()
def test_zones_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'zone_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/zone_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.zones,
zone.ZoneCollection)
self.assertIsInstance(self.fabric_inst.zones, zone.ZoneCollection)
# On refreshing the fabric instance...
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'fabric.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/fabric.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst.invalidate()
self.fabric_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'zone_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/zone_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.zones,
zone.ZoneCollection)
self.assertIsInstance(self.fabric_inst.zones, zone.ZoneCollection)
class FabricCollectionTestCase(testtools.TestCase):
def setUp(self):
super(FabricCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'fabric_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/fabric_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_col = fabric.FabricCollection(
self.conn, '/redfish/v1/Fabrics', redfish_version='1.0.2')
self.conn, "/redfish/v1/Fabrics", redfish_version="1.0.2"
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.fabric_col.redfish_version)
self.assertEqual('Fabric Collection',
self.fabric_col.name)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE',),
self.fabric_col.members_identities)
self.assertEqual("1.0.2", self.fabric_col.redfish_version)
self.assertEqual("Fabric Collection", self.fabric_col.name)
self.assertEqual(
("/redfish/v1/Fabrics/NVMeoE",), self.fabric_col.members_identities
)
@mock.patch.object(fabric, 'Fabric', autospec=True)
@mock.patch.object(fabric, "Fabric", autospec=True)
def test_get_member(self, mock_fabric):
self.fabric_col.get_member('/redfish/v1/Fabrics/NVMeoE')
self.fabric_col.get_member("/redfish/v1/Fabrics/NVMeoE")
mock_fabric.assert_called_once_with(
self.fabric_col._conn, '/redfish/v1/Fabrics/NVMeoE',
self.fabric_col._conn,
"/redfish/v1/Fabrics/NVMeoE",
redfish_version=self.fabric_col.redfish_version,
registries=None,
)
@mock.patch.object(fabric, 'Fabric', autospec=True)
@mock.patch.object(fabric, "Fabric", autospec=True)
def test_get_members(self, mock_fabric):
members = self.fabric_col.get_members()
mock_fabric.assert_called_once_with(
self.fabric_col._conn, '/redfish/v1/Fabrics/NVMeoE',
self.fabric_col._conn,
"/redfish/v1/Fabrics/NVMeoE",
redfish_version=self.fabric_col.redfish_version,
registries=None,
)

File diff suppressed because it is too large Load Diff

View File

@ -24,122 +24,143 @@ from rsd_lib.resources.v2_4.storage_service import volume
class StorageServiceTestCase(testtools.TestCase):
def setUp(self):
super(StorageServiceTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/storage_service.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/storage_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_inst = storage_service.StorageService(
self.conn, '/redfish/v1/StorageServices/NVMeoE1',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/StorageServices/NVMeoE1",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.storage_service_inst.redfish_version)
self.assertEqual('Storage Service description',
self.storage_service_inst.description)
self.assertEqual('NVMeoE1', self.storage_service_inst.identity)
self.assertEqual('Storage Service', self.storage_service_inst.name)
self.assertEqual('Enabled', self.storage_service_inst.status.state)
self.assertEqual('OK', self.storage_service_inst.status.health)
self.assertEqual('OK', self.storage_service_inst.status.health_rollup)
self.assertEqual("1.0.2", self.storage_service_inst.redfish_version)
self.assertEqual(
"Storage Service description",
self.storage_service_inst.description,
)
self.assertEqual("NVMeoE1", self.storage_service_inst.identity)
self.assertEqual("Storage Service", self.storage_service_inst.name)
self.assertEqual("Enabled", self.storage_service_inst.status.state)
self.assertEqual("OK", self.storage_service_inst.status.health)
self.assertEqual("OK", self.storage_service_inst.status.health_rollup)
def test__get_volume_collection_path(self):
expected = '/redfish/v1/StorageServices/1/Volumes'
expected = "/redfish/v1/StorageServices/1/Volumes"
result = self.storage_service_inst._get_volume_collection_path()
self.assertEqual(expected, result)
def test__get_volume_collection_path_missing_processors_attr(self):
self.storage_service_inst._json.pop('Volumes')
self.storage_service_inst._json.pop("Volumes")
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Volumes',
self.storage_service_inst._get_volume_collection_path)
exceptions.MissingAttributeError,
"attribute Volumes",
self.storage_service_inst._get_volume_collection_path,
)
def test_volumes(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'volume_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/volume_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_volumes = self.storage_service_inst.volumes
# | THEN |
self.assertIsInstance(actual_volumes,
volume.VolumeCollection)
self.assertIsInstance(actual_volumes, volume.VolumeCollection)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_volumes,
self.storage_service_inst.volumes)
self.assertIs(actual_volumes, self.storage_service_inst.volumes)
self.conn.get.return_value.json.assert_not_called()
def test_volumes_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'volume_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/volume_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.volumes,
volume.VolumeCollection)
self.assertIsInstance(
self.storage_service_inst.volumes, volume.VolumeCollection
)
# On refreshing the storage service instance...
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'storage_service.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/storage_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_inst.invalidate()
self.storage_service_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'volume_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/volume_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.volumes,
volume.VolumeCollection)
self.assertIsInstance(
self.storage_service_inst.volumes, volume.VolumeCollection
)
class StorageServiceCollectionTestCase(testtools.TestCase):
def setUp(self):
super(StorageServiceCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'storage_service_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/"
"storage_service_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_col = storage_service.StorageServiceCollection(
self.conn, '/redfish/v1/StorageServices', redfish_version='1.0.2')
self.conn, "/redfish/v1/StorageServices", redfish_version="1.0.2"
)
def test__parse_attributes(self):
self.assertEqual('1.0.2', self.storage_service_col.redfish_version)
self.assertEqual('Storage Services Collection',
self.storage_service_col.name)
self.assertEqual(('/redfish/v1/StorageServices/NVMeoE1',),
self.storage_service_col.members_identities)
self.assertEqual("1.0.2", self.storage_service_col.redfish_version)
self.assertEqual(
"Storage Services Collection", self.storage_service_col.name
)
self.assertEqual(
("/redfish/v1/StorageServices/NVMeoE1",),
self.storage_service_col.members_identities,
)
@mock.patch.object(storage_service, 'StorageService', autospec=True)
@mock.patch.object(storage_service, "StorageService", autospec=True)
def test_get_member(self, mock_storage_service):
self.storage_service_col.get_member(
'/redfish/v1/StorageServices/NVMeoE1')
"/redfish/v1/StorageServices/NVMeoE1"
)
mock_storage_service.assert_called_once_with(
self.storage_service_col._conn,
'/redfish/v1/StorageServices/NVMeoE1',
"/redfish/v1/StorageServices/NVMeoE1",
redfish_version=self.storage_service_col.redfish_version,
registries=None,
)
@mock.patch.object(storage_service, 'StorageService', autospec=True)
@mock.patch.object(storage_service, "StorageService", autospec=True)
def test_get_members(self, mock_storage_service):
members = self.storage_service_col.get_members()
mock_storage_service.assert_called_once_with(
self.storage_service_col._conn,
'/redfish/v1/StorageServices/NVMeoE1',
"/redfish/v1/StorageServices/NVMeoE1",
redfish_version=self.storage_service_col.redfish_version,
registries=None)
registries=None,
)
self.assertIsInstance(members, list)
self.assertEqual(1, len(members))

View File

@ -23,311 +23,399 @@ from rsd_lib.resources.v2_4.system import processor
class ProcessorTestCase(testtools.TestCase):
def setUp(self):
super(ProcessorTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/processor.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/processor.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.processor_inst = processor.Processor(
self.conn, '/redfish/v1/Systems/System1/Processors/CPU1',
redfish_version='1.1.0')
self.conn,
"/redfish/v1/Systems/System1/Processors/CPU1",
redfish_version="1.1.0",
)
def test__parse_attributes(self):
self.assertEqual('1.1.0', self.processor_inst.redfish_version)
self.assertEqual('CPU1', self.processor_inst.identity)
self.assertEqual('Processor', self.processor_inst.name)
self.assertEqual("1.1.0", self.processor_inst.redfish_version)
self.assertEqual("CPU1", self.processor_inst.identity)
self.assertEqual("Processor", self.processor_inst.name)
self.assertEqual(None, self.processor_inst.description)
self.assertEqual('CPU 1', self.processor_inst.socket)
self.assertEqual('CPU', self.processor_inst.processor_type)
self.assertEqual('x86', self.processor_inst.processor_architecture)
self.assertEqual('x86-64', self.processor_inst.instruction_set)
self.assertEqual('Intel(R) Corporation',
self.processor_inst.manufacturer)
self.assertEqual('Multi-Core Intel(R) Xeon(R) processor 7xxx Series',
self.processor_inst.model)
self.assertEqual("CPU 1", self.processor_inst.socket)
self.assertEqual("CPU", self.processor_inst.processor_type)
self.assertEqual("x86", self.processor_inst.processor_architecture)
self.assertEqual("x86-64", self.processor_inst.instruction_set)
self.assertEqual(
"Intel(R) Corporation", self.processor_inst.manufacturer
)
self.assertEqual(
"Multi-Core Intel(R) Xeon(R) processor 7xxx Series",
self.processor_inst.model,
)
self.assertEqual(3700, self.processor_inst.max_speed_mhz)
self.assertEqual(
'0x42', self.processor_inst.processor_id.effective_family)
"0x42", self.processor_inst.processor_id.effective_family
)
self.assertEqual(
'0x61', self.processor_inst.processor_id.effective_model)
"0x61", self.processor_inst.processor_id.effective_model
)
self.assertEqual(
'0x34AC34DC8901274A',
self.processor_inst.processor_id.identification_registers)
"0x34AC34DC8901274A",
self.processor_inst.processor_id.identification_registers,
)
self.assertEqual(
'0x429943', self.processor_inst.processor_id.microcode_info)
self.assertEqual('0x1', self.processor_inst.processor_id.step)
"0x429943", self.processor_inst.processor_id.microcode_info
)
self.assertEqual("0x1", self.processor_inst.processor_id.step)
self.assertEqual(
'GenuineIntel', self.processor_inst.processor_id.vendor_id)
self.assertEqual('OK', self.processor_inst.status.health)
self.assertEqual('OK', self.processor_inst.status.health_rollup)
self.assertEqual('Enabled', self.processor_inst.status.state)
"GenuineIntel", self.processor_inst.processor_id.vendor_id
)
self.assertEqual("OK", self.processor_inst.status.health)
self.assertEqual("OK", self.processor_inst.status.health_rollup)
self.assertEqual("Enabled", self.processor_inst.status.state)
self.assertEqual(8, self.processor_inst.total_cores)
self.assertEqual(16, self.processor_inst.total_threads)
self.assertEqual('E5', self.processor_inst.oem.intel_rackscale.brand)
self.assertEqual("E5", self.processor_inst.oem.intel_rackscale.brand)
self.assertEqual(
['sse', 'sse2', 'sse3'],
self.processor_inst.oem.intel_rackscale.capabilities)
["sse", "sse2", "sse3"],
self.processor_inst.oem.intel_rackscale.capabilities,
)
self.assertEqual(
'L2Cache',
self.processor_inst.oem.intel_rackscale.on_package_memory[0].
memory_type)
"L2Cache",
self.processor_inst.oem.intel_rackscale.on_package_memory[
0
].memory_type,
)
self.assertEqual(
2,
self.processor_inst.oem.intel_rackscale.on_package_memory[0].
capacity_mb)
self.processor_inst.oem.intel_rackscale.on_package_memory[
0
].capacity_mb,
)
self.assertEqual(
None,
self.processor_inst.oem.intel_rackscale.on_package_memory[0].
speed_mhz)
self.processor_inst.oem.intel_rackscale.on_package_memory[
0
].speed_mhz,
)
self.assertEqual(
'L3Cache',
self.processor_inst.oem.intel_rackscale.on_package_memory[1].
memory_type)
"L3Cache",
self.processor_inst.oem.intel_rackscale.on_package_memory[
1
].memory_type,
)
self.assertEqual(
20,
self.processor_inst.oem.intel_rackscale.on_package_memory[1].
capacity_mb)
self.processor_inst.oem.intel_rackscale.on_package_memory[
1
].capacity_mb,
)
self.assertEqual(
None,
self.processor_inst.oem.intel_rackscale.on_package_memory[1].
speed_mhz)
self.processor_inst.oem.intel_rackscale.on_package_memory[
1
].speed_mhz,
)
self.assertEqual(
160,
self.processor_inst.oem.intel_rackscale.thermal_design_power_watt)
self.processor_inst.oem.intel_rackscale.thermal_design_power_watt,
)
self.assertEqual(
'/redfish/v1/Systems/System1/Processors/CPU1/Metrics',
self.processor_inst.oem.intel_rackscale.metrics)
"/redfish/v1/Systems/System1/Processors/CPU1/Metrics",
self.processor_inst.oem.intel_rackscale.metrics,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_00h)
extended_identification_registers.eax_00h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_01h)
extended_identification_registers.eax_01h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_02h)
extended_identification_registers.eax_02h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_03h)
extended_identification_registers.eax_03h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_04h)
extended_identification_registers.eax_04h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_05h)
extended_identification_registers.eax_05h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_07h)
extended_identification_registers.eax_07h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_80000000h)
extended_identification_registers.eax_80000000h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_80000001h)
extended_identification_registers.eax_80000001h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_80000002h)
extended_identification_registers.eax_80000002h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_80000003h)
extended_identification_registers.eax_80000003h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_80000004h)
extended_identification_registers.eax_80000004h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_80000005h)
extended_identification_registers.eax_80000005h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_80000006h)
extended_identification_registers.eax_80000006h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_80000007h)
extended_identification_registers.eax_80000007h,
)
self.assertEqual(
"0x0429943FFFFFFFFF",
self.processor_inst.oem.intel_rackscale.
extended_identification_registers.eax_80000008h)
extended_identification_registers.eax_80000008h,
)
self.assertEqual(
"/redfish/v1/Chassis/1/PCIeDevices/Devices/1/Functions/1",
self.processor_inst.oem.intel_rackscale.pcie_function)
self.processor_inst.oem.intel_rackscale.pcie_function,
)
self.assertEqual(
'Discrete', self.processor_inst.oem.intel_rackscale.fpga.fpga_type)
"Discrete", self.processor_inst.oem.intel_rackscale.fpga.fpga_type
)
self.assertEqual(
'Stratix10', self.processor_inst.oem.intel_rackscale.fpga.model)
"Stratix10", self.processor_inst.oem.intel_rackscale.fpga.model
)
self.assertEqual(
'0x6400002fc614bb9',
self.processor_inst.oem.intel_rackscale.fpga.fw_id)
"0x6400002fc614bb9",
self.processor_inst.oem.intel_rackscale.fpga.fw_id,
)
self.assertEqual(
'Intel(R) Corporation',
self.processor_inst.oem.intel_rackscale.fpga.fw_manufacturer)
"Intel(R) Corporation",
self.processor_inst.oem.intel_rackscale.fpga.fw_manufacturer,
)
self.assertEqual(
"Blue v.1.00.86",
self.processor_inst.oem.intel_rackscale.fpga.fw_version)
self.processor_inst.oem.intel_rackscale.fpga.fw_version,
)
self.assertEqual(
"8xPCIe-4",
self.processor_inst.oem.intel_rackscale.fpga.host_interface)
self.processor_inst.oem.intel_rackscale.fpga.host_interface,
)
self.assertEqual(
["4x10G"],
self.processor_inst.oem.intel_rackscale.fpga.external_interfaces)
self.processor_inst.oem.intel_rackscale.fpga.external_interfaces,
)
self.assertEqual(
"I2C",
self.processor_inst.oem.intel_rackscale.fpga.sideband_interface)
self.processor_inst.oem.intel_rackscale.fpga.sideband_interface,
)
self.assertEqual(
1,
self.processor_inst.oem.intel_rackscale.fpga.
pcie_virtual_functions)
pcie_virtual_functions,
)
self.assertEqual(
True,
self.processor_inst.oem.intel_rackscale.fpga.
programmable_from_host)
programmable_from_host,
)
self.assertEqual(
1,
self.processor_inst.oem.intel_rackscale.fpga.reconfiguration_slots)
self.processor_inst.oem.intel_rackscale.fpga.reconfiguration_slots,
)
self.assertEqual(
"/redfish/v1/Systems/System1/Processors/FPGA1/Functions",
self.processor_inst.oem.intel_rackscale.fpga.
acceleration_functions)
acceleration_functions,
)
self.assertEqual(
"AFU0",
self.processor_inst.oem.intel_rackscale.fpga.
reconfiguration_slots_details[0].slot_id)
reconfiguration_slots_details[0].slot_id,
)
self.assertEqual(
"00000000-0000-0000-0000-000000000000",
self.processor_inst.oem.intel_rackscale.fpga.
reconfiguration_slots_details[0].uuid)
reconfiguration_slots_details[0].uuid,
)
self.assertEqual(
True,
self.processor_inst.oem.intel_rackscale.fpga.
reconfiguration_slots_details[0].programmable_from_host)
reconfiguration_slots_details[0].programmable_from_host,
)
self.assertEqual(
'/redfish/v1/Chassis/Chassis1', self.processor_inst.links.chassis)
"/redfish/v1/Chassis/Chassis1", self.processor_inst.links.chassis
)
self.assertEqual(
'/redfish/v1/Fabrics/PCIe/Switches/1/Ports/Down1',
self.processor_inst.links.oem.intel_rackscale.connected_port)
"/redfish/v1/Fabrics/PCIe/Switches/1/Ports/Down1",
self.processor_inst.links.oem.intel_rackscale.connected_port,
)
self.assertEqual(
('/redfish/v1/Fabrics/FPGAoF/Endpoints/1',),
self.processor_inst.links.oem.intel_rackscale.endpoints)
("/redfish/v1/Fabrics/FPGAoF/Endpoints/1",),
self.processor_inst.links.oem.intel_rackscale.endpoints,
)
self.assertEqual(
('/redfish/v1/Systems/System1/Processors/1',),
self.processor_inst.links.oem.intel_rackscale.connected_processors)
("/redfish/v1/Systems/System1/Processors/1",),
self.processor_inst.links.oem.intel_rackscale.connected_processors,
)
def test__get_sub_processors_path(self):
self.assertEqual(
'/redfish/v1/Systems/System1/Processors/CPU1/SubProcessors',
self.processor_inst._get_sub_processors_path())
"/redfish/v1/Systems/System1/Processors/CPU1/SubProcessors",
self.processor_inst._get_sub_processors_path(),
)
def test__get_sub_processors_path_missing_attr(self):
self.processor_inst._json.pop('SubProcessors')
with self.assertRaisesRegex(exceptions.MissingAttributeError,
'attribute SubProcessors'):
self.processor_inst._json.pop("SubProcessors")
with self.assertRaisesRegex(
exceptions.MissingAttributeError, "attribute SubProcessors"
):
self.processor_inst._get_sub_processors_path()
def test_sub_processors(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'processor_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/"
"processor_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_processor_col = self.processor_inst.sub_processors
# | THEN |
self.assertIsInstance(actual_processor_col,
processor.ProcessorCollection)
self.assertIsInstance(
actual_processor_col, processor.ProcessorCollection
)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_processor_col,
self.processor_inst.sub_processors)
self.assertIs(actual_processor_col, self.processor_inst.sub_processors)
self.conn.get.return_value.json.assert_not_called()
def test_sub_processors_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'processor_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/"
"processor_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.processor_inst.sub_processors,
processor.ProcessorCollection)
self.assertIsInstance(
self.processor_inst.sub_processors, processor.ProcessorCollection
)
# On refreshing the processor instance...
with open('rsd_lib/tests/unit/json_samples/v2_4/processor.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/processor.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.processor_inst.invalidate()
self.processor_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'processor_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/"
"processor_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.processor_inst.sub_processors,
processor.ProcessorCollection)
self.assertIsInstance(
self.processor_inst.sub_processors, processor.ProcessorCollection
)
class ProcessorCollectionTestCase(testtools.TestCase):
def setUp(self):
super(ProcessorCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'processor_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/"
"processor_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.processor_col = processor.ProcessorCollection(
self.conn, '/redfish/v1/Systems/System1/Processors',
redfish_version='1.1.0')
self.conn,
"/redfish/v1/Systems/System1/Processors",
redfish_version="1.1.0",
)
def test__parse_attributes(self):
self.assertEqual('1.1.0', self.processor_col.redfish_version)
self.assertEqual(('/redfish/v1/Systems/System1/Processors/CPU1',
'/redfish/v1/Systems/System1/Processors/FPGA1'),
self.processor_col.members_identities)
self.assertEqual("1.1.0", self.processor_col.redfish_version)
self.assertEqual(
(
"/redfish/v1/Systems/System1/Processors/CPU1",
"/redfish/v1/Systems/System1/Processors/FPGA1",
),
self.processor_col.members_identities,
)
@mock.patch.object(processor, 'Processor', autospec=True)
@mock.patch.object(processor, "Processor", autospec=True)
def test_get_member(self, mock_system):
self.processor_col.get_member(
'/redfish/v1/Systems/System1/Processors/CPU1')
"/redfish/v1/Systems/System1/Processors/CPU1"
)
mock_system.assert_called_once_with(
self.processor_col._conn,
'/redfish/v1/Systems/System1/Processors/CPU1',
"/redfish/v1/Systems/System1/Processors/CPU1",
redfish_version=self.processor_col.redfish_version,
registries=None,
)
@mock.patch.object(processor, 'Processor', autospec=True)
@mock.patch.object(processor, "Processor", autospec=True)
def test_get_members(self, mock_system):
members = self.processor_col.get_members()
calls = [
mock.call(self.processor_col._conn,
'/redfish/v1/Systems/System1/Processors/CPU1',
redfish_version=self.processor_col.redfish_version,
registries=None),
mock.call(self.processor_col._conn,
'/redfish/v1/Systems/System1/Processors/FPGA1',
redfish_version=self.processor_col.redfish_version,
registries=None)
mock.call(
self.processor_col._conn,
"/redfish/v1/Systems/System1/Processors/CPU1",
redfish_version=self.processor_col.redfish_version,
registries=None,
),
mock.call(
self.processor_col._conn,
"/redfish/v1/Systems/System1/Processors/FPGA1",
redfish_version=self.processor_col.redfish_version,
registries=None,
),
]
mock_system.assert_has_calls(calls)
self.assertIsInstance(members, list)

View File

@ -22,110 +22,121 @@ from rsd_lib.resources.v2_4.system import system
class SystemTestCase(testtools.TestCase):
def setUp(self):
super(SystemTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/system.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/system.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_inst = system.System(
self.conn, '/redfish/v1/Systems/System1',
redfish_version='1.0.2')
self.conn, "/redfish/v1/Systems/System1", redfish_version="1.0.2"
)
def test_processors(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'processor_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/"
"processor_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_processors = self.system_inst.processors
# | THEN |
self.assertIsInstance(actual_processors,
processor.ProcessorCollection)
self.assertIsInstance(actual_processors, processor.ProcessorCollection)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN |
# tests for same object on invoking subsequently
self.assertIs(actual_processors,
self.system_inst.processors)
self.assertIs(actual_processors, self.system_inst.processors)
self.conn.get.return_value.json.assert_not_called()
def test_processors_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'processor_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/"
"processor_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.processors,
processor.ProcessorCollection)
self.assertIsInstance(
self.system_inst.processors, processor.ProcessorCollection
)
# On refreshing the system instance...
with open('rsd_lib/tests/unit/json_samples/v2_4/system.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/system.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_inst.invalidate()
self.system_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'processor_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/"
"processor_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.processors,
processor.ProcessorCollection)
self.assertIsInstance(
self.system_inst.processors, processor.ProcessorCollection
)
class SystemCollectionTestCase(testtools.TestCase):
def setUp(self):
super(SystemCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/'
'system_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_4/system_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_col = system.SystemCollection(
self.conn, '/redfish/v1/Systems',
redfish_version='1.1.0')
self.conn, "/redfish/v1/Systems", redfish_version="1.1.0"
)
def test__parse_attributes(self):
self.assertEqual('1.1.0', self.system_col.redfish_version)
self.assertEqual(('/redfish/v1/Systems/System1',
'/redfish/v1/Systems/System2'),
self.system_col.members_identities)
self.assertEqual("1.1.0", self.system_col.redfish_version)
self.assertEqual(
("/redfish/v1/Systems/System1", "/redfish/v1/Systems/System2"),
self.system_col.members_identities,
)
@mock.patch.object(system, 'System', autospec=True)
@mock.patch.object(system, "System", autospec=True)
def test_get_member(self, mock_system):
self.system_col.get_member(
'/redfish/v1/Systems/System1')
self.system_col.get_member("/redfish/v1/Systems/System1")
mock_system.assert_called_once_with(
self.system_col._conn,
'/redfish/v1/Systems/System1',
"/redfish/v1/Systems/System1",
redfish_version=self.system_col.redfish_version,
registries=None,
)
@mock.patch.object(system, 'System', autospec=True)
@mock.patch.object(system, "System", autospec=True)
def test_get_members(self, mock_system):
members = self.system_col.get_members()
calls = [
mock.call(
self.system_col._conn,
'/redfish/v1/Systems/System1',
"/redfish/v1/Systems/System1",
redfish_version=self.system_col.redfish_version,
registries=None,
),
mock.call(
self.system_col._conn,
'/redfish/v1/Systems/System2',
"/redfish/v1/Systems/System2",
redfish_version=self.system_col.redfish_version,
registries=None,
)
),
]
mock_system.assert_has_calls(calls)
self.assertIsInstance(members, list)

View File

@ -37,11 +37,10 @@ from rsd_lib.resources.v2_4.system import system as v2_4_system
class RSDLibV2_3TestCase(testtools.TestCase):
def setUp(self):
super(RSDLibV2_3TestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/root.json', 'r') as f:
with open("rsd_lib/tests/unit/json_samples/v2_4/root.json", "r") as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.rsd = v2_4.RSDLibV2_4(self.conn)
@ -52,165 +51,207 @@ class RSDLibV2_3TestCase(testtools.TestCase):
self.assertEqual("/redfish/v1/Nodes", self.rsd._nodes_path)
self.assertEqual("/redfish/v1/Chassis", self.rsd._chassis_path)
self.assertEqual("/redfish/v1/Fabrics", self.rsd._fabrics_path)
self.assertEqual("/redfish/v1/StorageServices",
self.rsd._storage_service_path)
self.assertEqual(
"/redfish/v1/StorageServices", self.rsd._storage_service_path
)
self.assertEqual("/redfish/v1/Managers", self.rsd._managers_path)
self.assertEqual("/redfish/v1/EthernetSwitches",
self.rsd._ethernet_switches_path)
self.assertEqual("/redfish/v1/TelemetryService",
self.rsd._telemetry_service_path)
self.assertEqual("/redfish/v1/TaskService",
self.rsd._task_service_path)
self.assertEqual("/redfish/v1/Registries",
self.rsd._registries_path)
self.assertEqual("/redfish/v1/UpdateService",
self.rsd._update_service_path)
self.assertEqual("/redfish/v1/EventService",
self.rsd._event_service_path)
self.assertEqual(
"/redfish/v1/EthernetSwitches", self.rsd._ethernet_switches_path
)
self.assertEqual(
"/redfish/v1/TelemetryService", self.rsd._telemetry_service_path
)
self.assertEqual(
"/redfish/v1/TaskService", self.rsd._task_service_path
)
self.assertEqual("/redfish/v1/Registries", self.rsd._registries_path)
self.assertEqual(
"/redfish/v1/UpdateService", self.rsd._update_service_path
)
self.assertEqual(
"/redfish/v1/EventService", self.rsd._event_service_path
)
@mock.patch.object(v2_4_system, 'SystemCollection', autospec=True)
@mock.patch.object(v2_4_system, "SystemCollection", autospec=True)
def test_get_system_collection(self, mock_system_collection):
self.rsd.get_system_collection()
mock_system_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Systems',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/Systems",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_4_system, 'System', autospec=True)
@mock.patch.object(v2_4_system, "System", autospec=True)
def test_get_system(self, mock_system):
self.rsd.get_system('fake-system-id')
self.rsd.get_system("fake-system-id")
mock_system.assert_called_once_with(
self.rsd._conn, 'fake-system-id',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"fake-system-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_4_node, 'NodeCollection', autospec=True)
@mock.patch.object(v2_4_node, "NodeCollection", autospec=True)
def test_get_node_collection(self, mock_node_collection):
self.rsd.get_node_collection()
mock_node_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Nodes',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/Nodes",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_4_node, 'Node', autospec=True)
@mock.patch.object(v2_4_node, "Node", autospec=True)
def test_get_node(self, mock_node):
self.rsd.get_node('fake-node-id')
self.rsd.get_node("fake-node-id")
mock_node.assert_called_once_with(
self.rsd._conn, 'fake-node-id',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"fake-node-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_4_fabric, 'FabricCollection', autospec=True)
@mock.patch.object(v2_4_fabric, "FabricCollection", autospec=True)
def test_get_fabric_collection(self, mock_fabric_collection):
self.rsd.get_fabric_collection()
mock_fabric_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Fabrics',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/Fabrics",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_4_fabric, 'Fabric', autospec=True)
@mock.patch.object(v2_4_fabric, "Fabric", autospec=True)
def test_get_fabric(self, mock_fabric):
self.rsd.get_fabric('fake-fabric-id')
self.rsd.get_fabric("fake-fabric-id")
mock_fabric.assert_called_once_with(
self.rsd._conn, 'fake-fabric-id',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"fake-fabric-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_chassis, 'ChassisCollection', autospec=True)
@mock.patch.object(v2_3_chassis, "ChassisCollection", autospec=True)
def test_get_chassis_collection(self, mock_chassis_collection):
self.rsd.get_chassis_collection()
mock_chassis_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Chassis',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/Chassis",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_chassis, 'Chassis', autospec=True)
@mock.patch.object(v2_3_chassis, "Chassis", autospec=True)
def test_get_chassis(self, mock_chassis):
self.rsd.get_chassis('fake-chassis-id')
self.rsd.get_chassis("fake-chassis-id")
mock_chassis.assert_called_once_with(
self.rsd._conn, 'fake-chassis-id',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"fake-chassis-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_4_storage_service, 'StorageServiceCollection',
autospec=True)
def test_get_storage_service_collection(self,
mock_storage_service_collection):
@mock.patch.object(
v2_4_storage_service, "StorageServiceCollection", autospec=True
)
def test_get_storage_service_collection(
self, mock_storage_service_collection
):
self.rsd.get_storage_service_collection()
mock_storage_service_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/StorageServices',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/StorageServices",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_4_storage_service, 'StorageService', autospec=True)
@mock.patch.object(v2_4_storage_service, "StorageService", autospec=True)
def test_get_storage_service(self, mock_storage_service):
self.rsd.get_storage_service('fake-storage-service-id')
self.rsd.get_storage_service("fake-storage-service-id")
mock_storage_service.assert_called_once_with(
self.rsd._conn, 'fake-storage-service-id',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"fake-storage-service-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_manager, 'ManagerCollection', autospec=True)
@mock.patch.object(v2_3_manager, "ManagerCollection", autospec=True)
def test_get_manager_collection(self, mock_manager_collection):
self.rsd.get_manager_collection()
mock_manager_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Managers',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/Managers",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_manager, 'Manager', autospec=True)
@mock.patch.object(v2_3_manager, "Manager", autospec=True)
def test_get_manager(self, mock_manager_service):
self.rsd.get_manager('fake-manager-id')
self.rsd.get_manager("fake-manager-id")
mock_manager_service.assert_called_once_with(
self.rsd._conn, 'fake-manager-id',
redfish_version=self.rsd.redfish_version
self.rsd._conn,
"fake-manager-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_ethernet_switch,
'EthernetSwitchCollection',
autospec=True)
def test_get_ethernet_switch_collection(self,
mock_ethernet_switch_collection):
self.rsd.get_ethernet_switch_collection()
mock_ethernet_switch_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/EthernetSwitches',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_3_ethernet_switch, 'EthernetSwitch', autospec=True)
def test_get_ethernet_switch(self, mock_ethernet_switch_service):
self.rsd.get_ethernet_switch('fake-ethernet-switch-id')
mock_ethernet_switch_service.assert_called_once_with(
self.rsd._conn, 'fake-ethernet-switch-id',
redfish_version=self.rsd.redfish_version
)
@mock.patch.object(v2_1_task_service, 'TaskService', autospec=True)
def test_get_task_service(
self, mock_task_service):
self.rsd.get_task_service()
mock_task_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/TaskService',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(
v2_1_registries, 'MessageRegistryFileCollection', autospec=True)
v2_3_ethernet_switch, "EthernetSwitchCollection", autospec=True
)
def test_get_ethernet_switch_collection(
self, mock_ethernet_switch_collection
):
self.rsd.get_ethernet_switch_collection()
mock_ethernet_switch_collection.assert_called_once_with(
self.rsd._conn,
"/redfish/v1/EthernetSwitches",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_ethernet_switch, "EthernetSwitch", autospec=True)
def test_get_ethernet_switch(self, mock_ethernet_switch_service):
self.rsd.get_ethernet_switch("fake-ethernet-switch-id")
mock_ethernet_switch_service.assert_called_once_with(
self.rsd._conn,
"fake-ethernet-switch-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_1_task_service, "TaskService", autospec=True)
def test_get_task_service(self, mock_task_service):
self.rsd.get_task_service()
mock_task_service.assert_called_once_with(
self.rsd._conn,
"/redfish/v1/TaskService",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(
v2_1_registries, "MessageRegistryFileCollection", autospec=True
)
def test_get_registries_collection(self, mock_registries_collection):
self.rsd.get_registries_collection()
mock_registries_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Registries',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_registries, 'MessageRegistryFile', autospec=True)
def test_get_registries(self, mock_registries_service):
self.rsd.get_registries('fake-registries-id')
mock_registries_service.assert_called_once_with(
self.rsd._conn, 'fake-registries-id',
redfish_version=self.rsd.redfish_version
self.rsd._conn,
"/redfish/v1/Registries",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_2_update_service, 'UpdateService', autospec=True)
def test_get_update_service(
self, mock_update_service):
@mock.patch.object(v2_1_registries, "MessageRegistryFile", autospec=True)
def test_get_registries(self, mock_registries_service):
self.rsd.get_registries("fake-registries-id")
mock_registries_service.assert_called_once_with(
self.rsd._conn,
"fake-registries-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_2_update_service, "UpdateService", autospec=True)
def test_get_update_service(self, mock_update_service):
self.rsd.get_update_service()
mock_update_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/UpdateService',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/UpdateService",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_1_event_service, 'EventService', autospec=True)
@mock.patch.object(v2_1_event_service, "EventService", autospec=True)
def test_get_event_service(self, mock_event_service):
self.rsd.get_event_service()
mock_event_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/EventService',
redfish_version=self.rsd.redfish_version)
self.rsd._conn,
"/redfish/v1/EventService",
redfish_version=self.rsd.redfish_version,
)
# @mock.patch.object(v2_2_telemetry, 'Telemetry', autospec=True)
# def test_get_telemetry_service(self, mock_telemetry_service):

View File

@ -27,59 +27,70 @@ from rsd_lib.resources import v2_4
class RSDLibTestCase(testtools.TestCase):
@mock.patch.object(connector, 'Connector', autospec=True)
@mock.patch.object(connector, "Connector", autospec=True)
def setUp(self, mock_connector):
super(RSDLibTestCase, self).setUp()
self.conn = mock.Mock()
mock_connector.return_value = self.conn
with open('rsd_lib/tests/unit/json_samples/v2_1/root.json', 'r') as f:
with open("rsd_lib/tests/unit/json_samples/v2_1/root.json", "r") as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.rsd = main.RSDLib('http://foo.bar:8442', username='foo',
password='bar', verify=True)
self.rsd = main.RSDLib(
"http://foo.bar:8442", username="foo", password="bar", verify=True
)
def test__parse_attributes(self):
self.assertEqual("2.1.0", self.rsd._rsd_api_version)
self.assertEqual("1.0.2", self.rsd._redfish_version)
@mock.patch.object(v2_4, 'RSDLibV2_4', autospec=True)
@mock.patch.object(v2_3, 'RSDLibV2_3', autospec=True)
@mock.patch.object(v2_2, 'RSDLibV2_2', autospec=True)
@mock.patch.object(v2_1, 'RSDLibV2_1', autospec=True)
def test_factory(self, mock_rsdlibv2_1, mock_rsdlibv2_2, mock_rsdlibv2_3,
mock_rsdlibv2_4):
@mock.patch.object(v2_4, "RSDLibV2_4", autospec=True)
@mock.patch.object(v2_3, "RSDLibV2_3", autospec=True)
@mock.patch.object(v2_2, "RSDLibV2_2", autospec=True)
@mock.patch.object(v2_1, "RSDLibV2_1", autospec=True)
def test_factory(
self,
mock_rsdlibv2_1,
mock_rsdlibv2_2,
mock_rsdlibv2_3,
mock_rsdlibv2_4,
):
self.rsd.factory()
mock_rsdlibv2_1.assert_called_once_with(
self.rsd._conn,
self.rsd._root_prefix,
redfish_version=self.rsd._redfish_version)
redfish_version=self.rsd._redfish_version,
)
self.rsd._rsd_api_version = "2.2.0"
self.rsd.factory()
mock_rsdlibv2_2.assert_called_once_with(
self.rsd._conn,
self.rsd._root_prefix,
redfish_version=self.rsd._redfish_version)
redfish_version=self.rsd._redfish_version,
)
self.rsd._rsd_api_version = "2.3.0"
self.rsd.factory()
mock_rsdlibv2_3.assert_called_once_with(
self.rsd._conn,
self.rsd._root_prefix,
redfish_version=self.rsd._redfish_version)
redfish_version=self.rsd._redfish_version,
)
self.rsd._rsd_api_version = "2.4.0"
self.rsd.factory()
mock_rsdlibv2_4.assert_called_once_with(
self.rsd._conn,
self.rsd._root_prefix,
redfish_version=self.rsd._redfish_version)
redfish_version=self.rsd._redfish_version,
)
def test_factory_unsupported_version(self):
self.rsd._rsd_api_version = "10.0.0"
expected_error_message = "The rsd-lib library doesn't support RSD "\
"API version 10.0.0."
expected_error_message = (
"The rsd-lib library doesn't support RSD API version 10.0.0."
)
with self.assertRaisesRegex(NotImplementedError,
expected_error_message):
with self.assertRaisesRegex(
NotImplementedError, expected_error_message
):
self.rsd.factory()

View File

@ -21,21 +21,22 @@ from rsd_lib import utils as rsd_lib_utils
class UtilsTestCase(testtools.TestCase):
def test_get_resource_identity(self):
self.assertIsNone(rsd_lib_utils.get_resource_identity(None))
self.assertIsNone(rsd_lib_utils.get_resource_identity({}))
self.assertEqual(
'/redfish/v1/Systems/437XR1138R2/BIOS',
rsd_lib_utils.get_resource_identity({
"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS"}))
"/redfish/v1/Systems/437XR1138R2/BIOS",
rsd_lib_utils.get_resource_identity(
{"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS"}
),
)
def test_num_or_none(self):
self.assertIsNone(rsd_lib_utils.num_or_none(None))
self.assertEqual(0, rsd_lib_utils.num_or_none('0'))
self.assertEqual(1, rsd_lib_utils.num_or_none('1'))
self.assertEqual(10, rsd_lib_utils.num_or_none('10.0'))
self.assertEqual(12.5, rsd_lib_utils.num_or_none('12.5'))
self.assertEqual(0, rsd_lib_utils.num_or_none("0"))
self.assertEqual(1, rsd_lib_utils.num_or_none("1"))
self.assertEqual(10, rsd_lib_utils.num_or_none("10.0"))
self.assertEqual(12.5, rsd_lib_utils.num_or_none("12.5"))
self.assertEqual(0, rsd_lib_utils.num_or_none(0))
self.assertEqual(1, rsd_lib_utils.num_or_none(1))
self.assertEqual(10, rsd_lib_utils.num_or_none(10.0))
@ -46,7 +47,7 @@ class UtilsTestCase(testtools.TestCase):
"Links": {
"PCIeDevices": [
{"@data.id": "/redfish/v1/Chassis/1/PCIeDevices/Device1"},
{"@data.id": "/redfish/v1/Chassis/1/PCIeDevices/Device2"}
{"@data.id": "/redfish/v1/Chassis/1/PCIeDevices/Device2"},
]
}
}
@ -58,42 +59,51 @@ class UtilsTestCase(testtools.TestCase):
ValueError,
rsd_lib_utils.get_sub_resource_path_list_by,
mock_resource,
None)
self.assertEqual(
sorted([
'/redfish/v1/Chassis/1/PCIeDevices/Device1',
'/redfish/v1/Chassis/1/PCIeDevices/Device2'
]),
sorted(rsd_lib_utils.get_sub_resource_path_list_by(
mock_resource, ["Links", "PCIeDevices"]))
None,
)
mock_resource.json = {'Links': {}}
self.assertEqual(
sorted(
[
"/redfish/v1/Chassis/1/PCIeDevices/Device1",
"/redfish/v1/Chassis/1/PCIeDevices/Device2",
]
),
sorted(
rsd_lib_utils.get_sub_resource_path_list_by(
mock_resource, ["Links", "PCIeDevices"]
)
),
)
mock_resource.json = {"Links": {}}
self.assertRaises(
exceptions.MissingAttributeError,
rsd_lib_utils.get_sub_resource_path_list_by,
mock_resource,
'Links'
"Links",
)
def test_camelcase_to_underscore_joined(self):
input_vs_expected = [
('GarbageCollection', 'garbage_collection'),
('DD', 'dd'),
('rr', 'rr'),
('AABbbC', 'aa_bbb_c'),
('AABbbCCCDd', 'aa_bbb_ccc_dd'),
('Manager', 'manager'),
('EthernetInterfaceCollection', 'ethernet_interface_collection'),
(' ', ' '),
("GarbageCollection", "garbage_collection"),
("DD", "dd"),
("rr", "rr"),
("AABbbC", "aa_bbb_c"),
("AABbbCCCDd", "aa_bbb_ccc_dd"),
("Manager", "manager"),
("EthernetInterfaceCollection", "ethernet_interface_collection"),
(" ", " "),
]
for inp, exp in input_vs_expected:
self.assertEqual(
exp, rsd_lib_utils.camelcase_to_underscore_joined(inp))
exp, rsd_lib_utils.camelcase_to_underscore_joined(inp)
)
def test_camelcase_to_underscore_joined_fails_with_empty_string(self):
self.assertRaisesRegex(
ValueError,
'"camelcase_str" cannot be empty',
rsd_lib_utils.camelcase_to_underscore_joined, '')
rsd_lib_utils.camelcase_to_underscore_joined,
"",
)

View File

@ -20,7 +20,7 @@ def get_resource_identity(resource):
if resource is None:
return None
else:
return resource.get('@odata.id', None)
return resource.get("@odata.id", None)
def num_or_none(x):
@ -62,9 +62,10 @@ def get_sub_resource_path_list_by(resource, subresource_name):
if not body:
raise exceptions.MissingAttributeError(
attribute='/'.join(subresource_name), resource=resource.path)
attribute="/".join(subresource_name), resource=resource.path
)
return [item.get('@data.id') for item in body]
return [item.get("@data.id") for item in body]
# TODO(linyang): Use the same function in sushy utils after sushy 1.8.1
@ -82,9 +83,11 @@ def camelcase_to_underscore_joined(camelcase_str):
for i, letter in enumerate(camelcase_str[1:], 1):
if letter.isupper():
try:
if (camelcase_str[i - 1].islower()
or camelcase_str[i + 1].islower()):
r += '_'
if (
camelcase_str[i - 1].islower()
or camelcase_str[i + 1].islower()
):
r += "_"
except IndexError:
pass