Skip to content
Snippets Groups Projects
Commit d0faa0e9 authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

L2SS-404: fix bugs after ticket review

parent ff9f994f
No related branches found
No related tags found
1 merge request!253Resolve L2SS-404 "Archiving setup development"
...@@ -33,10 +33,10 @@ class TestArchiverUtil(base.TestCase): ...@@ -33,10 +33,10 @@ class TestArchiverUtil(base.TestCase):
def test_get_parameters_from_attribute(self): def test_get_parameters_from_attribute(self):
"""Test if the attribute archiving parameters are correctly retrieved from the JSON config file""" """Test if the attribute archiving parameters are correctly retrieved from the JSON config file"""
self.assertIsNotNone(self.config_dict) self.assertIsNotNone(self.config_dict)
suffixes = self.config_dict.get('_global_suffixes') suffixes = self.config_dict['_global_suffixes']
archive_period, event_period, abs_change, rel_change = get_parameters_from_attribute(self.device_name, self.attribute_name, archive_period, event_period, abs_change, rel_change = get_parameters_from_attribute(self.device_name, self.attribute_name,
suffixes, self.config_dict) suffixes, self.config_dict)
self.assertEqual(archive_period,int(suffixes[2].get('archive_period'))) self.assertEqual(archive_period,int(suffixes[2]['archive_period']))
self.assertEqual(event_period,int(suffixes[2].get('event_period'))) self.assertEqual(event_period,int(suffixes[2]['event_period']))
self.assertEqual(abs_change,int(suffixes[2].get('abs_change'))) self.assertEqual(abs_change,int(suffixes[2]['abs_change']))
self.assertEqual(rel_change,suffixes[2].get('rel_change')) self.assertEqual(rel_change,suffixes[2]['rel_change'])
...@@ -105,26 +105,26 @@ class Archiver(): ...@@ -105,26 +105,26 @@ class Archiver():
Apply the customized strategy defined by the given archiver configuration. Apply the customized strategy defined by the given archiver configuration.
""" """
# Set global development env variables # Set global development env variables
var_dict = config_dict.get('_global_variables') var_dict = config_dict['_global_variables']
self.dev_polling_time = int(var_dict.get('development_polling_time')) self.dev_polling_time = int(var_dict['development_polling_time'])
abs_change = var_dict.get('development_archive_abs_change') abs_change = var_dict['development_archive_abs_change']
rel_change = var_dict.get('development_archive_rel_change') rel_change = var_dict['development_archive_rel_change']
self.dev_archive_abs_change = None if abs_change == 'None' else int(abs_change) self.dev_archive_abs_change = None and int(abs_change)
self.dev_archive_rel_change = None if rel_change == 'None' else int(rel_change) self.dev_archive_rel_change = None and int(rel_change)
self.dev_archive_period = int(var_dict.get('development_archive_period')) self.dev_archive_period = int(var_dict['development_archive_period'])
self.dev_event_period = int(var_dict.get('development_event_period')) self.dev_event_period = int(var_dict['development_event_period'])
self.dev_strategy = var_dict.get('development_strategy') self.dev_strategy = var_dict['development_strategy']
suffixes = config_dict.get('_global_suffixes') # suffixes list of attributes that need to be archived suffixes = config_dict['_global_suffixes'] # suffixes list of attributes that need to be archived
# Set devices archiving # Set devices archiving
env_dict = config_dict.get('devices') env_dict = config_dict['devices']
for device in env_dict: for device in env_dict:
try: try:
dev_env = str(env_dict[device].get('environment')) # Get device environment dev_env = str(env_dict[device]['environment']) # Get device environment
if dev_env == 'development': # DEV environment -> all attributes are excluded by default if dev_env == 'development': # DEV environment -> all attributes are excluded by default
include_node = env_dict[device].get('include',[]) include_node = env_dict[device].get('include',[])
include_att_list = [] include_att_list = []
for a in include_node: for a in include_node:
include_att_list.append(a.get('attribute')) include_att_list.append(a['attribute'])
# Add attributes with defined suffixes # Add attributes with defined suffixes
include_att_list.extend(get_attributes_from_suffix(device,suffixes)) include_att_list.extend(get_attributes_from_suffix(device,suffixes))
self.remove_attributes_by_device(device, exclude=include_att_list) self.remove_attributes_by_device(device, exclude=include_att_list)
...@@ -192,8 +192,8 @@ class Archiver(): ...@@ -192,8 +192,8 @@ class Archiver():
self.cm.write_attribute('SetStrategy', strategy) self.cm.write_attribute('SetStrategy', strategy)
self.cm.write_attribute('SetPollingPeriod', polling_period) self.cm.write_attribute('SetPollingPeriod', polling_period)
self.cm.write_attribute('SetPeriodEvent', event_period) self.cm.write_attribute('SetPeriodEvent', event_period)
self.cm.write_attribute('SetAbsoluteEvent', abs_change) if not(abs_change is None or abs_change=="None"): self.cm.write_attribute('SetAbsoluteEvent', abs_change)
if (not(rel_change is None or rel_change=="None")): self.cm.write_attribute('SetRelativeEvent', rel_change) if not(rel_change is None or rel_change=="None"): self.cm.write_attribute('SetRelativeEvent', rel_change)
self.cm.AttributeAdd() self.cm.AttributeAdd()
logger.info(f"Attribute {attribute_name} added to archiving list!") logger.info(f"Attribute {attribute_name} added to archiving list!")
except DevFailed as e: except DevFailed as e:
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
"_global_variables": { "_global_variables": {
"development_polling_time": "1000", "development_polling_time": "1000",
"development_archive_abs_change": "1", "development_archive_abs_change": "1",
"development_archive_rel_change": "None", "development_archive_rel_change": null,
"development_archive_period": "10000", "development_archive_period": "10000",
"development_event_period": "1000", "development_event_period": "1000",
"development_strategy": "RUN" "development_strategy": "RUN"
}, },
"_global_suffixes":[ "_global_suffixes":[
{"attribute": "_error_R", "archive_period": "10000", "event_period": "1000", "abs_change": "1", "rel_change": "None"}, {"attribute": "_error_R", "archive_period": "10000", "event_period": "1000", "abs_change": "1", "rel_change": null},
{"attribute": "_good_R", "archive_period": "10000", "event_period": "1000", "abs_change": "1", "rel_change": "None"}, {"attribute": "_good_R", "archive_period": "10000", "event_period": "1000", "abs_change": "1", "rel_change": null},
{"attribute": "_mask_RW", "archive_period": "10000", "event_period": "1000", "abs_change": "1", "rel_change": "None"}, {"attribute": "_mask_RW", "archive_period": "10000", "event_period": "1000", "abs_change": "1", "rel_change": null},
{"attribute": "_version_R", "archive_period": "60000", "event_period": "10000", "abs_change": "1", "rel_change": "None"} {"attribute": "_version_R", "archive_period": "60000", "event_period": "10000", "abs_change": "1", "rel_change": null}
], ],
"devices": { "devices": {
"STAT/RECV/1": { "STAT/RECV/1": {
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
"FPGA_scrap_RW" "FPGA_scrap_RW"
], ],
"include": [ "include": [
{"attribute":"FPGA_temp_R", "archive_period": "10000", "event_period": "1000", "abs_change": "1", "rel_change": "None"}, {"attribute":"FPGA_temp_R", "archive_period": "10000", "event_period": "1000", "abs_change": "1", "rel_change": null},
{"attribute":"FPGA_firmware_version_R", "archive_period": "60000", "event_period": "10000", "abs_change": "1", "rel_change": "None"} {"attribute":"FPGA_firmware_version_R", "archive_period": "60000", "event_period": "10000", "abs_change": "1", "rel_change": null}
] ]
}, },
"STAT/SST/1": { "STAT/SST/1": {
......
...@@ -85,9 +85,9 @@ def get_attributes_from_suffix(device_name:str, suffixes:list): ...@@ -85,9 +85,9 @@ def get_attributes_from_suffix(device_name:str, suffixes:list):
attribute_list = device.get_attribute_list() attribute_list = device.get_attribute_list()
result = [] result = []
for s in suffixes: for s in suffixes:
att_name = s.get('attribute') att_name = s['attribute']
# Search suffix substring in the device attribute list # Search suffix substring in the device attribute list
result.extend([a for a in attribute_list if att_name.lower() in a.lower()]) result.extend([a for a in attribute_list if a.lower().endswith(att_name.lower())])
return result return result
def get_parameters_from_attribute(device_name:str, attribute_name:str, suffixes: list, config_dict:dict): def get_parameters_from_attribute(device_name:str, attribute_name:str, suffixes: list, config_dict:dict):
...@@ -95,19 +95,19 @@ def get_parameters_from_attribute(device_name:str, attribute_name:str, suffixes: ...@@ -95,19 +95,19 @@ def get_parameters_from_attribute(device_name:str, attribute_name:str, suffixes:
Return the archiving parameters defined in the configuration file for a certain attribute Return the archiving parameters defined in the configuration file for a certain attribute
""" """
# Search if the attribute parameters are listed inside the device configuration # Search if the attribute parameters are listed inside the device configuration
included_attrs = config_dict.get('devices').get(device_name).get('include') included_attrs = config_dict['devices'][device_name]['include']
for a in included_attrs: for a in included_attrs:
if (attribute_name.lower() == a.get('attribute').lower()): if attribute_name.lower() == a['attribute'].lower():
archive_period = int(a.get('archive_period')) archive_period = int(a['archive_period'])
event_period = int(a.get('event_period')) event_period = int(a['event_period'])
abs_change = int(a.get('abs_change')) abs_change = a['abs_change'] and int(a['abs_change'])
rel_change = a.get('rel_change') rel_change = a['rel_change'] and int(a['rel_change'])
return archive_period, event_period, abs_change, rel_change return archive_period, event_period, abs_change, rel_change
# Search if the archiving parameters are listed inside the global suffixes attributes # Search if the archiving parameters are listed inside the global suffixes attributes
for a in suffixes: for a in suffixes:
if (a.get('attribute').lower() in attribute_name.lower()): if attribute_name.lower().endswith(a['attribute'].lower()):
archive_period = int(a.get('archive_period')) archive_period = int(a['archive_period'])
event_period = int(a.get('event_period')) event_period = int(a['event_period'])
abs_change = int(a.get('abs_change')) abs_change = a['abs_change'] and int(a['abs_change'])
rel_change = a.get('rel_change') rel_change = a['rel_change'] and int(a['rel_change'])
return archive_period, event_period, abs_change, rel_change return archive_period, event_period, abs_change, rel_change
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment