def configure_attribute(attribute): conf_manager_proxy = DeviceProxy("archiving/hdbpp/confmanager01") #logging.info(conf_manager_proxy.Status()) evt_subscriber_device_fqdn = "archiving/hdbpp/eventsubscriber01" evt_subscriber_device_proxy = DeviceProxy(evt_subscriber_device_fqdn) is_already_archived = False attr_list = evt_subscriber_device_proxy.read_attribute( "AttributeList").value if attr_list is not None: for already_archived in attr_list: #logging.info("Comparing: " + str(attribute) + " and " + str(already_archived).lower()) if attribute in str(already_archived).lower(): is_already_archived = True #logging.info("is_already_archived: True") break if not is_already_archived: # wait for the attribute to be up and running for configuring it. #logging.info("Adding attribute not archived....") max_retries = 10 sleep_time = 30 for x in range(0, max_retries): try: att = AttributeProxy(attribute) att.read() #logging.info("Attribute online value=" + str(att.read())) break except DevFailed as df: if (x == (max_retries - 1)): raise df logging.info("DevFailed exception: " + str(df.args[0].reason) + ". Sleeping for " + str(sleep_time) + "ss") sleep(sleep_time) conf_manager_proxy.write_attribute("SetAttributeName", attribute) conf_manager_proxy.write_attribute("SetArchiver", evt_subscriber_device_fqdn) conf_manager_proxy.write_attribute("SetStrategy", "ALWAYS") conf_manager_proxy.write_attribute("SetPollingPeriod", 1000) conf_manager_proxy.write_attribute("SetPeriodEvent", 3000) conf_manager_proxy.AttributeAdd() evt_subscriber_device_proxy.Start() sleep(3) # the polling result_config_manager = conf_manager_proxy.AttributeStatus(attribute) result_evt_subscriber = evt_subscriber_device_proxy.AttributeStatus( attribute) assert "Archiving : Started" in result_config_manager assert "Archiving : Started" in result_evt_subscriber conf_manager_proxy.AttributeRemove(attribute)
class ArchiverHelper: def __init__( self, conf_manager="archiving/hdbpp/confmanager01", eventsubscriber="archiving/hdbpp/eventsubscriber01", ): self.conf_manager = conf_manager self.eventsubscriber = eventsubscriber self.conf_manager_proxy = DeviceProxy(self.conf_manager) self.evt_subscriber_proxy = DeviceProxy(self.eventsubscriber) def attribute_add(self, fqdn, polling_period=1000, period_event=3000): if not self.is_already_archived(fqdn): AttributeProxy(fqdn).read() self.conf_manager_proxy.write_attribute("SetAttributeName", fqdn) self.conf_manager_proxy.write_attribute("SetArchiver", self.eventsubscriber) self.conf_manager_proxy.write_attribute("SetStrategy", "ALWAYS") self.conf_manager_proxy.write_attribute("SetPollingPeriod", int(polling_period)) self.conf_manager_proxy.write_attribute("SetPeriodEvent", int(period_event)) self.conf_manager_proxy.AttributeAdd() return True return False def attribute_list(self): return self.evt_subscriber_proxy.read_attribute("AttributeList").value def is_already_archived(self, fqdn): attr_list = self.attribute_list() if attr_list is not None: for already_archived in attr_list: if fqdn in str(already_archived).lower(): return True return False def start_archiving(self, fqdn=None, polling_period=1000, period_event=3000): if fqdn is not None: self.attribute_add(fqdn, polling_period, period_event) return self.evt_subscriber_proxy.Start() def stop_archiving(self, fqdn): self.evt_subscriber_proxy.AttributeStop(fqdn) return self.conf_manager_proxy.AttributeRemove(fqdn) def evt_subscriber_attribute_status(self, fqdn): return self.evt_subscriber_proxy.AttributeStatus(fqdn) def conf_manager_attribute_status(self, fqdn): return self.conf_manager_proxy.AttributeStatus(fqdn) def is_started(self, fqdn): return "Archiving : Started" in self.evt_subscriber_attribute_status( fqdn) def wait_for_start(self, fqdn, sleep_time=0.1, max_retries=30): total_sleep_time = 0 for x in range(0, max_retries): try: if ("Archiving : Started" in self.conf_manager_attribute_status(fqdn)): break except: pass sleep(sleep_time) total_sleep_time += 1 return total_sleep_time * sleep_time