From b913e0f5b2a2db0dea17b6f80c0a6029aa28a8a0 Mon Sep 17 00:00:00 2001 From: Debayan Ray Date: Fri, 5 Jan 2018 01:18:29 -0500 Subject: [PATCH] Changes to support Sushy 1.3.0 The new Sushy 1.3.0 library has some changes for which proliantutils needs changes to support the existing functionalities which it serves using Sushy library. This commit takes care of those changes. It also removes the version dependency of Sushy from proliantutils requirements and hence the latest Sushy release gets picked up. Change-Id: I1088d1b357bfe5c7cd76185bc4da484471ac3f6c --- proliantutils/redfish/main.py | 15 +++--- .../account_service/account_service.py | 15 ++++-- .../redfish/resources/manager/manager.py | 15 ++++-- .../redfish/resources/system/bios.py | 29 +++++++--- .../resources/system/ethernet_interface.py | 9 +++- .../redfish/resources/system/iscsi.py | 13 +++-- .../redfish/resources/system/pci_device.py | 18 +++++-- .../system/storage/array_controller.py | 30 ++++++++--- .../resources/system/storage/logical_drive.py | 9 +++- .../system/storage/physical_drive.py | 9 +++- .../system/storage/simple_storage.py | 18 +++++-- .../resources/system/storage/smart_storage.py | 15 ++++-- .../resources/system/storage/storage.py | 24 +++++++-- .../resources/system/storage/volume.py | 9 +++- .../redfish/resources/system/system.py | 48 +++++++++++++---- .../account_service/test_account_service.py | 11 ++-- .../redfish/resources/manager/test_manager.py | 10 ++-- .../resources/system/storage/test_storage.py | 6 ++- .../redfish/resources/system/test_bios.py | 53 +++++++++++++------ .../redfish/resources/system/test_iscsi.py | 13 +++-- .../redfish/resources/system/test_system.py | 43 +++++++++++---- proliantutils/tests/redfish/test_connector.py | 9 ++-- requirements.txt | 2 +- 23 files changed, 316 insertions(+), 107 deletions(-) diff --git a/proliantutils/redfish/main.py b/proliantutils/redfish/main.py index b02e955b..eecf6682 100644 --- a/proliantutils/redfish/main.py +++ b/proliantutils/redfish/main.py @@ -16,7 +16,7 @@ __author__ = 'HPE' import sushy -from proliantutils.redfish import connector +from proliantutils.redfish import connector as prutils_connector from proliantutils.redfish.resources.account_service import account_service from proliantutils.redfish.resources.manager import manager from proliantutils.redfish.resources.system import system @@ -34,7 +34,8 @@ class HPESushy(sushy.Sushy): """ def __init__(self, base_url, username=None, password=None, - root_prefix='/redfish/v1/', verify=True): + root_prefix='/redfish/v1/', verify=True, + auth=None, connector=None): """Initializes HPE specific sushy object. :param base_url: The base URL to the Redfish controller. It @@ -51,11 +52,13 @@ class HPESushy(sushy.Sushy): the driver will ignore verifying the SSL certificate; if it's a path the driver will use the specified certificate or one of the certificates in the directory. Defaults to True. + :param auth: An authentication mechanism to utilize. + :param connector: A user-defined connector object. Defaults to None. """ - self._root_prefix = root_prefix - super(sushy.Sushy, self).__init__( - connector.HPEConnector(base_url, username, password, verify), - path=self._root_prefix) + super(HPESushy, self).__init__( + base_url, username, password, + root_prefix=root_prefix, verify=verify, auth=auth, + connector=prutils_connector.HPEConnector(base_url, verify=verify)) def get_system_collection_path(self): return utils.get_subresource_path_by(self, 'Systems') diff --git a/proliantutils/redfish/resources/account_service/account_service.py b/proliantutils/redfish/resources/account_service/account_service.py index c8ca8650..21e56748 100644 --- a/proliantutils/redfish/resources/account_service/account_service.py +++ b/proliantutils/redfish/resources/account_service/account_service.py @@ -37,8 +37,17 @@ class HPEAccountService(base.ResourceBase): self._conn, utils.get_subresource_path_by(self, 'Accounts'), redfish_version=self.redfish_version) + self._accounts.refresh(force=False) return self._accounts - def refresh(self): - super(HPEAccountService, self).refresh() - self._accounts = 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. + """ + super(HPEAccountService, self)._do_refresh(force) + + if self._accounts is not None: + self._accounts.invalidate(force) diff --git a/proliantutils/redfish/resources/manager/manager.py b/proliantutils/redfish/resources/manager/manager.py index ffb01125..c3d6d31a 100644 --- a/proliantutils/redfish/resources/manager/manager.py +++ b/proliantutils/redfish/resources/manager/manager.py @@ -52,8 +52,17 @@ class HPEManager(manager.Manager): utils.get_subresource_path_by(self, 'VirtualMedia'), redfish_version=self.redfish_version) + self._virtual_media.refresh(force=False) return self._virtual_media - def refresh(self): - super(HPEManager, self).refresh() - self._virtual_media = 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. + """ + super(HPEManager, self)._do_refresh(force) + + if self._virtual_media is not None: + self._virtual_media.invalidate(force) diff --git a/proliantutils/redfish/resources/system/bios.py b/proliantutils/redfish/resources/system/bios.py index 22b579f8..55c0bbec 100644 --- a/proliantutils/redfish/resources/system/bios.py +++ b/proliantutils/redfish/resources/system/bios.py @@ -66,6 +66,7 @@ class BIOSSettings(base.ResourceBase): self, ["@Redfish.Settings", "SettingsObject"]), redfish_version=self.redfish_version) + self._pending_settings.refresh(force=False) return self._pending_settings @property @@ -82,6 +83,7 @@ class BIOSSettings(base.ResourceBase): self, ["Oem", "Hpe", "Links", "Boot"]), redfish_version=self.redfish_version) + self._boot_settings.refresh(force=False) return self._boot_settings @property @@ -98,6 +100,7 @@ class BIOSSettings(base.ResourceBase): self, ["Oem", "Hpe", "Links", "iScsi"]), redfish_version=self.redfish_version) + self._iscsi_resource.refresh(force=False) return self._iscsi_resource @property @@ -114,6 +117,7 @@ class BIOSSettings(base.ResourceBase): self, ["Oem", "Hpe", "Links", "Mappings"]), redfish_version=self.redfish_version) + self._bios_mappings.refresh(force=False) return self._bios_mappings def _get_base_configs(self): @@ -124,6 +128,7 @@ class BIOSSettings(base.ResourceBase): self, ["Oem", "Hpe", "Links", "BaseConfigs"]), redfish_version=self.redfish_version) + self._base_configs.refresh(force=False) return self._base_configs def update_bios_to_default(self): @@ -131,13 +136,23 @@ class BIOSSettings(base.ResourceBase): self.pending_settings.update_bios_data_by_post( self._get_base_configs().default_config) - def refresh(self): - super(BIOSSettings, self).refresh() - self._pending_settings = None - self._boot_settings = None - self._base_configs = None - self._iscsi_resource = None - self._bios_mappings = 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. + """ + 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): diff --git a/proliantutils/redfish/resources/system/ethernet_interface.py b/proliantutils/redfish/resources/system/ethernet_interface.py index 68166a6f..f4186239 100644 --- a/proliantutils/redfish/resources/system/ethernet_interface.py +++ b/proliantutils/redfish/resources/system/ethernet_interface.py @@ -82,6 +82,11 @@ class EthernetInterfaceCollection(base.ResourceCollectionBase): self._summary = mac_dict return self._summary - def refresh(self): - super(EthernetInterfaceCollection, self).refresh() + 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 diff --git a/proliantutils/redfish/resources/system/iscsi.py b/proliantutils/redfish/resources/system/iscsi.py index 078a1b0b..367a0640 100644 --- a/proliantutils/redfish/resources/system/iscsi.py +++ b/proliantutils/redfish/resources/system/iscsi.py @@ -52,11 +52,18 @@ class ISCSIResource(base.ResourceBase): self, ["@Redfish.Settings", "SettingsObject"]), redfish_version=self.redfish_version) + self._iscsi_settings.refresh(force=False) return self._iscsi_settings - def refresh(self): - super(ISCSIResource, self).refresh() - self._iscsi_settings = 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. + """ + if self._iscsi_settings is not None: + self._iscsi_settings.invalidate(force) class ISCSISettings(base.ResourceBase): diff --git a/proliantutils/redfish/resources/system/pci_device.py b/proliantutils/redfish/resources/system/pci_device.py index d4e4f804..30ef9933 100644 --- a/proliantutils/redfish/resources/system/pci_device.py +++ b/proliantutils/redfish/resources/system/pci_device.py @@ -34,8 +34,13 @@ class PCIDevice(base.ResourceBase): _nic_capacity = None - def refresh(self): - super(PCIDevice, self).refresh() + 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 @@ -71,8 +76,13 @@ class PCIDeviceCollection(base.ResourceCollectionBase): self._gpu_devices.append(member) return self._gpu_devices - def refresh(self): - super(PCIDeviceCollection, self).refresh() + 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 diff --git a/proliantutils/redfish/resources/system/storage/array_controller.py b/proliantutils/redfish/resources/system/storage/array_controller.py index 65b8b17d..408bc51f 100644 --- a/proliantutils/redfish/resources/system/storage/array_controller.py +++ b/proliantutils/redfish/resources/system/storage/array_controller.py @@ -47,6 +47,8 @@ class HPEArrayController(base.ResourceBase): 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 @property @@ -59,12 +61,23 @@ class HPEArrayController(base.ResourceBase): 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 refresh(self): - super(HPEArrayController, self).refresh() - self._physical_drives = None - self._logical_drives = 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. + """ + 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) class HPEArrayControllerCollection(base.ResourceCollectionBase): @@ -153,8 +166,13 @@ class HPEArrayControllerCollection(base.ResourceCollectionBase): member.physical_drives.drive_rotational_speed_rpm) return self._drive_rotational_speed_rpm - def refresh(self): - super(HPEArrayControllerCollection, self).refresh() + 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 diff --git a/proliantutils/redfish/resources/system/storage/logical_drive.py b/proliantutils/redfish/resources/system/storage/logical_drive.py index 5929a392..d7a98e7d 100644 --- a/proliantutils/redfish/resources/system/storage/logical_drive.py +++ b/proliantutils/redfish/resources/system/storage/logical_drive.py @@ -68,7 +68,12 @@ class HPELogicalDriveCollection(base.ResourceCollectionBase): mappings.RAID_LEVEL_MAP_REV.get(member.raid)) return self._logical_raid_levels - def refresh(self): - super(HPELogicalDriveCollection, self).refresh() + 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 diff --git a/proliantutils/redfish/resources/system/storage/physical_drive.py b/proliantutils/redfish/resources/system/storage/physical_drive.py index 612ec7dc..4cf04b66 100644 --- a/proliantutils/redfish/resources/system/storage/physical_drive.py +++ b/proliantutils/redfish/resources/system/storage/physical_drive.py @@ -96,8 +96,13 @@ class HPEPhysicalDriveCollection(base.ResourceCollectionBase): member.rotational_speed_rpm) return self._drive_rotational_speed_rpm - def refresh(self): - super(HPEPhysicalDriveCollection, self).refresh() + 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 diff --git a/proliantutils/redfish/resources/system/storage/simple_storage.py b/proliantutils/redfish/resources/system/storage/simple_storage.py index a9db991d..c1c51563 100644 --- a/proliantutils/redfish/resources/system/storage/simple_storage.py +++ b/proliantutils/redfish/resources/system/storage/simple_storage.py @@ -48,8 +48,13 @@ class SimpleStorage(base.ResourceBase): if device.get('CapacityBytes') is not None])) return self._maximum_size_bytes - def refresh(self): - super(SimpleStorage, self).refresh() + 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 @@ -73,6 +78,11 @@ class SimpleStorageCollection(base.ResourceCollectionBase): for member in self.get_members()])) return self._maximum_size_bytes - def refresh(self): - super(SimpleStorageCollection, self).refresh() + 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 diff --git a/proliantutils/redfish/resources/system/storage/smart_storage.py b/proliantutils/redfish/resources/system/storage/smart_storage.py index d5e48a3a..cae09c69 100644 --- a/proliantutils/redfish/resources/system/storage/smart_storage.py +++ b/proliantutils/redfish/resources/system/storage/smart_storage.py @@ -51,6 +51,8 @@ class HPESmartStorage(base.ResourceBase): 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 @property @@ -112,11 +114,18 @@ class HPESmartStorage(base.ResourceBase): self.array_controllers.drive_rotational_speed_rpm) return self._drive_rotational_speed_rpm - def refresh(self): - super(HPESmartStorage, self).refresh() + 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._array_controllers = None self._has_ssd = None self._has_rotational = None self._logical_raid_levels = None diff --git a/proliantutils/redfish/resources/system/storage/storage.py b/proliantutils/redfish/resources/system/storage/storage.py index 8e3d09a5..2b3a8251 100644 --- a/proliantutils/redfish/resources/system/storage/storage.py +++ b/proliantutils/redfish/resources/system/storage/storage.py @@ -56,6 +56,8 @@ class Storage(base.ResourceBase): 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 def _drives_list(self): @@ -129,10 +131,17 @@ class Storage(base.ResourceBase): member.rotation_speed_rpm) return self._drive_rotational_speed_rpm - def refresh(self): - super(Storage, self).refresh() + 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._volumes = None self._has_ssd = None self._has_rotational = None self._has_nvme_ssd = None @@ -224,8 +233,13 @@ class StorageCollection(base.ResourceCollectionBase): member.drive_rotational_speed_rpm) return self._drive_rotational_speed_rpm - def refresh(self): - super(StorageCollection, self).refresh() + 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 diff --git a/proliantutils/redfish/resources/system/storage/volume.py b/proliantutils/redfish/resources/system/storage/volume.py index 2812fb6c..a886f263 100644 --- a/proliantutils/redfish/resources/system/storage/volume.py +++ b/proliantutils/redfish/resources/system/storage/volume.py @@ -48,6 +48,11 @@ class VolumeCollection(base.ResourceCollectionBase): for member in self.get_members()])) return self._maximum_size_bytes - def refresh(self): - super(VolumeCollection, self).refresh() + 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 diff --git a/proliantutils/redfish/resources/system/system.py b/proliantutils/redfish/resources/system/system.py index c98a8fba..889a88ae 100644 --- a/proliantutils/redfish/resources/system/system.py +++ b/proliantutils/redfish/resources/system/system.py @@ -134,6 +134,7 @@ class HPESystem(system.System): self._conn, utils.get_subresource_path_by(self, 'Bios'), redfish_version=self.redfish_version) + self._bios_settings.refresh(force=False) return self._bios_settings def update_persistent_boot(self, devices=[], persistent=False): @@ -188,6 +189,8 @@ class HPESystem(system.System): 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 @property @@ -202,18 +205,34 @@ class HPESystem(system.System): 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 refresh(self): - super(HPESystem, self).refresh() - self._bios_settings = None - self._pci_devices = None - self._secure_boot = None - self._ethernet_interfaces = None - self._smart_storage = None - self._storages = None - self._simple_storages = None - self._memory = 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. + """ + 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) def _get_hpe_sub_resource_collection_path(self, sub_res): path = None @@ -235,6 +254,7 @@ class HPESystem(system.System): self._get_hpe_sub_resource_collection_path(sub_res), redfish_version=self.redfish_version)) + self._ethernet_interfaces.refresh(force=False) return self._ethernet_interfaces @property @@ -250,6 +270,8 @@ class HPESystem(system.System): 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 @property @@ -263,6 +285,8 @@ class HPESystem(system.System): 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 @property @@ -271,12 +295,13 @@ class HPESystem(system.System): :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 @property @@ -292,4 +317,5 @@ class HPESystem(system.System): self, 'Memory'), redfish_version=self.redfish_version) + self._memory.refresh(force=False) return self._memory 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 bd68e975..4fa4c66a 100644 --- a/proliantutils/tests/redfish/resources/account_service/test_account_service.py +++ b/proliantutils/tests/redfish/resources/account_service/test_account_service.py @@ -57,11 +57,16 @@ class HPEAccountServiceTestCase(testtools.TestCase): 'json_samples/account_service.json', 'r') as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) - self.acc_inst.refresh() - self.assertIsNone(self.acc_inst._accounts) + self.acc_inst.invalidate() + self.acc_inst.refresh(force=False) + + self.assertIsNotNone(self.acc_inst._accounts) + self.assertTrue(self.acc_inst._accounts._is_stale) 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()) - self.assertIsInstance(accounts, account.HPEAccountCollection) + self.assertIsInstance(self.acc_inst.accounts, + account.HPEAccountCollection) + self.assertFalse(self.acc_inst._accounts._is_stale) diff --git a/proliantutils/tests/redfish/resources/manager/test_manager.py b/proliantutils/tests/redfish/resources/manager/test_manager.py index 65cf7246..6865742d 100644 --- a/proliantutils/tests/redfish/resources/manager/test_manager.py +++ b/proliantutils/tests/redfish/resources/manager/test_manager.py @@ -74,12 +74,16 @@ class HPEManagerTestCase(testtools.TestCase): 'json_samples/manager.json', 'r') as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) - self.mgr_inst.refresh() - self.assertIsNone(self.mgr_inst._virtual_media) + 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) with open('proliantutils/tests/redfish/' 'json_samples/vmedia_collection.json', 'r') as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) - self.assertIsInstance(actual_vmedia, + self.assertIsInstance(self.mgr_inst.virtual_media, virtual_media.VirtualMediaCollection) + self.assertFalse(self.mgr_inst._virtual_media._is_stale) diff --git a/proliantutils/tests/redfish/resources/system/storage/test_storage.py b/proliantutils/tests/redfish/resources/system/storage/test_storage.py index ff9000b3..d5b8d5ef 100644 --- a/proliantutils/tests/redfish/resources/system/storage/test_storage.py +++ b/proliantutils/tests/redfish/resources/system/storage/test_storage.py @@ -59,8 +59,10 @@ class StorageTestCase(testtools.TestCase): actual_log_dr = self.sys_stor.volumes self.assertIs(actual_log_dr, self.sys_stor.volumes) - self.sys_stor.refresh() - self.assertIsNone(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) def test__drives_list(self): self.conn.get.return_value.json.reset_mock() diff --git a/proliantutils/tests/redfish/resources/system/test_bios.py b/proliantutils/tests/redfish/resources/system/test_bios.py index 0226be92..aba12ad4 100644 --- a/proliantutils/tests/redfish/resources/system/test_bios.py +++ b/proliantutils/tests/redfish/resources/system/test_bios.py @@ -141,16 +141,20 @@ class BIOSSettingsTestCase(testtools.TestCase): self.conn.get.return_value.json.return_value = ( json.loads(f.read())['Default']) - self.bios_inst.refresh() - self.assertIsNone(self.bios_inst._pending_settings) + 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) with open('proliantutils/tests/redfish/' 'json_samples/bios.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())['BIOS_pending_settings_default']) - self.assertIsInstance(actual_settings, + self.assertIsInstance(self.bios_inst.pending_settings, bios.BIOSPendingSettings) + self.assertFalse(self.bios_inst._pending_settings._is_stale) def test_boot_settings_on_refresh(self): with open('proliantutils/tests/redfish/' @@ -166,16 +170,20 @@ class BIOSSettingsTestCase(testtools.TestCase): self.conn.get.return_value.json.return_value = ( json.loads(f.read())['Default']) - self.bios_inst.refresh() - self.assertIsNone(self.bios_inst._boot_settings) + 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) with open('proliantutils/tests/redfish/' 'json_samples/bios_boot.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())['Default']) - self.assertIsInstance(actual_settings, + self.assertIsInstance(self.bios_inst.boot_settings, bios.BIOSBootSettings) + self.assertFalse(self.bios_inst._boot_settings._is_stale) def test_bios_mappings_on_refresh(self): with open('proliantutils/tests/redfish/' @@ -191,16 +199,20 @@ class BIOSSettingsTestCase(testtools.TestCase): self.conn.get.return_value.json.return_value = ( json.loads(f.read())['Default']) - self.bios_inst.refresh() - self.assertIsNone(self.bios_inst._bios_mappings) + 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) with open('proliantutils/tests/redfish/' 'json_samples/bios_mappings.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())['Default']) - self.assertIsInstance(actual_settings, + self.assertIsInstance(self.bios_inst.bios_mappings, bios.BIOSMappings) + self.assertFalse(self.bios_inst._bios_mappings._is_stale) def test_iscsi_resource_on_refresh(self): with open('proliantutils/tests/redfish/' @@ -215,15 +227,21 @@ class BIOSSettingsTestCase(testtools.TestCase): 'json_samples/bios.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())['Default']) - self.bios_inst.refresh() - self.assertIsNone(self.bios_inst._iscsi_resource) + + 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) with open('proliantutils/tests/redfish/' 'json_samples/iscsi.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())) - self.assertIsInstance(actual_settings, + + self.assertIsInstance(self.bios_inst.iscsi_resource, iscsi.ISCSIResource) + self.assertFalse(self.bios_inst._iscsi_resource._is_stale) def test__get_base_configs_on_refresh(self): with open('proliantutils/tests/redfish/' @@ -237,14 +255,19 @@ class BIOSSettingsTestCase(testtools.TestCase): self.conn.get.return_value.json.return_value = ( json.loads(f.read())['Default']) - self.bios_inst.refresh() - self.assertIsNone(self.bios_inst._base_configs) + 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) 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()) - self.assertIsInstance(default_settings, bios.BIOSBaseConfigs) + self.assertIsInstance(self.bios_inst._get_base_configs(), + bios.BIOSBaseConfigs) + self.assertFalse(self.bios_inst._base_configs._is_stale) class BIOSBaseConfigsTestCase(testtools.TestCase): diff --git a/proliantutils/tests/redfish/resources/system/test_iscsi.py b/proliantutils/tests/redfish/resources/system/test_iscsi.py index d3cce63e..5b908132 100644 --- a/proliantutils/tests/redfish/resources/system/test_iscsi.py +++ b/proliantutils/tests/redfish/resources/system/test_iscsi.py @@ -66,7 +66,7 @@ class ISCSIResourceTestCase(testtools.TestCase): self.iscsi_inst.iscsi_settings) self.conn.get.return_value.json.assert_not_called() - def test_iscsi_resource_on_refresh(self): + def test_iscsi_settings_on_refresh(self): with open('proliantutils/tests/redfish/' 'json_samples/iscsi_settings.json', 'r') as f: self.conn.get.return_value.json.return_value = ( @@ -79,15 +79,20 @@ class ISCSIResourceTestCase(testtools.TestCase): 'json_samples/iscsi.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())) - self.iscsi_inst.refresh() - self.assertIsNone(self.iscsi_inst._iscsi_settings) + + 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) with open('proliantutils/tests/redfish/' 'json_samples/iscsi_settings.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())['Default']) - self.assertIsInstance(actual_settings, + self.assertIsInstance(self.iscsi_inst.iscsi_settings, iscsi.ISCSISettings) + self.assertFalse(self.iscsi_inst._iscsi_settings._is_stale) def test_attributes(self): with open('proliantutils/tests/redfish/' diff --git a/proliantutils/tests/redfish/resources/system/test_system.py b/proliantutils/tests/redfish/resources/system/test_system.py index 55f9d77a..948cd935 100644 --- a/proliantutils/tests/redfish/resources/system/test_system.py +++ b/proliantutils/tests/redfish/resources/system/test_system.py @@ -131,10 +131,13 @@ class HPESystemTestCase(testtools.TestCase): 'json_samples/system.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())['default']) - self.sys_inst.refresh() + + self.sys_inst.invalidate() + self.sys_inst.refresh(force=False) # | WHEN & THEN | - self.assertIsNone(self.sys_inst._bios_settings) + self.assertIsNotNone(self.sys_inst._bios_settings) + self.assertTrue(self.sys_inst._bios_settings._is_stale) # | GIVEN | with open('proliantutils/tests/redfish/json_samples/bios.json', @@ -143,6 +146,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) def test_update_persistent_boot_uefi_target(self): with open('proliantutils/tests/redfish/' @@ -252,10 +256,13 @@ class HPESystemTestCase(testtools.TestCase): 'json_samples/system.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())['default']) - self.sys_inst.refresh() + + self.sys_inst.invalidate() + self.sys_inst.refresh(force=False) # | WHEN & THEN | - self.assertIsNone(self.sys_inst._secure_boot) + self.assertIsNotNone(self.sys_inst._secure_boot) + self.assertTrue(self.sys_inst._secure_boot._is_stale) # | GIVEN | with open('proliantutils/tests/redfish/json_samples/secure_boot.json', @@ -265,6 +272,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) @mock.patch.object(utils, 'get_subresource_path_by') def test_get_hpe_sub_resource_collection_path(self, res_mock): @@ -399,13 +407,19 @@ class HPESystemTestCase(testtools.TestCase): 'json_samples/system.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())['default']) - self.sys_inst.refresh() - self.assertIsNone(self.sys_inst._simple_storages) + + 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) + 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) def test_memory(self): self.assertIsNone(self.sys_inst._memory) @@ -437,10 +451,13 @@ class HPESystemTestCase(testtools.TestCase): 'json_samples/system.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())['default']) - self.sys_inst.refresh() + + self.sys_inst.invalidate() + self.sys_inst.refresh(force=False) # | WHEN & THEN | - self.assertIsNone(self.sys_inst._memory) + self.assertIsNotNone(self.sys_inst._memory) + self.assertTrue(self.sys_inst._memory._is_stale) # | GIVEN | with open('proliantutils/tests/redfish/json_samples/' @@ -449,6 +466,7 @@ class HPESystemTestCase(testtools.TestCase): # | WHEN & THEN | self.assertIsInstance(self.sys_inst.memory, memory.MemoryCollection) + self.assertFalse(self.sys_inst._memory._is_stale) def test_storage_on_refresh(self): with open('proliantutils/tests/redfish/json_samples/' @@ -462,11 +480,16 @@ class HPESystemTestCase(testtools.TestCase): 'json_samples/system.json', 'r') as f: self.conn.get.return_value.json.return_value = ( json.loads(f.read())['default']) - self.sys_inst.refresh() - self.assertIsNone(self.sys_inst._storages) + + self.sys_inst.invalidate() + self.sys_inst.refresh(force=False) + + self.assertIsNotNone(self.sys_inst._storages) + self.assertTrue(self.sys_inst._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) diff --git a/proliantutils/tests/redfish/test_connector.py b/proliantutils/tests/redfish/test_connector.py index 321882c4..d29698b1 100644 --- a/proliantutils/tests/redfish/test_connector.py +++ b/proliantutils/tests/redfish/test_connector.py @@ -32,8 +32,7 @@ class HPEConnectorTestCase(testtools.TestCase): "Hello", "World"] hpe_conn = hpe_connector.HPEConnector( - 'http://foo.bar:1234', username='user', - password='pass', verify=True) + 'http://foo.bar:1234', verify=True) headers = {'X-Fake': 'header'} hpe_conn._op('GET', path='fake/path', data=None, headers=headers) conn_mock.assert_called_once_with(hpe_conn, 'GET', path='fake/path', @@ -46,8 +45,7 @@ class HPEConnectorTestCase(testtools.TestCase): exceptions.ConnectionError, "Hello", "World"] hpe_conn = hpe_connector.HPEConnector( - 'http://foo.bar:1234', username='user', - password='pass', verify=True) + 'http://foo.bar:1234', verify=True) headers = {'X-Fake': 'header'} lval = hpe_conn._op('GET', path='fake/path', data=None, headers=headers) @@ -62,8 +60,7 @@ class HPEConnectorTestCase(testtools.TestCase): ["Hello", "World"]) hpe_conn = hpe_connector.HPEConnector( - 'http://foo.bar:1234', username='user', - password='pass', verify=True) + 'http://foo.bar:1234', verify=True) headers = {'X-Fake': 'header'} self.assertRaises( exceptions.ConnectionError, hpe_conn._op, diff --git a/requirements.txt b/requirements.txt index 82fc5a61..1ce97522 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.0.0 +sushy