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 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): class StatusField(base.CompositeField):
"""This Field describes the status of a resource and its children.""" """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""" """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""" """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.""" """Indicates the known state of the resource, such as if it is enabled."""

View File

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

View File

@ -26,15 +26,22 @@ from rsd_lib.resources import v2_4
class RSDLib(base.ResourceBase): class RSDLib(base.ResourceBase):
_redfish_version = base.Field(['RedfishVersion'], required=True) _redfish_version = base.Field(["RedfishVersion"], required=True)
"""FabricCollection path""" """FabricCollection path"""
_rsd_api_version = base.Field(['Oem', 'Intel_RackScale', 'ApiVersion'], _rsd_api_version = base.Field(
required=True) ["Oem", "Intel_RackScale", "ApiVersion"], required=True
)
"""RSD API version""" """RSD API version"""
def __init__(self, base_url, username=None, password=None, def __init__(
root_prefix='/redfish/v1/', verify=True): self,
base_url,
username=None,
password=None,
root_prefix="/redfish/v1/",
verify=True,
):
"""A class representing a RootService """A class representing a RootService
:param base_url: The base URL to the Redfish controller. It :param base_url: The base URL to the Redfish controller. It
@ -55,7 +62,8 @@ class RSDLib(base.ResourceBase):
self._root_prefix = root_prefix self._root_prefix = root_prefix
super(RSDLib, self).__init__( super(RSDLib, self).__init__(
connector.Connector(base_url, username, password, verify), connector.Connector(base_url, username, password, verify),
path=self._root_prefix) path=self._root_prefix,
)
def factory(self): def factory(self):
"""Return different resource module according to RSD API Version """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"): 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 # Use the interface of RSD API 2.1.0 to interact with RSD 2.1.0 and
# all previous version. # all previous version.
return v2_1.RSDLibV2_1(self._conn, self._root_prefix, return v2_1.RSDLibV2_1(
redfish_version=self._redfish_version) self._conn,
elif version.StrictVersion("2.2.0") <= rsd_version \ self._root_prefix,
and rsd_version < version.StrictVersion("2.3.0"): 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 # Specific interface for RSD 2.2 version
return v2_2.RSDLibV2_2(self._conn, self._root_prefix, return v2_2.RSDLibV2_2(
redfish_version=self._redfish_version) self._conn,
elif version.StrictVersion("2.3.0") <= rsd_version \ self._root_prefix,
and rsd_version < version.StrictVersion("2.4.0"): 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 # Specific interface for RSD 2.3 version
return v2_3.RSDLibV2_3(self._conn, self._root_prefix, return v2_3.RSDLibV2_3(
redfish_version=self._redfish_version) self._conn,
elif version.StrictVersion("2.4.0") <= rsd_version \ self._root_prefix,
and rsd_version < version.StrictVersion("2.5.0"): 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 # Specific interface for RSD 2.4 version
return v2_4.RSDLibV2_4(self._conn, self._root_prefix, return v2_4.RSDLibV2_4(
redfish_version=self._redfish_version) self._conn,
self._root_prefix,
redfish_version=self._redfish_version,
)
else: else:
raise NotImplementedError( raise NotImplementedError(
"The rsd-lib library doesn't support RSD API " "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 from rsd_lib.resources.v2_1.task import task_service
RESOURCE_CLASS = { RESOURCE_CLASS = {
'Chassis': chassis.Chassis, "Chassis": chassis.Chassis,
'ChassisCollection': chassis.ChassisCollection, "ChassisCollection": chassis.ChassisCollection,
'ComposedNode': node.Node, "ComposedNode": node.Node,
'ComposedNodeCollection': node.NodeCollection, "ComposedNodeCollection": node.NodeCollection,
'ComputerSystem': system.System, "ComputerSystem": system.System,
'ComputerSystemCollection': system.SystemCollection, "ComputerSystemCollection": system.SystemCollection,
'Drive': drive.Drive, "Drive": drive.Drive,
'Endpoint': endpoint.Endpoint, "Endpoint": endpoint.Endpoint,
'EndpointCollection': endpoint.EndpointCollection, "EndpointCollection": endpoint.EndpointCollection,
'EthernetInterface': ethernet_interface.EthernetInterface, "EthernetInterface": ethernet_interface.EthernetInterface,
'EthernetInterfaceCollection': "EthernetInterfaceCollection":
ethernet_interface.EthernetInterfaceCollection, ethernet_interface.EthernetInterfaceCollection,
'EthernetSwitch': ethernet_switch.EthernetSwitch, "EthernetSwitch": ethernet_switch.EthernetSwitch,
'EthernetSwitchACL': ethernet_switch_acl.EthernetSwitchACL, "EthernetSwitchACL": ethernet_switch_acl.EthernetSwitchACL,
'EthernetSwitchACLCollection': "EthernetSwitchACLCollection":
ethernet_switch_acl.EthernetSwitchACLCollection, ethernet_switch_acl.EthernetSwitchACLCollection,
'EthernetSwitchACLRule': ethernet_switch_acl_rule.EthernetSwitchACLRule, "EthernetSwitchACLRule": ethernet_switch_acl_rule.EthernetSwitchACLRule,
'EthernetSwitchACLRuleCollection': "EthernetSwitchACLRuleCollection":
ethernet_switch_acl_rule.EthernetSwitchACLRuleCollection, ethernet_switch_acl_rule.EthernetSwitchACLRuleCollection,
'EthernetSwitchCollection': ethernet_switch.EthernetSwitchCollection, "EthernetSwitchCollection": ethernet_switch.EthernetSwitchCollection,
'EthernetSwitchPort': ethernet_switch_port.EthernetSwitchPort, "EthernetSwitchPort": ethernet_switch_port.EthernetSwitchPort,
'EthernetSwitchPortCollection': "EthernetSwitchPortCollection":
ethernet_switch_port.EthernetSwitchPortCollection, ethernet_switch_port.EthernetSwitchPortCollection,
'EthernetSwitchStaticMAC': "EthernetSwitchStaticMAC":
ethernet_switch_static_mac.EthernetSwitchStaticMAC, ethernet_switch_static_mac.EthernetSwitchStaticMAC,
'EthernetSwitchStaticMACCollection': "EthernetSwitchStaticMACCollection":
ethernet_switch_static_mac.EthernetSwitchStaticMACCollection, ethernet_switch_static_mac.EthernetSwitchStaticMACCollection,
'EventDestination': event_destination.EventDestination, "EventDestination": event_destination.EventDestination,
'EventDestinationCollection': event_destination.EventDestinationCollection, "EventDestinationCollection": event_destination.EventDestinationCollection,
'EventService': event_service.EventService, "EventService": event_service.EventService,
'Fabric': fabric.Fabric, "Fabric": fabric.Fabric,
'FabricCollection': fabric.FabricCollection, "FabricCollection": fabric.FabricCollection,
'LogEntry': log_entry.LogEntry, "LogEntry": log_entry.LogEntry,
'LogEntryCollection': log_entry.LogEntryCollection, "LogEntryCollection": log_entry.LogEntryCollection,
'LogService': log_service.LogService, "LogService": log_service.LogService,
'LogServiceCollection': log_service.LogServiceCollection, "LogServiceCollection": log_service.LogServiceCollection,
'LogicalDrive': logical_drive.LogicalDrive, "LogicalDrive": logical_drive.LogicalDrive,
'LogicalDriveCollection': logical_drive.LogicalDriveCollection, "LogicalDriveCollection": logical_drive.LogicalDriveCollection,
'Manager': manager.Manager, "Manager": manager.Manager,
'ManagerCollection': manager.ManagerCollection, "ManagerCollection": manager.ManagerCollection,
'ManagerNetworkProtocol': manager_network_protocol.ManagerNetworkProtocol, "ManagerNetworkProtocol": manager_network_protocol.ManagerNetworkProtocol,
'Memory': memory.Memory, "Memory": memory.Memory,
'MemoryCollection': memory.MemoryCollection, "MemoryCollection": memory.MemoryCollection,
'MessageRegistryFile': message_registry_file.MessageRegistryFile, "MessageRegistryFile": message_registry_file.MessageRegistryFile,
'MessageRegistryFileCollection': "MessageRegistryFileCollection":
message_registry_file.MessageRegistryFileCollection, message_registry_file.MessageRegistryFileCollection,
'NetworkDeviceFunction': network_device_function.NetworkDeviceFunction, "NetworkDeviceFunction": network_device_function.NetworkDeviceFunction,
'NetworkDeviceFunctionCollection': "NetworkDeviceFunctionCollection":
network_device_function.NetworkDeviceFunctionCollection, network_device_function.NetworkDeviceFunctionCollection,
'NetworkInterface': network_interface.NetworkInterface, "NetworkInterface": network_interface.NetworkInterface,
'NetworkInterfaceCollection': network_interface.NetworkInterfaceCollection, "NetworkInterfaceCollection": network_interface.NetworkInterfaceCollection,
'PCIeDevice': pcie_device.PCIeDevice, "PCIeDevice": pcie_device.PCIeDevice,
'PCIeFunction': pcie_function.PCIeFunction, "PCIeFunction": pcie_function.PCIeFunction,
'PhysicalDrive': physical_drive.PhysicalDrive, "PhysicalDrive": physical_drive.PhysicalDrive,
'PhysicalDriveCollection': physical_drive.PhysicalDriveCollection, "PhysicalDriveCollection": physical_drive.PhysicalDriveCollection,
'Port': port.Port, "Port": port.Port,
'PortCollection': port.PortCollection, "PortCollection": port.PortCollection,
'Power': power.Power, "Power": power.Power,
'PowerZone': power_zone.PowerZone, "PowerZone": power_zone.PowerZone,
'PowerZoneCollection': power_zone.PowerZoneCollection, "PowerZoneCollection": power_zone.PowerZoneCollection,
'Processor': processor.Processor, "Processor": processor.Processor,
'ProcessorCollection': processor.ProcessorCollection, "ProcessorCollection": processor.ProcessorCollection,
'RemoteTarget': remote_target.RemoteTarget, "RemoteTarget": remote_target.RemoteTarget,
'RemoteTargetCollection': "RemoteTargetCollection": remote_target.RemoteTargetCollection,
remote_target.RemoteTargetCollection, "SerialInterface": serial_interface.SerialInterface,
'SerialInterface': serial_interface.SerialInterface, "SerialInterfaceCollection": serial_interface.SerialInterfaceCollection,
'SerialInterfaceCollection': serial_interface.SerialInterfaceCollection, "SimpleStorage": simple_storage.SimpleStorage,
'SimpleStorage': simple_storage.SimpleStorage, "SimpleStorageCollection": simple_storage.SimpleStorageCollection,
'SimpleStorageCollection': simple_storage.SimpleStorageCollection, "Storage": storage.Storage,
'Storage': storage.Storage, "StorageCollection": storage.StorageCollection,
'StorageCollection': storage.StorageCollection, "StorageService": storage_service.StorageService,
'StorageService': storage_service.StorageService, "StorageServiceCollection": storage_service.StorageServiceCollection,
'StorageServiceCollection': storage_service.StorageServiceCollection, "Switch": switch.Switch,
'Switch': switch.Switch, "SwitchCollection": switch.SwitchCollection,
'SwitchCollection': switch.SwitchCollection, "Task": task.Task,
'Task': task.Task, "TaskCollection": task.TaskCollection,
'TaskCollection': task.TaskCollection, "TaskService": task_service.TaskService,
'TaskService': task_service.TaskService, "Thermal": thermal.Thermal,
'Thermal': thermal.Thermal, "ThermalZone": thermal_zone.ThermalZone,
'ThermalZone': thermal_zone.ThermalZone, "ThermalZoneCollection": thermal_zone.ThermalZoneCollection,
'ThermalZoneCollection': "VLanNetworkInterface": vlan_network_interface.VLanNetworkInterface,
thermal_zone.ThermalZoneCollection, "VLanNetworkInterfaceCollection":
'VLanNetworkInterface':
vlan_network_interface.VLanNetworkInterface,
'VLanNetworkInterfaceCollection':
vlan_network_interface.VLanNetworkInterfaceCollection, vlan_network_interface.VLanNetworkInterfaceCollection,
'VirtualMedia': virtual_media.VirtualMedia, "VirtualMedia": virtual_media.VirtualMedia,
'VirtualMediaCollection': virtual_media.VirtualMediaCollection, "VirtualMediaCollection": virtual_media.VirtualMediaCollection,
'Volume': volume.Volume, "Volume": volume.Volume,
'VolumeCollection': volume.VolumeCollection, "VolumeCollection": volume.VolumeCollection,
'Zone': zone.Zone, "Zone": zone.Zone,
'ZoneCollection': zone.ZoneCollection "ZoneCollection": zone.ZoneCollection,
} }

View File

@ -26,80 +26,88 @@ LOG = logging.getLogger(__name__)
class ClassToPriorityMappingField(base.ListField): 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( traffic_class = base.Field(
'TrafficClass', adapter=rsd_lib_utils.num_or_none) "TrafficClass", adapter=rsd_lib_utils.num_or_none
)
class PriorityFlowControlField(base.CompositeField): 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): 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( traffic_class = base.Field(
'TrafficClass', adapter=rsd_lib_utils.num_or_none) "TrafficClass", adapter=rsd_lib_utils.num_or_none
)
class TrafficClassficationField(base.ListField): 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( traffic_class = base.Field(
'TrafficClass', adapter=rsd_lib_utils.num_or_none) "TrafficClass", adapter=rsd_lib_utils.num_or_none
)
class TransmissionSelectionField(base.ListField): class TransmissionSelectionField(base.ListField):
bandwidth_percent = base.Field( bandwidth_percent = base.Field(
'BandwidthPercent', adapter=rsd_lib_utils.num_or_none) "BandwidthPercent", adapter=rsd_lib_utils.num_or_none
)
traffic_class = base.Field( 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 EthernetSwitch(v2_2_ethernet_switch.EthernetSwitch):
class_to_priority_mapping = ClassToPriorityMappingField( class_to_priority_mapping = ClassToPriorityMappingField(
'ClassToPriorityMapping') "ClassToPriorityMapping"
)
"""The ethernet switch class to priority mapping""" """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""" """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""" """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""" """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""" """The ethernet switch max acl number"""
metrics = base.Field('Metrics', default=(), metrics = base.Field(
adapter=rsd_lib_utils.get_resource_identity) "Metrics", default=(), adapter=rsd_lib_utils.get_resource_identity
)
"""The ethernet switch metrics""" """The ethernet switch metrics"""
priority_flow_control = PriorityFlowControlField('PriorityFlowControl') priority_flow_control = PriorityFlowControlField("PriorityFlowControl")
"""The ethernet switch priority flow control""" """The ethernet switch priority flow control"""
priority_to_class_mapping = PriorityToClassMappingField( priority_to_class_mapping = PriorityToClassMappingField(
'PriorityToClassMapping') "PriorityToClassMapping"
)
"""The ethernet switch priority to class mapping""" """The ethernet switch priority to class mapping"""
traffic_classification = TrafficClassficationField('TrafficClassification') traffic_classification = TrafficClassficationField("TrafficClassification")
"""The ethernet switch traffic classification""" """The ethernet switch traffic classification"""
transmission_selection = TransmissionSelectionField( transmission_selection = TransmissionSelectionField(
'TransmissionSelection') "TransmissionSelection"
)
"""The ethernet switch transmission selection""" """The ethernet switch transmission selection"""
class EthernetSwitchCollection(rsd_lib_base.ResourceCollectionBase): class EthernetSwitchCollection(rsd_lib_base.ResourceCollectionBase):
@property @property
def _resource_type(self): def _resource_type(self):
return EthernetSwitch return EthernetSwitch

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -19,63 +19,65 @@ from rsd_lib import utils as rsd_lib_utils
class LifeTimeField(base.CompositeField): class LifeTimeField(base.CompositeField):
unit_size_bytes = base.Field('UnitSizeBytes', unit_size_bytes = base.Field(
adapter=rsd_lib_utils.num_or_none) "UnitSizeBytes", adapter=rsd_lib_utils.num_or_none
)
"""The size of a unit in bytes used by UnitsRead and UnitsWritten""" """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 """ """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""" """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""" """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""" """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""" """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""" """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""" """The amount of time in minutes the driver controller is busy"""
class HealthDataField(base.CompositeField): class HealthDataField(base.CompositeField):
available_spare_percentage = base.Field('AvailableSparePercentage') available_spare_percentage = base.Field("AvailableSparePercentage")
"""The percentage of the remaining spare capacity available""" """The percentage of the remaining spare capacity available"""
predicted_media_life_used_percent = base.Field( predicted_media_life_used_percent = base.Field(
'PredictedMediaLifeUsedPercent') "PredictedMediaLifeUsedPercent"
)
"""The percentage of life remaining in the driver's media""" """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""" """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""" """The number of media and data integrity errors of this drive"""
class DriveMetrics(rsd_lib_base.ResourceBase): class DriveMetrics(rsd_lib_base.ResourceBase):
name = base.Field('Name') name = base.Field("Name")
"""Drive metrics name""" """Drive metrics name"""
identity = base.Field('Id') identity = base.Field("Id")
"""Drive metrics id""" """Drive metrics id"""
description = base.Field('Description') description = base.Field("Description")
"""Drive metrics description""" """Drive metrics description"""
life_time = LifeTimeField('LifeTime') life_time = LifeTimeField("LifeTime")
"""The life time metrics for this drive""" """The life time metrics for this drive"""
health_data = HealthDataField('HealthData') health_data = HealthDataField("HealthData")
"""The health data metrics for this drive""" """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""" """The temperature in Kelvin degrees of this drive"""

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,235 +14,267 @@
# under the License. # under the License.
processor_req_schema = { processor_req_schema = {
'type': 'array', "type": "array",
'items': [{ "items": [
'type': 'object', {
'properties': { "type": "object",
'@odata.type': {'type': 'string'}, "properties": {
'Model': {'type': 'string'}, "@odata.type": {"type": "string"},
'TotalCores': {'type': 'number'}, "Model": {"type": "string"},
'AchievableSpeedMHz': {'type': 'number'}, "TotalCores": {"type": "number"},
'InstructionSet': { "AchievableSpeedMHz": {"type": "number"},
'type': 'string', "InstructionSet": {
'enum': ['x86', 'x86-64', 'IA-64', 'ARM-A32', "type": "string",
'ARM-A64', 'MIPS32', 'MIPS64', 'OEM'] "enum": [
}, "x86",
'Oem': { "x86-64",
'type': 'object', "IA-64",
'properties': { "ARM-A32",
'Intel_RackScale': { "ARM-A64",
'type': 'object', "MIPS32",
'properties': { "MIPS64",
'Brand': { "OEM",
'type': 'string', ],
'enum': ['E3', 'E5', 'E7', 'X3', 'X5', 'X7', },
'I3', 'I5', 'I7', 'Silver', 'Gold', "Oem": {
'Platinum', 'Unknown'] "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': { "additionalProperties": False,
'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,
}]
} }
memory_req_schema = { memory_req_schema = {
'type': 'array', "type": "array",
'items': [{ "items": [
'type': 'object', {
'properties': { "type": "object",
'@odata.type': {'type': 'string'}, "properties": {
'CapacityMiB': {'type': 'number'}, "@odata.type": {"type": "string"},
'MemoryType': { "CapacityMiB": {"type": "number"},
'type': 'string', "MemoryType": {
'enum': ['DRAM', 'NVDIMM_N', 'NVDIMM_F', 'NVMDIMM_P', "type": "string",
'IntelOptane'] "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': { "additionalProperties": False,
'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,
}]
} }
remote_drive_req_schema = { remote_drive_req_schema = {
'type': 'array', "type": "array",
'items': [{ "items": [
'type': 'object', {
'properties': { "type": "object",
'@odata.type': {'type': 'string'}, "properties": {
'CapacityGiB': {'type': 'number'}, "@odata.type": {"type": "string"},
'Protocol': { "CapacityGiB": {"type": "number"},
'type': 'string', "Protocol": {
'enum': ['iSCSI', 'NVMeOverFabrics'] "type": "string",
}, "enum": ["iSCSI", "NVMeOverFabrics"],
'Master': { },
'type': 'object', "Master": {
'properties': { "type": "object",
'Type': { "properties": {
'type': 'string', "Type": {
'enum': ['Snapshot', 'Clone'] "type": "string",
"enum": ["Snapshot", "Clone"],
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
}, },
'Resource': { },
'type': 'object', "Resource": {
'properties': { "type": "object",
'@odata.id': {'type': 'string'} "properties": {"@odata.id": {"type": "string"}},
} },
}
}
}, },
'Resource': { "additionalProperties": False,
'type': 'object', }
'properties': { ],
'@odata.id': {'type': 'string'}
}
}
},
'additionalProperties': False,
}]
} }
local_drive_req_schema = { local_drive_req_schema = {
'type': 'array', "type": "array",
'items': [{ "items": [
'type': 'object', {
'properties': { "type": "object",
'@odata.type': {'type': 'string'}, "properties": {
'CapacityGiB': {'type': 'number'}, "@odata.type": {"type": "string"},
'Type': { "CapacityGiB": {"type": "number"},
'type': 'string', "Type": {"type": "string", "enum": ["HDD", "SSD"]},
'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'}, "additionalProperties": False,
'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,
}]
} }
ethernet_interface_req_schema = { ethernet_interface_req_schema = {
'type': 'array', "type": "array",
'items': [{ "items": [
'type': 'object', {
'properties': { "type": "object",
'@odata.type': {'type': 'string'}, "properties": {
'SpeedMbps': {'type': 'number'}, "@odata.type": {"type": "string"},
'PrimaryVLAN': {'type': 'number'}, "SpeedMbps": {"type": "number"},
'VLANs': { "PrimaryVLAN": {"type": "number"},
'type': 'array', "VLANs": {
'additionalItems': { "type": "array",
'type': 'object', "additionalItems": {
'properties': { "type": "object",
'VLANId': {'type': 'number'}, "properties": {
'Tagged': {'type': 'boolean'} "VLANId": {"type": "number"},
} "Tagged": {"type": "boolean"},
} },
},
},
"Resource": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
"Chassis": {
"type": "object",
"properties": {"@odata.id": {"type": "string"}},
},
}, },
'Resource': { "additionalProperties": False,
'type': 'object', }
'properties': { ],
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
},
'additionalProperties': False,
}]
} }
security_req_schema = { security_req_schema = {
'type': 'object', "type": "object",
'properties': { "properties": {
'@odata.type': {'type': 'string'}, "@odata.type": {"type": "string"},
'TpmPresent': {'type': 'boolean'}, "TpmPresent": {"type": "boolean"},
'TpmInterfaceType': {'type': 'string'}, "TpmInterfaceType": {"type": "string"},
'TxtEnabled': {'type': 'boolean'}, "TxtEnabled": {"type": "boolean"},
'ClearTPMOnDelete': {'type': 'boolean'}, "ClearTPMOnDelete": {"type": "boolean"},
'PersistentMemoryOperationOnDelete': { "PersistentMemoryOperationOnDelete": {
'type': 'string', "type": "string",
'enum': ['PreserveConfiguration', 'SecureErase', 'OverwritePCD'] "enum": ["PreserveConfiguration", "SecureErase", "OverwritePCD"],
} },
}, },
'additionalProperties': False, "additionalProperties": False,
} }
total_system_core_req_schema = { total_system_core_req_schema = {"type": "number"}
'type': 'number'
}
total_system_memory_req_schema = { total_system_memory_req_schema = {"type": "number"}
'type': 'number'
}

View File

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

View File

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

View File

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

View File

@ -15,7 +15,6 @@
def fake_request_get(json_data): def fake_request_get(json_data):
class MockResponse(object): class MockResponse(object):
def __init__(self, json_data): def __init__(self, json_data):
self.json_data = 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): def fake_request_post(json_data, headers=None):
class MockResponse(object): class MockResponse(object):
def __init__(self, json_data, headers): def __init__(self, json_data, headers):
self.json_data = json_data self.json_data = json_data

View File

@ -359,7 +359,7 @@ class TestChassisCollection(base.TestCase):
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(PowerZoneTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(ThermalTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(ThermalZoneTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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... # On refreshing the port instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -166,7 +166,7 @@ class EthernetSwtichTestCase(testtools.TestCase):
# On refreshing... # On refreshing...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -146,7 +146,7 @@ class EthernetSwitchACLTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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... # On refreshing the acl_rule instance...
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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): def test__parse_attributes(self):
self.assertEqual("1.0.2", self.acl_rule_col.redfish_version) self.assertEqual("1.0.2", self.acl_rule_col.redfish_version)
self.assertEqual( self.assertEqual(
"Ethernet Switch Access Control " "List Rules Collection", "Ethernet Switch Access Control List Rules Collection",
self.acl_rule_col.name, self.acl_rule_col.name,
) )
self.assertEqual( self.assertEqual(
("/redfish/v1/EthernetSwitches/Switch1/ACLs/ACL1/" "Rules/Rule1",), ("/redfish/v1/EthernetSwitches/Switch1/ACLs/ACL1/Rules/Rule1",),
self.acl_rule_col.members_identities, self.acl_rule_col.members_identities,
) )
@ -313,7 +313,7 @@ class EthernetSwitchACLRuleCollectionTestCase(testtools.TestCase):
) )
self.assertEqual( self.assertEqual(
result, 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): def test_add_acl_rule_invalid_reqs(self):

View File

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

View File

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

View File

@ -99,7 +99,7 @@ class EventServiceTestCase(testtools.TestCase):
# On refreshing the event_service instance... # On refreshing the event_service instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(EndpointCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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/NVMeDrivePF1",
"/redfish/v1/Fabrics/PCIe/Endpoints/NVMeDrivePF2", "/redfish/v1/Fabrics/PCIe/Endpoints/NVMeDrivePF2",
"/redfish/v1/Fabrics/PCIe/" "Endpoints/HostRootComplex1", "/redfish/v1/Fabrics/PCIe/Endpoints/HostRootComplex1",
), ),
self.endpoint_col.members_identities, self.endpoint_col.members_identities,
) )
@ -126,7 +126,7 @@ class EndpointCollectionTestCase(testtools.TestCase):
members = self.endpoint_col.get_members() members = self.endpoint_col.get_members()
mock_endpoint.assert_called_with( mock_endpoint.assert_called_with(
self.endpoint_col._conn, self.endpoint_col._conn,
"/redfish/v1/Fabrics/PCIe/Endpoints" "/HostRootComplex1", "/redfish/v1/Fabrics/PCIe/Endpoints/HostRootComplex1",
redfish_version=self.endpoint_col.redfish_version, redfish_version=self.endpoint_col.redfish_version,
registries=None, registries=None,
) )

View File

@ -51,7 +51,7 @@ class FabricTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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): def test_endpoints_on_refresh(self):
# | GIVEN | # | GIVEN |
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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... # On refreshing the fabric instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -91,7 +91,7 @@ class FabricTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -103,7 +103,7 @@ class FabricTestCase(testtools.TestCase):
def test_switches(self): def test_switches(self):
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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): def test_switches_on_refresh(self):
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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 self.fabric_inst.switches, switch.SwitchCollection
) )
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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) self.fabric_inst.refresh(force=False)
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -144,7 +144,7 @@ class FabricTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
@ -163,7 +163,7 @@ class FabricTestCase(testtools.TestCase):
def test_zones_on_refresh(self): def test_zones_on_refresh(self):
# | GIVEN | # | GIVEN |
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
@ -171,7 +171,7 @@ class FabricTestCase(testtools.TestCase):
# On refreshing the fabric instance... # On refreshing the fabric instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -180,7 +180,7 @@ class FabricTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
@ -192,7 +192,7 @@ class FabricCollectionTestCase(testtools.TestCase):
super(FabricCollectionTestCase, self).setUp() super(FabricCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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.port_inst.actions.reset.allowed_values,
) )
self.assertEqual( self.assertEqual(
("/redfish/v1/Fabrics/PCIe/Endpoints/" "HostRootComplex1",), ("/redfish/v1/Fabrics/PCIe/Endpoints/HostRootComplex1",),
self.port_inst.links.associated_endpoints, self.port_inst.links.associated_endpoints,
) )
self.assertEqual( self.assertEqual(
@ -163,7 +163,7 @@ class PortCollectionTestCase(testtools.TestCase):
members = self.port_col.get_members() members = self.port_col.get_members()
mock_port.assert_called_with( mock_port.assert_called_with(
self.port_col._conn, 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", redfish_version="1.0.2",
registries=None, registries=None,
) )

View File

@ -60,7 +60,7 @@ class SwitchTestCase(testtools.TestCase):
"/redfish/v1/Chassis/PCIeSwitch1", self.switch_inst.links.chassis "/redfish/v1/Chassis/PCIeSwitch1", self.switch_inst.links.chassis
) )
self.assertEqual( 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.switch_inst.actions.reset.target_uri,
) )
self.assertEqual( self.assertEqual(
@ -78,7 +78,7 @@ class SwitchTestCase(testtools.TestCase):
def test_get__reset_action_element(self): def test_get__reset_action_element(self):
value = self.switch_inst._get_reset_action_element() value = self.switch_inst._get_reset_action_element()
self.assertEqual( self.assertEqual(
"/redfish/v1/Fabrics/PCIe/Switches/1/Actions/" "Switch.Reset", "/redfish/v1/Fabrics/PCIe/Switches/1/Actions/Switch.Reset",
value.target_uri, value.target_uri,
) )
self.assertEqual(["GracefulRestart"], value.allowed_values) self.assertEqual(["GracefulRestart"], value.allowed_values)
@ -116,7 +116,7 @@ class SwitchTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
@ -135,7 +135,7 @@ class SwitchTestCase(testtools.TestCase):
def test_ports_on_refresh(self): def test_ports_on_refresh(self):
# | GIVEN | # | GIVEN |
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
@ -143,7 +143,7 @@ class SwitchTestCase(testtools.TestCase):
# On refreshing the manager instance... # On refreshing the manager instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -152,7 +152,7 @@ class SwitchTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
@ -164,7 +164,7 @@ class SwitchCollectionTestCase(testtools.TestCase):
super(SwitchCollectionTestCase, self).setUp() super(SwitchCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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("PCIe Zone 1", self.zone_inst.name)
self.assertEqual( self.assertEqual(
( (
"/redfish/v1/Fabrics/PCIe/" "Endpoints/HostRootComplex1", "/redfish/v1/Fabrics/PCIe/Endpoints/HostRootComplex1",
"/redfish/v1/Fabrics/PCIe/Endpoints/NVMeDrivePF2", "/redfish/v1/Fabrics/PCIe/Endpoints/NVMeDrivePF2",
), ),
self.zone_inst.links.endpoints, self.zone_inst.links.endpoints,
@ -98,7 +98,7 @@ class ZoneCollectionTestCase(testtools.TestCase):
super(ZoneCollectionTestCase, self).setUp() super(ZoneCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
self.zone_col = zone.ZoneCollection( self.zone_col = zone.ZoneCollection(

View File

@ -137,7 +137,7 @@ class TestManager(base.TestCase):
# On refreshing the manager instance... # On refreshing the manager instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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... # On refreshing the manager instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -227,7 +227,7 @@ class TestManagerCollection(base.TestCase):
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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): def test_get__reset_action_element(self):
value = self.node_inst._get_reset_action_element() value = self.node_inst._get_reset_action_element()
self.assertEqual( self.assertEqual(
"/redfish/v1/Nodes/Node1/Actions/" "ComposedNode.Reset", "/redfish/v1/Nodes/Node1/Actions/ComposedNode.Reset",
value.target_uri, value.target_uri,
) )
self.assertEqual( self.assertEqual(

View File

@ -90,7 +90,7 @@ class StorageServiceTestCase(testtools.TestCase):
# On refreshing the storage service instance... # On refreshing the storage service instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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... # On refreshing the storage service instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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... # On refreshing the storage service instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(MemoryCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(NetworkInterface, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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... # On refreshing the network_interface instance...
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(PCIeDeviceTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(PCIeFunctionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(StorageSubsystemTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -155,7 +155,7 @@ class StorageSubsystemCollectionTestCase(testtools.TestCase):
super(StorageSubsystemCollectionTestCase, self).setUp() super(StorageSubsystemCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() self.conn = mock.Mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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, exceptions.ConnectionError,
self.rsd._get_resource_class_from_path, self.rsd._get_resource_class_from_path,
"/redfish/v1/Chassis/1", "/redfish/v1/Chassis/1",
RESOURCE_CLASS RESOURCE_CLASS,
) )
self.conn.reset() self.conn.reset()
@ -255,7 +255,7 @@ class RSDLibV2_1TestCase(testtools.TestCase):
"/redfish/v1/Chassis/1", "/redfish/v1/Chassis/1",
self.rsd._get_resource_class_from_path, self.rsd._get_resource_class_from_path,
"/redfish/v1/Chassis/1", "/redfish/v1/Chassis/1",
RESOURCE_CLASS RESOURCE_CLASS,
) )
self.conn.reset() self.conn.reset()
@ -266,8 +266,8 @@ class RSDLibV2_1TestCase(testtools.TestCase):
self.assertEqual( self.assertEqual(
chassis.Chassis, chassis.Chassis,
self.rsd._get_resource_class_from_path( self.rsd._get_resource_class_from_path(
"/redfish/v1/Chassis/1", "/redfish/v1/Chassis/1", RESOURCE_CLASS
RESOURCE_CLASS), ),
) )
self.conn.reset() self.conn.reset()

View File

@ -28,7 +28,7 @@ class EthernetSwitchTestCase(testtools.TestCase):
super(EthernetSwitchTestCase, self).setUp() super(EthernetSwitchTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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... # On refreshing the port instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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... # On refreshing the metrics instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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.metrics_inst = ethernet_switch_metrics.EthernetSwitchMetrics(
self.conn, self.conn,
"/redfish/v1/EthernetSwitches/" "Switch1/Metrics", "/redfish/v1/EthernetSwitches/Switch1/Metrics",
redfish_version="1.0.2", 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( self.conn.post.return_value = request_fakes.fake_request_post(
None, None,
headers={ 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 | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
@ -95,7 +95,7 @@ class MemoryTestCase(testtools.TestCase):
def test_metrics_on_refresh(self): def test_metrics_on_refresh(self):
# | GIVEN | # | GIVEN |
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
@ -114,7 +114,7 @@ class MemoryTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
@ -128,7 +128,7 @@ class MemoryCollectionTestCase(testtools.TestCase):
super(MemoryCollectionTestCase, self).setUp() super(MemoryCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(MemoryMetricsTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -223,7 +223,7 @@ class ProcessorTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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): def test_metrics_on_refresh(self):
# | GIVEN | # | GIVEN |
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -265,7 +265,7 @@ class ProcessorTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(ProcessorMetricsTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())

View File

@ -214,7 +214,7 @@ class SystemTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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): def test_memory_on_refresh(self):
# | GIVEN | # | GIVEN |
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -252,7 +252,7 @@ class SystemTestCase(testtools.TestCase):
# | GIVEN | # | GIVEN |
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
@ -265,7 +265,7 @@ class SystemCollectionTestCase(testtools.TestCase):
super(SystemCollectionTestCase, self).setUp() super(SystemCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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() super(MetricDefinitionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open( 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", "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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... # On refreshing the telemetry service instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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( with open(
"rsd_lib/tests/unit/json_samples/v2_2/telemetry_service.json", "rsd_lib/tests/unit/json_samples/v2_2/telemetry_service.json",
"r" "r",
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads( self.conn.get.return_value.json.return_value = json.loads(
f.read() f.read()
) )
self.assertIsInstance( self.assertIsInstance(
self.rsd.get_resource( self.rsd.get_resource("/redfish/v1/TelemetryService"),
"/redfish/v1/TelemetryService"), v2_2_telemetry_service.TelemetryService,
v2_2_telemetry_service.TelemetryService
) )
def test_get_resource_with_no_class_match(self): 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... # On refreshing the update service instance...
with open( 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: ) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) 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): class TestEthernetSwtich(base.TestCase):
def setUp(self): def setUp(self):
super(TestEthernetSwtich, self).setUp() super(TestEthernetSwtich, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/ethernet_switch.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.ethernet_switch_inst = ethernet_switch.EthernetSwitch( self.ethernet_switch_inst = ethernet_switch.EthernetSwitch(
self.conn, self.conn,
'/redfish/v1/EthernetSwitches/Switch1', "/redfish/v1/EthernetSwitches/Switch1",
redfish_version='1.0.2') redfish_version="1.0.2",
)
def test_parse_attributes(self): def test_parse_attributes(self):
self.assertEqual('1.0.2', self.ethernet_switch_inst.redfish_version) 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.identity)
self.assertEqual('Switch1', self.ethernet_switch_inst.name) self.assertEqual("Switch1", self.ethernet_switch_inst.name)
self.assertEqual('description-as-string', self.assertEqual(
self.ethernet_switch_inst.description) "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("Quanta", self.ethernet_switch_inst.manufacturer)
self.assertEqual('02/21/2015 00:00:00', self.assertEqual("ly8_rangley", self.ethernet_switch_inst.model)
self.ethernet_switch_inst.manufacturing_date) self.assertEqual(
self.assertEqual('2M220100SL', self.ethernet_switch_inst.serial_number) "02/21/2015 00:00:00", self.ethernet_switch_inst.manufacturing_date
self.assertEqual('1LY8UZZ0007', self.ethernet_switch_inst.part_number) )
self.assertEqual('ONIE', self.ethernet_switch_inst.firmware_name) self.assertEqual("2M220100SL", self.ethernet_switch_inst.serial_number)
self.assertEqual('1.1', self.ethernet_switch_inst.firmware_version) self.assertEqual("1LY8UZZ0007", self.ethernet_switch_inst.part_number)
self.assertEqual('TOR', self.ethernet_switch_inst.role) self.assertEqual("ONIE", self.ethernet_switch_inst.firmware_name)
self.assertEqual('Enabled', self.ethernet_switch_inst.status.state) self.assertEqual("1.1", self.ethernet_switch_inst.firmware_version)
self.assertEqual('OK', self.ethernet_switch_inst.status.health) self.assertEqual("TOR", self.ethernet_switch_inst.role)
self.assertEqual('/redfish/v1/Chassis/FabricModule1', self.assertEqual("Enabled", self.ethernet_switch_inst.status.state)
self.ethernet_switch_inst.links.chassis) self.assertEqual("OK", self.ethernet_switch_inst.status.health)
self.assertEqual(('/redfish/v1/Managers/PSME',), self.assertEqual(
self.ethernet_switch_inst.links.managed_by) "/redfish/v1/Chassis/FabricModule1",
self.assertEqual(5, self.ethernet_switch_inst.links.chassis,
self.ethernet_switch_inst. )
class_to_priority_mapping[0].priority) self.assertEqual(
self.assertEqual(1, ("/redfish/v1/Managers/PSME",),
self.ethernet_switch_inst. self.ethernet_switch_inst.links.managed_by,
class_to_priority_mapping[0].traffic_class) )
self.assertEqual(5, self.assertEqual(
self.ethernet_switch_inst. 5, self.ethernet_switch_inst.class_to_priority_mapping[0].priority
class_to_priority_mapping[1].priority) )
self.assertEqual(2, self.assertEqual(
self.ethernet_switch_inst. 1,
class_to_priority_mapping[1].traffic_class) 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.dcbx_enabled)
self.assertEqual(True, self.ethernet_switch_inst.ets_enabled) self.assertEqual(True, self.ethernet_switch_inst.ets_enabled)
self.assertEqual(True, self.ethernet_switch_inst.lldp_enabled) self.assertEqual(True, self.ethernet_switch_inst.lldp_enabled)
self.assertEqual(4, self.ethernet_switch_inst.max_acl_number) self.assertEqual(4, self.ethernet_switch_inst.max_acl_number)
self.assertEqual('/redfish/v1/EthernetSwitches/Switch1/Metrics', self.assertEqual(
self.ethernet_switch_inst.metrics) "/redfish/v1/EthernetSwitches/Switch1/Metrics",
self.assertEqual(True, self.ethernet_switch_inst.metrics,
self.ethernet_switch_inst. )
priority_flow_control.enabled) self.assertEqual(
self.assertEqual([0, 1, 6, 7], True, self.ethernet_switch_inst.priority_flow_control.enabled
self.ethernet_switch_inst. )
priority_flow_control.lossless_priorities) self.assertEqual(
self.assertEqual(5, [0, 1, 6, 7],
self.ethernet_switch_inst. self.ethernet_switch_inst.priority_flow_control.
priority_to_class_mapping[0].priority) lossless_priorities,
self.assertEqual(1, )
self.ethernet_switch_inst. self.assertEqual(
priority_to_class_mapping[0].traffic_class) 5, self.ethernet_switch_inst.priority_to_class_mapping[0].priority
self.assertEqual(6, )
self.ethernet_switch_inst. self.assertEqual(
priority_to_class_mapping[1].priority) 1,
self.assertEqual(2, self.ethernet_switch_inst.priority_to_class_mapping[
self.ethernet_switch_inst. 0
priority_to_class_mapping[1].traffic_class) ].traffic_class,
self.assertEqual(4791, )
self.ethernet_switch_inst. self.assertEqual(
traffic_classification[0].port) 6, self.ethernet_switch_inst.priority_to_class_mapping[1].priority
self.assertEqual('UDP', )
self.ethernet_switch_inst. self.assertEqual(
traffic_classification[0].protocol) 2,
self.assertEqual(1, self.ethernet_switch_inst.priority_to_class_mapping[
self.ethernet_switch_inst. 1
traffic_classification[0].traffic_class) ].traffic_class,
self.assertEqual(860, )
self.ethernet_switch_inst. self.assertEqual(
traffic_classification[1].port) 4791, self.ethernet_switch_inst.traffic_classification[0].port
self.assertEqual('TCP', )
self.ethernet_switch_inst. self.assertEqual(
traffic_classification[1].protocol) "UDP", self.ethernet_switch_inst.traffic_classification[0].protocol
self.assertEqual(2, )
self.ethernet_switch_inst. self.assertEqual(
traffic_classification[1].traffic_class) 1,
self.assertEqual(3260, self.ethernet_switch_inst.traffic_classification[0].traffic_class,
self.ethernet_switch_inst. )
traffic_classification[2].port) self.assertEqual(
self.assertEqual('TCP', 860, self.ethernet_switch_inst.traffic_classification[1].port
self.ethernet_switch_inst. )
traffic_classification[2].protocol) self.assertEqual(
self.assertEqual(2, "TCP", self.ethernet_switch_inst.traffic_classification[1].protocol
self.ethernet_switch_inst. )
traffic_classification[2].traffic_class) self.assertEqual(
self.assertEqual(60, 2,
self.ethernet_switch_inst. self.ethernet_switch_inst.traffic_classification[1].traffic_class,
transmission_selection[0].bandwidth_percent) )
self.assertEqual(1, self.assertEqual(
self.ethernet_switch_inst. 3260, self.ethernet_switch_inst.traffic_classification[2].port
transmission_selection[0].traffic_class) )
self.assertEqual(30, self.assertEqual(
self.ethernet_switch_inst. "TCP", self.ethernet_switch_inst.traffic_classification[2].protocol
transmission_selection[1].bandwidth_percent) )
self.assertEqual(2, self.assertEqual(
self.ethernet_switch_inst. 2,
transmission_selection[1].traffic_class) 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): class EthernetSwitchCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(EthernetSwitchCollectionTestCase, self).setUp() super(EthernetSwitchCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'ethernet_switch_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.ethernet_switch_col = ethernet_switch.EthernetSwitchCollection( self.ethernet_switch_col = ethernet_switch.EthernetSwitchCollection(
self.conn, self.conn, "redfish/v1/EthernetSwitches", redfish_version="1.0.2"
'redfish/v1/EthernetSwitches', )
redfish_version='1.0.2')
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.ethernet_switch_col.redfish_version) self.assertEqual("1.0.2", self.ethernet_switch_col.redfish_version)
self.assertEqual('Ethernet Switches Collection', self.assertEqual(
self.ethernet_switch_col.name) "Ethernet Switches Collection", self.ethernet_switch_col.name
self.assertEqual(('/redfish/v1/EthernetSwitches/Switch1',), )
self.ethernet_switch_col.members_identities) 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): def test_get_member(self, mock_ethernet_switch):
self.ethernet_switch_col.get_member( self.ethernet_switch_col.get_member(
'/redfish/v1/EthernetSwitches/Switch1') "/redfish/v1/EthernetSwitches/Switch1"
)
mock_ethernet_switch.assert_called_once_with( mock_ethernet_switch.assert_called_once_with(
self.ethernet_switch_col._conn, self.ethernet_switch_col._conn,
'/redfish/v1/EthernetSwitches/Switch1', "/redfish/v1/EthernetSwitches/Switch1",
redfish_version=self.ethernet_switch_col.redfish_version, redfish_version=self.ethernet_switch_col.redfish_version,
registries=None, 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): def test_get_members(self, mock_ethernet_switch):
members = self.ethernet_switch_col.get_members() members = self.ethernet_switch_col.get_members()
self.assertEqual(mock_ethernet_switch.call_count, 1) 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): class EndpointTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(EndpointTestCase, self).setUp() super(EndpointTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/endpoint_1.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.endpoint_inst = endpoint.Endpoint( self.endpoint_inst = endpoint.Endpoint(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Endpoints/1', self.conn,
redfish_version='1.0.2') "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.endpoint_inst.redfish_version) self.assertEqual("1.0.2", self.endpoint_inst.redfish_version)
self.assertEqual('Fabric Endpoint', self.assertEqual("Fabric Endpoint", self.endpoint_inst.description)
self.endpoint_inst.description) self.assertEqual("1", self.endpoint_inst.identity)
self.assertEqual('1', self.endpoint_inst.identity) self.assertEqual("Fabric Endpoint", self.endpoint_inst.name)
self.assertEqual('Fabric Endpoint', self.endpoint_inst.name) self.assertEqual(
self.assertEqual('Target', "Target", self.endpoint_inst.connected_entities[0].entity_role
self.endpoint_inst.connected_entities[0].entity_role) )
self.assertEqual('/redfish/v1/StorageServices/1/Volumes/1', self.assertEqual(
self.endpoint_inst.connected_entities[0].entity_link) "/redfish/v1/StorageServices/1/Volumes/1",
self.assertEqual('Enabled', self.endpoint_inst.status.state) self.endpoint_inst.connected_entities[0].entity_link,
self.assertEqual('OK', self.endpoint_inst.status.health) )
self.assertEqual('OK', self.endpoint_inst.status.health_rollup) self.assertEqual("Enabled", self.endpoint_inst.status.state)
self.assertEqual('NVMeOverFabrics', self.endpoint_inst.protocol) self.assertEqual("OK", self.endpoint_inst.status.health)
self.assertEqual('NQN', self.assertEqual("OK", self.endpoint_inst.status.health_rollup)
self.endpoint_inst.identifiers[0].name_format) self.assertEqual("NVMeOverFabrics", self.endpoint_inst.protocol)
self.assertEqual('nqn.2014-08.org.nvmexpress:NVMf:uuid:' self.assertEqual("NQN", self.endpoint_inst.identifiers[0].name_format)
'397f9b78-7e94-11e7-9ea4-001e67dfa170', self.assertEqual(
self.endpoint_inst.identifiers[0].name) "nqn.2014-08.org.nvmexpress:NVMf:uuid:"
self.assertEqual('UUID', "397f9b78-7e94-11e7-9ea4-001e67dfa170",
self.endpoint_inst.identifiers[1].name_format) self.endpoint_inst.identifiers[0].name,
self.assertEqual('397f9b78-7e94-11e7-9ea4-001e67dfa170', )
self.endpoint_inst.identifiers[1].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.ports)
self.assertEqual((), self.endpoint_inst.links.endpoints) 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( self.assertEqual(
'RoCEv2', ("/redfish/v1/Fabrics/NVMeoE/Zones/1",),
self.endpoint_inst.ip_transport_details[0].transport_protocol) self.endpoint_inst.links.zones,
)
self.assertEqual( self.assertEqual(
'192.168.0.10', "/redfish/v1/Systems/Target/EthernetInterfaces/1",
self.endpoint_inst.ip_transport_details[0].ipv4_address) self.endpoint_inst.links.interface,
)
self.assertEqual( 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(1023, self.endpoint_inst.ip_transport_details[0].port)
self.assertEqual(None, self.endpoint_inst.oem.authentication) self.assertEqual(None, self.endpoint_inst.oem.authentication)
with open('rsd_lib/tests/unit/json_samples/v2_3/endpoint_2.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.endpoint_inst.refresh() self.endpoint_inst.refresh()
self.assertEqual('1.0.2', self.endpoint_inst.redfish_version) self.assertEqual("1.0.2", self.endpoint_inst.redfish_version)
self.assertEqual('Fabric Initiator Endpoint', self.assertEqual(
self.endpoint_inst.description) "Fabric Initiator Endpoint", self.endpoint_inst.description
self.assertEqual('1', self.endpoint_inst.identity) )
self.assertEqual('Fabric Endpoint', self.endpoint_inst.name) self.assertEqual("1", self.endpoint_inst.identity)
self.assertEqual('Initiator', self.assertEqual("Fabric Endpoint", self.endpoint_inst.name)
self.endpoint_inst.connected_entities[0].entity_role) self.assertEqual(
self.assertEqual(None, "Initiator", self.endpoint_inst.connected_entities[0].entity_role
self.endpoint_inst.connected_entities[0].entity_link) )
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.state)
self.assertEqual(None, self.endpoint_inst.status.health) self.assertEqual(None, self.endpoint_inst.status.health)
self.assertEqual(None, self.endpoint_inst.status.health_rollup) self.assertEqual(None, self.endpoint_inst.status.health_rollup)
self.assertEqual('NVMeOverFabrics', self.endpoint_inst.protocol) self.assertEqual("NVMeOverFabrics", self.endpoint_inst.protocol)
self.assertEqual('NQN', self.assertEqual("NQN", self.endpoint_inst.identifiers[0].name_format)
self.endpoint_inst.identifiers[0].name_format) self.assertEqual(
self.assertEqual('nqn.2014-08.org.nvmexpress:NVMf:uuid:' "nqn.2014-08.org.nvmexpress:NVMf:uuid:"
'12345678-90ab-cdef-0000-000000000000', "12345678-90ab-cdef-0000-000000000000",
self.endpoint_inst.identifiers[0].name) self.endpoint_inst.identifiers[0].name,
self.assertEqual('UUID', )
self.endpoint_inst.identifiers[1].name_format) self.assertEqual("UUID", self.endpoint_inst.identifiers[1].name_format)
self.assertEqual('12345678-90ab-cdef-0000-000000000000', self.assertEqual(
self.endpoint_inst.identifiers[1].name) "12345678-90ab-cdef-0000-000000000000",
self.endpoint_inst.identifiers[1].name,
)
self.assertEqual((), self.endpoint_inst.links.ports) self.assertEqual((), self.endpoint_inst.links.ports)
self.assertEqual((), self.endpoint_inst.links.endpoints) self.assertEqual((), self.endpoint_inst.links.endpoints)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Zones/1',), self.assertEqual(
self.endpoint_inst.links.zones) ("/redfish/v1/Fabrics/NVMeoE/Zones/1",),
self.endpoint_inst.links.zones,
)
self.assertEqual(None, self.endpoint_inst.links.interface) self.assertEqual(None, self.endpoint_inst.links.interface)
self.assertEqual( self.assertEqual(
'RoCEv2', "RoCEv2",
self.endpoint_inst.ip_transport_details[0].transport_protocol) self.endpoint_inst.ip_transport_details[0].transport_protocol,
)
self.assertEqual( self.assertEqual(
'192.168.0.10', "192.168.0.10",
self.endpoint_inst.ip_transport_details[0].ipv4_address) self.endpoint_inst.ip_transport_details[0].ipv4_address,
)
self.assertEqual( 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(4791, self.endpoint_inst.ip_transport_details[0].port)
self.assertEqual(None, self.endpoint_inst.oem.authentication) self.assertEqual(None, self.endpoint_inst.oem.authentication)
def test_update_authentication(self): 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( self.endpoint_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1', "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
data={ data={
"Oem": { "Oem": {
"Intel_RackScale": { "Intel_RackScale": {
"@odata.type": "#Intel.Oem.Endpoint", "@odata.type": "#Intel.Oem.Endpoint",
"Authentication": {"Username": "fake-username"} "Authentication": {"Username": "fake-username"},
} }
} }
}) },
)
self.endpoint_inst._conn.patch.reset_mock() 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( self.endpoint_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1', "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
data={ data={
"Oem": { "Oem": {
"Intel_RackScale": { "Intel_RackScale": {
"@odata.type": "#Intel.Oem.Endpoint", "@odata.type": "#Intel.Oem.Endpoint",
"Authentication": {"Password": "fake-password"} "Authentication": {"Password": "fake-password"},
} }
} }
}) },
)
self.endpoint_inst._conn.patch.reset_mock() self.endpoint_inst._conn.patch.reset_mock()
self.endpoint_inst.update_authentication(username='fake-username', self.endpoint_inst.update_authentication(
password='fake-password') username="fake-username", password="fake-password"
)
self.endpoint_inst._conn.patch.assert_called_once_with( self.endpoint_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1', "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
data={ data={
"Oem": { "Oem": {
"Intel_RackScale": { "Intel_RackScale": {
"@odata.type": "#Intel.Oem.Endpoint", "@odata.type": "#Intel.Oem.Endpoint",
"Authentication": { "Authentication": {
"Username": "fake-username", "Username": "fake-username",
"Password": "fake-password" "Password": "fake-password",
} },
} }
} }
}) },
)
def test_update_authentication_with_invalid_parameter(self): def test_update_authentication_with_invalid_parameter(self):
with self.assertRaisesRegex( with self.assertRaisesRegex(
ValueError, 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() self.endpoint_inst.update_authentication()
def test_delete(self): def test_delete(self):
self.endpoint_inst.delete() self.endpoint_inst.delete()
self.endpoint_inst._conn.delete.assert_called_once_with( self.endpoint_inst._conn.delete.assert_called_once_with(
self.endpoint_inst.path) self.endpoint_inst.path
)
class EndpointCollectionTestCase(testtools.TestCase): class EndpointCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(EndpointCollectionTestCase, self).setUp() super(EndpointCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'endpoint_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
self.conn.post.return_value = request_fakes.fake_request_post( self.conn.post.return_value = request_fakes.fake_request_post(
None, headers={"Location": "https://localhost:8443/redfish/v1/" None,
"Fabrics/NVMeoE/Endpoints/3"}) headers={
"Location": "https://localhost:8443/redfish/v1/"
"Fabrics/NVMeoE/Endpoints/3"
},
)
self.endpoint_col = endpoint.EndpointCollection( self.endpoint_col = endpoint.EndpointCollection(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Endpoints', self.conn,
redfish_version='1.0.2') "/redfish/v1/Fabrics/NVMeoE/Endpoints",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.endpoint_col.redfish_version) self.assertEqual("1.0.2", self.endpoint_col.redfish_version)
self.assertEqual('Endpoint Collection', self.assertEqual("Endpoint Collection", self.endpoint_col.name)
self.endpoint_col.name) self.assertEqual(
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Endpoints/1', (
'/redfish/v1/Fabrics/NVMeoE/Endpoints/2'), "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
self.endpoint_col.members_identities) "/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): def test_get_member(self, mock_endpoint):
self.endpoint_col.get_member( self.endpoint_col.get_member("/redfish/v1/Fabrics/NVMeoE/Endpoints/1")
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1')
mock_endpoint.assert_called_once_with( mock_endpoint.assert_called_once_with(
self.endpoint_col._conn, self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1', "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version=self.endpoint_col.redfish_version, redfish_version=self.endpoint_col.redfish_version,
registries=None, registries=None,
) )
@mock.patch.object(endpoint, 'Endpoint', autospec=True) @mock.patch.object(endpoint, "Endpoint", autospec=True)
def test_get_members(self, mock_endpoint): def test_get_members(self, mock_endpoint):
members = self.endpoint_col.get_members() members = self.endpoint_col.get_members()
calls = [ calls = [
mock.call( mock.call(
self.endpoint_col._conn, self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1', "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version=self.endpoint_col.redfish_version, redfish_version=self.endpoint_col.redfish_version,
registries=None, registries=None,
), ),
mock.call( mock.call(
self.endpoint_col._conn, self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/2', "/redfish/v1/Fabrics/NVMeoE/Endpoints/2",
redfish_version=self.endpoint_col.redfish_version, redfish_version=self.endpoint_col.redfish_version,
registries=None, registries=None,
) ),
] ]
mock_endpoint.assert_has_calls(calls) mock_endpoint.assert_has_calls(calls)
self.assertIsInstance(members, list) self.assertIsInstance(members, list)
@ -238,7 +277,7 @@ class EndpointCollectionTestCase(testtools.TestCase):
{ {
"DurableNameFormat": "NQN", "DurableNameFormat": "NQN",
"DurableName": "nqn.2014-08.org.nvmexpress:NVMf:" "DurableName": "nqn.2014-08.org.nvmexpress:NVMf:"
"uuid:397f9b78-7e94-11e7-9ea4-001e67dfa170" "uuid:397f9b78-7e94-11e7-9ea4-001e67dfa170",
} }
], ],
"ConnectedEntities": [ "ConnectedEntities": [
@ -246,7 +285,7 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityLink": { "EntityLink": {
"@odata.id": "/redfish/v1/StorageServices/1/Volumes/1" "@odata.id": "/redfish/v1/StorageServices/1/Volumes/1"
}, },
"EntityRole": "Target" "EntityRole": "Target",
} }
], ],
"Links": { "Links": {
@ -255,19 +294,19 @@ class EndpointCollectionTestCase(testtools.TestCase):
"Interfaces": [ "Interfaces": [
{ {
"@odata.id": "/redfish/v1/Systems/Target/" "@odata.id": "/redfish/v1/Systems/Target/"
"EthernetInterfaces/1" "EthernetInterfaces/1"
} }
] ]
} }
} }
} },
} }
result = self.endpoint_col.create_endpoint( result = self.endpoint_col.create_endpoint(
identifiers=[ identifiers=[
{ {
"DurableNameFormat": "NQN", "DurableNameFormat": "NQN",
"DurableName": "nqn.2014-08.org.nvmexpress:NVMf:" "DurableName": "nqn.2014-08.org.nvmexpress:NVMf:"
"uuid:397f9b78-7e94-11e7-9ea4-001e67dfa170" "uuid:397f9b78-7e94-11e7-9ea4-001e67dfa170",
} }
], ],
connected_entities=[ connected_entities=[
@ -275,15 +314,16 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityLink": { "EntityLink": {
"@odata.id": "/redfish/v1/StorageServices/1/Volumes/1" "@odata.id": "/redfish/v1/StorageServices/1/Volumes/1"
}, },
"EntityRole": "Target" "EntityRole": "Target",
} }
], ],
protocol="NVMeOverFabrics", 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( self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs) "/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
self.assertEqual(result, )
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3') self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
self.endpoint_col._conn.post.reset_mock() self.endpoint_col._conn.post.reset_mock()
reqs = { reqs = {
@ -292,7 +332,7 @@ class EndpointCollectionTestCase(testtools.TestCase):
{ {
"DurableNameFormat": "iQN", "DurableNameFormat": "iQN",
"DurableName": "iqn.1986-03.com.intel:my_storage-uuid:" "DurableName": "iqn.1986-03.com.intel:my_storage-uuid:"
"397f9b78-7e94-11e7-9ea4-001e67dfa170" "397f9b78-7e94-11e7-9ea4-001e67dfa170",
} }
], ],
"ConnectedEntities": [ "ConnectedEntities": [
@ -302,28 +342,25 @@ class EndpointCollectionTestCase(testtools.TestCase):
}, },
"EntityRole": "Target", "EntityRole": "Target",
"Identifiers": [ "Identifiers": [
{ {"DurableNameFormat": "LUN", "DurableName": "1"}
"DurableNameFormat": "LUN", ],
"DurableName": "1"
}
]
} }
], ],
"Oem": { "Oem": {
"Intel_RackScale": { "Intel_RackScale": {
"Authentication": { "Authentication": {
"Username": "userA", "Username": "userA",
"Password": "passB" "Password": "passB",
} }
} }
} },
} }
result = self.endpoint_col.create_endpoint( result = self.endpoint_col.create_endpoint(
identifiers=[ identifiers=[
{ {
"DurableNameFormat": "iQN", "DurableNameFormat": "iQN",
"DurableName": "iqn.1986-03.com.intel:my_storage-uuid:" "DurableName": "iqn.1986-03.com.intel:my_storage-uuid:"
"397f9b78-7e94-11e7-9ea4-001e67dfa170" "397f9b78-7e94-11e7-9ea4-001e67dfa170",
} }
], ],
connected_entities=[ connected_entities=[
@ -333,29 +370,24 @@ class EndpointCollectionTestCase(testtools.TestCase):
}, },
"EntityRole": "Target", "EntityRole": "Target",
"Identifiers": [ "Identifiers": [
{ {"DurableNameFormat": "LUN", "DurableName": "1"}
"DurableNameFormat": "LUN", ],
"DurableName": "1"
}
]
} }
], ],
protocol="iSCSI", protocol="iSCSI",
authentication={ authentication={"Username": "userA", "Password": "passB"},
"Username": "userA", )
"Password": "passB"
})
self.endpoint_col._conn.post.assert_called_once_with( self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs) "/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
self.assertEqual(result, )
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3') self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
def test_create_endpoint_with_invalid_reqs(self): def test_create_endpoint_with_invalid_reqs(self):
identifiers = [ identifiers = [
{ {
"DurableNameFormat": "iQN", "DurableNameFormat": "iQN",
"DurableName": "iqn.1986-03.com.intel:my_storage-uuid:" "DurableName": "iqn.1986-03.com.intel:my_storage-uuid:"
"397f9b78-7e94-11e7-9ea4-001e67dfa170" "397f9b78-7e94-11e7-9ea4-001e67dfa170",
} }
] ]
connected_entities = [ connected_entities = [
@ -365,87 +397,104 @@ class EndpointCollectionTestCase(testtools.TestCase):
}, },
"EntityRole": "Target", "EntityRole": "Target",
"Identifiers": [ "Identifiers": [
{ {"DurableNameFormat": "LUN", "DurableName": "1"}
"DurableNameFormat": "LUN", ],
"DurableName": "1"
}
]
} }
] ]
result = self.endpoint_col.create_endpoint( result = self.endpoint_col.create_endpoint(
identifiers=identifiers, connected_entities=connected_entities) identifiers=identifiers, connected_entities=connected_entities
self.assertEqual(result, )
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3') self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
# Test invalid identifiers argument # Test invalid identifiers argument
invalid_identifiers = copy.deepcopy(identifiers) invalid_identifiers = copy.deepcopy(identifiers)
invalid_identifiers[0]['DurableNameFormat'] = 'fake-format' invalid_identifiers[0]["DurableNameFormat"] = "fake-format"
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=invalid_identifiers, self.endpoint_col.create_endpoint,
connected_entities=connected_entities) identifiers=invalid_identifiers,
connected_entities=connected_entities,
)
invalid_identifiers = copy.deepcopy(identifiers) invalid_identifiers = copy.deepcopy(identifiers)
invalid_identifiers[0].pop('DurableNameFormat') invalid_identifiers[0].pop("DurableNameFormat")
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=invalid_identifiers, self.endpoint_col.create_endpoint,
connected_entities=connected_entities) identifiers=invalid_identifiers,
connected_entities=connected_entities,
)
invalid_identifiers = copy.deepcopy(identifiers) invalid_identifiers = copy.deepcopy(identifiers)
invalid_identifiers[0].pop('DurableName') invalid_identifiers[0].pop("DurableName")
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=invalid_identifiers, self.endpoint_col.create_endpoint,
connected_entities=connected_entities) identifiers=invalid_identifiers,
connected_entities=connected_entities,
)
# Test invalid connected_entities argument # Test invalid connected_entities argument
invalid_connected_entities = copy.deepcopy(connected_entities) invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0]['EntityRole'] = 'fake-format' invalid_connected_entities[0]["EntityRole"] = "fake-format"
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=identifiers, self.endpoint_col.create_endpoint,
connected_entities=invalid_connected_entities) identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
invalid_connected_entities = copy.deepcopy(connected_entities) invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0]['EntityLink'].pop('@odata.id') invalid_connected_entities[0]["EntityLink"].pop("@odata.id")
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=identifiers, self.endpoint_col.create_endpoint,
connected_entities=invalid_connected_entities) identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
invalid_connected_entities = copy.deepcopy(connected_entities) invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0].pop('EntityLink') invalid_connected_entities[0].pop("EntityLink")
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=identifiers, self.endpoint_col.create_endpoint,
connected_entities=invalid_connected_entities) identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
invalid_connected_entities = copy.deepcopy(connected_entities) invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0].pop('EntityRole') invalid_connected_entities[0].pop("EntityRole")
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=identifiers, self.endpoint_col.create_endpoint,
connected_entities=invalid_connected_entities) identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
# Test invalid protocol argument # Test invalid protocol argument
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=identifiers, self.endpoint_col.create_endpoint,
connected_entities=connected_entities, identifiers=identifiers,
protocol=1) connected_entities=connected_entities,
protocol=1,
)
# Test invalid interface argument # Test invalid interface argument
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=identifiers, self.endpoint_col.create_endpoint,
connected_entities=connected_entities, identifiers=identifiers,
interface=1) connected_entities=connected_entities,
interface=1,
)
# Test invalid authentication argument # Test invalid authentication argument
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=identifiers, self.endpoint_col.create_endpoint,
connected_entities=connected_entities, identifiers=identifiers,
authentication={'Username': 1}) 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): class FabricTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(FabricTestCase, self).setUp() super(FabricTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/fabric.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst = fabric.Fabric( self.fabric_inst = fabric.Fabric(
self.conn, '/redfish/v1/Fabrics/NVMeoE', self.conn, "/redfish/v1/Fabrics/NVMeoE", redfish_version="1.0.2"
redfish_version='1.0.2') )
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.fabric_inst.redfish_version) self.assertEqual("1.0.2", self.fabric_inst.redfish_version)
self.assertEqual('NVMeoE', self.fabric_inst.identity) self.assertEqual("NVMeoE", self.fabric_inst.identity)
self.assertEqual(None, self.fabric_inst.name) 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(None, self.fabric_inst.max_zones)
self.assertEqual('Enabled', self.fabric_inst.status.state) self.assertEqual("Enabled", self.fabric_inst.status.state)
self.assertEqual('OK', self.fabric_inst.status.health) self.assertEqual("OK", self.fabric_inst.status.health)
self.assertEqual('OK', self.fabric_inst.status.health_rollup) self.assertEqual("OK", self.fabric_inst.status.health_rollup)
def test__get_endpoint_collection_path(self): 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() result = self.fabric_inst._get_endpoint_collection_path()
self.assertEqual(expected, result) self.assertEqual(expected, result)
def test__get_endpoint_collection_path_missing_attr(self): def test__get_endpoint_collection_path_missing_attr(self):
self.fabric_inst._json.pop('Endpoints') self.fabric_inst._json.pop("Endpoints")
self.assertRaisesRegex( self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Endpoints', exceptions.MissingAttributeError,
self.fabric_inst._get_endpoint_collection_path) "attribute Endpoints",
self.fabric_inst._get_endpoint_collection_path,
)
def test_endpoints(self): def test_endpoints(self):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'endpoint_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
actual_endpoints = self.fabric_inst.endpoints actual_endpoints = self.fabric_inst.endpoints
# | THEN | # | THEN |
self.assertIsInstance(actual_endpoints, self.assertIsInstance(actual_endpoints, endpoint.EndpointCollection)
endpoint.EndpointCollection)
self.conn.get.return_value.json.assert_called_once_with() self.conn.get.return_value.json.assert_called_once_with()
# reset mock # reset mock
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN | # | WHEN & THEN |
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_endpoints, self.assertIs(actual_endpoints, self.fabric_inst.endpoints)
self.fabric_inst.endpoints)
self.conn.get.return_value.json.assert_not_called() self.conn.get.return_value.json.assert_not_called()
def test_endpoints_on_refresh(self): def test_endpoints_on_refresh(self):
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'endpoint_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.endpoints, self.assertIsInstance(
endpoint.EndpointCollection) self.fabric_inst.endpoints, endpoint.EndpointCollection
)
# On refreshing the fabric instance... # On refreshing the fabric instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'fabric.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst.invalidate() self.fabric_inst.invalidate()
self.fabric_inst.refresh(force=False) self.fabric_inst.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'endpoint_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.endpoints, self.assertIsInstance(
endpoint.EndpointCollection) self.fabric_inst.endpoints, endpoint.EndpointCollection
)
def test__get_zone_collection_path(self): 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() result = self.fabric_inst._get_zone_collection_path()
self.assertEqual(expected, result) self.assertEqual(expected, result)
def test__get_zone_collection_path_missing_attr(self): def test__get_zone_collection_path_missing_attr(self):
self.fabric_inst._json.pop('Zones') self.fabric_inst._json.pop("Zones")
self.assertRaisesRegex( self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Zones', exceptions.MissingAttributeError,
self.fabric_inst._get_zone_collection_path) "attribute Zones",
self.fabric_inst._get_zone_collection_path,
)
def test_zones(self): def test_zones(self):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'zone_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
actual_zones = self.fabric_inst.zones actual_zones = self.fabric_inst.zones
# | THEN | # | THEN |
self.assertIsInstance(actual_zones, self.assertIsInstance(actual_zones, zone.ZoneCollection)
zone.ZoneCollection)
self.conn.get.return_value.json.assert_called_once_with() self.conn.get.return_value.json.assert_called_once_with()
# reset mock # reset mock
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN | # | WHEN & THEN |
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_zones, self.assertIs(actual_zones, self.fabric_inst.zones)
self.fabric_inst.zones)
self.conn.get.return_value.json.assert_not_called() self.conn.get.return_value.json.assert_not_called()
def test_zones_on_refresh(self): def test_zones_on_refresh(self):
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'zone_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.zones, self.assertIsInstance(self.fabric_inst.zones, zone.ZoneCollection)
zone.ZoneCollection)
# On refreshing the fabric instance... # On refreshing the fabric instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'fabric.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst.invalidate() self.fabric_inst.invalidate()
self.fabric_inst.refresh(force=False) self.fabric_inst.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'zone_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.zones, self.assertIsInstance(self.fabric_inst.zones, zone.ZoneCollection)
zone.ZoneCollection)
class FabricCollectionTestCase(testtools.TestCase): class FabricCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(FabricCollectionTestCase, self).setUp() super(FabricCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'fabric_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_col = fabric.FabricCollection( 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): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.fabric_col.redfish_version) self.assertEqual("1.0.2", self.fabric_col.redfish_version)
self.assertEqual('Fabric Collection', self.assertEqual("Fabric Collection", self.fabric_col.name)
self.fabric_col.name) self.assertEqual(
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE',), ("/redfish/v1/Fabrics/NVMeoE",), self.fabric_col.members_identities
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): 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( 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, redfish_version=self.fabric_col.redfish_version,
registries=None, registries=None,
) )
@mock.patch.object(fabric, 'Fabric', autospec=True) @mock.patch.object(fabric, "Fabric", autospec=True)
def test_get_members(self, mock_fabric): def test_get_members(self, mock_fabric):
members = self.fabric_col.get_members() members = self.fabric_col.get_members()
mock_fabric.assert_called_once_with( 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, redfish_version=self.fabric_col.redfish_version,
registries=None, registries=None,
) )

View File

@ -23,91 +23,124 @@ from rsd_lib.tests.unit.fakes import request_fakes
class ZoneTestCase(testtools.TestCase): class ZoneTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(ZoneTestCase, self).setUp() super(ZoneTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/zone.json', with open("rsd_lib/tests/unit/json_samples/v2_3/zone.json", "r") as f:
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
self.zone_inst = zone.Zone( self.zone_inst = zone.Zone(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Zones/1', self.conn,
redfish_version='1.0.2') "/redfish/v1/Fabrics/NVMeoE/Zones/1",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.zone_inst.redfish_version) self.assertEqual("1.0.2", self.zone_inst.redfish_version)
self.assertEqual('Zone 1', self.assertEqual("Zone 1", self.zone_inst.description)
self.zone_inst.description) self.assertEqual("1", self.zone_inst.identity)
self.assertEqual('1', self.zone_inst.identity) self.assertEqual("Zone 1", self.zone_inst.name)
self.assertEqual('Zone 1', self.zone_inst.name) self.assertEqual(
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Endpoints/1', (
'/redfish/v1/Fabrics/NVMeoE/Endpoints/2'), "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
self.zone_inst.links.endpoints) "/redfish/v1/Fabrics/NVMeoE/Endpoints/2",
self.assertEqual('Enabled', self.zone_inst.status.state) ),
self.assertEqual('OK', self.zone_inst.status.health) 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): def test_update(self):
self.zone_inst.update( self.zone_inst.update(["/redfish/v1/Fabrics/NVMeoE/Endpoints/1"])
['/redfish/v1/Fabrics/NVMeoE/Endpoints/1'])
self.zone_inst._conn.patch.assert_called_once_with( self.zone_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Zones/1', "/redfish/v1/Fabrics/NVMeoE/Zones/1",
data={"Links": {"Endpoints": data={
[{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/1"}]}}) "Links": {
"Endpoints": [
{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/1"}
]
}
},
)
self.zone_inst._conn.patch.reset_mock() self.zone_inst._conn.patch.reset_mock()
self.zone_inst.update( 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( self.zone_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Zones/1', "/redfish/v1/Fabrics/NVMeoE/Zones/1",
data={"Links": {"Endpoints": data={
[{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/2"}, "Links": {
{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/3"}]}}) "Endpoints": [
{
"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints"
"/2"
},
{
"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints"
"/3"
},
]
}
},
)
def test_delete(self): def test_delete(self):
self.zone_inst.delete() self.zone_inst.delete()
self.zone_inst._conn.delete.assert_called_once_with( self.zone_inst._conn.delete.assert_called_once_with(
self.zone_inst.path) self.zone_inst.path
)
class ZoneCollectionTestCase(testtools.TestCase): class ZoneCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(ZoneCollectionTestCase, self).setUp() super(ZoneCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'zone_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
self.conn.post.return_value = request_fakes.fake_request_post( self.conn.post.return_value = request_fakes.fake_request_post(
None, headers={"Location": "https://localhost:8443/redfish/v1/" None,
"Fabrics/NVMeoE/Zones/2"}) headers={
"Location": "https://localhost:8443/redfish/v1/"
"Fabrics/NVMeoE/Zones/2"
},
)
self.zone_col = zone.ZoneCollection( self.zone_col = zone.ZoneCollection(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Zones', self.conn,
redfish_version='1.0.2') "/redfish/v1/Fabrics/NVMeoE/Zones",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.zone_col.redfish_version) self.assertEqual("1.0.2", self.zone_col.redfish_version)
self.assertEqual('Zone Collection', self.assertEqual("Zone Collection", self.zone_col.name)
self.zone_col.name) self.assertEqual(
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Zones/1',), ("/redfish/v1/Fabrics/NVMeoE/Zones/1",),
self.zone_col.members_identities) 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): 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( 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, redfish_version=self.zone_col.redfish_version,
registries=None, registries=None,
) )
@mock.patch.object(zone, 'Zone', autospec=True) @mock.patch.object(zone, "Zone", autospec=True)
def test_get_members(self, mock_zone): def test_get_members(self, mock_zone):
members = self.zone_col.get_members() members = self.zone_col.get_members()
mock_zone.assert_called_with( 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, redfish_version=self.zone_col.redfish_version,
registries=None, registries=None,
) )
@ -116,12 +149,26 @@ class ZoneCollectionTestCase(testtools.TestCase):
def test_create_zone(self): def test_create_zone(self):
result = self.zone_col.create_zone( 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( self.zone_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Zones', "/redfish/v1/Fabrics/NVMeoE/Zones",
data={"Links": {"Endpoints": data={
[{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/2"}, "Links": {
{"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints/3"}]}}) "Endpoints": [
self.assertEqual(result, {
'/redfish/v1/Fabrics/NVMeoE/Zones/2') "@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): class TestManager(base.TestCase):
def setUp(self): def setUp(self):
super(TestManager, self).setUp() super(TestManager, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/manager.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.manager_inst = manager.Manager(self.conn, self.manager_inst = manager.Manager(
'/redfish/v1/Manager/PSME', self.conn, "/redfish/v1/Manager/PSME", redfish_version="1.0.2"
redfish_version='1.0.2') )
def test_ethernet_interfaces(self): def test_ethernet_interfaces(self):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'manager_ethernet_interface_collection.json', 'r') as f: "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()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
actual_ethernet_interfaces = self.manager_inst.ethernet_interfaces actual_ethernet_interfaces = self.manager_inst.ethernet_interfaces
# | THEN | # | THEN |
self.assertIsInstance(actual_ethernet_interfaces, self.assertIsInstance(
ethernet_interface.EthernetInterfaceCollection) actual_ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection,
)
self.conn.get.return_value.json.assert_called_once_with() self.conn.get.return_value.json.assert_called_once_with()
# reset mock # reset mock
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN | # | WHEN & THEN |
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_ethernet_interfaces, self.assertIs(
self.manager_inst.ethernet_interfaces) actual_ethernet_interfaces, self.manager_inst.ethernet_interfaces
)
self.conn.get.return_value.json.assert_not_called() self.conn.get.return_value.json.assert_not_called()
def test_ethernet_interfaces_on_refresh(self): def test_ethernet_interfaces_on_refresh(self):
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'manager_ethernet_interface_collection.json', 'r') as f: "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()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.manager_inst.ethernet_interfaces, self.assertIsInstance(
ethernet_interface.EthernetInterfaceCollection) self.manager_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection,
)
# On refreshing the manager instance... # On refreshing the manager instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'manager.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.manager_inst.invalidate() self.manager_inst.invalidate()
self.manager_inst.refresh(force=False) self.manager_inst.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'manager_ethernet_interface_collection.json', 'r') as f: "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()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.manager_inst.ethernet_interfaces, self.assertIsInstance(
ethernet_interface.EthernetInterfaceCollection) self.manager_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection,
)
class TestManagerCollection(base.TestCase): class TestManagerCollection(base.TestCase):
def setUp(self): def setUp(self):
super(TestManagerCollection, self).setUp() super(TestManagerCollection, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'manager_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.manager_col = manager.ManagerCollection(self.conn, self.manager_col = manager.ManagerCollection(
'redfish/v1/Managers', self.conn, "redfish/v1/Managers", redfish_version="1.0.2"
redfish_version='1.0.2') )
def test_parse_attributes(self): def test_parse_attributes(self):
self.assertEqual('1.0.2', self.manager_col.redfish_version) self.assertEqual("1.0.2", self.manager_col.redfish_version)
self.assertEqual('Manager Collection', self.manager_col.name) self.assertEqual("Manager Collection", self.manager_col.name)
self.assertEqual(('/redfish/v1/Managers/BMC1', self.assertEqual(
'/redfish/v1/Managers/BMC2', (
'/redfish/v1/Managers/PSME',), "/redfish/v1/Managers/BMC1",
self.manager_col.members_identities) "/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): 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( mock_manager.assert_called_once_with(
self.manager_col._conn, self.manager_col._conn,
'/redfish/v1/Managers/BMC1', "/redfish/v1/Managers/BMC1",
redfish_version=self.manager_col.redfish_version, redfish_version=self.manager_col.redfish_version,
registries=None, registries=None,
) )
@mock.patch.object(manager, 'Manager', autospec=True) @mock.patch.object(manager, "Manager", autospec=True)
def test_get_members(self, mock_manager): def test_get_members(self, mock_manager):
members = self.manager_col.get_members() members = self.manager_col.get_members()
self.assertEqual(mock_manager.call_count, 3) 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): class AttachResourceActionInfoTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(AttachResourceActionInfoTestCase, self).setUp() super(AttachResourceActionInfoTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'attach_action_info.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.attach_action_info = attach_action_info.AttachResourceActionInfo( self.attach_action_info = attach_action_info.AttachResourceActionInfo(
self.conn, '/redfish/v1/Nodes/2/Actions/AttachResourceActionInfo', self.conn,
redfish_version='1.0.2') "/redfish/v1/Nodes/2/Actions/AttachResourceActionInfo",
redfish_version="1.0.2",
)
def test__parse_attributes(self): 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(None, self.attach_action_info.description)
self.assertEqual('AttachResourceActionInfo', self.assertEqual(
self.attach_action_info.identity) "AttachResourceActionInfo", self.attach_action_info.identity
self.assertEqual('Attach Resource ActionInfo', )
self.attach_action_info.name) self.assertEqual(
"Attach Resource ActionInfo", self.attach_action_info.name
)
def test_parameters(self): def test_parameters(self):
# | WHEN | # | WHEN |
@ -53,21 +58,20 @@ class AttachResourceActionInfoTestCase(testtools.TestCase):
"object_data_type": "#Resource.Resource", "object_data_type": "#Resource.Resource",
"allowable_values": ( "allowable_values": (
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1", "/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1",
) ),
}, },
{ {
"name": "Protocol", "name": "Protocol",
"required": False, "required": False,
"data_type": "String", "data_type": "String",
"object_data_type": None, "object_data_type": None,
"allowable_values": ["NVMeOverFabrics"] "allowable_values": ["NVMeOverFabrics"],
} },
] ]
self.assertEqual(expected, actual_parameters) self.assertEqual(expected, actual_parameters)
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_parameters, self.assertIs(actual_parameters, self.attach_action_info.parameters)
self.attach_action_info.parameters)
def test_parameters_on_refresh(self): def test_parameters_on_refresh(self):
expected = [ expected = [
@ -78,15 +82,15 @@ class AttachResourceActionInfoTestCase(testtools.TestCase):
"object_data_type": "#Resource.Resource", "object_data_type": "#Resource.Resource",
"allowable_values": ( "allowable_values": (
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1", "/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1",
) ),
}, },
{ {
"name": "Protocol", "name": "Protocol",
"required": False, "required": False,
"data_type": "String", "data_type": "String",
"object_data_type": None, "object_data_type": None,
"allowable_values": ["NVMeOverFabrics"] "allowable_values": ["NVMeOverFabrics"],
} },
] ]
self.assertEqual(expected, self.attach_action_info.parameters) self.assertEqual(expected, self.attach_action_info.parameters)
@ -94,8 +98,11 @@ class AttachResourceActionInfoTestCase(testtools.TestCase):
self.attach_action_info.refresh(force=False) self.attach_action_info.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'storage_pool_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertEqual(expected, self.attach_action_info.parameters) 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): class NodeTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(NodeTestCase, self).setUp() super(NodeTestCase, self).setUp()
self.conn = mock.Mock() 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.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst = node.Node( self.node_inst = node.Node(
self.conn, '/redfish/v1/Nodes/Node1', self.conn, "/redfish/v1/Nodes/Node1", redfish_version="1.0.2"
redfish_version='1.0.2') )
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual(True, self.node_inst.clear_tpm_on_delete) self.assertEqual(True, self.node_inst.clear_tpm_on_delete)
@ -42,26 +41,32 @@ class NodeTestCase(testtools.TestCase):
def test_update_node(self): def test_update_node(self):
self.node_inst.update(clear_tpm_on_delete=True) self.node_inst.update(clear_tpm_on_delete=True)
self.node_inst._conn.patch.assert_called_once_with( 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): def test_update_node_with_invalid_parameter(self):
with self.assertRaisesRegex( with self.assertRaisesRegex(
exceptions.InvalidParameterValueError, exceptions.InvalidParameterValueError,
'The parameter "clear_tpm_on_delete" value "fake-value" is'): 'The parameter "clear_tpm_on_delete" value "fake-value" is',
self.node_inst.update(clear_tpm_on_delete='fake-value') ):
self.node_inst.update(clear_tpm_on_delete="fake-value")
def test__get_attach_endpoint_action_element(self): def test__get_attach_endpoint_action_element(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'attach_action_info.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
value = self.node_inst._get_attach_endpoint_action_element() value = self.node_inst._get_attach_endpoint_action_element()
self.assertEqual('/redfish/v1/Nodes/Node1/Actions/' self.assertEqual(
'ComposedNode.AttachResource', "/redfish/v1/Nodes/Node1/Actions/ComposedNode.AttachResource",
value.target_uri) value.target_uri,
self.assertEqual('/redfish/v1/Nodes/Node1/Actions/' )
'AttachResourceActionInfo', self.assertEqual(
value.action_info_path) "/redfish/v1/Nodes/Node1/Actions/AttachResourceActionInfo",
value.action_info_path,
)
expected = [ expected = [
{ {
"name": "Resource", "name": "Resource",
@ -70,21 +75,23 @@ class NodeTestCase(testtools.TestCase):
"object_data_type": "#Resource.Resource", "object_data_type": "#Resource.Resource",
"allowable_values": ( "allowable_values": (
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1", "/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1",
) ),
}, },
{ {
"name": "Protocol", "name": "Protocol",
"required": False, "required": False,
"data_type": "String", "data_type": "String",
"object_data_type": None, "object_data_type": None,
"allowable_values": ["NVMeOverFabrics"] "allowable_values": ["NVMeOverFabrics"],
} },
] ]
self.assertEqual(expected, value.action_info.parameters) self.assertEqual(expected, value.action_info.parameters)
def test_get_allowed_attach_endpoints(self): def test_get_allowed_attach_endpoints(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'attach_action_info.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
expected = self.node_inst.get_allowed_attach_endpoints() expected = self.node_inst.get_allowed_attach_endpoints()
@ -92,55 +99,79 @@ class NodeTestCase(testtools.TestCase):
self.assertEqual(expected, result) self.assertEqual(expected, result)
def test_attach_endpoint(self): def test_attach_endpoint(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'attach_action_info.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst.attach_endpoint( 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",
protocol='NVMeOverFabrics') protocol="NVMeOverFabrics",
)
self.node_inst._conn.post.assert_called_once_with( self.node_inst._conn.post.assert_called_once_with(
'/redfish/v1/Nodes/Node1/Actions/ComposedNode.AttachResource', "/redfish/v1/Nodes/Node1/Actions/ComposedNode.AttachResource",
data={'Resource': {'@odata.id': '/redfish/v1/StorageServices' data={
'/1-sv-1/Volumes/1-sv-1-vl-1'}, "Resource": {
'Protocol': 'NVMeOverFabrics'}) "@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): def test_attach_endpoint_only_with_resource_uri(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'attach_action_info.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst.attach_endpoint( 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( self.node_inst._conn.post.assert_called_once_with(
'/redfish/v1/Nodes/Node1/Actions/ComposedNode.AttachResource', "/redfish/v1/Nodes/Node1/Actions/ComposedNode.AttachResource",
data={'Resource': {'@odata.id': '/redfish/v1/StorageServices' data={
'/1-sv-1/Volumes/1-sv-1-vl-1'}}) "Resource": {
"@odata.id": "/redfish/v1/StorageServices"
"/1-sv-1/Volumes/1-sv-1-vl-1"
}
},
)
def test_attach_endpoint_invalid_parameter(self): def test_attach_endpoint_invalid_parameter(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'attach_action_info.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
with self.assertRaisesRegex( with self.assertRaisesRegex(
exceptions.InvalidParameterValueError, exceptions.InvalidParameterValueError,
'"resource" value.*{0}'.format( '"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): def test__get_detach_endpoint_action_element(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'attach_action_info.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
value = self.node_inst._get_detach_endpoint_action_element() value = self.node_inst._get_detach_endpoint_action_element()
self.assertEqual('/redfish/v1/Nodes/Node1/Actions/' self.assertEqual(
'ComposedNode.DetachResource', "/redfish/v1/Nodes/Node1/Actions/ComposedNode.DetachResource",
value.target_uri) value.target_uri,
self.assertEqual('/redfish/v1/Nodes/Node1/Actions/' )
'DetachResourceActionInfo', self.assertEqual(
value.action_info_path) "/redfish/v1/Nodes/Node1/Actions/DetachResourceActionInfo",
value.action_info_path,
)
expected = [ expected = [
{ {
"name": "Resource", "name": "Resource",
@ -149,21 +180,23 @@ class NodeTestCase(testtools.TestCase):
"object_data_type": "#Resource.Resource", "object_data_type": "#Resource.Resource",
"allowable_values": ( "allowable_values": (
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1", "/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1",
) ),
}, },
{ {
"name": "Protocol", "name": "Protocol",
"required": False, "required": False,
"data_type": "String", "data_type": "String",
"object_data_type": None, "object_data_type": None,
"allowable_values": ["NVMeOverFabrics"] "allowable_values": ["NVMeOverFabrics"],
} },
] ]
self.assertEqual(expected, value.action_info.parameters) self.assertEqual(expected, value.action_info.parameters)
def test_get_allowed_detach_endpoints(self): def test_get_allowed_detach_endpoints(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'attach_action_info.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
expected = self.node_inst.get_allowed_detach_endpoints() expected = self.node_inst.get_allowed_detach_endpoints()
@ -171,46 +204,62 @@ class NodeTestCase(testtools.TestCase):
self.assertEqual(expected, result) self.assertEqual(expected, result)
def test_detach_endpoint(self): def test_detach_endpoint(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'attach_action_info.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst.detach_endpoint( 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( self.node_inst._conn.post.assert_called_once_with(
'/redfish/v1/Nodes/Node1/Actions/ComposedNode.DetachResource', "/redfish/v1/Nodes/Node1/Actions/ComposedNode.DetachResource",
data={'Resource': {'@odata.id': '/redfish/v1/StorageServices' data={
'/1-sv-1/Volumes/1-sv-1-vl-1'}}) "Resource": {
"@odata.id": "/redfish/v1/StorageServices"
"/1-sv-1/Volumes/1-sv-1-vl-1"
}
},
)
def test_detach_endpoint_invalid_parameter(self): def test_detach_endpoint_invalid_parameter(self):
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'attach_action_info.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
with self.assertRaisesRegex( with self.assertRaisesRegex(
exceptions.InvalidParameterValueError, exceptions.InvalidParameterValueError,
'"resource" value.*{0}'.format( '"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): def test_refresh(self):
self.assertIsNone(self.node_inst._actions.attach_endpoint.action_info) self.assertIsNone(self.node_inst._actions.attach_endpoint.action_info)
self.assertIsNone(self.node_inst._actions.detach_endpoint.action_info) self.assertIsNone(self.node_inst._actions.detach_endpoint.action_info)
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'attach_action_info.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst._get_attach_endpoint_action_element() self.node_inst._get_attach_endpoint_action_element()
self.node_inst._get_detach_endpoint_action_element() self.node_inst._get_detach_endpoint_action_element()
self.assertIsNotNone( self.assertIsNotNone(
self.node_inst._actions.attach_endpoint.action_info) self.node_inst._actions.attach_endpoint.action_info
)
self.assertIsNotNone( 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.conn.get.return_value.json.return_value = json.loads(f.read())
self.node_inst.refresh() self.node_inst.refresh()
@ -219,40 +268,48 @@ class NodeTestCase(testtools.TestCase):
class NodeCollectionTestCase(testtools.TestCase): class NodeCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(NodeCollectionTestCase, self).setUp() super(NodeCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/node_collection.json', with open(
'r') as f: "rsd_lib/tests/unit/json_samples/v2_3/node_collection.json", "r"
) as f:
self.conn.get.return_value = request_fakes.fake_request_get( 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( self.conn.post.return_value = request_fakes.fake_request_post(
None, headers={"Location": "https://localhost:8443/" None,
"redfish/v1/Nodes/1"}) headers={
"Location": "https://localhost:8443/redfish/v1/Nodes/1"
},
)
self.node_col = node.NodeCollection( 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): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.node_col.redfish_version) self.assertEqual("1.0.2", self.node_col.redfish_version)
self.assertEqual('Composed Node Collection', self.node_col.name) self.assertEqual("Composed Node Collection", self.node_col.name)
self.assertEqual(('/redfish/v1/Nodes/1',), self.assertEqual(
self.node_col.members_identities) ("/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): 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( 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, redfish_version=self.node_col.redfish_version,
registries=None, registries=None,
) )
@mock.patch.object(node, 'Node', autospec=True) @mock.patch.object(node, "Node", autospec=True)
def test_get_members(self, mock_node): def test_get_members(self, mock_node):
members = self.node_col.get_members() members = self.node_col.get_members()
mock_node.assert_called_once_with( 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, redfish_version=self.node_col.redfish_version,
registries=None, registries=None,
) )
@ -261,284 +318,330 @@ class NodeCollectionTestCase(testtools.TestCase):
def test__get_compose_action_element(self): def test__get_compose_action_element(self):
value = self.node_col._get_compose_action_element() value = self.node_col._get_compose_action_element()
self.assertEqual('/redfish/v1/Nodes/Actions/Allocate', self.assertEqual(
value.target_uri) "/redfish/v1/Nodes/Actions/Allocate", value.target_uri
)
def test_compose_node_no_reqs(self): def test_compose_node_no_reqs(self):
result = self.node_col.compose_node() result = self.node_col.compose_node()
self.node_col._conn.post.assert_called_once_with( self.node_col._conn.post.assert_called_once_with(
'/redfish/v1/Nodes/Actions/Allocate', data={}) "/redfish/v1/Nodes/Actions/Allocate", data={}
self.assertEqual(result, '/redfish/v1/Nodes/1') )
self.assertEqual(result, "/redfish/v1/Nodes/1")
def test_compose_node(self): def test_compose_node(self):
reqs = { reqs = {
'Name': 'test', "Name": "test",
'Description': 'this is a test node', "Description": "this is a test node",
'Processors': [{ "Processors": [
'TotalCores': 4, {
'ProcessorType': 'FPGA', "TotalCores": 4,
'Oem': { "ProcessorType": "FPGA",
'Brand': 'Platinum', "Oem": {"Brand": "Platinum", "Capabilities": ["sse"]},
'Capabilities': ['sse']
} }
}], ],
'Memory': [{ "Memory": [{"CapacityMiB": 8000}],
'CapacityMiB': 8000 "RemoteDrives": [
}], {
'RemoteDrives': [{ "CapacityGiB": 80,
'CapacityGiB': 80, "Protocol": "NVMeOverFabrics",
'Protocol': 'NVMeOverFabrics', "Master": {
'Master': { "Type": "Snapshot",
'Type': 'Snapshot', "Resource": {
'Resource': { "@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
'@odata.id': "Volumes/102"
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102' },
} },
}, "Resource": {
'Resource': { "@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
'@odata.id': "Volumes/102"
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102' },
} }
}], ],
'Security': { "Security": {
'TpmPresent': True, "TpmPresent": True,
'TpmInterfaceType': 'TPM2_0', "TpmInterfaceType": "TPM2_0",
'TxtEnabled': True, "TxtEnabled": True,
'ClearTPMOnDelete': True "ClearTPMOnDelete": True,
}, },
'TotalSystemCoreCount': 8, "TotalSystemCoreCount": 8,
'TotalSystemMemoryMiB': 16000 "TotalSystemMemoryMiB": 16000,
} }
result = self.node_col.compose_node( result = self.node_col.compose_node(
name='test', description='this is a test node', name="test",
processor_req=[{ description="this is a test node",
'TotalCores': 4, processor_req=[
'ProcessorType': 'FPGA', {
'Oem': { "TotalCores": 4,
'Brand': 'Platinum', "ProcessorType": "FPGA",
'Capabilities': ['sse'] "Oem": {"Brand": "Platinum", "Capabilities": ["sse"]},
} }
}], ],
memory_req=[{'CapacityMiB': 8000}], memory_req=[{"CapacityMiB": 8000}],
remote_drive_req=[{ remote_drive_req=[
'CapacityGiB': 80, {
'Protocol': 'NVMeOverFabrics', "CapacityGiB": 80,
'Master': { "Protocol": "NVMeOverFabrics",
'Type': 'Snapshot', "Master": {
'Resource': { "Type": "Snapshot",
'@odata.id': "Resource": {
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102' "@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
} "Volumes/102"
}, },
'Resource': { },
'@odata.id': "Resource": {
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102' "@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
"Volumes/102"
},
} }
}], ],
security_req={ security_req={
'TpmPresent': True, "TpmPresent": True,
'TpmInterfaceType': 'TPM2_0', "TpmInterfaceType": "TPM2_0",
'TxtEnabled': True, "TxtEnabled": True,
'ClearTPMOnDelete': True "ClearTPMOnDelete": True,
}, },
total_system_core_req=8, total_system_core_req=8,
total_system_memory_req=16000) total_system_memory_req=16000,
)
self.node_col._conn.post.assert_called_once_with( self.node_col._conn.post.assert_called_once_with(
'/redfish/v1/Nodes/Actions/Allocate', data=reqs) "/redfish/v1/Nodes/Actions/Allocate", data=reqs
self.assertEqual(result, '/redfish/v1/Nodes/1') )
self.assertEqual(result, "/redfish/v1/Nodes/1")
def test_compose_node_with_invalid_reqs(self): def test_compose_node_with_invalid_reqs(self):
# Wrong processor type # Wrong processor type
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, 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( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
processor_req=[{ description="this is a test node",
'TotalCores': 4, processor_req=[{"TotalCores": 4, "ProcessorType": "invalid"}],
'ProcessorType': 'invalid'}]) )
# Wrong processor Oem Brand # Wrong processor Oem Brand
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, jsonschema.exceptions.ValidationError,
("'invalid' is not one of \['E3', 'E5'")): ("'invalid' is not one of \['E3', 'E5'"),
):
self.node_col.compose_node( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
processor_req=[{ description="this is a test node",
'TotalCores': 4, processor_req=[
'Oem': { {
'Brand': 'invalid', "TotalCores": 4,
'Capabilities': ['sse'] "Oem": {"Brand": "invalid", "Capabilities": ["sse"]},
} }
}]) ],
)
# Wrong processor Oem Capabilities # Wrong processor Oem Capabilities
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, jsonschema.exceptions.ValidationError,
("'sse' is not of type 'array'")): ("'sse' is not of type 'array'"),
):
self.node_col.compose_node( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
processor_req=[{ description="this is a test node",
'TotalCores': 4, processor_req=[
'Oem': { {
'Brand': 'E3', "TotalCores": 4,
'Capabilities': 'sse' "Oem": {"Brand": "E3", "Capabilities": "sse"},
} }
}]) ],
)
# Wrong processor Oem Capabilities # Wrong processor Oem Capabilities
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, jsonschema.exceptions.ValidationError,
("0 is not of type 'string'")): ("0 is not of type 'string'"),
):
self.node_col.compose_node( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
processor_req=[{ description="this is a test node",
'TotalCores': 4, processor_req=[
'Oem': { {
'Brand': 'E3', "TotalCores": 4,
'Capabilities': [0] "Oem": {"Brand": "E3", "Capabilities": [0]},
} }
}]) ],
)
# Wrong remote drive CapacityGiB # Wrong remote drive CapacityGiB
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, jsonschema.exceptions.ValidationError,
("'invalid' is not of type 'number'")): ("'invalid' is not of type 'number'"),
):
self.node_col.compose_node( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
remote_drive_req=[{ description="this is a test node",
'CapacityGiB': 'invalid', remote_drive_req=[
'Protocol': 'NVMeOverFabrics', {
'Master': { "CapacityGiB": "invalid",
'Type': 'Snapshot', "Protocol": "NVMeOverFabrics",
'Resource': { "Master": {
'@odata.id': "Type": "Snapshot",
'/redfish/v1/StorageServices/NVMeoE1/Volumes/' "Resource": {
'102' "@odata.id": "/redfish/v1/StorageServices/"
} "NVMeoE1/Volumes/"
}, "102"
'Resource': { },
'@odata.id': },
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102' "Resource": {
} "@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
}]) "Volumes/102"
},
}
],
)
# Wrong remote drive Protocol # Wrong remote drive Protocol
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, jsonschema.exceptions.ValidationError,
("'invalid' is not one of \['iSCSI', 'NVMeOverFabrics'\]")): ("'invalid' is not one of \['iSCSI', 'NVMeOverFabrics'\]"),
):
self.node_col.compose_node( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
remote_drive_req=[{ description="this is a test node",
'CapacityGiB': 80, remote_drive_req=[
'Protocol': 'invalid', {
'Master': { "CapacityGiB": 80,
'Type': 'Snapshot', "Protocol": "invalid",
'Resource': { "Master": {
'@odata.id': "Type": "Snapshot",
'/redfish/v1/StorageServices/NVMeoE1/Volumes/' "Resource": {
'102' "@odata.id": "/redfish/v1/StorageServices/"
} "NVMeoE1/Volumes/"
}, "102"
'Resource': { },
'@odata.id': },
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102' "Resource": {
} "@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
}]) "Volumes/102"
},
}
],
)
# Wrong remote drive Master Type # Wrong remote drive Master Type
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, jsonschema.exceptions.ValidationError,
("'invalid' is not one of \['Snapshot', 'Clone'\]")): ("'invalid' is not one of \['Snapshot', 'Clone'\]"),
):
self.node_col.compose_node( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
remote_drive_req=[{ description="this is a test node",
'CapacityGiB': 80, remote_drive_req=[
'Protocol': 'iSCSI', {
'Master': { "CapacityGiB": 80,
'Type': 'invalid', "Protocol": "iSCSI",
'Resource': { "Master": {
'@odata.id': "Type": "invalid",
'/redfish/v1/StorageServices/NVMeoE1/Volumes/' "Resource": {
'102' "@odata.id": "/redfish/v1/StorageServices/"
} "NVMeoE1/Volumes/"
}, "102"
'Resource': { },
'@odata.id': },
'/redfish/v1/StorageServices/NVMeoE1/Volumes/102' "Resource": {
} "@odata.id": "/redfish/v1/StorageServices/NVMeoE1/"
}]) "Volumes/102"
},
}
],
)
# Wrong security parameter "TpmPresent" # Wrong security parameter "TpmPresent"
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, jsonschema.exceptions.ValidationError,
"'invalid' is not of type 'boolean'"): "'invalid' is not of type 'boolean'",
):
self.node_col.compose_node( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
description="this is a test node",
security_req={ security_req={
'TpmPresent': 'invalid', "TpmPresent": "invalid",
'TpmInterfaceType': 'TPM2_0', "TpmInterfaceType": "TPM2_0",
'TxtEnabled': True, "TxtEnabled": True,
'ClearTPMOnDelete': True "ClearTPMOnDelete": True,
}) },
)
# Wrong security parameter "TpmInterfaceType" # Wrong security parameter "TpmInterfaceType"
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, jsonschema.exceptions.ValidationError,
"True is not of type 'string'"): "True is not of type 'string'",
):
self.node_col.compose_node( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
description="this is a test node",
security_req={ security_req={
'TpmPresent': False, "TpmPresent": False,
'TpmInterfaceType': True, "TpmInterfaceType": True,
'TxtEnabled': True, "TxtEnabled": True,
'ClearTPMOnDelete': True "ClearTPMOnDelete": True,
}) },
)
# Wrong security parameter "TxtEnabled" # Wrong security parameter "TxtEnabled"
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, jsonschema.exceptions.ValidationError,
"'invalid' is not of type 'boolean'"): "'invalid' is not of type 'boolean'",
):
self.node_col.compose_node( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
description="this is a test node",
security_req={ security_req={
'TpmPresent': True, "TpmPresent": True,
'TpmInterfaceType': 'TPM2_0', "TpmInterfaceType": "TPM2_0",
'TxtEnabled': 'invalid', "TxtEnabled": "invalid",
'ClearTPMOnDelete': True "ClearTPMOnDelete": True,
}) },
)
# Wrong security parameter "ClearTPMOnDelete" # Wrong security parameter "ClearTPMOnDelete"
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, jsonschema.exceptions.ValidationError,
"'invalid' is not of type 'boolean'"): "'invalid' is not of type 'boolean'",
):
self.node_col.compose_node( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
description="this is a test node",
security_req={ security_req={
'TpmPresent': True, "TpmPresent": True,
'TpmInterfaceType': 'TPM2_0', "TpmInterfaceType": "TPM2_0",
'TxtEnabled': True, "TxtEnabled": True,
'ClearTPMOnDelete': 'invalid' "ClearTPMOnDelete": "invalid",
}) },
)
# Wrong additional security parameter # Wrong additional security parameter
with self.assertRaisesRegex( with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError, 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( self.node_col.compose_node(
name='test', description='this is a test node', name="test",
description="this is a test node",
security_req={ security_req={
'TpmPresent': True, "TpmPresent": True,
'TpmInterfaceType': 'TPM2_0', "TpmInterfaceType": "TPM2_0",
'TxtEnabled': False, "TxtEnabled": False,
'invalid-key': 'invalid-value' "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): class DriveTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(DriveTestCase, self).setUp() super(DriveTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/drive.json', with open("rsd_lib/tests/unit/json_samples/v2_3/drive.json", "r") as f:
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read()) self.conn.get.return_value.json.return_value = json.loads(f.read())
self.drive_inst = drive.Drive( self.drive_inst = drive.Drive(
self.conn, '/redfish/v1/Chassis/1/Drives/1', self.conn,
redfish_version='1.0.2') "/redfish/v1/Chassis/1/Drives/1",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.drive_inst.redfish_version) self.assertEqual("1.0.2", self.drive_inst.redfish_version)
self.assertEqual('2', self.drive_inst.identity) self.assertEqual("2", self.drive_inst.identity)
self.assertEqual('Physical Drive', self.drive_inst.name) self.assertEqual("Physical Drive", self.drive_inst.name)
self.assertEqual('2', self.drive_inst.identity) self.assertEqual("2", self.drive_inst.identity)
self.assertEqual('NVMe', self.drive_inst.protocol) self.assertEqual("NVMe", self.drive_inst.protocol)
self.assertEqual('NVMe', self.drive_inst.drive_type) self.assertEqual("NVMe", self.drive_inst.drive_type)
self.assertEqual('SSD', self.drive_inst.media_type) self.assertEqual("SSD", self.drive_inst.media_type)
self.assertEqual(2442408680913, self.drive_inst.capacity_bytes) self.assertEqual(2442408680913, self.drive_inst.capacity_bytes)
self.assertEqual('Intel Corporation', self.drive_inst.manufacturer) self.assertEqual("Intel Corporation", self.drive_inst.manufacturer)
self.assertEqual('E323', self.drive_inst.model) self.assertEqual("E323", self.drive_inst.model)
self.assertEqual(None, self.drive_inst.revision) self.assertEqual(None, self.drive_inst.revision)
self.assertEqual(None, self.drive_inst.sku) self.assertEqual(None, self.drive_inst.sku)
self.assertEqual('123fed3029c-b23394-121', self.assertEqual(
self.drive_inst.serial_number) "123fed3029c-b23394-121", self.drive_inst.serial_number
)
self.assertEqual(None, self.drive_inst.part_number) self.assertEqual(None, self.drive_inst.part_number)
self.assertEqual(None, self.drive_inst.asset_tag) self.assertEqual(None, self.drive_inst.asset_tag)
self.assertEqual(None, self.drive_inst.rotation_speed_rpm) self.assertEqual(None, self.drive_inst.rotation_speed_rpm)
self.assertEqual('397f9b78-7e94-11e7-9ea4-001e67dfa170', self.assertEqual(
self.drive_inst.identifiers[0].durable_name) "397f9b78-7e94-11e7-9ea4-001e67dfa170",
self.assertEqual('UUID', self.drive_inst.identifiers[0].durable_name,
self.drive_inst.identifiers[0].durable_name_format) )
self.assertEqual('3', self.drive_inst.location[0].info) self.assertEqual(
self.assertEqual('DriveBay number', "UUID", self.drive_inst.identifiers[0].durable_name_format
self.drive_inst.location[0].info_format) )
self.assertEqual('Enabled', self.drive_inst.status.state) self.assertEqual("3", self.drive_inst.location[0].info)
self.assertEqual('OK', self.drive_inst.status.health) self.assertEqual(
self.assertEqual('OK', self.drive_inst.status.health_rollup) "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(False, self.drive_inst.oem.erased)
self.assertEqual(True, self.drive_inst.oem.erase_on_detach) 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.storage)
self.assertEqual(None, self.drive_inst.oem.pcie_function) self.assertEqual(None, self.drive_inst.oem.pcie_function)
self.assertEqual(None, self.drive_inst.status_indicator) 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.capable_speed_gbs)
self.assertEqual(None, self.drive_inst.negotiated_speed_gbs) self.assertEqual(None, self.drive_inst.negotiated_speed_gbs)
self.assertEqual(95, self.drive_inst.predicted_media_life_left_percent) self.assertEqual(95, self.drive_inst.predicted_media_life_left_percent)
self.assertEqual('/redfish/v1/Chassis/1', self.assertEqual(
self.drive_inst.links.chassis) "/redfish/v1/Chassis/1", self.drive_inst.links.chassis
)
self.assertEqual((), self.drive_inst.links.volumes) self.assertEqual((), self.drive_inst.links.volumes)
self.assertEqual((), self.drive_inst.links.endpoints) self.assertEqual((), self.drive_inst.links.endpoints)
def test_get_metrics_path(self): 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() result = self.drive_inst._get_metrics_path()
self.assertEqual(expected, result) self.assertEqual(expected, result)
def test_drive_metrics(self): def test_drive_metrics(self):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'drive_metrics.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
actual_drive_metrics = self.drive_inst.metrics actual_drive_metrics = self.drive_inst.metrics
# | THEN | # | THEN |
self.assertIsInstance(actual_drive_metrics, self.assertIsInstance(actual_drive_metrics, drive_metrics.DriveMetrics)
drive_metrics.DriveMetrics)
self.conn.get.return_value.json.assert_called_once_with() self.conn.get.return_value.json.assert_called_once_with()
# reset mock # reset mock
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN | # | WHEN & THEN |
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_drive_metrics, self.assertIs(actual_drive_metrics, self.drive_inst.metrics)
self.drive_inst.metrics)
self.conn.get.return_value.json.assert_not_called() self.conn.get.return_value.json.assert_not_called()
def test_drive_metrics_on_refresh(self): def test_drive_metrics_on_refresh(self):
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'drive_metrics.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.drive_inst.metrics, self.assertIsInstance(
drive_metrics.DriveMetrics) self.drive_inst.metrics, drive_metrics.DriveMetrics
)
# On refreshing the chassis instance... # On refreshing the chassis instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'drive.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.drive_inst.invalidate() self.drive_inst.invalidate()
self.drive_inst.refresh(force=False) self.drive_inst.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'drive_metrics.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.drive_inst.metrics, self.assertIsInstance(
drive_metrics.DriveMetrics) self.drive_inst.metrics, drive_metrics.DriveMetrics
)
class DriveCollectionTestCase(testtools.TestCase): class DriveCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(DriveCollectionTestCase, self).setUp() super(DriveCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'drive_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.drive_col = drive.DriveCollection( self.drive_col = drive.DriveCollection(
self.conn, '/redfish/v1/StorageServices/NVMeoE1/Drives', self.conn,
redfish_version='1.0.2') "/redfish/v1/StorageServices/NVMeoE1/Drives",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.drive_col.redfish_version) self.assertEqual("1.0.2", self.drive_col.redfish_version)
self.assertEqual('Drives', self.assertEqual("Drives", self.drive_col.name)
self.drive_col.name)
self.assertEqual( self.assertEqual(
('/redfish/v1/Chassis/1/Drives/1', (
'/redfish/v1/Chassis/1/Drives/2'), "/redfish/v1/Chassis/1/Drives/1",
self.drive_col.members_identities) "/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): def test_get_member(self, mock_drive):
self.drive_col.get_member( self.drive_col.get_member("/redfish/v1/Chassis/1/Drives/1")
'/redfish/v1/Chassis/1/Drives/1')
mock_drive.assert_called_once_with( mock_drive.assert_called_once_with(
self.drive_col._conn, self.drive_col._conn,
'/redfish/v1/Chassis/1/Drives/1', "/redfish/v1/Chassis/1/Drives/1",
redfish_version=self.drive_col.redfish_version, redfish_version=self.drive_col.redfish_version,
registries=None, registries=None,
) )
@mock.patch.object(drive, 'Drive', autospec=True) @mock.patch.object(drive, "Drive", autospec=True)
def test_get_members(self, mock_drive): def test_get_members(self, mock_drive):
members = self.drive_col.get_members() members = self.drive_col.get_members()
calls = [ calls = [
mock.call( mock.call(
self.drive_col._conn, self.drive_col._conn,
'/redfish/v1/Chassis/1/Drives/1', "/redfish/v1/Chassis/1/Drives/1",
redfish_version=self.drive_col.redfish_version, redfish_version=self.drive_col.redfish_version,
registries=None, registries=None,
), ),
mock.call( mock.call(
self.drive_col._conn, self.drive_col._conn,
'/redfish/v1/Chassis/1/Drives/2', "/redfish/v1/Chassis/1/Drives/2",
redfish_version=self.drive_col.redfish_version, redfish_version=self.drive_col.redfish_version,
registries=None, registries=None,
) ),
] ]
mock_drive.assert_has_calls(calls) mock_drive.assert_has_calls(calls)
self.assertIsInstance(members, list) 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): class DriveMetricsTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(DriveMetricsTestCase, self).setUp() super(DriveMetricsTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/drive_metrics.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.drive_metrics_inst = drive_metrics.DriveMetrics( self.drive_metrics_inst = drive_metrics.DriveMetrics(
self.conn, '/redfish/v1/Chassis/1/Drives/1/Metrics', self.conn,
redfish_version='1.0.2') "/redfish/v1/Chassis/1/Drives/1/Metrics",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('Drive Metrics for Drive', self.assertEqual(
self.drive_metrics_inst.name) "Drive Metrics for Drive", self.drive_metrics_inst.name
self.assertEqual('Metrics for Drive 1', )
self.drive_metrics_inst.description) self.assertEqual(
self.assertEqual('Metrics', self.drive_metrics_inst.identity) "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) self.assertEqual(318, self.drive_metrics_inst.temperature_kelvin)
life_time = self.drive_metrics_inst.life_time 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): class StoragePoolTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(StoragePoolTestCase, self).setUp() super(StoragePoolTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/storage_pool.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_pool_inst = storage_pool.StoragePool( self.storage_pool_inst = storage_pool.StoragePool(
self.conn, '/redfish/v1/StorageServices/NVMeoE1/StoragePool/2', self.conn,
redfish_version='1.0.2') "/redfish/v1/StorageServices/NVMeoE1/StoragePool/2",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.storage_pool_inst.redfish_version) 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( 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( self.assertEqual(
'SystemPath', "/dev/nvme5", self.storage_pool_inst.identifier.durable_name
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( self.assertEqual(
('/redfish/v1/Chassis/1/Drives/2',), "SystemPath", self.storage_pool_inst.identifier.durable_name_format
self.storage_pool_inst.capacity_sources[0].providing_drives) )
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( self.assertEqual(
512174850048, 512174850048,
self.storage_pool_inst.capacity_sources[0]. self.storage_pool_inst.capacity_sources[
provided_capacity.allocated_bytes) 0
].provided_capacity.allocated_bytes,
)
self.assertEqual( self.assertEqual(
3071983104, 3071983104,
self.storage_pool_inst.capacity_sources[0]. self.storage_pool_inst.capacity_sources[
provided_capacity.consumed_bytes) 0
].provided_capacity.consumed_bytes,
)
self.assertEqual( self.assertEqual(
None, None,
self.storage_pool_inst.capacity_sources[0]. self.storage_pool_inst.capacity_sources[
provided_capacity.guaranteed_bytes) 0
].provided_capacity.guaranteed_bytes,
)
self.assertEqual( self.assertEqual(
None, None,
self.storage_pool_inst.capacity_sources[0]. self.storage_pool_inst.capacity_sources[
provided_capacity.provisioned_bytes) 0
].provided_capacity.provisioned_bytes,
)
def test__get_allocated_volumes_path(self): def test__get_allocated_volumes_path(self):
expected = '/redfish/v1/StorageServices/NVMeoE1/StoragePools/'\ expected = (
'2/AllocatedVolumes' "/redfish/v1/StorageServices/NVMeoE1/StoragePools/"
"2/AllocatedVolumes"
)
result = self.storage_pool_inst._get_allocated_volumes_path() result = self.storage_pool_inst._get_allocated_volumes_path()
self.assertEqual(expected, result) self.assertEqual(expected, result)
def test__get_allocated_volumes_path_missing_processors_attr(self): 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( self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute AllocatedVolumes', exceptions.MissingAttributeError,
self.storage_pool_inst._get_allocated_volumes_path) "attribute AllocatedVolumes",
self.storage_pool_inst._get_allocated_volumes_path,
)
def test_allocated_volumes(self): def test_allocated_volumes(self):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'volume_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
actual_volumes = self.storage_pool_inst.allocated_volumes actual_volumes = self.storage_pool_inst.allocated_volumes
# | THEN | # | THEN |
self.assertIsInstance(actual_volumes, self.assertIsInstance(actual_volumes, volume.VolumeCollection)
volume.VolumeCollection)
self.conn.get.return_value.json.assert_called_once_with() self.conn.get.return_value.json.assert_called_once_with()
# reset mock # reset mock
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN | # | WHEN & THEN |
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_volumes, self.assertIs(actual_volumes, self.storage_pool_inst.allocated_volumes)
self.storage_pool_inst.allocated_volumes)
self.conn.get.return_value.json.assert_not_called() self.conn.get.return_value.json.assert_not_called()
def test_allocated_volumes_on_refresh(self): def test_allocated_volumes_on_refresh(self):
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'volume_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.storage_pool_inst.allocated_volumes, self.assertIsInstance(
volume.VolumeCollection) self.storage_pool_inst.allocated_volumes, volume.VolumeCollection
)
# On refreshing the storage service instance... # On refreshing the storage service instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'storage_pool.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_pool_inst.invalidate() self.storage_pool_inst.invalidate()
self.storage_pool_inst.refresh(force=False) self.storage_pool_inst.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'volume_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.storage_pool_inst.allocated_volumes, self.assertIsInstance(
volume.VolumeCollection) self.storage_pool_inst.allocated_volumes, volume.VolumeCollection
)
def test__get_allocated_pools_path(self): def test__get_allocated_pools_path(self):
expected = '/redfish/v1/StorageServices/NVMeoE1/StoragePools/'\ expected = (
'2/AllocatedPools' "/redfish/v1/StorageServices/NVMeoE1/StoragePools/"
"2/AllocatedPools"
)
result = self.storage_pool_inst._get_allocated_pools_path() result = self.storage_pool_inst._get_allocated_pools_path()
self.assertEqual(expected, result) self.assertEqual(expected, result)
def test__get_allocated_pools_path_missing_processors_attr(self): 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( self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute AllocatedPools', exceptions.MissingAttributeError,
self.storage_pool_inst._get_allocated_pools_path) "attribute AllocatedPools",
self.storage_pool_inst._get_allocated_pools_path,
)
def test_allocated_pools(self): def test_allocated_pools(self):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'storage_pool_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
actual_storage_pools = self.storage_pool_inst.allocated_pools actual_storage_pools = self.storage_pool_inst.allocated_pools
# | THEN | # | THEN |
self.assertIsInstance(actual_storage_pools, self.assertIsInstance(
storage_pool.StoragePoolCollection) actual_storage_pools, storage_pool.StoragePoolCollection
)
self.conn.get.return_value.json.assert_called_once_with() self.conn.get.return_value.json.assert_called_once_with()
# reset mock # reset mock
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN | # | WHEN & THEN |
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_storage_pools, self.assertIs(
self.storage_pool_inst.allocated_pools) actual_storage_pools, self.storage_pool_inst.allocated_pools
)
self.conn.get.return_value.json.assert_not_called() self.conn.get.return_value.json.assert_not_called()
def test_allocated_pools_on_refresh(self): def test_allocated_pools_on_refresh(self):
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'storage_pool_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.storage_pool_inst.allocated_pools, self.assertIsInstance(
storage_pool.StoragePoolCollection) self.storage_pool_inst.allocated_pools,
storage_pool.StoragePoolCollection,
)
# On refreshing the storage service instance... # On refreshing the storage service instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'storage_pool.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_pool_inst.invalidate() self.storage_pool_inst.invalidate()
self.storage_pool_inst.refresh(force=False) self.storage_pool_inst.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'storage_pool_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.storage_pool_inst.allocated_pools, self.assertIsInstance(
storage_pool.StoragePoolCollection) self.storage_pool_inst.allocated_pools,
storage_pool.StoragePoolCollection,
)
class StoragePoolCollectionTestCase(testtools.TestCase): class StoragePoolCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(StoragePoolCollectionTestCase, self).setUp() super(StoragePoolCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'storage_pool_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_pool_col = storage_pool.StoragePoolCollection( self.storage_pool_col = storage_pool.StoragePoolCollection(
self.conn, '/redfish/v1/StorageServices/NVMeoE1/StoragePools', self.conn,
redfish_version='1.0.2') "/redfish/v1/StorageServices/NVMeoE1/StoragePools",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.storage_pool_col.redfish_version) self.assertEqual("1.0.2", self.storage_pool_col.redfish_version)
self.assertEqual('StoragePools Collection', self.assertEqual("StoragePools Collection", self.storage_pool_col.name)
self.storage_pool_col.name)
self.assertEqual( self.assertEqual(
('/redfish/v1/StorageServices/NVMeoE1/StoragePools/1', (
'/redfish/v1/StorageServices/NVMeoE1/StoragePools/2'), "/redfish/v1/StorageServices/NVMeoE1/StoragePools/1",
self.storage_pool_col.members_identities) "/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): def test_get_member(self, mock_storage_pool):
self.storage_pool_col.get_member( 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( mock_storage_pool.assert_called_once_with(
self.storage_pool_col._conn, 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, redfish_version=self.storage_pool_col.redfish_version,
registries=None, 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): def test_get_members(self, mock_storage_pool):
members = self.storage_pool_col.get_members() members = self.storage_pool_col.get_members()
calls = [ calls = [
mock.call( mock.call(
self.storage_pool_col._conn, 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, redfish_version=self.storage_pool_col.redfish_version,
registries=None, registries=None,
), ),
mock.call( mock.call(
self.storage_pool_col._conn, 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, redfish_version=self.storage_pool_col.redfish_version,
registries=None, registries=None,
) ),
] ]
mock_storage_pool.assert_has_calls(calls) mock_storage_pool.assert_has_calls(calls)
self.assertIsInstance(members, list) self.assertIsInstance(members, list)

View File

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

View File

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

View File

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

View File

@ -23,17 +23,19 @@ from rsd_lib.resources.v2_3.system import system
class SystemTestCase(testtools.TestCase): class SystemTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(SystemTestCase, self).setUp() super(SystemTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/system.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_inst = system.System( self.system_inst = system.System(
self.conn, '/redfish/v1/Systems/437XR1138R2', self.conn,
redfish_version='1.1.0') "/redfish/v1/Systems/437XR1138R2",
redfish_version="1.1.0",
)
def test_class_inherit(self): def test_class_inherit(self):
self.assertIsInstance(self.system_inst, system.System) self.assertIsInstance(self.system_inst, system.System)
@ -42,95 +44,113 @@ class SystemTestCase(testtools.TestCase):
def test_ethernet_interfaces(self): def test_ethernet_interfaces(self):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'system_ethernet_interface_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
actual_ethernet_interface_col = self.system_inst.ethernet_interfaces actual_ethernet_interface_col = self.system_inst.ethernet_interfaces
# | THEN | # | THEN |
self.assertIsInstance(actual_ethernet_interface_col, self.assertIsInstance(
ethernet_interface.EthernetInterfaceCollection) actual_ethernet_interface_col,
ethernet_interface.EthernetInterfaceCollection,
)
self.conn.get.return_value.json.assert_called_once_with() self.conn.get.return_value.json.assert_called_once_with()
# reset mock # reset mock
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN | # | WHEN & THEN |
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_ethernet_interface_col, self.assertIs(
self.system_inst.ethernet_interfaces) actual_ethernet_interface_col, self.system_inst.ethernet_interfaces
)
self.conn.get.return_value.json.assert_not_called() self.conn.get.return_value.json.assert_not_called()
def test_ethernet_interfaces_on_refresh(self): def test_ethernet_interfaces_on_refresh(self):
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'system_ethernet_interface_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.system_inst.ethernet_interfaces, self.assertIsInstance(
ethernet_interface.EthernetInterfaceCollection) self.system_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection,
)
# on refreshing the system instance... # on refreshing the system instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/system.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_inst.invalidate() self.system_inst.invalidate()
self.system_inst.refresh(force=False) self.system_inst.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'system_ethernet_interface_collection.json', 'r') as f: "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()) self.conn.get.return_value.son.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.system_inst.ethernet_interfaces, self.assertIsInstance(
ethernet_interface.EthernetInterfaceCollection) self.system_inst.ethernet_interfaces,
ethernet_interface.EthernetInterfaceCollection,
)
class SystemCollectionTestCase(testtools.TestCase): class SystemCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(SystemCollectionTestCase, self).setUp() super(SystemCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/' with open(
'system_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_col = system.SystemCollection( self.system_col = system.SystemCollection(
self.conn, '/redfish/v1/Systems', self.conn, "/redfish/v1/Systems", redfish_version="1.1.0"
redfish_version='1.1.0') )
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.1.0', self.system_col.redfish_version) self.assertEqual("1.1.0", self.system_col.redfish_version)
self.assertEqual(('/redfish/v1/Systems/System1', self.assertEqual(
'/redfish/v1/Systems/System2'), ("/redfish/v1/Systems/System1", "/redfish/v1/Systems/System2"),
self.system_col.members_identities) 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): def test_get_member(self, mock_system):
self.system_col.get_member( self.system_col.get_member("/redfish/v1/Systems/System1")
'/redfish/v1/Systems/System1')
mock_system.assert_called_once_with( mock_system.assert_called_once_with(
self.system_col._conn, self.system_col._conn,
'/redfish/v1/Systems/System1', "/redfish/v1/Systems/System1",
redfish_version=self.system_col.redfish_version, redfish_version=self.system_col.redfish_version,
registries=None, registries=None,
) )
@mock.patch.object(system, 'System', autospec=True) @mock.patch.object(system, "System", autospec=True)
def test_get_members(self, mock_system): def test_get_members(self, mock_system):
members = self.system_col.get_members() members = self.system_col.get_members()
calls = [ calls = [
mock.call( mock.call(
self.system_col._conn, self.system_col._conn,
'/redfish/v1/Systems/System1', "/redfish/v1/Systems/System1",
redfish_version=self.system_col.redfish_version, redfish_version=self.system_col.redfish_version,
registries=None, registries=None,
), ),
mock.call( mock.call(
self.system_col._conn, self.system_col._conn,
'/redfish/v1/Systems/System2', "/redfish/v1/Systems/System2",
redfish_version=self.system_col.redfish_version, redfish_version=self.system_col.redfish_version,
registries=None, registries=None,
) ),
] ]
mock_system.assert_has_calls(calls) mock_system.assert_has_calls(calls)
self.assertIsInstance(members, list) 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): class RSDLibV2_3TestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(RSDLibV2_3TestCase, self).setUp() super(RSDLibV2_3TestCase, self).setUp()
self.conn = mock.Mock() 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.conn.get.return_value.json.return_value = json.loads(f.read())
self.rsd = v2_3.RSDLibV2_3(self.conn) 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/Nodes", self.rsd._nodes_path)
self.assertEqual("/redfish/v1/Chassis", self.rsd._chassis_path) self.assertEqual("/redfish/v1/Chassis", self.rsd._chassis_path)
self.assertEqual("/redfish/v1/Fabrics", self.rsd._fabrics_path) self.assertEqual("/redfish/v1/Fabrics", self.rsd._fabrics_path)
self.assertEqual("/redfish/v1/StorageServices", self.assertEqual(
self.rsd._storage_service_path) "/redfish/v1/StorageServices", self.rsd._storage_service_path
)
self.assertEqual("/redfish/v1/Managers", self.rsd._managers_path) self.assertEqual("/redfish/v1/Managers", self.rsd._managers_path)
self.assertEqual("/redfish/v1/EthernetSwitches", self.assertEqual(
self.rsd._ethernet_switches_path) "/redfish/v1/EthernetSwitches", self.rsd._ethernet_switches_path
self.assertEqual("/redfish/v1/TelemetryService", )
self.rsd._telemetry_service_path) self.assertEqual(
self.assertEqual("/redfish/v1/TaskService", "/redfish/v1/TelemetryService", self.rsd._telemetry_service_path
self.rsd._task_service_path) )
self.assertEqual("/redfish/v1/Registries", self.assertEqual(
self.rsd._registries_path) "/redfish/v1/TaskService", self.rsd._task_service_path
self.assertEqual("/redfish/v1/UpdateService", )
self.rsd._update_service_path) self.assertEqual("/redfish/v1/Registries", self.rsd._registries_path)
self.assertEqual("/redfish/v1/EventService", self.assertEqual(
self.rsd._event_service_path) "/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): def test_get_system_collection(self, mock_system_collection):
self.rsd.get_system_collection() self.rsd.get_system_collection()
mock_system_collection.assert_called_once_with( mock_system_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Systems', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_system.assert_called_once_with(
self.rsd._conn, 'fake-system-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "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): def test_get_node_collection(self, mock_node_collection):
self.rsd.get_node_collection() self.rsd.get_node_collection()
mock_node_collection.assert_called_once_with( mock_node_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Nodes', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_node.assert_called_once_with(
self.rsd._conn, 'fake-node-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "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): def test_get_fabric_collection(self, mock_fabric_collection):
self.rsd.get_fabric_collection() self.rsd.get_fabric_collection()
mock_fabric_collection.assert_called_once_with( mock_fabric_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Fabrics', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_fabric.assert_called_once_with(
self.rsd._conn, 'fake-fabric-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "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): def test_get_chassis_collection(self, mock_chassis_collection):
self.rsd.get_chassis_collection() self.rsd.get_chassis_collection()
mock_chassis_collection.assert_called_once_with( mock_chassis_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Chassis', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_chassis.assert_called_once_with(
self.rsd._conn, 'fake-chassis-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "fake-chassis-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_3_storage_service, 'StorageServiceCollection', @mock.patch.object(
autospec=True) v2_3_storage_service, "StorageServiceCollection", autospec=True
def test_get_storage_service_collection(self, )
mock_storage_service_collection): def test_get_storage_service_collection(
self, mock_storage_service_collection
):
self.rsd.get_storage_service_collection() self.rsd.get_storage_service_collection()
mock_storage_service_collection.assert_called_once_with( mock_storage_service_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/StorageServices', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_storage_service.assert_called_once_with(
self.rsd._conn, 'fake-storage-service-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "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): def test_get_manager_collection(self, mock_manager_collection):
self.rsd.get_manager_collection() self.rsd.get_manager_collection()
mock_manager_collection.assert_called_once_with( mock_manager_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Managers', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_manager_service.assert_called_once_with(
self.rsd._conn, 'fake-manager-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version "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( @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): def test_get_registries_collection(self, mock_registries_collection):
self.rsd.get_registries_collection() self.rsd.get_registries_collection()
mock_registries_collection.assert_called_once_with( mock_registries_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Registries', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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
) )
@mock.patch.object(v2_2_update_service, 'UpdateService', autospec=True) @mock.patch.object(v2_1_registries, "MessageRegistryFile", autospec=True)
def test_get_update_service( def test_get_registries(self, mock_registries_service):
self, mock_update_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() self.rsd.get_update_service()
mock_update_service.assert_called_once_with( mock_update_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/UpdateService', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): def test_get_event_service(self, mock_event_service):
self.rsd.get_event_service() self.rsd.get_event_service()
mock_event_service.assert_called_once_with( mock_event_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/EventService', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/redfish/v1/EventService",
redfish_version=self.rsd.redfish_version,
)
# @mock.patch.object(v2_2_telemetry, 'Telemetry', autospec=True) # @mock.patch.object(v2_2_telemetry, 'Telemetry', autospec=True)
# def test_get_telemetry_service(self, mock_telemetry_service): # 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, return_value=v2_3_storage_service.storage_pool.StoragePool,
): ):
with open( with open(
"rsd_lib/tests/unit/json_samples/v2_3/storage_pool.json", "rsd_lib/tests/unit/json_samples/v2_3/storage_pool.json", "r"
"r"
) as f: ) as f:
self.conn.get.return_value.json.return_value = json.loads( self.conn.get.return_value.json.return_value = json.loads(
f.read() f.read()
) )
self.assertIsInstance( self.assertIsInstance(
self.rsd.get_resource( self.rsd.get_resource("/redfish/v1/TelemetryService"),
"/redfish/v1/TelemetryService"), v2_3_storage_service.storage_pool.StoragePool,
v2_3_storage_service.storage_pool.StoragePool
) )
def test_get_resource_with_no_class_match(self): 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): class EndpointTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(EndpointTestCase, self).setUp() super(EndpointTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/endpoint.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.endpoint_inst = endpoint.Endpoint( self.endpoint_inst = endpoint.Endpoint(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Endpoints/1', self.conn,
redfish_version='1.0.2') "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.endpoint_inst.redfish_version) self.assertEqual("1.0.2", self.endpoint_inst.redfish_version)
self.assertEqual('Fabric Endpoint', self.assertEqual("Fabric Endpoint", self.endpoint_inst.description)
self.endpoint_inst.description) self.assertEqual("1", self.endpoint_inst.identity)
self.assertEqual('1', self.endpoint_inst.identity) self.assertEqual("Fabric Endpoint", self.endpoint_inst.name)
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( self.assertEqual(
'Drive', self.endpoint_inst.connected_entities[0].entity_type) "Target", self.endpoint_inst.connected_entities[0].entity_role
)
self.assertEqual( self.assertEqual(
'UUID', "/redfish/v1/Chassis/PCIeSwitch1/Drives/Disk.Bay.0",
self.endpoint_inst.connected_entities[0].identifiers[0]. self.endpoint_inst.connected_entities[0].entity_link,
name_format) )
self.assertEqual( self.assertEqual(
'00000000-0000-0000-0000-000000000000', "Drive", self.endpoint_inst.connected_entities[0].entity_type
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( self.assertEqual(
'NVMeOverFabrics', self.endpoint_inst.endpoint_protocol) "UUID",
self.assertEqual('NQN', self.endpoint_inst.connected_entities[0]
self.endpoint_inst.identifiers[0].name_format) .identifiers[0]
self.assertEqual('nqn.2014-08.org.nvmexpress:NVMf:uuid:' .name_format,
'397f9b78-7e94-11e7-9ea4-001e67dfa170', )
self.endpoint_inst.identifiers[0].name) self.assertEqual(
self.assertEqual('UUID', "00000000-0000-0000-0000-000000000000",
self.endpoint_inst.identifiers[1].name_format) self.endpoint_inst.connected_entities[0].identifiers[0].name,
self.assertEqual('397f9b78-7e94-11e7-9ea4-001e67dfa170', )
self.endpoint_inst.identifiers[1].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( self.assertEqual(
('/redfish/v1/Fabrics/PCIe/Switches/1/Ports/Down1',), ("/redfish/v1/Fabrics/PCIe/Switches/1/Ports/Down1",),
self.endpoint_inst.links.ports) self.endpoint_inst.links.ports,
)
self.assertEqual( self.assertEqual(
('/redfish/v1/Fabrics/PCIe/Endpoints',), ("/redfish/v1/Fabrics/PCIe/Endpoints",),
self.endpoint_inst.links.endpoints) self.endpoint_inst.links.endpoints,
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Zones/1',), )
self.endpoint_inst.links.oem.intel_rackscale.zones)
self.assertEqual( self.assertEqual(
('/redfish/v1/Systems/Target/EthernetInterfaces/1',), ("/redfish/v1/Fabrics/NVMeoE/Zones/1",),
self.endpoint_inst.links.oem.intel_rackscale.interfaces) self.endpoint_inst.links.oem.intel_rackscale.zones,
)
self.assertEqual( self.assertEqual(
'RoCEv2', ("/redfish/v1/Systems/Target/EthernetInterfaces/1",),
self.endpoint_inst.ip_transport_details[0].transport_protocol) self.endpoint_inst.links.oem.intel_rackscale.interfaces,
)
self.assertEqual( self.assertEqual(
'192.168.0.10', "RoCEv2",
self.endpoint_inst.ip_transport_details[0].ipv4_address) self.endpoint_inst.ip_transport_details[0].transport_protocol,
)
self.assertEqual( 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(1023, self.endpoint_inst.ip_transport_details[0].port)
self.assertEqual( self.assertEqual(
None, self.endpoint_inst.oem.intel_rackscale.authentication) None, self.endpoint_inst.oem.intel_rackscale.authentication
)
self.assertEqual( self.assertEqual(
'FPGA-oF', "FPGA-oF", self.endpoint_inst.oem.intel_rackscale.endpoint_protocol
self.endpoint_inst.oem.intel_rackscale.endpoint_protocol) )
class EndpointCollectionTestCase(testtools.TestCase): class EndpointCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(EndpointCollectionTestCase, self).setUp() super(EndpointCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'endpoint_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
self.conn.post.return_value = request_fakes.fake_request_post( self.conn.post.return_value = request_fakes.fake_request_post(
None, headers={"Location": "https://localhost:8443/redfish/v1/" None,
"Fabrics/NVMeoE/Endpoints/3"}) headers={
"Location": "https://localhost:8443/redfish/v1/"
"Fabrics/NVMeoE/Endpoints/3"
},
)
self.endpoint_col = endpoint.EndpointCollection( self.endpoint_col = endpoint.EndpointCollection(
self.conn, '/redfish/v1/Fabrics/NVMeoE/Endpoints', self.conn,
redfish_version='1.0.2') "/redfish/v1/Fabrics/NVMeoE/Endpoints",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.endpoint_col.redfish_version) self.assertEqual("1.0.2", self.endpoint_col.redfish_version)
self.assertEqual('Endpoint Collection', self.assertEqual("Endpoint Collection", self.endpoint_col.name)
self.endpoint_col.name) self.assertEqual(
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE/Endpoints/1', (
'/redfish/v1/Fabrics/NVMeoE/Endpoints/2'), "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
self.endpoint_col.members_identities) "/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): def test_get_member(self, mock_endpoint):
self.endpoint_col.get_member( self.endpoint_col.get_member("/redfish/v1/Fabrics/NVMeoE/Endpoints/1")
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1')
mock_endpoint.assert_called_once_with( mock_endpoint.assert_called_once_with(
self.endpoint_col._conn, self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1', "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version=self.endpoint_col.redfish_version, redfish_version=self.endpoint_col.redfish_version,
registries=None, registries=None,
) )
@mock.patch.object(endpoint, 'Endpoint', autospec=True) @mock.patch.object(endpoint, "Endpoint", autospec=True)
def test_get_members(self, mock_endpoint): def test_get_members(self, mock_endpoint):
members = self.endpoint_col.get_members() members = self.endpoint_col.get_members()
calls = [ calls = [
mock.call( mock.call(
self.endpoint_col._conn, self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/1', "/redfish/v1/Fabrics/NVMeoE/Endpoints/1",
redfish_version=self.endpoint_col.redfish_version, redfish_version=self.endpoint_col.redfish_version,
registries=None, registries=None,
), ),
mock.call( mock.call(
self.endpoint_col._conn, self.endpoint_col._conn,
'/redfish/v1/Fabrics/NVMeoE/Endpoints/2', "/redfish/v1/Fabrics/NVMeoE/Endpoints/2",
redfish_version=self.endpoint_col.redfish_version, redfish_version=self.endpoint_col.redfish_version,
registries=None, registries=None,
) ),
] ]
mock_endpoint.assert_has_calls(calls) mock_endpoint.assert_has_calls(calls)
self.assertIsInstance(members, list) self.assertIsInstance(members, list)
@ -158,40 +187,35 @@ class EndpointCollectionTestCase(testtools.TestCase):
reqs = { reqs = {
"EndpointProtocol": "PCIe", "EndpointProtocol": "PCIe",
"ConnectedEntities": [ "ConnectedEntities": [
{ {"EntityRole": "Initiator", "EntityLink": None}
"EntityRole": "Initiator",
"EntityLink": None
}
], ],
"Links": { "Links": {
"Ports": [ "Ports": [
{ {
"@odata.id": "/redfish/v1/Fabrics/PCIe/Switches/1/" "@odata.id": "/redfish/v1/Fabrics/PCIe/Switches/1/"
"Ports/Up1" "Ports/Up1"
} }
] ]
} },
} }
result = self.endpoint_col.create_endpoint( result = self.endpoint_col.create_endpoint(
links={ links={
"Ports": [ "Ports": [
{ {
"@odata.id": "/redfish/v1/Fabrics/PCIe/Switches/1/" "@odata.id": "/redfish/v1/Fabrics/PCIe/Switches/1/"
"Ports/Up1" "Ports/Up1"
} }
] ]
}, },
connected_entities=[ connected_entities=[
{ {"EntityRole": "Initiator", "EntityLink": None}
"EntityRole": "Initiator",
"EntityLink": None
}
], ],
protocol="PCIe") protocol="PCIe",
)
self.endpoint_col._conn.post.assert_called_once_with( self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs) "/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
self.assertEqual(result, )
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3') self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
self.endpoint_col._conn.post.reset_mock() self.endpoint_col._conn.post.reset_mock()
reqs = { reqs = {
@ -201,10 +225,10 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityRole": "Target", "EntityRole": "Target",
"EntityLink": { "EntityLink": {
"@odata.id": "/redfish/v1/Systems/System1/Processors/" "@odata.id": "/redfish/v1/Systems/System1/Processors/"
"FPGA1" "FPGA1"
} },
} }
] ],
} }
result = self.endpoint_col.create_endpoint( result = self.endpoint_col.create_endpoint(
connected_entities=[ connected_entities=[
@ -212,60 +236,48 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityRole": "Target", "EntityRole": "Target",
"EntityLink": { "EntityLink": {
"@odata.id": "/redfish/v1/Systems/System1/Processors/" "@odata.id": "/redfish/v1/Systems/System1/Processors/"
"FPGA1" "FPGA1"
} },
} }
], ],
protocol="PCIe") protocol="PCIe",
)
self.endpoint_col._conn.post.assert_called_once_with( self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs) "/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
self.assertEqual(result, )
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3') self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
self.endpoint_col._conn.post.reset_mock() self.endpoint_col._conn.post.reset_mock()
reqs = { reqs = {
"EndpointProtocol": "OEM", "EndpointProtocol": "OEM",
"ConnectedEntities": [ "ConnectedEntities": [
{ {"EntityRole": "Initiator", "EntityLink": None}
"EntityRole": "Initiator",
"EntityLink": None
}
], ],
"Identifiers": [ "Identifiers": [
{ {
"DurableName": "12345678-90ab-cdef-0000-000000000000", "DurableName": "12345678-90ab-cdef-0000-000000000000",
"DurableNameFormat": "UUID" "DurableNameFormat": "UUID",
} }
], ],
"Oem": { "Oem": {"Intel_RackScale": {"EndpointProtocol": "FPGA-oF"}},
"Intel_RackScale": {
"EndpointProtocol": "FPGA-oF"
}
}
} }
result = self.endpoint_col.create_endpoint( result = self.endpoint_col.create_endpoint(
connected_entities=[ connected_entities=[
{ {"EntityRole": "Initiator", "EntityLink": None}
"EntityRole": "Initiator",
"EntityLink": None
}
], ],
protocol="OEM", protocol="OEM",
identifiers=[ identifiers=[
{ {
"DurableName": "12345678-90ab-cdef-0000-000000000000", "DurableName": "12345678-90ab-cdef-0000-000000000000",
"DurableNameFormat": "UUID" "DurableNameFormat": "UUID",
} }
], ],
oem={ oem={"Intel_RackScale": {"EndpointProtocol": "FPGA-oF"}},
"Intel_RackScale": { )
"EndpointProtocol": "FPGA-oF"
}
})
self.endpoint_col._conn.post.assert_called_once_with( self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs) "/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
self.assertEqual(result, )
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3') self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
self.endpoint_col._conn.post.reset_mock() self.endpoint_col._conn.post.reset_mock()
reqs = { reqs = {
@ -274,32 +286,26 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityRole": "Target", "EntityRole": "Target",
"EntityLink": { "EntityLink": {
"@odata.id": "/redfish/v1/Systems/System1/Processors/" "@odata.id": "/redfish/v1/Systems/System1/Processors/"
"FPGA1" "FPGA1"
} },
} }
], ],
"Identifiers": [ "Identifiers": [
{ {
"DurableName": "123e4567-e89b-12d3-a456-426655440000", "DurableName": "123e4567-e89b-12d3-a456-426655440000",
"DurableNameFormat": "UUID" "DurableNameFormat": "UUID",
} }
], ],
"IPTransportDetails": [ "IPTransportDetails": [
{ {
"TransportProtocol": "RoCEv2", "TransportProtocol": "RoCEv2",
"IPv4Address": { "IPv4Address": {"Address": "192.168.0.10"},
"Address": "192.168.0.10"
},
"IPv6Address": {}, "IPv6Address": {},
"Port": 4424 "Port": 4424,
} }
], ],
"EndpointProtocol": "OEM", "EndpointProtocol": "OEM",
"Oem": { "Oem": {"Intel_RackScale": {"EndpointProtocol": "FPGA-oF"}},
"Intel_RackScale": {
"EndpointProtocol": "FPGA-oF"
}
}
} }
result = self.endpoint_col.create_endpoint( result = self.endpoint_col.create_endpoint(
connected_entities=[ connected_entities=[
@ -307,43 +313,38 @@ class EndpointCollectionTestCase(testtools.TestCase):
"EntityRole": "Target", "EntityRole": "Target",
"EntityLink": { "EntityLink": {
"@odata.id": "/redfish/v1/Systems/System1/Processors/" "@odata.id": "/redfish/v1/Systems/System1/Processors/"
"FPGA1" "FPGA1"
} },
} }
], ],
identifiers=[ identifiers=[
{ {
"DurableName": "123e4567-e89b-12d3-a456-426655440000", "DurableName": "123e4567-e89b-12d3-a456-426655440000",
"DurableNameFormat": "UUID" "DurableNameFormat": "UUID",
} }
], ],
ip_transport_details=[ ip_transport_details=[
{ {
"TransportProtocol": "RoCEv2", "TransportProtocol": "RoCEv2",
"IPv4Address": { "IPv4Address": {"Address": "192.168.0.10"},
"Address": "192.168.0.10"
},
"IPv6Address": {}, "IPv6Address": {},
"Port": 4424 "Port": 4424,
} }
], ],
protocol="OEM", protocol="OEM",
oem={ oem={"Intel_RackScale": {"EndpointProtocol": "FPGA-oF"}},
"Intel_RackScale": { )
"EndpointProtocol": "FPGA-oF"
}
})
self.endpoint_col._conn.post.assert_called_once_with( self.endpoint_col._conn.post.assert_called_once_with(
'/redfish/v1/Fabrics/NVMeoE/Endpoints', data=reqs) "/redfish/v1/Fabrics/NVMeoE/Endpoints", data=reqs
self.assertEqual(result, )
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3') self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
def test_create_endpoint_with_invalid_reqs(self): def test_create_endpoint_with_invalid_reqs(self):
identifiers = [ identifiers = [
{ {
"DurableNameFormat": "iQN", "DurableNameFormat": "iQN",
"DurableName": "iqn.1986-03.com.intel:my_storage-uuid:" "DurableName": "iqn.1986-03.com.intel:my_storage-uuid:"
"397f9b78-7e94-11e7-9ea4-001e67dfa170" "397f9b78-7e94-11e7-9ea4-001e67dfa170",
} }
] ]
connected_entities = [ connected_entities = [
@ -353,59 +354,68 @@ class EndpointCollectionTestCase(testtools.TestCase):
}, },
"EntityRole": "Target", "EntityRole": "Target",
"Identifiers": [ "Identifiers": [
{ {"DurableNameFormat": "LUN", "DurableName": "1"}
"DurableNameFormat": "LUN", ],
"DurableName": "1"
}
]
} }
] ]
result = self.endpoint_col.create_endpoint( result = self.endpoint_col.create_endpoint(
identifiers=identifiers, connected_entities=connected_entities) identifiers=identifiers, connected_entities=connected_entities
self.assertEqual(result, )
'/redfish/v1/Fabrics/NVMeoE/Endpoints/3') self.assertEqual(result, "/redfish/v1/Fabrics/NVMeoE/Endpoints/3")
# Test invalid identifiers argument # Test invalid identifiers argument
invalid_identifiers = copy.deepcopy(identifiers) invalid_identifiers = copy.deepcopy(identifiers)
invalid_identifiers[0].pop('DurableNameFormat') invalid_identifiers[0].pop("DurableNameFormat")
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=invalid_identifiers, self.endpoint_col.create_endpoint,
connected_entities=connected_entities) identifiers=invalid_identifiers,
connected_entities=connected_entities,
)
invalid_identifiers = copy.deepcopy(identifiers) invalid_identifiers = copy.deepcopy(identifiers)
invalid_identifiers[0].pop('DurableName') invalid_identifiers[0].pop("DurableName")
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=invalid_identifiers, self.endpoint_col.create_endpoint,
connected_entities=connected_entities) identifiers=invalid_identifiers,
connected_entities=connected_entities,
)
# Test invalid connected_entities argument # Test invalid connected_entities argument
invalid_connected_entities = copy.deepcopy(connected_entities) invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0]['EntityRole'] = 'fake-format' invalid_connected_entities[0]["EntityRole"] = "fake-format"
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=identifiers, self.endpoint_col.create_endpoint,
connected_entities=invalid_connected_entities) identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
invalid_connected_entities = copy.deepcopy(connected_entities) invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0]['EntityLink'].pop('@odata.id') invalid_connected_entities[0]["EntityLink"].pop("@odata.id")
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=identifiers, self.endpoint_col.create_endpoint,
connected_entities=invalid_connected_entities) identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
invalid_connected_entities = copy.deepcopy(connected_entities) invalid_connected_entities = copy.deepcopy(connected_entities)
invalid_connected_entities[0].pop('EntityRole') invalid_connected_entities[0].pop("EntityRole")
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=identifiers, self.endpoint_col.create_endpoint,
connected_entities=invalid_connected_entities) identifiers=identifiers,
connected_entities=invalid_connected_entities,
)
# Test invalid protocol argument # Test invalid protocol argument
self.assertRaises(jsonschema.exceptions.ValidationError, self.assertRaises(
self.endpoint_col.create_endpoint, jsonschema.exceptions.ValidationError,
identifiers=identifiers, self.endpoint_col.create_endpoint,
connected_entities=connected_entities, identifiers=identifiers,
protocol=1) 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): class FabricTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(FabricTestCase, self).setUp() super(FabricTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/fabric.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst = fabric.Fabric( self.fabric_inst = fabric.Fabric(
self.conn, '/redfish/v1/Fabrics/NVMeoE', self.conn, "/redfish/v1/Fabrics/NVMeoE", redfish_version="1.0.2"
redfish_version='1.0.2') )
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.fabric_inst.redfish_version) self.assertEqual("1.0.2", self.fabric_inst.redfish_version)
self.assertEqual('NVMeoE', self.fabric_inst.identity) self.assertEqual("NVMeoE", self.fabric_inst.identity)
self.assertEqual(None, self.fabric_inst.name) 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(None, self.fabric_inst.max_zones)
self.assertEqual('Enabled', self.fabric_inst.status.state) self.assertEqual("Enabled", self.fabric_inst.status.state)
self.assertEqual('OK', self.fabric_inst.status.health) self.assertEqual("OK", self.fabric_inst.status.health)
self.assertEqual('OK', self.fabric_inst.status.health_rollup) self.assertEqual("OK", self.fabric_inst.status.health_rollup)
def test__get_endpoint_collection_path(self): 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() result = self.fabric_inst._get_endpoint_collection_path()
self.assertEqual(expected, result) self.assertEqual(expected, result)
def test__get_endpoint_collection_path_missing_attr(self): def test__get_endpoint_collection_path_missing_attr(self):
self.fabric_inst._json.pop('Endpoints') self.fabric_inst._json.pop("Endpoints")
self.assertRaisesRegex( self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Endpoints', exceptions.MissingAttributeError,
self.fabric_inst._get_endpoint_collection_path) "attribute Endpoints",
self.fabric_inst._get_endpoint_collection_path,
)
def test_endpoints(self): def test_endpoints(self):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'endpoint_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
actual_endpoints = self.fabric_inst.endpoints actual_endpoints = self.fabric_inst.endpoints
# | THEN | # | THEN |
self.assertIsInstance(actual_endpoints, self.assertIsInstance(actual_endpoints, endpoint.EndpointCollection)
endpoint.EndpointCollection)
self.conn.get.return_value.json.assert_called_once_with() self.conn.get.return_value.json.assert_called_once_with()
# reset mock # reset mock
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN | # | WHEN & THEN |
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_endpoints, self.assertIs(actual_endpoints, self.fabric_inst.endpoints)
self.fabric_inst.endpoints)
self.conn.get.return_value.json.assert_not_called() self.conn.get.return_value.json.assert_not_called()
def test_endpoints_on_refresh(self): def test_endpoints_on_refresh(self):
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'endpoint_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.endpoints, self.assertIsInstance(
endpoint.EndpointCollection) self.fabric_inst.endpoints, endpoint.EndpointCollection
)
# On refreshing the fabric instance... # On refreshing the fabric instance...
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'fabric.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst.invalidate() self.fabric_inst.invalidate()
self.fabric_inst.refresh(force=False) self.fabric_inst.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'endpoint_collection.json', 'r') as f: "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.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.endpoints, self.assertIsInstance(
endpoint.EndpointCollection) self.fabric_inst.endpoints, endpoint.EndpointCollection
)
def test__get_zone_collection_path(self): 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() result = self.fabric_inst._get_zone_collection_path()
self.assertEqual(expected, result) self.assertEqual(expected, result)
def test__get_zone_collection_path_missing_attr(self): def test__get_zone_collection_path_missing_attr(self):
self.fabric_inst._json.pop('Zones') self.fabric_inst._json.pop("Zones")
self.assertRaisesRegex( self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Zones', exceptions.MissingAttributeError,
self.fabric_inst._get_zone_collection_path) "attribute Zones",
self.fabric_inst._get_zone_collection_path,
)
def test_zones(self): def test_zones(self):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'zone_collection.json', 'r') as f: "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()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
actual_zones = self.fabric_inst.zones actual_zones = self.fabric_inst.zones
# | THEN | # | THEN |
self.assertIsInstance(actual_zones, self.assertIsInstance(actual_zones, zone.ZoneCollection)
zone.ZoneCollection)
self.conn.get.return_value.json.assert_called_once_with() self.conn.get.return_value.json.assert_called_once_with()
# reset mock # reset mock
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN | # | WHEN & THEN |
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_zones, self.assertIs(actual_zones, self.fabric_inst.zones)
self.fabric_inst.zones)
self.conn.get.return_value.json.assert_not_called() self.conn.get.return_value.json.assert_not_called()
def test_zones_on_refresh(self): def test_zones_on_refresh(self):
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'zone_collection.json', 'r') as f: "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()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.zones, self.assertIsInstance(self.fabric_inst.zones, zone.ZoneCollection)
zone.ZoneCollection)
# On refreshing the fabric instance... # On refreshing the fabric instance...
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'fabric.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst.invalidate() self.fabric_inst.invalidate()
self.fabric_inst.refresh(force=False) self.fabric_inst.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'zone_collection.json', 'r') as f: "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()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.fabric_inst.zones, self.assertIsInstance(self.fabric_inst.zones, zone.ZoneCollection)
zone.ZoneCollection)
class FabricCollectionTestCase(testtools.TestCase): class FabricCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(FabricCollectionTestCase, self).setUp() super(FabricCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'fabric_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_col = fabric.FabricCollection( 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): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.fabric_col.redfish_version) self.assertEqual("1.0.2", self.fabric_col.redfish_version)
self.assertEqual('Fabric Collection', self.assertEqual("Fabric Collection", self.fabric_col.name)
self.fabric_col.name) self.assertEqual(
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE',), ("/redfish/v1/Fabrics/NVMeoE",), self.fabric_col.members_identities
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): 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( 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, redfish_version=self.fabric_col.redfish_version,
registries=None, registries=None,
) )
@mock.patch.object(fabric, 'Fabric', autospec=True) @mock.patch.object(fabric, "Fabric", autospec=True)
def test_get_members(self, mock_fabric): def test_get_members(self, mock_fabric):
members = self.fabric_col.get_members() members = self.fabric_col.get_members()
mock_fabric.assert_called_once_with( 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, redfish_version=self.fabric_col.redfish_version,
registries=None, 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): class StorageServiceTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(StorageServiceTestCase, self).setUp() super(StorageServiceTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/storage_service.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_inst = storage_service.StorageService( self.storage_service_inst = storage_service.StorageService(
self.conn, '/redfish/v1/StorageServices/NVMeoE1', self.conn,
redfish_version='1.0.2') "/redfish/v1/StorageServices/NVMeoE1",
redfish_version="1.0.2",
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.storage_service_inst.redfish_version) self.assertEqual("1.0.2", self.storage_service_inst.redfish_version)
self.assertEqual('Storage Service description', self.assertEqual(
self.storage_service_inst.description) "Storage Service description",
self.assertEqual('NVMeoE1', self.storage_service_inst.identity) self.storage_service_inst.description,
self.assertEqual('Storage Service', self.storage_service_inst.name) )
self.assertEqual('Enabled', self.storage_service_inst.status.state) self.assertEqual("NVMeoE1", self.storage_service_inst.identity)
self.assertEqual('OK', self.storage_service_inst.status.health) self.assertEqual("Storage Service", self.storage_service_inst.name)
self.assertEqual('OK', self.storage_service_inst.status.health_rollup) 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): 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() result = self.storage_service_inst._get_volume_collection_path()
self.assertEqual(expected, result) self.assertEqual(expected, result)
def test__get_volume_collection_path_missing_processors_attr(self): 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( self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Volumes', exceptions.MissingAttributeError,
self.storage_service_inst._get_volume_collection_path) "attribute Volumes",
self.storage_service_inst._get_volume_collection_path,
)
def test_volumes(self): def test_volumes(self):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'volume_collection.json', 'r') as f: "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()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
actual_volumes = self.storage_service_inst.volumes actual_volumes = self.storage_service_inst.volumes
# | THEN | # | THEN |
self.assertIsInstance(actual_volumes, self.assertIsInstance(actual_volumes, volume.VolumeCollection)
volume.VolumeCollection)
self.conn.get.return_value.json.assert_called_once_with() self.conn.get.return_value.json.assert_called_once_with()
# reset mock # reset mock
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN | # | WHEN & THEN |
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_volumes, self.assertIs(actual_volumes, self.storage_service_inst.volumes)
self.storage_service_inst.volumes)
self.conn.get.return_value.json.assert_not_called() self.conn.get.return_value.json.assert_not_called()
def test_volumes_on_refresh(self): def test_volumes_on_refresh(self):
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'volume_collection.json', 'r') as f: "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()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.volumes, self.assertIsInstance(
volume.VolumeCollection) self.storage_service_inst.volumes, volume.VolumeCollection
)
# On refreshing the storage service instance... # On refreshing the storage service instance...
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'storage_service.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_inst.invalidate() self.storage_service_inst.invalidate()
self.storage_service_inst.refresh(force=False) self.storage_service_inst.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'volume_collection.json', 'r') as f: "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()) self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.storage_service_inst.volumes, self.assertIsInstance(
volume.VolumeCollection) self.storage_service_inst.volumes, volume.VolumeCollection
)
class StorageServiceCollectionTestCase(testtools.TestCase): class StorageServiceCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(StorageServiceCollectionTestCase, self).setUp() super(StorageServiceCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'storage_service_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.storage_service_col = storage_service.StorageServiceCollection( 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): def test__parse_attributes(self):
self.assertEqual('1.0.2', self.storage_service_col.redfish_version) self.assertEqual("1.0.2", self.storage_service_col.redfish_version)
self.assertEqual('Storage Services Collection', self.assertEqual(
self.storage_service_col.name) "Storage Services Collection", self.storage_service_col.name
self.assertEqual(('/redfish/v1/StorageServices/NVMeoE1',), )
self.storage_service_col.members_identities) 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): def test_get_member(self, mock_storage_service):
self.storage_service_col.get_member( self.storage_service_col.get_member(
'/redfish/v1/StorageServices/NVMeoE1') "/redfish/v1/StorageServices/NVMeoE1"
)
mock_storage_service.assert_called_once_with( mock_storage_service.assert_called_once_with(
self.storage_service_col._conn, self.storage_service_col._conn,
'/redfish/v1/StorageServices/NVMeoE1', "/redfish/v1/StorageServices/NVMeoE1",
redfish_version=self.storage_service_col.redfish_version, redfish_version=self.storage_service_col.redfish_version,
registries=None, 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): def test_get_members(self, mock_storage_service):
members = self.storage_service_col.get_members() members = self.storage_service_col.get_members()
mock_storage_service.assert_called_once_with( mock_storage_service.assert_called_once_with(
self.storage_service_col._conn, self.storage_service_col._conn,
'/redfish/v1/StorageServices/NVMeoE1', "/redfish/v1/StorageServices/NVMeoE1",
redfish_version=self.storage_service_col.redfish_version, redfish_version=self.storage_service_col.redfish_version,
registries=None) registries=None,
)
self.assertIsInstance(members, list) self.assertIsInstance(members, list)
self.assertEqual(1, len(members)) self.assertEqual(1, len(members))

View File

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

View File

@ -22,110 +22,121 @@ from rsd_lib.resources.v2_4.system import system
class SystemTestCase(testtools.TestCase): class SystemTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(SystemTestCase, self).setUp() super(SystemTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/system.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_inst = system.System( self.system_inst = system.System(
self.conn, '/redfish/v1/Systems/System1', self.conn, "/redfish/v1/Systems/System1", redfish_version="1.0.2"
redfish_version='1.0.2') )
def test_processors(self): def test_processors(self):
# | GIVEN | # | GIVEN |
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'processor_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN | # | WHEN |
actual_processors = self.system_inst.processors actual_processors = self.system_inst.processors
# | THEN | # | THEN |
self.assertIsInstance(actual_processors, self.assertIsInstance(actual_processors, processor.ProcessorCollection)
processor.ProcessorCollection)
self.conn.get.return_value.json.assert_called_once_with() self.conn.get.return_value.json.assert_called_once_with()
# reset mock # reset mock
self.conn.get.return_value.json.reset_mock() self.conn.get.return_value.json.reset_mock()
# | WHEN & THEN | # | WHEN & THEN |
# tests for same object on invoking subsequently # tests for same object on invoking subsequently
self.assertIs(actual_processors, self.assertIs(actual_processors, self.system_inst.processors)
self.system_inst.processors)
self.conn.get.return_value.json.assert_not_called() self.conn.get.return_value.json.assert_not_called()
def test_processors_on_refresh(self): def test_processors_on_refresh(self):
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'processor_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.system_inst.processors, self.assertIsInstance(
processor.ProcessorCollection) self.system_inst.processors, processor.ProcessorCollection
)
# On refreshing the system instance... # On refreshing the system instance...
with open('rsd_lib/tests/unit/json_samples/v2_4/system.json', with open(
'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_inst.invalidate() self.system_inst.invalidate()
self.system_inst.refresh(force=False) self.system_inst.refresh(force=False)
# | GIVEN | # | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'processor_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN | # | WHEN & THEN |
self.assertIsInstance(self.system_inst.processors, self.assertIsInstance(
processor.ProcessorCollection) self.system_inst.processors, processor.ProcessorCollection
)
class SystemCollectionTestCase(testtools.TestCase): class SystemCollectionTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(SystemCollectionTestCase, self).setUp() super(SystemCollectionTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/' with open(
'system_collection.json', 'r') as f: "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.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_col = system.SystemCollection( self.system_col = system.SystemCollection(
self.conn, '/redfish/v1/Systems', self.conn, "/redfish/v1/Systems", redfish_version="1.1.0"
redfish_version='1.1.0') )
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual('1.1.0', self.system_col.redfish_version) self.assertEqual("1.1.0", self.system_col.redfish_version)
self.assertEqual(('/redfish/v1/Systems/System1', self.assertEqual(
'/redfish/v1/Systems/System2'), ("/redfish/v1/Systems/System1", "/redfish/v1/Systems/System2"),
self.system_col.members_identities) 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): def test_get_member(self, mock_system):
self.system_col.get_member( self.system_col.get_member("/redfish/v1/Systems/System1")
'/redfish/v1/Systems/System1')
mock_system.assert_called_once_with( mock_system.assert_called_once_with(
self.system_col._conn, self.system_col._conn,
'/redfish/v1/Systems/System1', "/redfish/v1/Systems/System1",
redfish_version=self.system_col.redfish_version, redfish_version=self.system_col.redfish_version,
registries=None, registries=None,
) )
@mock.patch.object(system, 'System', autospec=True) @mock.patch.object(system, "System", autospec=True)
def test_get_members(self, mock_system): def test_get_members(self, mock_system):
members = self.system_col.get_members() members = self.system_col.get_members()
calls = [ calls = [
mock.call( mock.call(
self.system_col._conn, self.system_col._conn,
'/redfish/v1/Systems/System1', "/redfish/v1/Systems/System1",
redfish_version=self.system_col.redfish_version, redfish_version=self.system_col.redfish_version,
registries=None, registries=None,
), ),
mock.call( mock.call(
self.system_col._conn, self.system_col._conn,
'/redfish/v1/Systems/System2', "/redfish/v1/Systems/System2",
redfish_version=self.system_col.redfish_version, redfish_version=self.system_col.redfish_version,
registries=None, registries=None,
) ),
] ]
mock_system.assert_has_calls(calls) mock_system.assert_has_calls(calls)
self.assertIsInstance(members, list) 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): class RSDLibV2_3TestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(RSDLibV2_3TestCase, self).setUp() super(RSDLibV2_3TestCase, self).setUp()
self.conn = mock.Mock() 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.conn.get.return_value.json.return_value = json.loads(f.read())
self.rsd = v2_4.RSDLibV2_4(self.conn) 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/Nodes", self.rsd._nodes_path)
self.assertEqual("/redfish/v1/Chassis", self.rsd._chassis_path) self.assertEqual("/redfish/v1/Chassis", self.rsd._chassis_path)
self.assertEqual("/redfish/v1/Fabrics", self.rsd._fabrics_path) self.assertEqual("/redfish/v1/Fabrics", self.rsd._fabrics_path)
self.assertEqual("/redfish/v1/StorageServices", self.assertEqual(
self.rsd._storage_service_path) "/redfish/v1/StorageServices", self.rsd._storage_service_path
)
self.assertEqual("/redfish/v1/Managers", self.rsd._managers_path) self.assertEqual("/redfish/v1/Managers", self.rsd._managers_path)
self.assertEqual("/redfish/v1/EthernetSwitches", self.assertEqual(
self.rsd._ethernet_switches_path) "/redfish/v1/EthernetSwitches", self.rsd._ethernet_switches_path
self.assertEqual("/redfish/v1/TelemetryService", )
self.rsd._telemetry_service_path) self.assertEqual(
self.assertEqual("/redfish/v1/TaskService", "/redfish/v1/TelemetryService", self.rsd._telemetry_service_path
self.rsd._task_service_path) )
self.assertEqual("/redfish/v1/Registries", self.assertEqual(
self.rsd._registries_path) "/redfish/v1/TaskService", self.rsd._task_service_path
self.assertEqual("/redfish/v1/UpdateService", )
self.rsd._update_service_path) self.assertEqual("/redfish/v1/Registries", self.rsd._registries_path)
self.assertEqual("/redfish/v1/EventService", self.assertEqual(
self.rsd._event_service_path) "/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): def test_get_system_collection(self, mock_system_collection):
self.rsd.get_system_collection() self.rsd.get_system_collection()
mock_system_collection.assert_called_once_with( mock_system_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Systems', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_system.assert_called_once_with(
self.rsd._conn, 'fake-system-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "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): def test_get_node_collection(self, mock_node_collection):
self.rsd.get_node_collection() self.rsd.get_node_collection()
mock_node_collection.assert_called_once_with( mock_node_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Nodes', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_node.assert_called_once_with(
self.rsd._conn, 'fake-node-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "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): def test_get_fabric_collection(self, mock_fabric_collection):
self.rsd.get_fabric_collection() self.rsd.get_fabric_collection()
mock_fabric_collection.assert_called_once_with( mock_fabric_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Fabrics', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_fabric.assert_called_once_with(
self.rsd._conn, 'fake-fabric-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "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): def test_get_chassis_collection(self, mock_chassis_collection):
self.rsd.get_chassis_collection() self.rsd.get_chassis_collection()
mock_chassis_collection.assert_called_once_with( mock_chassis_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Chassis', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_chassis.assert_called_once_with(
self.rsd._conn, 'fake-chassis-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "fake-chassis-id",
redfish_version=self.rsd.redfish_version,
)
@mock.patch.object(v2_4_storage_service, 'StorageServiceCollection', @mock.patch.object(
autospec=True) v2_4_storage_service, "StorageServiceCollection", autospec=True
def test_get_storage_service_collection(self, )
mock_storage_service_collection): def test_get_storage_service_collection(
self, mock_storage_service_collection
):
self.rsd.get_storage_service_collection() self.rsd.get_storage_service_collection()
mock_storage_service_collection.assert_called_once_with( mock_storage_service_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/StorageServices', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_storage_service.assert_called_once_with(
self.rsd._conn, 'fake-storage-service-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "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): def test_get_manager_collection(self, mock_manager_collection):
self.rsd.get_manager_collection() self.rsd.get_manager_collection()
mock_manager_collection.assert_called_once_with( mock_manager_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Managers', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): 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( mock_manager_service.assert_called_once_with(
self.rsd._conn, 'fake-manager-id', self.rsd._conn,
redfish_version=self.rsd.redfish_version "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( @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): def test_get_registries_collection(self, mock_registries_collection):
self.rsd.get_registries_collection() self.rsd.get_registries_collection()
mock_registries_collection.assert_called_once_with( mock_registries_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Registries', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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
) )
@mock.patch.object(v2_2_update_service, 'UpdateService', autospec=True) @mock.patch.object(v2_1_registries, "MessageRegistryFile", autospec=True)
def test_get_update_service( def test_get_registries(self, mock_registries_service):
self, mock_update_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() self.rsd.get_update_service()
mock_update_service.assert_called_once_with( mock_update_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/UpdateService', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/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): def test_get_event_service(self, mock_event_service):
self.rsd.get_event_service() self.rsd.get_event_service()
mock_event_service.assert_called_once_with( mock_event_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/EventService', self.rsd._conn,
redfish_version=self.rsd.redfish_version) "/redfish/v1/EventService",
redfish_version=self.rsd.redfish_version,
)
# @mock.patch.object(v2_2_telemetry, 'Telemetry', autospec=True) # @mock.patch.object(v2_2_telemetry, 'Telemetry', autospec=True)
# def test_get_telemetry_service(self, mock_telemetry_service): # 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): class RSDLibTestCase(testtools.TestCase):
@mock.patch.object(connector, "Connector", autospec=True)
@mock.patch.object(connector, 'Connector', autospec=True)
def setUp(self, mock_connector): def setUp(self, mock_connector):
super(RSDLibTestCase, self).setUp() super(RSDLibTestCase, self).setUp()
self.conn = mock.Mock() self.conn = mock.Mock()
mock_connector.return_value = self.conn 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.conn.get.return_value.json.return_value = json.loads(f.read())
self.rsd = main.RSDLib('http://foo.bar:8442', username='foo', self.rsd = main.RSDLib(
password='bar', verify=True) "http://foo.bar:8442", username="foo", password="bar", verify=True
)
def test__parse_attributes(self): def test__parse_attributes(self):
self.assertEqual("2.1.0", self.rsd._rsd_api_version) self.assertEqual("2.1.0", self.rsd._rsd_api_version)
self.assertEqual("1.0.2", self.rsd._redfish_version) self.assertEqual("1.0.2", self.rsd._redfish_version)
@mock.patch.object(v2_4, 'RSDLibV2_4', autospec=True) @mock.patch.object(v2_4, "RSDLibV2_4", autospec=True)
@mock.patch.object(v2_3, 'RSDLibV2_3', autospec=True) @mock.patch.object(v2_3, "RSDLibV2_3", autospec=True)
@mock.patch.object(v2_2, 'RSDLibV2_2', autospec=True) @mock.patch.object(v2_2, "RSDLibV2_2", autospec=True)
@mock.patch.object(v2_1, 'RSDLibV2_1', autospec=True) @mock.patch.object(v2_1, "RSDLibV2_1", autospec=True)
def test_factory(self, mock_rsdlibv2_1, mock_rsdlibv2_2, mock_rsdlibv2_3, def test_factory(
mock_rsdlibv2_4): self,
mock_rsdlibv2_1,
mock_rsdlibv2_2,
mock_rsdlibv2_3,
mock_rsdlibv2_4,
):
self.rsd.factory() self.rsd.factory()
mock_rsdlibv2_1.assert_called_once_with( mock_rsdlibv2_1.assert_called_once_with(
self.rsd._conn, self.rsd._conn,
self.rsd._root_prefix, 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._rsd_api_version = "2.2.0"
self.rsd.factory() self.rsd.factory()
mock_rsdlibv2_2.assert_called_once_with( mock_rsdlibv2_2.assert_called_once_with(
self.rsd._conn, self.rsd._conn,
self.rsd._root_prefix, 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._rsd_api_version = "2.3.0"
self.rsd.factory() self.rsd.factory()
mock_rsdlibv2_3.assert_called_once_with( mock_rsdlibv2_3.assert_called_once_with(
self.rsd._conn, self.rsd._conn,
self.rsd._root_prefix, 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._rsd_api_version = "2.4.0"
self.rsd.factory() self.rsd.factory()
mock_rsdlibv2_4.assert_called_once_with( mock_rsdlibv2_4.assert_called_once_with(
self.rsd._conn, self.rsd._conn,
self.rsd._root_prefix, self.rsd._root_prefix,
redfish_version=self.rsd._redfish_version) redfish_version=self.rsd._redfish_version,
)
def test_factory_unsupported_version(self): def test_factory_unsupported_version(self):
self.rsd._rsd_api_version = "10.0.0" self.rsd._rsd_api_version = "10.0.0"
expected_error_message = "The rsd-lib library doesn't support RSD "\ expected_error_message = (
"API version 10.0.0." "The rsd-lib library doesn't support RSD API version 10.0.0."
)
with self.assertRaisesRegex(NotImplementedError, with self.assertRaisesRegex(
expected_error_message): NotImplementedError, expected_error_message
):
self.rsd.factory() self.rsd.factory()

View File

@ -21,21 +21,22 @@ from rsd_lib import utils as rsd_lib_utils
class UtilsTestCase(testtools.TestCase): class UtilsTestCase(testtools.TestCase):
def test_get_resource_identity(self): def test_get_resource_identity(self):
self.assertIsNone(rsd_lib_utils.get_resource_identity(None)) self.assertIsNone(rsd_lib_utils.get_resource_identity(None))
self.assertIsNone(rsd_lib_utils.get_resource_identity({})) self.assertIsNone(rsd_lib_utils.get_resource_identity({}))
self.assertEqual( self.assertEqual(
'/redfish/v1/Systems/437XR1138R2/BIOS', "/redfish/v1/Systems/437XR1138R2/BIOS",
rsd_lib_utils.get_resource_identity({ rsd_lib_utils.get_resource_identity(
"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS"})) {"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS"}
),
)
def test_num_or_none(self): def test_num_or_none(self):
self.assertIsNone(rsd_lib_utils.num_or_none(None)) self.assertIsNone(rsd_lib_utils.num_or_none(None))
self.assertEqual(0, rsd_lib_utils.num_or_none('0')) self.assertEqual(0, rsd_lib_utils.num_or_none("0"))
self.assertEqual(1, rsd_lib_utils.num_or_none('1')) self.assertEqual(1, rsd_lib_utils.num_or_none("1"))
self.assertEqual(10, rsd_lib_utils.num_or_none('10.0')) 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(12.5, rsd_lib_utils.num_or_none("12.5"))
self.assertEqual(0, rsd_lib_utils.num_or_none(0)) self.assertEqual(0, rsd_lib_utils.num_or_none(0))
self.assertEqual(1, rsd_lib_utils.num_or_none(1)) self.assertEqual(1, rsd_lib_utils.num_or_none(1))
self.assertEqual(10, rsd_lib_utils.num_or_none(10.0)) self.assertEqual(10, rsd_lib_utils.num_or_none(10.0))
@ -46,7 +47,7 @@ class UtilsTestCase(testtools.TestCase):
"Links": { "Links": {
"PCIeDevices": [ "PCIeDevices": [
{"@data.id": "/redfish/v1/Chassis/1/PCIeDevices/Device1"}, {"@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, ValueError,
rsd_lib_utils.get_sub_resource_path_list_by, rsd_lib_utils.get_sub_resource_path_list_by,
mock_resource, mock_resource,
None) 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"]))
) )
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( self.assertRaises(
exceptions.MissingAttributeError, exceptions.MissingAttributeError,
rsd_lib_utils.get_sub_resource_path_list_by, rsd_lib_utils.get_sub_resource_path_list_by,
mock_resource, mock_resource,
'Links' "Links",
) )
def test_camelcase_to_underscore_joined(self): def test_camelcase_to_underscore_joined(self):
input_vs_expected = [ input_vs_expected = [
('GarbageCollection', 'garbage_collection'), ("GarbageCollection", "garbage_collection"),
('DD', 'dd'), ("DD", "dd"),
('rr', 'rr'), ("rr", "rr"),
('AABbbC', 'aa_bbb_c'), ("AABbbC", "aa_bbb_c"),
('AABbbCCCDd', 'aa_bbb_ccc_dd'), ("AABbbCCCDd", "aa_bbb_ccc_dd"),
('Manager', 'manager'), ("Manager", "manager"),
('EthernetInterfaceCollection', 'ethernet_interface_collection'), ("EthernetInterfaceCollection", "ethernet_interface_collection"),
(' ', ' '), (" ", " "),
] ]
for inp, exp in input_vs_expected: for inp, exp in input_vs_expected:
self.assertEqual( 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): def test_camelcase_to_underscore_joined_fails_with_empty_string(self):
self.assertRaisesRegex( self.assertRaisesRegex(
ValueError, ValueError,
'"camelcase_str" cannot be empty', '"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: if resource is None:
return None return None
else: else:
return resource.get('@odata.id', None) return resource.get("@odata.id", None)
def num_or_none(x): def num_or_none(x):
@ -62,9 +62,10 @@ def get_sub_resource_path_list_by(resource, subresource_name):
if not body: if not body:
raise exceptions.MissingAttributeError( 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 # 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): for i, letter in enumerate(camelcase_str[1:], 1):
if letter.isupper(): if letter.isupper():
try: try:
if (camelcase_str[i - 1].islower() if (
or camelcase_str[i + 1].islower()): camelcase_str[i - 1].islower()
r += '_' or camelcase_str[i + 1].islower()
):
r += "_"
except IndexError: except IndexError:
pass pass