diff --git a/proliantutils/redfish/resources/account_service/account_service.py b/proliantutils/redfish/resources/account_service/account_service.py index 21e56748..53a9506a 100644 --- a/proliantutils/redfish/resources/account_service/account_service.py +++ b/proliantutils/redfish/resources/account_service/account_service.py @@ -13,6 +13,7 @@ # under the License. from sushy.resources import base +from sushy import utils as sushy_utils from proliantutils.redfish.resources.account_service import account from proliantutils.redfish import utils @@ -25,29 +26,10 @@ class HPEAccountService(base.ResourceBase): from sushy """ - _accounts = None - @property + @sushy_utils.cache_it def accounts(self): - """Property to provide instance of HPEAccountCollection - - """ - if self._accounts is None: - self._accounts = account.HPEAccountCollection( - self._conn, utils.get_subresource_path_by(self, 'Accounts'), - redfish_version=self.redfish_version) - - self._accounts.refresh(force=False) - return self._accounts - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - super(HPEAccountService, self)._do_refresh(force) - - if self._accounts is not None: - self._accounts.invalidate(force) + """Property to provide instance of HPEAccountCollection""" + return account.HPEAccountCollection( + self._conn, utils.get_subresource_path_by(self, 'Accounts'), + redfish_version=self.redfish_version) diff --git a/proliantutils/redfish/resources/manager/manager.py b/proliantutils/redfish/resources/manager/manager.py index c3d6d31a..38cd85bf 100644 --- a/proliantutils/redfish/resources/manager/manager.py +++ b/proliantutils/redfish/resources/manager/manager.py @@ -15,6 +15,7 @@ __author__ = 'HPE' from sushy.resources.manager import manager +from sushy import utils as sushy_utils from proliantutils.redfish.resources.manager import virtual_media from proliantutils.redfish import utils @@ -27,8 +28,6 @@ class HPEManager(manager.Manager): from sushy """ - _virtual_media = None - def set_license(self, key): """Set the license on a redfish system @@ -40,29 +39,13 @@ class HPEManager(manager.Manager): self._conn.post(license_service_uri, data=data) @property + @sushy_utils.cache_it def virtual_media(self): """Property to provide reference to `VirtualMediaCollection` instance. It is calculated once when the first time it is queried. On refresh, this property gets reset. """ - if self._virtual_media is None: - self._virtual_media = virtual_media.VirtualMediaCollection( - self._conn, - utils.get_subresource_path_by(self, 'VirtualMedia'), - redfish_version=self.redfish_version) - - self._virtual_media.refresh(force=False) - return self._virtual_media - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - super(HPEManager, self)._do_refresh(force) - - if self._virtual_media is not None: - self._virtual_media.invalidate(force) + return virtual_media.VirtualMediaCollection( + self._conn, utils.get_subresource_path_by(self, 'VirtualMedia'), + redfish_version=self.redfish_version) diff --git a/proliantutils/redfish/resources/system/bios.py b/proliantutils/redfish/resources/system/bios.py index c45b7c45..5983e87b 100644 --- a/proliantutils/redfish/resources/system/bios.py +++ b/proliantutils/redfish/resources/system/bios.py @@ -14,6 +14,7 @@ import sushy from sushy.resources import base +from sushy import utils as sushy_utils from proliantutils import exception from proliantutils import log @@ -46,29 +47,18 @@ class BIOSSettings(base.ResourceBase): cpu_vt = base.MappedField(["Attributes", "ProcVirtualization"], mappings.CPUVT_MAP) - _iscsi_resource = None - _bios_mappings = None - - _pending_settings = None - _boot_settings = None - _base_configs = None - @property + @sushy_utils.cache_it def pending_settings(self): """Property to provide reference to bios_pending_settings instance It is calculated once when the first time it is queried. On refresh, this property gets reset. """ - if self._pending_settings is None: - self._pending_settings = BIOSPendingSettings( - self._conn, - utils.get_subresource_path_by( - self, ["@Redfish.Settings", "SettingsObject"]), - redfish_version=self.redfish_version) - - self._pending_settings.refresh(force=False) - return self._pending_settings + return BIOSPendingSettings( + self._conn, utils.get_subresource_path_by( + self, ["@Redfish.Settings", "SettingsObject"]), + redfish_version=self.redfish_version) @property def default_settings(self): @@ -79,90 +69,57 @@ class BIOSSettings(base.ResourceBase): return self._get_base_configs().default_config @property + @sushy_utils.cache_it def boot_settings(self): """Property to provide reference to bios boot instance It is calculated once when the first time it is queried. On refresh, this property gets reset. """ - if self._boot_settings is None: - self._boot_settings = BIOSBootSettings( - self._conn, - utils.get_subresource_path_by( - self, ["Oem", "Hpe", "Links", "Boot"]), - redfish_version=self.redfish_version) - - self._boot_settings.refresh(force=False) - return self._boot_settings + return BIOSBootSettings( + self._conn, utils.get_subresource_path_by( + self, ["Oem", "Hpe", "Links", "Boot"]), + redfish_version=self.redfish_version) @property + @sushy_utils.cache_it def iscsi_resource(self): """Property to provide reference to bios iscsi resource instance It is calculated once when the first time it is queried. On refresh, this property gets reset. """ - if self._iscsi_resource is None: - self._iscsi_resource = iscsi.ISCSIResource( - self._conn, - utils.get_subresource_path_by( - self, ["Oem", "Hpe", "Links", "iScsi"]), - redfish_version=self.redfish_version) - - self._iscsi_resource.refresh(force=False) - return self._iscsi_resource + return iscsi.ISCSIResource( + self._conn, utils.get_subresource_path_by( + self, ["Oem", "Hpe", "Links", "iScsi"]), + redfish_version=self.redfish_version) @property + @sushy_utils.cache_it def bios_mappings(self): """Property to provide reference to bios mappings instance It is calculated once when the first time it is queried. On refresh, this property gets reset. """ - if self._bios_mappings is None: - self._bios_mappings = BIOSMappings( - self._conn, - utils.get_subresource_path_by( - self, ["Oem", "Hpe", "Links", "Mappings"]), - redfish_version=self.redfish_version) - - self._bios_mappings.refresh(force=False) - return self._bios_mappings + return BIOSMappings( + self._conn, utils.get_subresource_path_by( + self, ["Oem", "Hpe", "Links", "Mappings"]), + redfish_version=self.redfish_version) + @sushy_utils.cache_it def _get_base_configs(self): """Method that returns object of bios base configs.""" - if self._base_configs is None: - self._base_configs = BIOSBaseConfigs( - self._conn, utils.get_subresource_path_by( - self, ["Oem", "Hpe", "Links", "BaseConfigs"]), - redfish_version=self.redfish_version) - - self._base_configs.refresh(force=False) - return self._base_configs + return BIOSBaseConfigs( + self._conn, utils.get_subresource_path_by( + self, ["Oem", "Hpe", "Links", "BaseConfigs"]), + redfish_version=self.redfish_version) def update_bios_to_default(self): """Updates bios default settings""" self.pending_settings.update_bios_data_by_post( self._get_base_configs().default_config) - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - if self._pending_settings is not None: - self._pending_settings.invalidate(force) - if self._boot_settings is not None: - self._boot_settings.invalidate(force) - if self._base_configs is not None: - self._base_configs.invalidate(force) - if self._iscsi_resource is not None: - self._iscsi_resource.invalidate(force) - if self._bios_mappings is not None: - self._bios_mappings.invalidate(force) - class BIOSBaseConfigs(base.ResourceBase): """Class that defines the functionality for BIOS base configuration.""" diff --git a/proliantutils/redfish/resources/system/ethernet_interface.py b/proliantutils/redfish/resources/system/ethernet_interface.py index f4186239..cdbda001 100644 --- a/proliantutils/redfish/resources/system/ethernet_interface.py +++ b/proliantutils/redfish/resources/system/ethernet_interface.py @@ -14,50 +14,25 @@ # License for the specific language governing permissions and limitations # under the License. -from proliantutils.redfish.resources.system import constants as sys_cons -from proliantutils.redfish.resources.system import mappings as sys_map from sushy.resources import base +from sushy.resources.system import ethernet_interface +from sushy import utils as sushy_utils -class HealthStatusField(base.CompositeField): - state = base.MappedField( - 'State', sys_map.HEALTH_STATE_VALUE_MAP) - health = base.MappedField('Health', sys_map.HEALTH_VALUE_MAP) +from proliantutils.redfish.resources.system import constants as sys_cons -class EthernetInterface(base.ResourceBase): - """This class represents the EthernetInterfaces resource""" - - identity = base.Field('Id', required=True) - """The Ethernet Interface identity string""" - - name = base.Field('Name') - """The name of the resource or array element""" - - description = base.Field('Description') - """Description""" - - permanent_mac_address = base.Field('PermanentMACAddress') - """This is the permanent MAC address assigned to this interface (port) """ - - mac_address = base.Field('MACAddress') - """This is the currently configured MAC address of the interface.""" - - speed_mbps = base.Field('SpeedMbps') - """This is the current speed in Mbps of this interface.""" - - status = HealthStatusField("Status") +EthernetInterface = ethernet_interface.EthernetInterface class EthernetInterfaceCollection(base.ResourceCollectionBase): - _summary = None - @property def _resource_type(self): return EthernetInterface @property + @sushy_utils.cache_it def summary(self): """property to return the summary MAC addresses and state @@ -69,24 +44,13 @@ class EthernetInterfaceCollection(base.ResourceCollectionBase): consumes the data in this format. Note: 'Id' is referred to as "Port number". """ - if self._summary is None: - mac_dict = {} - for eth in self.get_members(): - if eth.mac_address is not None: - if (eth.status is not None and - eth.status.health == sys_cons.HEALTH_OK - and eth.status.state == - sys_cons.HEALTH_STATE_ENABLED): - mac_dict.update( - {'Port ' + eth.identity: eth.mac_address}) - self._summary = mac_dict - return self._summary - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - self._summary = None + mac_dict = {} + for eth in self.get_members(): + if eth.mac_address is not None: + if (eth.status is not None and + eth.status.health == sys_cons.HEALTH_OK + and eth.status.state == + sys_cons.HEALTH_STATE_ENABLED): + mac_dict.update( + {'Port ' + eth.identity: eth.mac_address}) + return mac_dict diff --git a/proliantutils/redfish/resources/system/iscsi.py b/proliantutils/redfish/resources/system/iscsi.py index 367a0640..0e82d2f7 100644 --- a/proliantutils/redfish/resources/system/iscsi.py +++ b/proliantutils/redfish/resources/system/iscsi.py @@ -13,6 +13,7 @@ # under the License. from sushy.resources import base +from sushy import utils as sushy_utils from proliantutils.redfish import utils @@ -25,8 +26,6 @@ class ISCSIResource(base.ResourceBase): """ iscsi_initiator = base.Field("iSCSIInitiatorName") - _iscsi_settings = None - def is_iscsi_boot_supported(self): """Checks whether iscsi boot is supported or not. @@ -39,31 +38,17 @@ class ISCSIResource(base.ResourceBase): ['@Redfish.Settings', 'SettingsObject']) @property + @sushy_utils.cache_it def iscsi_settings(self): """Property to provide reference to iSCSI settings instance It is calculated once when the first time it is queried. On refresh, this property gets reset. """ - if self._iscsi_settings is None: - self._iscsi_settings = ISCSISettings( - self._conn, - utils.get_subresource_path_by( - self, ["@Redfish.Settings", "SettingsObject"]), - redfish_version=self.redfish_version) - - self._iscsi_settings.refresh(force=False) - return self._iscsi_settings - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - if self._iscsi_settings is not None: - self._iscsi_settings.invalidate(force) + return ISCSISettings( + self._conn, utils.get_subresource_path_by( + self, ["@Redfish.Settings", "SettingsObject"]), + redfish_version=self.redfish_version) class ISCSISettings(base.ResourceBase): diff --git a/proliantutils/redfish/resources/system/pci_device.py b/proliantutils/redfish/resources/system/pci_device.py index 30ef9933..0c7354cf 100644 --- a/proliantutils/redfish/resources/system/pci_device.py +++ b/proliantutils/redfish/resources/system/pci_device.py @@ -15,6 +15,7 @@ import logging from sushy.resources import base +from sushy import utils as sushy_utils LOG = logging.getLogger(__name__) @@ -32,64 +33,34 @@ class PCIDevice(base.ResourceBase): sub_class_code = base.Field('SubclassCode') - _nic_capacity = None - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - self._nic_capacity = None - @property + @sushy_utils.cache_it def nic_capacity(self): - if self._nic_capacity is None: - for item in self.name.split(): - if 'Gb' in item: - capacity = item.strip('Gb') - self._nic_capacity = ( - int(capacity) if capacity.isdigit() else 0) - break - else: - self._nic_capacity = 0 - return self._nic_capacity + for item in self.name.split(): + if 'Gb' in item: + capacity = item.strip('Gb') + return int(capacity) if capacity.isdigit() else 0 + return 0 class PCIDeviceCollection(base.ResourceCollectionBase): - _gpu_devices = None - _max_nic_capacity = None - @property def _resource_type(self): return PCIDevice @property + @sushy_utils.cache_it def gpu_devices(self): - if self._gpu_devices is None: - self._gpu_devices = [] - for member in self.get_members(): - if member.class_code in CLASSCODE_FOR_GPU_DEVICES: - if member.sub_class_code in SUBCLASSCODE_FOR_GPU_DEVICES: - self._gpu_devices.append(member) - return self._gpu_devices - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - self._gpu_devices = None - self._max_nic_capacity = None + gpu_devices = [] + for member in self.get_members(): + if member.class_code in CLASSCODE_FOR_GPU_DEVICES: + if member.sub_class_code in SUBCLASSCODE_FOR_GPU_DEVICES: + gpu_devices.append(member) + return gpu_devices @property + @sushy_utils.cache_it def max_nic_capacity(self): """Gets the maximum NIC capacity""" - if self._max_nic_capacity is None: - self._max_nic_capacity = ( - str(max([m.nic_capacity for m in self.get_members()])) + 'Gb') - return self._max_nic_capacity + return str(max([m.nic_capacity for m in self.get_members()])) + 'Gb' diff --git a/proliantutils/redfish/resources/system/storage/array_controller.py b/proliantutils/redfish/resources/system/storage/array_controller.py index 78d52867..af58b3cd 100644 --- a/proliantutils/redfish/resources/system/storage/array_controller.py +++ b/proliantutils/redfish/resources/system/storage/array_controller.py @@ -14,6 +14,8 @@ import logging +from sushy import utils as sushy_utils + from proliantutils.redfish.resources.system.storage import logical_drive from proliantutils.redfish.resources.system.storage import physical_drive from proliantutils.redfish import utils @@ -40,149 +42,102 @@ class HPEArrayController(base.ResourceBase): location = base.Field('Location') """Controller slot location""" - _logical_drives = None - _physical_drives = None - @property + @sushy_utils.cache_it def logical_drives(self): """Gets the resource HPELogicalDriveCollection of ArrayControllers""" - if self._logical_drives is None: - self._logical_drives = ( - logical_drive.HPELogicalDriveCollection( - self._conn, utils.get_subresource_path_by( - self, ['Links', 'LogicalDrives']), - redfish_version=self.redfish_version)) - - self._logical_drives.refresh(force=False) - return self._logical_drives + return logical_drive.HPELogicalDriveCollection( + self._conn, utils.get_subresource_path_by( + self, ['Links', 'LogicalDrives']), + redfish_version=self.redfish_version) @property + @sushy_utils.cache_it def physical_drives(self): """Gets the resource HPEPhysicalDriveCollection of ArrayControllers""" - - if self._physical_drives is None: - self._physical_drives = ( - physical_drive.HPEPhysicalDriveCollection( - self._conn, utils.get_subresource_path_by( - self, ['Links', 'PhysicalDrives']), - redfish_version=self.redfish_version)) - - self._physical_drives.refresh(force=False) - return self._physical_drives - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - super(HPEArrayController, self)._do_refresh(force) - - if self._physical_drives is not None: - self._physical_drives.invalidate(force) - if self._logical_drives is not None: - self._logical_drives.invalidate(force) + return physical_drive.HPEPhysicalDriveCollection( + self._conn, utils.get_subresource_path_by( + self, ['Links', 'PhysicalDrives']), + redfish_version=self.redfish_version) class HPEArrayControllerCollection(base.ResourceCollectionBase): """This class represents the collection of HPEArrayControllers""" - _logical_drives_maximum_size_mib = None - _physical_drives_maximum_size_mib = None - _has_ssd = None - _has_rotational = None - _logical_raid_levels = None - _drive_rotational_speed_rpm = None - _get_models = None - _get_default_controller = None - @property def _resource_type(self): return HPEArrayController @property + @sushy_utils.cache_it def logical_drives_maximum_size_mib(self): """Gets the biggest logical drive :returns the size in MiB. """ - if self._logical_drives_maximum_size_mib is None: - self._logical_drives_maximum_size_mib = ( - utils.max_safe([member.logical_drives.maximum_size_mib - for member in self.get_members()])) - return self._logical_drives_maximum_size_mib + return utils.max_safe([member.logical_drives.maximum_size_mib + for member in self.get_members()]) @property + @sushy_utils.cache_it def physical_drives_maximum_size_mib(self): """Gets the biggest disk :returns the size in MiB. """ - if self._physical_drives_maximum_size_mib is None: - self._physical_drives_maximum_size_mib = ( - utils.max_safe([member.physical_drives.maximum_size_mib - for member in self.get_members()])) - return self._physical_drives_maximum_size_mib + return utils.max_safe([member.physical_drives.maximum_size_mib + for member in self.get_members()]) @property + @sushy_utils.cache_it def has_ssd(self): """Return true if any of the drive under ArrayControllers is ssd""" - - if self._has_ssd is None: - self._has_ssd = False - for member in self.get_members(): - if member.physical_drives.has_ssd: - self._has_ssd = True - break - return self._has_ssd + for member in self.get_members(): + if member.physical_drives.has_ssd: + return True + return False @property + @sushy_utils.cache_it def has_rotational(self): """Return true if any of the drive under ArrayControllers is ssd""" - - if self._has_rotational is None: - self._has_rotational = False - for member in self.get_members(): - if member.physical_drives.has_rotational: - self._has_rotational = True - break - return self._has_rotational + for member in self.get_members(): + if member.physical_drives.has_rotational: + return True + return False @property + @sushy_utils.cache_it def logical_raid_levels(self): """Gets the raid level for each logical volume :returns the set of list of raid levels configured """ - if self._logical_raid_levels is None: - self._logical_raid_levels = set() - for member in self.get_members(): - self._logical_raid_levels.update( - member.logical_drives.logical_raid_levels) - return self._logical_raid_levels + lg_raid_lvls = set() + for member in self.get_members(): + lg_raid_lvls.update(member.logical_drives.logical_raid_levels) + return lg_raid_lvls @property + @sushy_utils.cache_it def drive_rotational_speed_rpm(self): """Gets the set of rotational speed of the HDD drives""" - if self._drive_rotational_speed_rpm is None: - self._drive_rotational_speed_rpm = set() - for member in self.get_members(): - self._drive_rotational_speed_rpm.update( - member.physical_drives.drive_rotational_speed_rpm) - return self._drive_rotational_speed_rpm + drv_rot_speed_rpm = set() + for member in self.get_members(): + drv_rot_speed_rpm.update( + member.physical_drives.drive_rotational_speed_rpm) + return drv_rot_speed_rpm @property + @sushy_utils.cache_it def get_default_controller(self): """Gets default array controller :returns default array controller """ - if self._get_default_controller is None: - self._get_default_controller = self.get_members()[0] - return self._get_default_controller + return self.get_members()[0] def array_controller_by_location(self, location): """Returns array controller instance by location @@ -201,19 +156,3 @@ class HPEArrayControllerCollection(base.ResourceCollectionBase): for member in self.get_members(): if member.model == model: return member - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - self._logical_drives_maximum_size_mib = None - self._physical_drives_maximum_size_mib = None - self._has_ssd = None - self._has_rotational = None - self._logical_raid_levels = None - self._drive_rotational_speed_rpm = None - self._get_models = None - self._get_default_controller = None diff --git a/proliantutils/redfish/resources/system/storage/logical_drive.py b/proliantutils/redfish/resources/system/storage/logical_drive.py index d7a98e7d..717f875f 100644 --- a/proliantutils/redfish/resources/system/storage/logical_drive.py +++ b/proliantutils/redfish/resources/system/storage/logical_drive.py @@ -13,6 +13,7 @@ # under the License. from sushy.resources import base +from sushy import utils as sushy_utils from proliantutils.redfish import utils @@ -36,44 +37,28 @@ class HPELogicalDrive(base.ResourceBase): class HPELogicalDriveCollection(base.ResourceCollectionBase): """This class represents the collection of LogicalDrives resource""" - _maximum_size_mib = None - _logical_raid_levels = None - @property def _resource_type(self): return HPELogicalDrive @property + @sushy_utils.cache_it def maximum_size_mib(self): """Gets the biggest logical drive :returns size in MiB. """ - if self._maximum_size_mib is None: - self._maximum_size_mib = ( - utils.max_safe([member.capacity_mib - for member in self.get_members()])) - return self._maximum_size_mib + return utils.max_safe([member.capacity_mib + for member in self.get_members()]) @property + @sushy_utils.cache_it def logical_raid_levels(self): """Gets the raid level for each logical volume :returns the set of list of raid levels configured. """ - if self._logical_raid_levels is None: - self._logical_raid_levels = set() - for member in self.get_members(): - self._logical_raid_levels.add( - mappings.RAID_LEVEL_MAP_REV.get(member.raid)) - return self._logical_raid_levels - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - self._maximum_size_mib = None - self._logical_raid_levels = None + lg_raid_lvls = set() + for member in self.get_members(): + lg_raid_lvls.add(mappings.RAID_LEVEL_MAP_REV.get(member.raid)) + return lg_raid_lvls diff --git a/proliantutils/redfish/resources/system/storage/physical_drive.py b/proliantutils/redfish/resources/system/storage/physical_drive.py index 4cf04b66..fab7277e 100644 --- a/proliantutils/redfish/resources/system/storage/physical_drive.py +++ b/proliantutils/redfish/resources/system/storage/physical_drive.py @@ -13,6 +13,7 @@ # under the License. from sushy.resources import base +from sushy import utils as sushy_utils from proliantutils.redfish import utils @@ -39,71 +40,44 @@ class HPEPhysicalDrive(base.ResourceBase): class HPEPhysicalDriveCollection(base.ResourceCollectionBase): """This class represents the collection of HPEPhysicalDrives resource""" - _maximum_size_mib = None - _has_ssd = None - _has_rotational = None - _drive_rotational_speed_rpm = None - @property def _resource_type(self): return HPEPhysicalDrive @property + @sushy_utils.cache_it def maximum_size_mib(self): """Gets the biggest physical drive :returns size in MiB. """ - if self._maximum_size_mib is None: - self._maximum_size_mib = ( - utils.max_safe([member.capacity_mib - for member in self.get_members()])) - return self._maximum_size_mib + return utils.max_safe([member.capacity_mib + for member in self.get_members()]) @property + @sushy_utils.cache_it def has_ssd(self): """Return true if the drive is ssd""" - - if self._has_ssd is None: - self._has_ssd = False - for member in self.get_members(): - if member.media_type == constants.MEDIA_TYPE_SSD: - self._has_ssd = True - break - return self._has_ssd + for member in self.get_members(): + if member.media_type == constants.MEDIA_TYPE_SSD: + return True + return False @property + @sushy_utils.cache_it def has_rotational(self): """Return true if the drive is HDD""" - - if self._has_rotational is None: - self._has_rotational = False - for member in self.get_members(): - if member.media_type == constants.MEDIA_TYPE_HDD: - self._has_rotational = True - break - return self._has_rotational + for member in self.get_members(): + if member.media_type == constants.MEDIA_TYPE_HDD: + return True + return False @property + @sushy_utils.cache_it def drive_rotational_speed_rpm(self): """Gets the set of rotational speed of the HDD drives""" - - if self._drive_rotational_speed_rpm is None: - self._drive_rotational_speed_rpm = set() - for member in self.get_members(): - if member.rotational_speed_rpm is not None: - self._drive_rotational_speed_rpm.add( - member.rotational_speed_rpm) - return self._drive_rotational_speed_rpm - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - self._maximum_size_mib = None - self._has_ssd = None - self._has_rotational = None - self._drive_rotational_speed_rpm = None + drv_rot_speed_rpm = set() + for member in self.get_members(): + if member.rotational_speed_rpm is not None: + drv_rot_speed_rpm.add(member.rotational_speed_rpm) + return drv_rot_speed_rpm diff --git a/proliantutils/redfish/resources/system/storage/simple_storage.py b/proliantutils/redfish/resources/system/storage/simple_storage.py index c1c51563..0c63699d 100644 --- a/proliantutils/redfish/resources/system/storage/simple_storage.py +++ b/proliantutils/redfish/resources/system/storage/simple_storage.py @@ -14,6 +14,7 @@ from sushy.resources import base +from sushy import utils as sushy_utils from proliantutils.redfish import utils @@ -33,29 +34,16 @@ class SimpleStorage(base.ResourceBase): devices = base.Field('Devices') """The storage devices associated with this resource""" - _maximum_size_bytes = None - @property + @sushy_utils.cache_it def maximum_size_bytes(self): """Gets the biggest disk drive :returns size in bytes. """ - if self._maximum_size_bytes is None: - self._maximum_size_bytes = ( - utils.max_safe([device.get('CapacityBytes') - for device in self.devices - if device.get('CapacityBytes') is not None])) - return self._maximum_size_bytes - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - self._maximum_size_bytes = None + return utils.max_safe( + [device.get('CapacityBytes') for device in self.devices + if device.get('CapacityBytes') is not None]) class SimpleStorageCollection(base.ResourceCollectionBase): @@ -64,25 +52,12 @@ class SimpleStorageCollection(base.ResourceCollectionBase): def _resource_type(self): return SimpleStorage - _maximum_size_bytes = None - @property + @sushy_utils.cache_it def maximum_size_bytes(self): """Gets the biggest disk drive :returns size in bytes. """ - if self._maximum_size_bytes is None: - self._maximum_size_bytes = ( - utils.max_safe([member.maximum_size_bytes - for member in self.get_members()])) - return self._maximum_size_bytes - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - self._maximum_size_bytes = None + return utils.max_safe([member.maximum_size_bytes + for member in self.get_members()]) diff --git a/proliantutils/redfish/resources/system/storage/smart_storage.py b/proliantutils/redfish/resources/system/storage/smart_storage.py index cae09c69..39498df5 100644 --- a/proliantutils/redfish/resources/system/storage/smart_storage.py +++ b/proliantutils/redfish/resources/system/storage/smart_storage.py @@ -14,9 +14,11 @@ import logging +from sushy.resources import base +from sushy import utils as sushy_utils + from proliantutils.redfish.resources.system.storage import array_controller from proliantutils.redfish import utils -from sushy.resources import base LOG = logging.getLogger(__name__) @@ -30,103 +32,60 @@ class HPESmartStorage(base.ResourceBase): description = base.Field('Description') """Description""" - _array_controllers = None - _logical_drives_maximum_size_mib = None - _physical_drives_maximum_size_mib = None - _has_ssd = None - _has_rotational = None - _logical_raid_levels = None - _drive_rotational_speed_rpm = None - @property + @sushy_utils.cache_it def array_controllers(self): """This property gets the list of instances for array controllers This property gets the list of instances for array controllers :returns: a list of instances of array controllers. """ - if self._array_controllers is None: - self._array_controllers = ( - array_controller.HPEArrayControllerCollection( - self._conn, utils.get_subresource_path_by( - self, ['Links', 'ArrayControllers']), - redfish_version=self.redfish_version)) - - self._array_controllers.refresh(force=False) - return self._array_controllers + return array_controller.HPEArrayControllerCollection( + self._conn, utils.get_subresource_path_by( + self, ['Links', 'ArrayControllers']), + redfish_version=self.redfish_version) @property + @sushy_utils.cache_it def logical_drives_maximum_size_mib(self): """Gets the biggest logical drive :Returns the size in MiB. """ - if self._logical_drives_maximum_size_mib is None: - self._logical_drives_maximum_size_mib = ( - self.array_controllers.logical_drives_maximum_size_mib) - return self._logical_drives_maximum_size_mib + return self.array_controllers.logical_drives_maximum_size_mib @property + @sushy_utils.cache_it def physical_drives_maximum_size_mib(self): """Gets the biggest disk drive :Returns the size in MiB. """ - if self._physical_drives_maximum_size_mib is None: - self._physical_drives_maximum_size_mib = ( - self.array_controllers.physical_drives_maximum_size_mib) - return self._physical_drives_maximum_size_mib + return self.array_controllers.physical_drives_maximum_size_mib @property + @sushy_utils.cache_it def has_ssd(self): """Return true if any of the drive under ArrayControllers is ssd""" - - if self._has_ssd is None: - self._has_ssd = self.array_controllers.has_ssd - return self._has_ssd + return self.array_controllers.has_ssd @property + @sushy_utils.cache_it def has_rotational(self): """Return true if any of the drive under ArrayControllers is HDD""" - - if self._has_rotational is None: - self._has_rotational = ( - self.array_controllers.has_rotational) - return self._has_rotational + return self.array_controllers.has_rotational @property + @sushy_utils.cache_it def logical_raid_levels(self): """Gets the raid level for each logical volume :returns the set of list of raid levels configured. """ - if self._logical_raid_levels is None: - self._logical_raid_levels = ( - self.array_controllers.logical_raid_levels) - return self._logical_raid_levels + return self.array_controllers.logical_raid_levels @property + @sushy_utils.cache_it def drive_rotational_speed_rpm(self): """Gets the list of rotational speed of the HDD drives""" - - if self._drive_rotational_speed_rpm is None: - self._drive_rotational_speed_rpm = ( - self.array_controllers.drive_rotational_speed_rpm) - return self._drive_rotational_speed_rpm - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - if self._array_controllers is not None: - self._array_controllers.invalidate(force) - - self._logical_drives_maximum_size_mib = None - self._physical_drives_maximum_size_mib = None - self._has_ssd = None - self._has_rotational = None - self._logical_raid_levels = None - self._drive_rotational_speed_rpm = None + return self.array_controllers.drive_rotational_speed_rpm diff --git a/proliantutils/redfish/resources/system/storage/storage.py b/proliantutils/redfish/resources/system/storage/storage.py index 2b3a8251..67dffa68 100644 --- a/proliantutils/redfish/resources/system/storage/storage.py +++ b/proliantutils/redfish/resources/system/storage/storage.py @@ -14,12 +14,14 @@ import logging +from sushy.resources import base +from sushy import utils as sushy_utils + from proliantutils.redfish.resources.system.storage import constants from proliantutils.redfish.resources.system.storage import drive as sys_drives from proliantutils.redfish.resources.system.storage \ import volume as sys_volumes from proliantutils.redfish import utils -from sushy.resources import base LOG = logging.getLogger(__name__) @@ -39,26 +41,16 @@ class Storage(base.ResourceBase): drives = base.Field('Drives') """The set of drives attached to the storage controllers""" - _volumes = None - _drives_maximum_size_bytes = None - _has_ssd = None - _has_rotational = None - _has_nvme_ssd = None - _drive_rotational_speed_rpm = None - @property + @sushy_utils.cache_it def volumes(self): """This property prepares the list of volumes :return a list of volumes. """ - if self._volumes is None: - self._volumes = sys_volumes.VolumeCollection( - self._conn, utils.get_subresource_path_by(self, 'Volumes'), - redfish_version=self.redfish_version) - - self._volumes.refresh(force=False) - return self._volumes + return sys_volumes.VolumeCollection( + self._conn, utils.get_subresource_path_by(self, 'Volumes'), + redfish_version=self.redfish_version) def _drives_list(self): """Gets the list of drives @@ -72,177 +64,114 @@ class Storage(base.ResourceBase): return drives_list @property + @sushy_utils.cache_it def drives_maximum_size_bytes(self): """Gets the biggest disk :returns the size in MiB. """ - if self._drives_maximum_size_bytes is None: - self._drives_maximum_size_bytes = ( - utils.max_safe([member.capacity_bytes - for member in self._drives_list()])) - return self._drives_maximum_size_bytes + return utils.max_safe([member.capacity_bytes + for member in self._drives_list()]) @property + @sushy_utils.cache_it def has_ssd(self): """Return true if any of the drive is ssd""" - - if self._has_ssd is None: - self._has_ssd = False - for member in self._drives_list(): - if member.media_type == constants.MEDIA_TYPE_SSD: - self._has_ssd = True - break - return self._has_ssd + for member in self._drives_list(): + if member.media_type == constants.MEDIA_TYPE_SSD: + return True + return False @property + @sushy_utils.cache_it def has_rotational(self): """Return true if any of the drive is HDD""" - - if self._has_rotational is None: - self._has_rotational = False - for member in self._drives_list(): - if member.media_type == constants.MEDIA_TYPE_HDD: - self._has_rotational = True - break - return self._has_rotational + for member in self._drives_list(): + if member.media_type == constants.MEDIA_TYPE_HDD: + return True + return False @property + @sushy_utils.cache_it def has_nvme_ssd(self): """Return True if the drive is SSD and protocol is NVMe""" - - if self._has_nvme_ssd is None: - self._has_nvme_ssd = False - for member in self._drives_list(): - if (member.media_type == constants.MEDIA_TYPE_SSD and - member.protocol == constants.PROTOCOL_NVMe): - self._has_nvme_ssd = True - return self._has_nvme_ssd + for member in self._drives_list(): + if (member.media_type == constants.MEDIA_TYPE_SSD and + member.protocol == constants.PROTOCOL_NVMe): + return True + return False @property + @sushy_utils.cache_it def drive_rotational_speed_rpm(self): """Gets set of rotational speed of the disks""" - if self._drive_rotational_speed_rpm is None: - self._drive_rotational_speed_rpm = set() - for member in self._drives_list(): - if member.rotation_speed_rpm is not None: - self._drive_rotational_speed_rpm.add( - member.rotation_speed_rpm) - return self._drive_rotational_speed_rpm - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - if self._volumes is not None: - self._volumes.invalidate(force) - - self._drives_maximum_size_bytes = None - self._has_ssd = None - self._has_rotational = None - self._has_nvme_ssd = None - self._drive_rotational_speed_rpm = None + drv_rot_speed_rpm = set() + for member in self._drives_list(): + if member.rotation_speed_rpm is not None: + drv_rot_speed_rpm.add(member.rotation_speed_rpm) + return drv_rot_speed_rpm class StorageCollection(base.ResourceCollectionBase): """This class represents the collection of Storage resource""" - _volumes_maximum_size_bytes = None - _drives_maximum_size_bytes = None - _has_ssd = None - _has_rotational = None - _has_nvme_ssd = None - _drive_rotational_speed_rpm = None - @property def _resource_type(self): return Storage @property + @sushy_utils.cache_it def volumes_maximum_size_bytes(self): """Gets the biggest logical drive :returns the size in MiB. """ - if self._volumes_maximum_size_bytes is None: - self._volumes_maximum_size_bytes = ( - utils.max_safe([member.volumes.maximum_size_bytes - for member in self.get_members()])) - return self._volumes_maximum_size_bytes + return utils.max_safe([member.volumes.maximum_size_bytes + for member in self.get_members()]) @property + @sushy_utils.cache_it def drives_maximum_size_bytes(self): """Gets the biggest disk :returns the size in MiB. """ - if self._drives_maximum_size_bytes is None: - self._drives_maximum_size_bytes = ( - utils.max_safe([member.drives_maximum_size_bytes - for member in self.get_members()])) - return self._drives_maximum_size_bytes + return utils.max_safe([member.drives_maximum_size_bytes + for member in self.get_members()]) @property + @sushy_utils.cache_it def has_ssd(self): """Return true if Storage has any drive as ssd""" - - if self._has_ssd is None: - self._has_ssd = False - for member in self.get_members(): - if member.has_ssd: - self._has_ssd = True - break - return self._has_ssd + for member in self.get_members(): + if member.has_ssd: + return True + return False @property + @sushy_utils.cache_it def has_rotational(self): """Return true if Storage has any drive as HDD""" - - if self._has_rotational is None: - self._has_rotational = False - for member in self.get_members(): - if member.has_rotational: - self._has_rotational = True - break - return self._has_rotational + for member in self.get_members(): + if member.has_rotational: + return True + return False @property + @sushy_utils.cache_it def has_nvme_ssd(self): """Return True if Storage has SSD drive and protocol is NVMe""" - - if self._has_nvme_ssd is None: - self._has_nvme_ssd = False - for member in self.get_members(): - if member.has_nvme_ssd: - self._has_nvme_ssd = True - break - return self._has_nvme_ssd + for member in self.get_members(): + if member.has_nvme_ssd: + return True + return False @property + @sushy_utils.cache_it def drive_rotational_speed_rpm(self): """Gets set of rotational speed of the disks""" - - if self._drive_rotational_speed_rpm is None: - self._drive_rotational_speed_rpm = set() - for member in self.get_members(): - self._drive_rotational_speed_rpm.update( - member.drive_rotational_speed_rpm) - return self._drive_rotational_speed_rpm - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - self._volumes_maximum_size_bytes = None - self._drives_maximum_size_bytes = None - self._has_ssd = None - self._has_rotational = None - self._has_nvme_ssd = None - self._drive_rotational_speed_rpm = None + drv_rot_speed_rpm = set() + for member in self.get_members(): + drv_rot_speed_rpm.update(member.drive_rotational_speed_rpm) + return drv_rot_speed_rpm diff --git a/proliantutils/redfish/resources/system/storage/volume.py b/proliantutils/redfish/resources/system/storage/volume.py index a886f263..957abed6 100644 --- a/proliantutils/redfish/resources/system/storage/volume.py +++ b/proliantutils/redfish/resources/system/storage/volume.py @@ -13,6 +13,7 @@ # under the License. from sushy.resources import base +from sushy import utils as sushy_utils from proliantutils.redfish import utils @@ -30,29 +31,16 @@ class Volume(base.ResourceBase): class VolumeCollection(base.ResourceCollectionBase): """This class represents the collection of Volume resource""" - _maximum_size_bytes = None - @property def _resource_type(self): return Volume @property + @sushy_utils.cache_it def maximum_size_bytes(self): """Gets the biggest volume :returns size in bytes. """ - if self._maximum_size_bytes is None: - self._maximum_size_bytes = ( - utils.max_safe([member.capacity_bytes - for member in self.get_members()])) - return self._maximum_size_bytes - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - self._maximum_size_bytes = None + return utils.max_safe([member.capacity_bytes + for member in self.get_members()]) diff --git a/proliantutils/redfish/resources/system/system.py b/proliantutils/redfish/resources/system/system.py index 8cc2bb0d..ba86da22 100644 --- a/proliantutils/redfish/resources/system/system.py +++ b/proliantutils/redfish/resources/system/system.py @@ -90,18 +90,6 @@ class HPESystem(system.System): _hpe_actions = HpeActionsField(['Oem', 'Hpe', 'Actions'], required=True) """Oem specific system extensibility actions""" - _bios_settings = None # ref to BIOSSettings instance - _secure_boot = None # ref to SecureBoot instance - - _smart_storage = None # SmartStorage instance - _simple_storages = None # SimpleStorage instance - _storages = None # Storage instance - _pci_devices = None # PCIDevice instance - - _ethernet_interfaces = None # EthernetInterface instance - - _memory = None # Memory instance - def _get_hpe_push_power_button_action_element(self): push_action = self._hpe_actions.computer_system_ext_powerbutton if not push_action: @@ -134,19 +122,16 @@ class HPESystem(system.System): self._conn.post(target_uri, data={'PushType': value}) @property + @sushy_utils.cache_it def bios_settings(self): """Property to provide reference to `BIOSSettings` instance It is calculated once when the first time it is queried. On refresh, this property gets reset. """ - if self._bios_settings is None: - self._bios_settings = bios.BIOSSettings( - self._conn, utils.get_subresource_path_by(self, 'Bios'), - redfish_version=self.redfish_version) - - self._bios_settings.refresh(force=False) - return self._bios_settings + return bios.BIOSSettings( + self._conn, utils.get_subresource_path_by(self, 'Bios'), + redfish_version=self.redfish_version) def update_persistent_boot(self, devices=[], persistent=False): """Changes the persistent boot device order in BIOS boot mode for host @@ -190,60 +175,28 @@ class HPESystem(system.System): self.set_system_boot_source(device, enabled=tenure) @property + @sushy_utils.cache_it def pci_devices(self): """Provides the collection of PCI devices It is calculated once when the first time it is queried. On refresh, this property gets reset. """ - if self._pci_devices is None: - self._pci_devices = pci_device.PCIDeviceCollection( - self._conn, utils.get_subresource_path_by( - self, ['Oem', 'Hpe', 'Links', 'PCIDevices'])) - - self._pci_devices.refresh(force=False) - return self._pci_devices + return pci_device.PCIDeviceCollection( + self._conn, utils.get_subresource_path_by( + self, ['Oem', 'Hpe', 'Links', 'PCIDevices'])) @property + @sushy_utils.cache_it def secure_boot(self): """Property to provide reference to `SecureBoot` instance It is calculated once when the first time it is queried. On refresh, this property gets reset. """ - if self._secure_boot is None: - self._secure_boot = secure_boot.SecureBoot( - self._conn, utils.get_subresource_path_by(self, 'SecureBoot'), - redfish_version=self.redfish_version) - - self._secure_boot.refresh(force=False) - return self._secure_boot - - def _do_refresh(self, force): - """Do custom resource specific refresh activities - - On refresh, all sub-resources are marked as stale, i.e. - greedy-refresh not done for them unless forced by ``force`` - argument. - """ - super(HPESystem, self)._do_refresh(force) - - if self._bios_settings is not None: - self._bios_settings.invalidate(force) - if self._pci_devices is not None: - self._pci_devices.invalidate(force) - if self._secure_boot is not None: - self._secure_boot.invalidate(force) - if self._ethernet_interfaces is not None: - self._ethernet_interfaces.invalidate(force) - if self._smart_storage is not None: - self._smart_storage.invalidate(force) - if self._storages is not None: - self._storages.invalidate(force) - if self._simple_storages is not None: - self._simple_storages.invalidate(force) - if self._memory is not None: - self._memory.invalidate(force) + return secure_boot.SecureBoot( + self._conn, utils.get_subresource_path_by(self, 'SecureBoot'), + redfish_version=self.redfish_version) def _get_hpe_sub_resource_collection_path(self, sub_res): path = None @@ -255,20 +208,16 @@ class HPESystem(system.System): return path @property + @sushy_utils.cache_it def ethernet_interfaces(self): """Provide reference to EthernetInterfacesCollection instance""" - if self._ethernet_interfaces is None: - sub_res = 'EthernetInterfaces' - self._ethernet_interfaces = ( - ethernet_interface.EthernetInterfaceCollection( - self._conn, - self._get_hpe_sub_resource_collection_path(sub_res), - redfish_version=self.redfish_version)) - - self._ethernet_interfaces.refresh(force=False) - return self._ethernet_interfaces + return ethernet_interface.EthernetInterfaceCollection( + self._conn, + self._get_hpe_sub_resource_collection_path('EthernetInterfaces'), + redfish_version=self.redfish_version) @property + @sushy_utils.cache_it def smart_storage(self): """This property gets the object for smart storage. @@ -276,60 +225,45 @@ class HPESystem(system.System): There is no collection for smart storages. :returns: an instance of smart storage """ - if self._smart_storage is None: - self._smart_storage = hpe_smart_storage.HPESmartStorage( - self._conn, utils.get_subresource_path_by( - self, ['Oem', 'Hpe', 'Links', 'SmartStorage']), - redfish_version=self.redfish_version) - - self._smart_storage.refresh(force=False) - return self._smart_storage + return hpe_smart_storage.HPESmartStorage( + self._conn, utils.get_subresource_path_by( + self, ['Oem', 'Hpe', 'Links', 'SmartStorage']), + redfish_version=self.redfish_version) @property + @sushy_utils.cache_it def storages(self): """This property gets the list of instances for Storages This property gets the list of instances for Storages :returns: a list of instances of Storages """ - if self._storages is None: - self._storages = storage.StorageCollection( - self._conn, utils.get_subresource_path_by(self, 'Storage'), - redfish_version=self.redfish_version) - - self._storages.refresh(force=False) - return self._storages + return storage.StorageCollection( + self._conn, utils.get_subresource_path_by(self, 'Storage'), + redfish_version=self.redfish_version) @property + @sushy_utils.cache_it def simple_storages(self): """This property gets the list of instances for SimpleStorages :returns: a list of instances of SimpleStorages """ - if self._simple_storages is None: - self._simple_storages = simple_storage.SimpleStorageCollection( - self._conn, utils.get_subresource_path_by( - self, 'SimpleStorage'), - redfish_version=self.redfish_version) - - self._simple_storages.refresh(force=False) - return self._simple_storages + return simple_storage.SimpleStorageCollection( + self._conn, utils.get_subresource_path_by(self, 'SimpleStorage'), + redfish_version=self.redfish_version) @property + @sushy_utils.cache_it def memory(self): """Property to provide reference to `MemoryCollection` instance It is calculated once when the first time it is queried. On refresh, this property gets reset. """ - if self._memory is None: - self._memory = memory.MemoryCollection( - self._conn, utils.get_subresource_path_by( - self, 'Memory'), - redfish_version=self.redfish_version) - - self._memory.refresh(force=False) - return self._memory + return memory.MemoryCollection( + self._conn, utils.get_subresource_path_by(self, 'Memory'), + redfish_version=self.redfish_version) def get_smart_storage_config(self, smart_storage_config_url): """Returns a SmartStorageConfig Instance for each controller.""" diff --git a/proliantutils/tests/redfish/resources/account_service/test_account_service.py b/proliantutils/tests/redfish/resources/account_service/test_account_service.py index 4fa4c66a..de064317 100644 --- a/proliantutils/tests/redfish/resources/account_service/test_account_service.py +++ b/proliantutils/tests/redfish/resources/account_service/test_account_service.py @@ -37,14 +37,12 @@ class HPEAccountServiceTestCase(testtools.TestCase): redfish_version='1.0.2') def test_accounts(self): - self.assertIsNone(self.acc_inst._accounts) - self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/account_collection.json', 'r') as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) - accounts = self.acc_inst.accounts - self.assertIsInstance(accounts, account.HPEAccountCollection) + self.assertIsInstance(self.acc_inst.accounts, + account.HPEAccountCollection) def test_accounts_on_refresh(self): with open('proliantutils/tests/redfish/' @@ -60,8 +58,7 @@ class HPEAccountServiceTestCase(testtools.TestCase): self.acc_inst.invalidate() self.acc_inst.refresh(force=False) - self.assertIsNotNone(self.acc_inst._accounts) - self.assertTrue(self.acc_inst._accounts._is_stale) + self.assertTrue(accounts._is_stale) with open('proliantutils/tests/redfish/' 'json_samples/account_collection.json', 'r') as f: @@ -69,4 +66,4 @@ class HPEAccountServiceTestCase(testtools.TestCase): self.assertIsInstance(self.acc_inst.accounts, account.HPEAccountCollection) - self.assertFalse(self.acc_inst._accounts._is_stale) + self.assertFalse(accounts._is_stale) diff --git a/proliantutils/tests/redfish/resources/manager/test_manager.py b/proliantutils/tests/redfish/resources/manager/test_manager.py index 6865742d..104de4f6 100644 --- a/proliantutils/tests/redfish/resources/manager/test_manager.py +++ b/proliantutils/tests/redfish/resources/manager/test_manager.py @@ -41,8 +41,6 @@ class HPEManagerTestCase(testtools.TestCase): data={'LicenseKey': 'testkey'}) def test_virtual_media(self): - self.assertIsNone(self.mgr_inst._virtual_media) - self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' @@ -77,8 +75,7 @@ class HPEManagerTestCase(testtools.TestCase): self.mgr_inst.invalidate() self.mgr_inst.refresh(force=False) - self.assertIsNotNone(self.mgr_inst._virtual_media) - self.assertTrue(self.mgr_inst._virtual_media._is_stale) + self.assertTrue(actual_vmedia._is_stale) with open('proliantutils/tests/redfish/' 'json_samples/vmedia_collection.json', 'r') as f: @@ -86,4 +83,4 @@ class HPEManagerTestCase(testtools.TestCase): self.assertIsInstance(self.mgr_inst.virtual_media, virtual_media.VirtualMediaCollection) - self.assertFalse(self.mgr_inst._virtual_media._is_stale) + self.assertFalse(actual_vmedia._is_stale) diff --git a/proliantutils/tests/redfish/resources/system/storage/test_array_controller.py b/proliantutils/tests/redfish/resources/system/storage/test_array_controller.py index c43f9e46..fed76586 100644 --- a/proliantutils/tests/redfish/resources/system/storage/test_array_controller.py +++ b/proliantutils/tests/redfish/resources/system/storage/test_array_controller.py @@ -45,7 +45,6 @@ class HPEArrayControllerTestCase(testtools.TestCase): def test_logical_drives(self): log_coll = None log_dr = None - self.assertIsNone(self.sys_stor._logical_drives) self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/logical_drive_collection.json') as f: @@ -65,7 +64,6 @@ class HPEArrayControllerTestCase(testtools.TestCase): def test_physical_drives(self): disk_coll = None disk_dr = None - self.assertIsNone(self.sys_stor._physical_drives) self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/disk_drive_collection.json') as f: @@ -123,7 +121,6 @@ class HPEArrayControllerCollectionTestCase(testtools.TestCase): self.assertEqual(1, len(members)) def test_logical_drives_maximum_size_mib(self): - self.assertIsNone(self.sys_stor_col._logical_drives_maximum_size_mib) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -146,7 +143,6 @@ class HPEArrayControllerCollectionTestCase(testtools.TestCase): self.assertEqual(expected, actual) def test_logical_raid_levels(self): - self.assertIsNone(self.sys_stor_col._logical_raid_levels) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -169,7 +165,6 @@ class HPEArrayControllerCollectionTestCase(testtools.TestCase): self.assertEqual(expected, actual) def test_physical_drives_maximum_size_mib(self): - self.assertIsNone(self.sys_stor_col._physical_drives_maximum_size_mib) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -192,7 +187,6 @@ class HPEArrayControllerCollectionTestCase(testtools.TestCase): self.assertEqual(expected, actual) def test_has_ssd(self): - self.assertIsNone(self.sys_stor_col._has_ssd) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -213,7 +207,6 @@ class HPEArrayControllerCollectionTestCase(testtools.TestCase): self.assertTrue(self.sys_stor_col.has_ssd) def test_has_rotational(self): - self.assertIsNone(self.sys_stor_col._has_rotational) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -234,7 +227,6 @@ class HPEArrayControllerCollectionTestCase(testtools.TestCase): self.assertTrue(self.sys_stor_col.has_rotational) def test_drive_rotational_speed_rpm(self): - self.assertIsNone(self.sys_stor_col._drive_rotational_speed_rpm) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -257,7 +249,6 @@ class HPEArrayControllerCollectionTestCase(testtools.TestCase): self.sys_stor_col.drive_rotational_speed_rpm) def test_get_default_controller(self): - self.assertIsNone(self.sys_stor_col._get_default_controller) self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/array_controller.json', 'r') as f: diff --git a/proliantutils/tests/redfish/resources/system/storage/test_logical_drive.py b/proliantutils/tests/redfish/resources/system/storage/test_logical_drive.py index d2b8f242..6793233a 100644 --- a/proliantutils/tests/redfish/resources/system/storage/test_logical_drive.py +++ b/proliantutils/tests/redfish/resources/system/storage/test_logical_drive.py @@ -93,7 +93,6 @@ class HPELogicalDriveCollectionTestCase(testtools.TestCase): self.assertEqual(2, len(members)) def test_maximum_size_mib(self): - self.assertIsNone(self.sys_stor_col._maximum_size_mib) self.conn.get.return_value.json.reset_mock() path = ('proliantutils/tests/redfish/json_samples/' 'logical_drive.json') @@ -106,7 +105,6 @@ class HPELogicalDriveCollectionTestCase(testtools.TestCase): self.assertEqual(expected, actual) def test_logical_raid_levels(self): - self.assertIsNone(self.sys_stor_col._logical_raid_levels) self.conn.get.return_value.json.reset_mock() path = ('proliantutils/tests/redfish/json_samples/' 'logical_drive.json') diff --git a/proliantutils/tests/redfish/resources/system/storage/test_physical_drive.py b/proliantutils/tests/redfish/resources/system/storage/test_physical_drive.py index 7d4a7570..3a38a532 100644 --- a/proliantutils/tests/redfish/resources/system/storage/test_physical_drive.py +++ b/proliantutils/tests/redfish/resources/system/storage/test_physical_drive.py @@ -94,7 +94,6 @@ class HPEPhysicalDriveCollectionTestCase(testtools.TestCase): self.assertEqual(2, len(members)) def test_maximum_size_mib(self): - self.assertIsNone(self.sys_stor_col._maximum_size_mib) self.conn.get.return_value.json.reset_mock() path = ('proliantutils/tests/redfish/json_samples/' 'disk_drive.json') @@ -107,7 +106,6 @@ class HPEPhysicalDriveCollectionTestCase(testtools.TestCase): self.assertEqual(expected, actual) def test_has_ssd(self): - self.assertIsNone(self.sys_stor_col._has_ssd) self.conn.get.return_value.json.reset_mock() path = ('proliantutils/tests/redfish/json_samples/' 'disk_drive.json') @@ -119,7 +117,6 @@ class HPEPhysicalDriveCollectionTestCase(testtools.TestCase): self.assertTrue(actual) def test_has_rotational(self): - self.assertIsNone(self.sys_stor_col._has_rotational) self.conn.get.return_value.json.reset_mock() path = ('proliantutils/tests/redfish/json_samples/' 'disk_drive.json') @@ -130,7 +127,6 @@ class HPEPhysicalDriveCollectionTestCase(testtools.TestCase): self.assertTrue(self.sys_stor_col.has_rotational) def test_drive_rotational_speed_rpm(self): - self.assertIsNone(self.sys_stor_col._drive_rotational_speed_rpm) self.conn.get.return_value.json.reset_mock() path = ('proliantutils/tests/redfish/json_samples/' 'disk_drive.json') diff --git a/proliantutils/tests/redfish/resources/system/storage/test_simple_storage.py b/proliantutils/tests/redfish/resources/system/storage/test_simple_storage.py index 29c62038..f4509e85 100644 --- a/proliantutils/tests/redfish/resources/system/storage/test_simple_storage.py +++ b/proliantutils/tests/redfish/resources/system/storage/test_simple_storage.py @@ -45,7 +45,6 @@ class SimpleStorageTestCase(testtools.TestCase): self.sys_simple.devices) def test_maximum_size_bytes(self): - self.assertIsNone(self.sys_simple._maximum_size_bytes) self.conn.get.return_value.json.reset_mock() expected = 8000000000000 actual = self.sys_simple.maximum_size_bytes @@ -53,7 +52,6 @@ class SimpleStorageTestCase(testtools.TestCase): def test_maximum_size_bytes_on_refresh(self): self.sys_simple.refresh() - self.assertIsNone(self.sys_simple._maximum_size_bytes) class SimpleStorageCollectionTestCase(testtools.TestCase): @@ -98,7 +96,6 @@ class SimpleStorageCollectionTestCase(testtools.TestCase): self.assertEqual(1, len(members)) def test_maximum_size_bytes(self): - self.assertIsNone(self.sys_simple_col._maximum_size_bytes) self.conn.get.return_value.json.reset_mock() path = ('proliantutils/tests/redfish/json_samples/' 'simple_storage.json') diff --git a/proliantutils/tests/redfish/resources/system/storage/test_smart_storage.py b/proliantutils/tests/redfish/resources/system/storage/test_smart_storage.py index 93cbe5c6..8bbffd7a 100644 --- a/proliantutils/tests/redfish/resources/system/storage/test_smart_storage.py +++ b/proliantutils/tests/redfish/resources/system/storage/test_smart_storage.py @@ -51,13 +51,10 @@ class HPESmartStorageTestCase(testtools.TestCase): 'array_controller.json', 'r') as f: value = (json.loads(f.read())) self.conn.get.return_value.json.side_effect = [coll, value] - self.assertIsNone(self.sys_stor._array_controllers) - self.sys_stor.array_controllers - self.assertIsInstance(self.sys_stor._array_controllers, + self.assertIsInstance(self.sys_stor.array_controllers, array_controller.HPEArrayControllerCollection) def test_logical_drives_maximum_size_mib(self): - self.assertIsNone(self.sys_stor._logical_drives_maximum_size_mib) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -84,7 +81,6 @@ class HPESmartStorageTestCase(testtools.TestCase): self.assertEqual(expected, actual) def test_logical_raid_levels(self): - self.assertIsNone(self.sys_stor._logical_raid_levels) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -111,7 +107,6 @@ class HPESmartStorageTestCase(testtools.TestCase): self.assertEqual(expected, actual) def test_physical_drives_maximum_size_mib(self): - self.assertIsNone(self.sys_stor._physical_drives_maximum_size_mib) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -138,7 +133,6 @@ class HPESmartStorageTestCase(testtools.TestCase): self.assertEqual(expected, actual) def test_has_ssd(self): - self.assertIsNone(self.sys_stor._has_ssd) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -163,7 +157,6 @@ class HPESmartStorageTestCase(testtools.TestCase): self.assertTrue(self.sys_stor.has_ssd) def test_has_rotaional(self): - self.assertIsNone(self.sys_stor._has_rotational) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -188,7 +181,6 @@ class HPESmartStorageTestCase(testtools.TestCase): self.assertTrue(self.sys_stor.has_rotational) def test_drive_rotational_speed_rpm(self): - self.assertIsNone(self.sys_stor._drive_rotational_speed_rpm) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' diff --git a/proliantutils/tests/redfish/resources/system/storage/test_storage.py b/proliantutils/tests/redfish/resources/system/storage/test_storage.py index d5b8d5ef..5aa7b96d 100644 --- a/proliantutils/tests/redfish/resources/system/storage/test_storage.py +++ b/proliantutils/tests/redfish/resources/system/storage/test_storage.py @@ -47,7 +47,6 @@ class StorageTestCase(testtools.TestCase): def test_volumes(self): log_coll = None log_dr = None - self.assertIsNone(self.sys_stor._volumes) self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/volume_collection.json') as f: @@ -56,13 +55,12 @@ class StorageTestCase(testtools.TestCase): 'json_samples/volume.json') as f: log_dr = json.loads(f.read()) self.conn.get.return_value.json.side_effect = [log_coll, log_dr] - actual_log_dr = self.sys_stor.volumes - self.assertIs(actual_log_dr, + actual_volumes = self.sys_stor.volumes + self.assertIs(actual_volumes, self.sys_stor.volumes) self.sys_stor.invalidate() self.sys_stor.refresh(force=False) - self.assertIsNotNone(self.sys_stor._volumes) - self.assertTrue(self.sys_stor._volumes._is_stale) + self.assertTrue(actual_volumes._is_stale) def test__drives_list(self): self.conn.get.return_value.json.reset_mock() @@ -76,7 +74,6 @@ class StorageTestCase(testtools.TestCase): self.assertIsInstance(actual_dr, list) def test_drives_maximum_size_bytes(self): - self.assertIsNone(self.sys_stor._drives_maximum_size_bytes) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -92,7 +89,6 @@ class StorageTestCase(testtools.TestCase): self.assertEqual(expected, actual) def test_has_ssd_true(self): - self.assertIsNone(self.sys_stor._has_ssd) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -106,7 +102,6 @@ class StorageTestCase(testtools.TestCase): self.assertTrue(self.sys_stor.has_ssd) def test_has_rotational(self): - self.assertIsNone(self.sys_stor._has_rotational) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -120,7 +115,6 @@ class StorageTestCase(testtools.TestCase): self.assertTrue(self.sys_stor.has_rotational) def test_has_nvme_ssd(self): - self.assertIsNone(self.sys_stor._has_nvme_ssd) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -134,7 +128,6 @@ class StorageTestCase(testtools.TestCase): self.assertTrue(self.sys_stor.has_nvme_ssd) def test_drive_rotational_speed_rpm(self): - self.assertIsNone(self.sys_stor._drive_rotational_speed_rpm) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -192,7 +185,6 @@ class StorageCollectionTestCase(testtools.TestCase): self.assertEqual(1, len(members)) def test_volumes_maximum_size_bytes(self): - self.assertIsNone(self.sys_stor_col._volumes_maximum_size_bytes) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -213,7 +205,6 @@ class StorageCollectionTestCase(testtools.TestCase): self.assertEqual(expected, actual) def test_drives_maximum_size_bytes(self): - self.assertIsNone(self.sys_stor_col._drives_maximum_size_bytes) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -233,7 +224,6 @@ class StorageCollectionTestCase(testtools.TestCase): self.assertEqual(expected, actual) def test_has_ssd_true(self): - self.assertIsNone(self.sys_stor_col._has_ssd) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -251,7 +241,6 @@ class StorageCollectionTestCase(testtools.TestCase): self.assertTrue(self.sys_stor_col.has_ssd) def test_has_rotational(self): - self.assertIsNone(self.sys_stor_col._has_rotational) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -269,7 +258,6 @@ class StorageCollectionTestCase(testtools.TestCase): self.assertTrue(self.sys_stor_col.has_rotational) def test_has_nvme_ssd(self): - self.assertIsNone(self.sys_stor_col._has_nvme_ssd) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -287,7 +275,6 @@ class StorageCollectionTestCase(testtools.TestCase): self.assertTrue(self.sys_stor_col.has_nvme_ssd) def test_drive_rotational_speed_rpm(self): - self.assertIsNone(self.sys_stor_col._drive_rotational_speed_rpm) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' diff --git a/proliantutils/tests/redfish/resources/system/storage/test_volume.py b/proliantutils/tests/redfish/resources/system/storage/test_volume.py index b9cf1895..4656d571 100644 --- a/proliantutils/tests/redfish/resources/system/storage/test_volume.py +++ b/proliantutils/tests/redfish/resources/system/storage/test_volume.py @@ -82,7 +82,6 @@ class VolumeCollectionTestCase(testtools.TestCase): self.assertEqual(1, len(members)) def test_maximum_size_bytes(self): - self.assertIsNone(self.sys_vol_col._maximum_size_bytes) self.conn.get.return_value.json.reset_mock() path = ('proliantutils/tests/redfish/json_samples/' 'volume.json') diff --git a/proliantutils/tests/redfish/resources/system/test_bios.py b/proliantutils/tests/redfish/resources/system/test_bios.py index aba12ad4..7bf30987 100644 --- a/proliantutils/tests/redfish/resources/system/test_bios.py +++ b/proliantutils/tests/redfish/resources/system/test_bios.py @@ -48,8 +48,6 @@ class BIOSSettingsTestCase(testtools.TestCase): self.bios_inst.cpu_vt) def test_pending_settings(self): - self.assertIsNone(self.bios_inst._pending_settings) - self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/bios.json', 'r') as f: @@ -66,8 +64,6 @@ class BIOSSettingsTestCase(testtools.TestCase): self.conn.get.return_value.json.assert_not_called() def test_boot_settings(self): - self.assertIsNone(self.bios_inst._boot_settings) - self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/bios_boot.json', 'r') as f: @@ -84,8 +80,6 @@ class BIOSSettingsTestCase(testtools.TestCase): self.conn.get.return_value.json.assert_not_called() def test_bios_mappings(self): - self.assertIsNone(self.bios_inst._bios_mappings) - self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/bios_mappings.json', 'r') as f: @@ -102,8 +96,6 @@ class BIOSSettingsTestCase(testtools.TestCase): self.conn.get.return_value.json.assert_not_called() def test_iscsi_resource(self): - self.assertIsNone(self.bios_inst._iscsi_resource) - self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/iscsi.json', 'r') as f: @@ -120,7 +112,6 @@ class BIOSSettingsTestCase(testtools.TestCase): self.conn.get.return_value.json.assert_not_called() def test__get_base_configs(self): - self.assertIsNone(self.bios_inst._base_configs) with open('proliantutils/tests/redfish/' 'json_samples/bios_base_configs.json', 'r') as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) @@ -144,8 +135,7 @@ class BIOSSettingsTestCase(testtools.TestCase): self.bios_inst.invalidate() self.bios_inst.refresh(force=False) - self.assertIsNotNone(self.bios_inst._pending_settings) - self.assertTrue(self.bios_inst._pending_settings._is_stale) + self.assertTrue(actual_settings._is_stale) with open('proliantutils/tests/redfish/' 'json_samples/bios.json', 'r') as f: @@ -154,7 +144,7 @@ class BIOSSettingsTestCase(testtools.TestCase): self.assertIsInstance(self.bios_inst.pending_settings, bios.BIOSPendingSettings) - self.assertFalse(self.bios_inst._pending_settings._is_stale) + self.assertFalse(actual_settings._is_stale) def test_boot_settings_on_refresh(self): with open('proliantutils/tests/redfish/' @@ -173,8 +163,7 @@ class BIOSSettingsTestCase(testtools.TestCase): self.bios_inst.invalidate() self.bios_inst.refresh(force=False) - self.assertIsNotNone(self.bios_inst._boot_settings) - self.assertTrue(self.bios_inst._boot_settings._is_stale) + self.assertTrue(actual_settings._is_stale) with open('proliantutils/tests/redfish/' 'json_samples/bios_boot.json', 'r') as f: @@ -183,7 +172,7 @@ class BIOSSettingsTestCase(testtools.TestCase): self.assertIsInstance(self.bios_inst.boot_settings, bios.BIOSBootSettings) - self.assertFalse(self.bios_inst._boot_settings._is_stale) + self.assertFalse(actual_settings._is_stale) def test_bios_mappings_on_refresh(self): with open('proliantutils/tests/redfish/' @@ -202,8 +191,7 @@ class BIOSSettingsTestCase(testtools.TestCase): self.bios_inst.invalidate() self.bios_inst.refresh(force=False) - self.assertIsNotNone(self.bios_inst._bios_mappings) - self.assertTrue(self.bios_inst._bios_mappings._is_stale) + self.assertTrue(actual_settings._is_stale) with open('proliantutils/tests/redfish/' 'json_samples/bios_mappings.json', 'r') as f: @@ -212,7 +200,7 @@ class BIOSSettingsTestCase(testtools.TestCase): self.assertIsInstance(self.bios_inst.bios_mappings, bios.BIOSMappings) - self.assertFalse(self.bios_inst._bios_mappings._is_stale) + self.assertFalse(actual_settings._is_stale) def test_iscsi_resource_on_refresh(self): with open('proliantutils/tests/redfish/' @@ -231,8 +219,7 @@ class BIOSSettingsTestCase(testtools.TestCase): self.bios_inst.invalidate() self.bios_inst.refresh(force=False) - self.assertIsNotNone(self.bios_inst._iscsi_resource) - self.assertTrue(self.bios_inst._iscsi_resource._is_stale) + self.assertTrue(actual_settings._is_stale) with open('proliantutils/tests/redfish/' 'json_samples/iscsi.json', 'r') as f: @@ -241,7 +228,7 @@ class BIOSSettingsTestCase(testtools.TestCase): self.assertIsInstance(self.bios_inst.iscsi_resource, iscsi.ISCSIResource) - self.assertFalse(self.bios_inst._iscsi_resource._is_stale) + self.assertFalse(actual_settings._is_stale) def test__get_base_configs_on_refresh(self): with open('proliantutils/tests/redfish/' @@ -258,8 +245,7 @@ class BIOSSettingsTestCase(testtools.TestCase): self.bios_inst.invalidate() self.bios_inst.refresh(force=False) - self.assertIsNotNone(self.bios_inst._base_configs) - self.assertTrue(self.bios_inst._base_configs._is_stale) + self.assertTrue(default_settings._is_stale) with open('proliantutils/tests/redfish/' 'json_samples/bios_base_configs.json', 'r') as f: @@ -267,7 +253,7 @@ class BIOSSettingsTestCase(testtools.TestCase): self.assertIsInstance(self.bios_inst._get_base_configs(), bios.BIOSBaseConfigs) - self.assertFalse(self.bios_inst._base_configs._is_stale) + self.assertFalse(default_settings._is_stale) class BIOSBaseConfigsTestCase(testtools.TestCase): diff --git a/proliantutils/tests/redfish/resources/system/test_ethernet_interface.py b/proliantutils/tests/redfish/resources/system/test_ethernet_interface.py index 221f0cf4..04628eba 100644 --- a/proliantutils/tests/redfish/resources/system/test_ethernet_interface.py +++ b/proliantutils/tests/redfish/resources/system/test_ethernet_interface.py @@ -98,7 +98,6 @@ class EthernetInterfaceCollectionTestCase(testtools.TestCase): self.assertEqual(1, len(members)) def test_summary(self): - self.assertIsNone(self.sys_eth_col._summary) self.conn.get.return_value.json.reset_mock() path = ('proliantutils/tests/redfish/json_samples/' 'ethernet_interface.json') diff --git a/proliantutils/tests/redfish/resources/system/test_iscsi.py b/proliantutils/tests/redfish/resources/system/test_iscsi.py index 5b908132..15afa40e 100644 --- a/proliantutils/tests/redfish/resources/system/test_iscsi.py +++ b/proliantutils/tests/redfish/resources/system/test_iscsi.py @@ -49,8 +49,6 @@ class ISCSIResourceTestCase(testtools.TestCase): self.assertEqual(ret_val, expected) def test_iscsi_settings(self): - self.assertIsNone(self.iscsi_inst._iscsi_settings) - self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/iscsi_settings.json', 'r') as f: @@ -83,8 +81,7 @@ class ISCSIResourceTestCase(testtools.TestCase): self.iscsi_inst.invalidate() self.iscsi_inst.refresh(force=False) - self.assertIsNotNone(self.iscsi_inst._iscsi_settings) - self.assertTrue(self.iscsi_inst._iscsi_settings._is_stale) + self.assertTrue(actual_settings._is_stale) with open('proliantutils/tests/redfish/' 'json_samples/iscsi_settings.json', 'r') as f: @@ -92,7 +89,7 @@ class ISCSIResourceTestCase(testtools.TestCase): json.loads(f.read())['Default']) self.assertIsInstance(self.iscsi_inst.iscsi_settings, iscsi.ISCSISettings) - self.assertFalse(self.iscsi_inst._iscsi_settings._is_stale) + self.assertFalse(actual_settings._is_stale) def test_attributes(self): with open('proliantutils/tests/redfish/' diff --git a/proliantutils/tests/redfish/resources/system/test_pci_device.py b/proliantutils/tests/redfish/resources/system/test_pci_device.py index 1f5491d7..30bb9776 100644 --- a/proliantutils/tests/redfish/resources/system/test_pci_device.py +++ b/proliantutils/tests/redfish/resources/system/test_pci_device.py @@ -87,7 +87,6 @@ class PCIDeviceCollectionTestCase(testtools.TestCase): self.assertEqual(2, len(members)) def test_gpu_devices(self): - self.assertIsNone(self.sys_pci_col._gpu_devices) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' @@ -99,11 +98,9 @@ class PCIDeviceCollectionTestCase(testtools.TestCase): with open(path, 'r') as f: val.append(json.loads(f.read())) self.conn.get.return_value.json.side_effect = val - self.sys_pci_col.gpu_devices - self.assertEqual(1, len(self.sys_pci_col._gpu_devices)) + self.assertEqual(1, len(self.sys_pci_col.gpu_devices)) def test_max_nic_capacity(self): - self.assertIsNone(self.sys_pci_col._max_nic_capacity) self.conn.get.return_value.json.reset_mock() val = [] path = ('proliantutils/tests/redfish/json_samples/' diff --git a/proliantutils/tests/redfish/resources/system/test_system.py b/proliantutils/tests/redfish/resources/system/test_system.py index 49c83333..69bf5f1d 100644 --- a/proliantutils/tests/redfish/resources/system/test_system.py +++ b/proliantutils/tests/redfish/resources/system/test_system.py @@ -80,7 +80,6 @@ class HPESystemTestCase(testtools.TestCase): self.sys_inst.push_power_button, 'invalid-value') def test_bios_settings(self): - self.assertIsNone(self.sys_inst._bios_settings) self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/bios.json', 'r') as f: @@ -125,7 +124,8 @@ class HPESystemTestCase(testtools.TestCase): 'r') as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) # | WHEN & THEN | - self.assertIsInstance(self.sys_inst.bios_settings, + actual_bios_settings = self.sys_inst.bios_settings + self.assertIsInstance(actual_bios_settings, bios.BIOSSettings) # On refreshing the system instance... @@ -138,8 +138,7 @@ class HPESystemTestCase(testtools.TestCase): self.sys_inst.refresh(force=False) # | WHEN & THEN | - self.assertIsNotNone(self.sys_inst._bios_settings) - self.assertTrue(self.sys_inst._bios_settings._is_stale) + self.assertTrue(actual_bios_settings._is_stale) # | GIVEN | with open('proliantutils/tests/redfish/json_samples/bios.json', @@ -148,7 +147,7 @@ class HPESystemTestCase(testtools.TestCase): # | WHEN & THEN | self.assertIsInstance(self.sys_inst.bios_settings, bios.BIOSSettings) - self.assertFalse(self.sys_inst._bios_settings._is_stale) + self.assertFalse(actual_bios_settings._is_stale) def test_update_persistent_boot_uefi_target(self): with open('proliantutils/tests/redfish/' @@ -189,7 +188,6 @@ class HPESystemTestCase(testtools.TestCase): pci_dev_return_value = None pci_dev1_return_value = None pci_coll_return_value = None - self.assertIsNone(self.sys_inst._pci_devices) self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/pci_device_collection.json') as f: @@ -220,8 +218,6 @@ class HPESystemTestCase(testtools.TestCase): _get_secure_boot) def test_secure_boot(self): - # check for the underneath variable value - self.assertIsNone(self.sys_inst._secure_boot) # | GIVEN | self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/json_samples/secure_boot.json', @@ -250,8 +246,8 @@ class HPESystemTestCase(testtools.TestCase): self.conn.get.return_value.json.return_value = ( json.loads(f.read())['default']) # | WHEN & THEN | - self.assertIsInstance(self.sys_inst.secure_boot, - secure_boot.SecureBoot) + actual_secure_boot = self.sys_inst.secure_boot + self.assertIsInstance(actual_secure_boot, secure_boot.SecureBoot) # On refreshing the system instance... with open('proliantutils/tests/redfish/' @@ -263,8 +259,7 @@ class HPESystemTestCase(testtools.TestCase): self.sys_inst.refresh(force=False) # | WHEN & THEN | - self.assertIsNotNone(self.sys_inst._secure_boot) - self.assertTrue(self.sys_inst._secure_boot._is_stale) + self.assertTrue(actual_secure_boot._is_stale) # | GIVEN | with open('proliantutils/tests/redfish/json_samples/secure_boot.json', @@ -274,7 +269,7 @@ class HPESystemTestCase(testtools.TestCase): # | WHEN & THEN | self.assertIsInstance(self.sys_inst.secure_boot, secure_boot.SecureBoot) - self.assertFalse(self.sys_inst._secure_boot._is_stale) + self.assertFalse(actual_secure_boot._is_stale) @mock.patch.object(utils, 'get_subresource_path_by') def test_get_hpe_sub_resource_collection_path(self, res_mock): @@ -317,11 +312,10 @@ class HPESystemTestCase(testtools.TestCase): eth_value = (json.loads(f.read())) self.conn.get.return_value.json.side_effect = [eth_coll, eth_value] - self.assertIsNone(self.sys_inst._ethernet_interfaces) actual_macs = self.sys_inst.ethernet_interfaces.summary self.assertEqual({'Port 1': '12:44:6A:3B:04:11'}, actual_macs) - self.assertIsInstance(self.sys_inst._ethernet_interfaces, + self.assertIsInstance(self.sys_inst.ethernet_interfaces, ethernet_interface.EthernetInterfaceCollection) def test_ethernet_interfaces_oem(self): @@ -348,11 +342,10 @@ class HPESystemTestCase(testtools.TestCase): eth_value = (json.loads(f.read())) self.conn.get.return_value.json.side_effect = [eth_coll, eth_value] - self.assertIsNone(self.sys_inst._ethernet_interfaces) actual_macs = self.sys_inst.ethernet_interfaces.summary self.assertEqual({'Port 1': '12:44:6A:3B:04:11'}, actual_macs) - self.assertIsInstance(self.sys_inst._ethernet_interfaces, + self.assertIsInstance(self.sys_inst.ethernet_interfaces, ethernet_interface.EthernetInterfaceCollection) def test_smart_storage(self): @@ -362,7 +355,6 @@ class HPESystemTestCase(testtools.TestCase): 'smart_storage.json', 'r') as f: value = (json.loads(f.read())) self.conn.get.return_value.json.return_value = value - self.assertIsNone(self.sys_inst._smart_storage) value = self.sys_inst.smart_storage self.assertIsInstance(value, smart_storage.HPESmartStorage) @@ -378,9 +370,8 @@ class HPESystemTestCase(testtools.TestCase): 'storage.json', 'r') as f: value = (json.loads(f.read())) self.conn.get.return_value.json.side_effect = [coll, value] - self.assertIsNone(self.sys_inst._storages) - value = self.sys_inst.storages - self.assertIsInstance(value, storage.StorageCollection) + self.assertIsInstance(self.sys_inst.storages, + storage.StorageCollection) def test_simple_storages(self): self.conn.get.return_value.json.reset_mock() @@ -394,16 +385,16 @@ class HPESystemTestCase(testtools.TestCase): 'simple_storage.json', 'r') as f: value = (json.loads(f.read())) self.conn.get.return_value.json.side_effect = [coll, value] - self.assertIsNone(self.sys_inst._simple_storages) - value = self.sys_inst.simple_storages - self.assertIsInstance(value, simple_storage.SimpleStorageCollection) + self.assertIsInstance(self.sys_inst.simple_storages, + simple_storage.SimpleStorageCollection) def test_simple_storage_on_refresh(self): with open('proliantutils/tests/redfish/json_samples/' 'simple_storage_collection.json', 'r') as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) - self.assertIsInstance(self.sys_inst.simple_storages, + actual_simple_storages = self.sys_inst.simple_storages + self.assertIsInstance(actual_simple_storages, simple_storage.SimpleStorageCollection) with open('proliantutils/tests/redfish/' 'json_samples/system.json', 'r') as f: @@ -413,18 +404,16 @@ class HPESystemTestCase(testtools.TestCase): self.sys_inst.invalidate() self.sys_inst.refresh(force=False) - self.assertIsNotNone(self.sys_inst._simple_storages) - self.assertTrue(self.sys_inst._simple_storages._is_stale) + self.assertTrue(actual_simple_storages._is_stale) with open('proliantutils/tests/redfish/json_samples/' 'simple_storage_collection.json', 'r') as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) self.assertIsInstance(self.sys_inst.simple_storages, simple_storage.SimpleStorageCollection) - self.assertFalse(self.sys_inst._simple_storages._is_stale) + self.assertFalse(actual_simple_storages._is_stale) def test_memory(self): - self.assertIsNone(self.sys_inst._memory) self.conn.get.return_value.json.reset_mock() with open('proliantutils/tests/redfish/' 'json_samples/memory_collection.json', 'r') as f: @@ -445,8 +434,8 @@ class HPESystemTestCase(testtools.TestCase): 'memory_collection.json', 'r') as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) # | WHEN & THEN | - self.assertIsInstance(self.sys_inst.memory, - memory.MemoryCollection) + actual_memory = self.sys_inst.memory + self.assertIsInstance(actual_memory, memory.MemoryCollection) # On refreshing the system instance... with open('proliantutils/tests/redfish/' @@ -458,8 +447,7 @@ class HPESystemTestCase(testtools.TestCase): self.sys_inst.refresh(force=False) # | WHEN & THEN | - self.assertIsNotNone(self.sys_inst._memory) - self.assertTrue(self.sys_inst._memory._is_stale) + self.assertTrue(actual_memory._is_stale) # | GIVEN | with open('proliantutils/tests/redfish/json_samples/' @@ -468,15 +456,15 @@ class HPESystemTestCase(testtools.TestCase): # | WHEN & THEN | self.assertIsInstance(self.sys_inst.memory, memory.MemoryCollection) - self.assertFalse(self.sys_inst._memory._is_stale) + self.assertFalse(actual_memory._is_stale) def test_storage_on_refresh(self): with open('proliantutils/tests/redfish/json_samples/' 'storage_collection.json', 'r') as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) - self.assertIsInstance(self.sys_inst.storages, - storage.StorageCollection) + actual_storages = self.sys_inst.storages + self.assertIsInstance(actual_storages, storage.StorageCollection) # On refreshing the system instance... with open('proliantutils/tests/redfish/' 'json_samples/system.json', 'r') as f: @@ -486,15 +474,14 @@ class HPESystemTestCase(testtools.TestCase): self.sys_inst.invalidate() self.sys_inst.refresh(force=False) - self.assertIsNotNone(self.sys_inst._storages) - self.assertTrue(self.sys_inst._storages._is_stale) + self.assertTrue(actual_storages._is_stale) with open('proliantutils/tests/redfish/json_samples/' 'simple_storage_collection.json', 'r') as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) self.assertIsInstance(self.sys_inst.storages, storage.StorageCollection) - self.assertFalse(self.sys_inst._storages._is_stale) + self.assertFalse(actual_storages._is_stale) def test_get_host_post_state(self): expected = sys_cons.POST_STATE_FINISHEDPOST diff --git a/requirements.txt b/requirements.txt index 048ceb1e..a7270170 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,4 @@ retrying!=1.3.0,>=1.2.3 # Apache-2.0 pysnmp>=4.2.3,<5.0.0 # BSD # Redfish communication uses the Sushy library -sushy>=1.3.1 +sushy>=1.7.0