Skip to content
Snippets Groups Projects
Commit fdb8b193 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-544: Wrap repeating check to swallow exceptions that indicate we...

L2SS-544: Wrap repeating check to swallow exceptions that indicate we stop/remove an attribute that is not being archived.
parent f384165b
No related branches found
No related tags found
1 merge request!199L2SS-544: Improve LibConfiguration parsing, and return a dict instead of list...
...@@ -55,6 +55,27 @@ def split_tango_name(tango_fqname:str, tango_type:str): ...@@ -55,6 +55,27 @@ def split_tango_name(tango_fqname:str, tango_type:str):
else: else:
raise ValueError(f"Invalid value: {tango_type}. Please provide 'device' or 'attribute'.") raise ValueError(f"Invalid value: {tango_type}. Please provide 'device' or 'attribute'.")
def warn_if_attribute_not_found():
"""
Log a warning if an exception is thrown indicating access to an non-existing attribute
was requested, and swallow the exception.
"""
def inner(func):
@wraps(func)
def warn_wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except DevFailed as e:
if e.args[0].reason == 'Attribute not found':
logger.warning(f"Attribute {attribute_name} not found!")
else:
raise
return warn_wrapper
return inner
class Archiver(): class Archiver():
""" """
The Archiver class implements the basic operations to perform attributes archiving The Archiver class implements the basic operations to perform attributes archiving
...@@ -241,20 +262,16 @@ class Archiver(): ...@@ -241,20 +262,16 @@ class Archiver():
else: else:
logger.warning(f"Attribute {attr_fullname} will not be archived because polling is set to FALSE!") logger.warning(f"Attribute {attr_fullname} will not be archived because polling is set to FALSE!")
@warn_if_attribute_not_found()
def remove_attribute_from_archiver(self, attribute_name:str): def remove_attribute_from_archiver(self, attribute_name:str):
""" """
Stops the data archiving of the attribute passed as input, and remove it from the subscriber's list. Stops the data archiving of the attribute passed as input, and remove it from the subscriber's list.
""" """
attribute_name = attribute_name_from_url(attribute_name) attribute_name = attribute_name_from_url(attribute_name)
try:
self.cm.AttributeStop(attribute_name) self.cm.AttributeStop(attribute_name)
self.cm.AttributeRemove(attribute_name) self.cm.AttributeRemove(attribute_name)
logger.warning(f"Attribute {attribute_name} removed!") logger.warning(f"Attribute {attribute_name} removed!")
except DevFailed as e:
if e.args[0].reason == 'Attribute not found':
logger.warning(f"Attribute {attribute_name} not found!")
else:
raise
def remove_attributes_by_device(self,device_name:str,exclude:list=[]): def remove_attributes_by_device(self,device_name:str,exclude:list=[]):
""" """
...@@ -289,33 +306,25 @@ class Archiver(): ...@@ -289,33 +306,25 @@ class Archiver():
attr_fullname = attribute_name_from_url(a) attr_fullname = attribute_name_from_url(a)
self.remove_attribute_from_archiver(attr_fullname) self.remove_attribute_from_archiver(attr_fullname)
@warn_if_attribute_not_found()
def start_archiving_attribute(self, attribute_name:str): def start_archiving_attribute(self, attribute_name:str):
""" """
Starts the archiving of the attribute passed as input. Starts the archiving of the attribute passed as input.
The attribute must be already present in the subscriber's list The attribute must be already present in the subscriber's list
""" """
attribute_name = attribute_name_from_url(attribute_name) attribute_name = attribute_name_from_url(attribute_name)
try:
self.cm.AttributeStart(attribute_name) self.cm.AttributeStart(attribute_name)
except DevFailed as e:
if e.args[0].reason == "Attribute not found":
logger.warning(f"Attribute {attribute_name} not found!")
else:
raise
@warn_if_attribute_not_found()
def stop_archiving_attribute(self, attribute_name:str): def stop_archiving_attribute(self, attribute_name:str):
""" """
Stops the archiving of the attribute passed as input. Stops the archiving of the attribute passed as input.
The attribute must be already present in the subscriber's list The attribute must be already present in the subscriber's list
""" """
attribute_name = attribute_name_from_url(attribute_name) attribute_name = attribute_name_from_url(attribute_name)
try:
self.cm.AttributeStop(attribute_name) self.cm.AttributeStop(attribute_name)
except DevFailed as e:
if e.args[0].reason == "Attribute not found":
logger.warning(f"Attribute {attribute_name} not found!")
else:
raise
def is_attribute_archived(self,attribute_name:str): def is_attribute_archived(self,attribute_name:str):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment