diff --git a/tangostationcontrol/tangostationcontrol/test/toolkit/test_archiver_util.py b/tangostationcontrol/tangostationcontrol/test/toolkit/test_archiver_util.py index ab77f4b20541873d68e00283b6dbe3f146c5ef40..9936046cf21bc709bb3fda523471d64b47a62a30 100644 --- a/tangostationcontrol/tangostationcontrol/test/toolkit/test_archiver_util.py +++ b/tangostationcontrol/tangostationcontrol/test/toolkit/test_archiver_util.py @@ -33,10 +33,10 @@ class TestArchiverUtil(base.TestCase): def test_get_parameters_from_attribute(self): """Test if the attribute archiving parameters are correctly retrieved from the JSON config file""" 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, suffixes, self.config_dict) - self.assertEqual(archive_period,int(suffixes[2].get('archive_period'))) - self.assertEqual(event_period,int(suffixes[2].get('event_period'))) - self.assertEqual(abs_change,int(suffixes[2].get('abs_change'))) - self.assertEqual(rel_change,suffixes[2].get('rel_change')) + self.assertEqual(archive_period,int(suffixes[2]['archive_period'])) + self.assertEqual(event_period,int(suffixes[2]['event_period'])) + self.assertEqual(abs_change,int(suffixes[2]['abs_change'])) + self.assertEqual(rel_change,suffixes[2]['rel_change']) diff --git a/tangostationcontrol/tangostationcontrol/toolkit/archiver.py b/tangostationcontrol/tangostationcontrol/toolkit/archiver.py index 4287290a7ba3ebcdd8a58d216e82720ae1e25c46..f4bd0592803ad910b6eda10b801aa5af8f71e135 100644 --- a/tangostationcontrol/tangostationcontrol/toolkit/archiver.py +++ b/tangostationcontrol/tangostationcontrol/toolkit/archiver.py @@ -105,26 +105,26 @@ class Archiver(): Apply the customized strategy defined by the given archiver configuration. """ # Set global development env variables - var_dict = config_dict.get('_global_variables') - self.dev_polling_time = int(var_dict.get('development_polling_time')) - abs_change = var_dict.get('development_archive_abs_change') - rel_change = var_dict.get('development_archive_rel_change') - self.dev_archive_abs_change = None if abs_change == 'None' else int(abs_change) - self.dev_archive_rel_change = None if rel_change == 'None' else int(rel_change) - self.dev_archive_period = int(var_dict.get('development_archive_period')) - self.dev_event_period = int(var_dict.get('development_event_period')) - self.dev_strategy = var_dict.get('development_strategy') - suffixes = config_dict.get('_global_suffixes') # suffixes list of attributes that need to be archived + var_dict = config_dict['_global_variables'] + self.dev_polling_time = int(var_dict['development_polling_time']) + abs_change = var_dict['development_archive_abs_change'] + rel_change = var_dict['development_archive_rel_change'] + self.dev_archive_abs_change = None and int(abs_change) + self.dev_archive_rel_change = None and int(rel_change) + self.dev_archive_period = int(var_dict['development_archive_period']) + self.dev_event_period = int(var_dict['development_event_period']) + self.dev_strategy = var_dict['development_strategy'] + suffixes = config_dict['_global_suffixes'] # suffixes list of attributes that need to be archived # Set devices archiving - env_dict = config_dict.get('devices') + env_dict = config_dict['devices'] for device in env_dict: 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 include_node = env_dict[device].get('include',[]) include_att_list = [] for a in include_node: - include_att_list.append(a.get('attribute')) + include_att_list.append(a['attribute']) # Add attributes with defined suffixes include_att_list.extend(get_attributes_from_suffix(device,suffixes)) self.remove_attributes_by_device(device, exclude=include_att_list) @@ -192,8 +192,8 @@ class Archiver(): self.cm.write_attribute('SetStrategy', strategy) self.cm.write_attribute('SetPollingPeriod', polling_period) self.cm.write_attribute('SetPeriodEvent', event_period) - 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(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) self.cm.AttributeAdd() logger.info(f"Attribute {attribute_name} added to archiving list!") except DevFailed as e: diff --git a/tangostationcontrol/tangostationcontrol/toolkit/archiver_config/lofar2.json b/tangostationcontrol/tangostationcontrol/toolkit/archiver_config/lofar2.json index 31d65db9836eb4705abb51d3cd588b8dbfdb787d..c519686dd99c7e47d719fc95ce8c82e6db2a8ba7 100644 --- a/tangostationcontrol/tangostationcontrol/toolkit/archiver_config/lofar2.json +++ b/tangostationcontrol/tangostationcontrol/toolkit/archiver_config/lofar2.json @@ -2,17 +2,17 @@ "_global_variables": { "development_polling_time": "1000", "development_archive_abs_change": "1", - "development_archive_rel_change": "None", + "development_archive_rel_change": null, "development_archive_period": "10000", "development_event_period": "1000", "development_strategy": "RUN" }, "_global_suffixes":[ - {"attribute": "_error_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": "None"}, - {"attribute": "_mask_RW", "archive_period": "10000", "event_period": "1000", "abs_change": "1", "rel_change": "None"}, - {"attribute": "_version_R", "archive_period": "60000", "event_period": "10000", "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": null}, + {"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": null} ], "devices": { "STAT/RECV/1": { @@ -33,8 +33,8 @@ "FPGA_scrap_RW" ], "include": [ - {"attribute":"FPGA_temp_R", "archive_period": "10000", "event_period": "1000", "abs_change": "1", "rel_change": "None"}, - {"attribute":"FPGA_firmware_version_R", "archive_period": "60000", "event_period": "10000", "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": null} ] }, "STAT/SST/1": { diff --git a/tangostationcontrol/tangostationcontrol/toolkit/archiver_util.py b/tangostationcontrol/tangostationcontrol/toolkit/archiver_util.py index e13d11106a8959618c8d011585e52a4236a1cefe..b01c8c51f4f33b72d926136d1b6bf42ebde26490 100644 --- a/tangostationcontrol/tangostationcontrol/toolkit/archiver_util.py +++ b/tangostationcontrol/tangostationcontrol/toolkit/archiver_util.py @@ -85,9 +85,9 @@ def get_attributes_from_suffix(device_name:str, suffixes:list): attribute_list = device.get_attribute_list() result = [] for s in suffixes: - att_name = s.get('attribute') + att_name = s['attribute'] # 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 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: Return the archiving parameters defined in the configuration file for a certain attribute """ # 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: - if (attribute_name.lower() == a.get('attribute').lower()): - archive_period = int(a.get('archive_period')) - event_period = int(a.get('event_period')) - abs_change = int(a.get('abs_change')) - rel_change = a.get('rel_change') + if attribute_name.lower() == a['attribute'].lower(): + archive_period = int(a['archive_period']) + event_period = int(a['event_period']) + abs_change = a['abs_change'] and int(a['abs_change']) + rel_change = a['rel_change'] and int(a['rel_change']) return archive_period, event_period, abs_change, rel_change # Search if the archiving parameters are listed inside the global suffixes attributes for a in suffixes: - if (a.get('attribute').lower() in attribute_name.lower()): - archive_period = int(a.get('archive_period')) - event_period = int(a.get('event_period')) - abs_change = int(a.get('abs_change')) - rel_change = a.get('rel_change') + if attribute_name.lower().endswith(a['attribute'].lower()): + archive_period = int(a['archive_period']) + event_period = int(a['event_period']) + abs_change = a['abs_change'] and int(a['abs_change']) + rel_change = a['rel_change'] and int(a['rel_change']) return archive_period, event_period, abs_change, rel_change