Follow-up to 27c725c
to move up `cache_clear
`
Move up ``cache_clear()`` to ``ResourceBase._do_refresh()`` method. It saves on a lot of ``_do_refresh()`` overrides in subclasses. Also change to ``Sequence`` (from ``Iterable``) in the caching implementation. Follow-up of Change: I7404a15beb029cb282ac6b84bb8b8fdb97ebcd4c Change-Id: Id6c6afcd9142bed0a7f59b9f8893fb86975a65bb
This commit is contained in:
parent
6d0d5896ec
commit
28ee59fd79
@ -316,12 +316,20 @@ class ResourceBase(object):
|
||||
resource specific refresh operations to be performed. This is a
|
||||
primitive method in the paradigm of Template design pattern.
|
||||
|
||||
As for the base implementation of this method the approach taken is:
|
||||
On refresh, all sub-resources are marked as stale. That means
|
||||
invalidate (or undefine) the exposed attributes for nested resources
|
||||
for fresh evaluation in subsequent calls to those exposed attributes.
|
||||
In other words greedy-refresh is not done for them, unless forced by
|
||||
``force`` argument.
|
||||
|
||||
:param force: should force refresh the resource and its sub-resources,
|
||||
if set to True.
|
||||
:raises: ResourceNotFoundError
|
||||
:raises: ConnectionError
|
||||
:raises: HTTPError
|
||||
"""
|
||||
utils.cache_clear(self, force_refresh=force)
|
||||
|
||||
def invalidate(self, force_refresh=False):
|
||||
"""Mark the resource as stale, prompting refresh() before getting used.
|
||||
@ -400,13 +408,3 @@ class ResourceCollectionBase(ResourceBase):
|
||||
:returns: A list of ``_resource_type`` objects
|
||||
"""
|
||||
return [self.get_member(id_) for id_ in self.members_identities]
|
||||
|
||||
def _do_refresh(self, force):
|
||||
"""Do refresh related activities.
|
||||
|
||||
Invalidate / Undefine the cache attributes here for fresh evaluation
|
||||
in subsequent calls to `get_members()` method. Other similar activities
|
||||
can also follow in future, if needed.
|
||||
"""
|
||||
super(ResourceCollectionBase, self)._do_refresh(force=force)
|
||||
utils.cache_clear(self, force)
|
||||
|
@ -87,10 +87,6 @@ class Manager(base.ResourceBase):
|
||||
"""
|
||||
super(Manager, self).__init__(connector, identity, redfish_version)
|
||||
|
||||
def _do_refresh(self, force):
|
||||
super(Manager, self)._do_refresh(force=force)
|
||||
utils.cache_clear(self, force)
|
||||
|
||||
def get_supported_graphical_console_types(self):
|
||||
"""Get the supported values for Graphical Console connection types.
|
||||
|
||||
|
@ -76,16 +76,6 @@ class SessionService(base.ResourceBase):
|
||||
self._conn, self._get_sessions_collection_path(),
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
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(SessionService, self)._do_refresh(force=force)
|
||||
utils.cache_clear(self, force)
|
||||
|
||||
def close_session(self, session_uri):
|
||||
"""This function is for closing a session based on its id.
|
||||
|
||||
|
@ -147,13 +147,3 @@ class Bios(base.ResourceBase):
|
||||
'OldPassword': old_password,
|
||||
'PasswordName': password_name})
|
||||
LOG.info('BIOS password %s is being changed', self.identity)
|
||||
|
||||
def _do_refresh(self, force=False):
|
||||
"""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(Bios, self)._do_refresh(force=force)
|
||||
utils.cache_clear(self, force)
|
||||
|
@ -73,13 +73,3 @@ class EthernetInterfaceCollection(base.ResourceCollectionBase):
|
||||
if eth.status.health == res_cons.HEALTH_OK:
|
||||
mac_dict[eth.mac_address] = eth.status.state
|
||||
return mac_dict
|
||||
|
||||
def _do_refresh(self, force=False):
|
||||
"""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(EthernetInterfaceCollection, self)._do_refresh(force)
|
||||
utils.cache_clear(self, force)
|
||||
|
@ -142,13 +142,3 @@ class ProcessorCollection(base.ResourceCollectionBase):
|
||||
"""
|
||||
super(ProcessorCollection, self).__init__(connector, path,
|
||||
redfish_version)
|
||||
|
||||
def _do_refresh(self, force=False):
|
||||
"""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(ProcessorCollection, self)._do_refresh(force=force)
|
||||
utils.cache_clear(self, force)
|
||||
|
@ -83,7 +83,3 @@ class SimpleStorageCollection(base.ResourceCollectionBase):
|
||||
refreshed.
|
||||
"""
|
||||
return utils.max_safe(self.disks_sizes_bytes)
|
||||
|
||||
def _do_refresh(self, force):
|
||||
super(SimpleStorageCollection, self)._do_refresh(force=force)
|
||||
utils.cache_clear(self, force)
|
||||
|
@ -95,13 +95,6 @@ class Storage(base.ResourceBase):
|
||||
self._conn, utils.get_sub_resource_path_by(self, 'Volumes'),
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
def _do_refresh(self, force):
|
||||
"""Do resource specific refresh activities."""
|
||||
# Note(deray): invalidate / undefine the attributes here for fresh
|
||||
# evaluation in subsequent calls to it's exposed property.
|
||||
super(Storage, self)._do_refresh(force=force)
|
||||
utils.cache_clear(self, force)
|
||||
|
||||
|
||||
class StorageCollection(base.ResourceCollectionBase):
|
||||
"""This class represents the collection of Storage resources"""
|
||||
@ -149,8 +142,3 @@ class StorageCollection(base.ResourceCollectionBase):
|
||||
refreshed.
|
||||
"""
|
||||
return utils.max_safe(self.volumes_sizes_bytes)
|
||||
|
||||
def _do_refresh(self, force):
|
||||
"""Do resource specific refresh activities"""
|
||||
super(StorageCollection, self)._do_refresh(force=force)
|
||||
utils.cache_clear(self, force)
|
||||
|
@ -62,7 +62,3 @@ class VolumeCollection(base.ResourceCollectionBase):
|
||||
|
||||
# NOTE(etingof): for backward compatibility
|
||||
max_size_bytes = max_volume_size_bytes
|
||||
|
||||
def _do_refresh(self, force):
|
||||
super(VolumeCollection, self)._do_refresh(force=force)
|
||||
utils.cache_clear(self, force)
|
||||
|
@ -332,16 +332,6 @@ class System(base.ResourceBase):
|
||||
self._conn, utils.get_sub_resource_path_by(self, "Storage"),
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
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(System, self)._do_refresh(force=force)
|
||||
utils.cache_clear(self, force)
|
||||
|
||||
|
||||
class SystemCollection(base.ResourceCollectionBase):
|
||||
|
||||
|
@ -139,9 +139,6 @@ class BaseResource(resource_base.ResourceBase):
|
||||
NestedResource(self._conn, "/nested_res2",
|
||||
redfish_version=self.redfish_version)]
|
||||
|
||||
def _do_refresh(self, force):
|
||||
utils.cache_clear(self, force)
|
||||
|
||||
|
||||
class CacheTestCase(base.TestCase):
|
||||
|
||||
|
@ -163,7 +163,7 @@ def cache_it(res_accessor_method):
|
||||
def _do_refresh(self, force):
|
||||
cache_clear(self, force)
|
||||
|
||||
If the returned value is a Sushy resource instance or an Iterable whose
|
||||
If the returned value is a Sushy resource instance or a sequence whose
|
||||
element is of type Sushy resource it handles the case of calling the
|
||||
``refresh()`` method of that resource. This is done to avoid unnecessary
|
||||
recreation of a new resource instance which got already created at the
|
||||
@ -215,7 +215,7 @@ def cache_it(res_accessor_method):
|
||||
|
||||
if isinstance(cache_attr_val, base.ResourceBase):
|
||||
cache_attr_val.refresh(force=False)
|
||||
elif isinstance(cache_attr_val, collections.Iterable):
|
||||
elif isinstance(cache_attr_val, collections.Sequence):
|
||||
for elem in cache_attr_val:
|
||||
if isinstance(elem, base.ResourceBase):
|
||||
elem.refresh(force=False)
|
||||
@ -237,15 +237,15 @@ def cache_clear(res_selfie, force_refresh, only_these=None):
|
||||
|
||||
:param res_selfie: the resource instance.
|
||||
:param force_refresh: force_refresh argument of ``invalidate()`` method.
|
||||
:param only_these: expects an Iterable of specific method names
|
||||
:param only_these: expects a sequence of specific method names
|
||||
for which the cached value/s need to be cleared only. When None, all
|
||||
the cached values are cleared.
|
||||
"""
|
||||
cache_attr_names = setdefaultattr(
|
||||
res_selfie, CACHE_ATTR_NAMES_VAR_NAME, set())
|
||||
if only_these is not None:
|
||||
if not isinstance(only_these, collections.Iterable):
|
||||
raise TypeError("'only_these' must be Iterable.")
|
||||
if not isinstance(only_these, collections.Sequence):
|
||||
raise TypeError("'only_these' must be a sequence.")
|
||||
|
||||
cache_attr_names = cache_attr_names.intersection(
|
||||
'_cache_' + attr for attr in only_these)
|
||||
@ -257,7 +257,7 @@ def cache_clear(res_selfie, force_refresh, only_these=None):
|
||||
|
||||
if isinstance(cache_attr_val, base.ResourceBase):
|
||||
cache_attr_val.invalidate(force_refresh)
|
||||
elif isinstance(cache_attr_val, collections.Iterable):
|
||||
elif isinstance(cache_attr_val, collections.Sequence):
|
||||
for elem in cache_attr_val:
|
||||
if isinstance(elem, base.ResourceBase):
|
||||
elem.invalidate(force_refresh)
|
||||
|
Loading…
Reference in New Issue
Block a user