Skip to content
Snippets Groups Projects
Commit 4742ba55 authored by user's avatar user
Browse files

AT1-709: Resolve review comment- Address pylint warnings.

parent a02bad89
Branches
No related tags found
No related merge requests found
"Script to configure hdbpp archiver"
#Imports #Imports
import sys, getopt import sys
import getopt
import json import json
from tango import DeviceProxy, DevFailed, AttributeProxy
from time import sleep from time import sleep
import os import os
from tango import DeviceProxy, DevFailed, AttributeProxy
def cm_configure_attributes(): def cm_configure_attributes():
"""Method to configure an attribute."""
configure_success_count = 0 configure_success_count = 0
configure_fail_count = 0 configure_fail_count = 0
already_configured_count = 0 already_configured_count = 0
total_attrib_count = 0 total_attrib_count = 0
attribute_started_count = 0 attribute_started_count = 0
error_starting_attrib_count = 0 error_starting_attrib_count = 0
with open(attr_list_file, 'r') as attrib_list_file: with open(ATTR_LIST_FILE, 'r') as attrib_list_file:
configuration_blocks = json.load(attrib_list_file) configuration_blocks = json.load(attrib_list_file)
for cb in configuration_blocks: for c_b in configuration_blocks:
attribute_list = cb['attributes'] attribute_list = c_b['attributes']
polling_period = cb['polling_period'] polling_period = c_b['polling_period']
period_event = cb['period_event'] period_event = c_b['period_event']
for attribute in attribute_list: for attribute in attribute_list:
total_attrib_count += 1 total_attrib_count += 1
...@@ -31,7 +34,9 @@ def cm_configure_attributes(): ...@@ -31,7 +34,9 @@ def cm_configure_attributes():
print("Attribute " + attribute + " already configured.") print("Attribute " + attribute + " already configured.")
is_already_archived = True is_already_archived = True
already_configured_count += 1 already_configured_count += 1
attribute_started_count, error_starting_attrib_count = start_archiving(attribute, attribute_started_count, error_starting_attrib_count) attribute_started_count, error_starting_attrib_count = \
start_archiving(attribute, attribute_started_count,
error_starting_attrib_count)
break break
if not is_already_archived: if not is_already_archived:
...@@ -39,30 +44,33 @@ def cm_configure_attributes(): ...@@ -39,30 +44,33 @@ def cm_configure_attributes():
max_retries = 5 max_retries = 5
sleep_time = 1 sleep_time = 1
not_online = False not_online = False
for x in range(0, max_retries): for loop_cnt in range(0, max_retries):
try: try:
att = AttributeProxy(attribute_fqdn) att = AttributeProxy(attribute_fqdn)
att.read() att.read()
break break
except DevFailed as df: except DevFailed as dev_failed:
if(x == (max_retries -1)): if loop_cnt == (max_retries -1):
print("Attribute " + attribute + " not online. Skipping it.") print("Attribute " + attribute + " not online. Skipping it.")
not_online = True not_online = True
break break
print("DevFailed exception: " + str(df.args[0].reason) + ". Sleeping for " + str(sleep_time) + "ss") print("DevFailed exception: " + str(dev_failed.args[0].reason) +
". Sleeping for " + str(sleep_time) + "ss")
sleep(sleep_time) sleep(sleep_time)
if (not_online): if not_online:
continue continue
try: try:
conf_manager_proxy.write_attribute("SetAttributeName", attribute_fqdn) conf_manager_proxy.write_attribute("SetAttributeName", attribute_fqdn)
conf_manager_proxy.write_attribute("SetArchiver", evt_subscriber_device_fqdn) conf_manager_proxy.write_attribute("SetArchiver",
EVT_SUBSCRIBER_DEVICE_FQDN)
conf_manager_proxy.write_attribute("SetStrategy", "ALWAYS") conf_manager_proxy.write_attribute("SetStrategy", "ALWAYS")
conf_manager_proxy.write_attribute("SetPollingPeriod", int(polling_period)) conf_manager_proxy.write_attribute("SetPollingPeriod", int(polling_period))
conf_manager_proxy.write_attribute("SetPeriodEvent", int(period_event)) conf_manager_proxy.write_attribute("SetPeriodEvent", int(period_event))
except Exception as except_occured: except Exception as except_occured:
print("Exception while setting configuration manager arrtibutes: ", except_occured) print("Exception while setting configuration manager arrtibutes: ",
except_occured)
configure_fail_count += 1 configure_fail_count += 1
continue continue
...@@ -70,14 +78,17 @@ def cm_configure_attributes(): ...@@ -70,14 +78,17 @@ def cm_configure_attributes():
conf_manager_proxy.AttributeAdd() conf_manager_proxy.AttributeAdd()
configure_success_count += 1 configure_success_count += 1
print ("attribute_fqdn " + attribute_fqdn + " " + " added successfuly") print ("attribute_fqdn " + attribute_fqdn + " " + " added successfuly")
except DevFailed as df: except DevFailed as dev_failed:
configure_fail_count += 1 configure_fail_count += 1
print("Exception occured while adding attribute for archiving: ", df) print("Exception occured while adding attribute for archiving: ",
dev_failed)
return configure_success_count, configure_fail_count, already_configured_count, total_attrib_count, attribute_started_count, error_starting_attrib_count return configure_success_count, configure_fail_count, already_configured_count,\
total_attrib_count, attribute_started_count, error_starting_attrib_count
def start_archiving(str_attribute, attribute_started_count, error_starting_attrib_count): def start_archiving(str_attribute, attribute_started_count, error_starting_attrib_count):
"""Method to start archiving an attribute."""
try: try:
conf_manager_proxy.command_inout("AttributeStart", str_attribute) conf_manager_proxy.command_inout("AttributeStart", str_attribute)
attribute_started_count +=1 attribute_started_count +=1
...@@ -88,9 +99,9 @@ def start_archiving(str_attribute, attribute_started_count, error_starting_attri ...@@ -88,9 +99,9 @@ def start_archiving(str_attribute, attribute_started_count, error_starting_attri
return attribute_started_count, error_starting_attrib_count return attribute_started_count, error_starting_attrib_count
# Main entrypoint of the script. # Main entrypoint of the script.
conf_manager_device_fqdn = "" CONF_MANAGER_DEVICE_FQDN = ""
evt_subscriber_device_fqdn = "" EVT_SUBSCRIBER_DEVICE_FQDN = ""
attr_list_file = "" ATTR_LIST_FILE = ""
## parse arguments ## parse arguments
try: try:
opts, args = getopt.getopt(sys.argv[1:], "c:e:a:", ["cm=", "es=", "attrfile="]) opts, args = getopt.getopt(sys.argv[1:], "c:e:a:", ["cm=", "es=", "attrfile="])
...@@ -105,39 +116,44 @@ except getopt.GetoptError: ...@@ -105,39 +116,44 @@ except getopt.GetoptError:
sys.exit(2) sys.exit(2)
for opt, arg in opts: for opt, arg in opts:
if opt in ("-c", "--cm"): if opt in ("-c", "--cm"):
conf_manager_device_fqdn = arg CONF_MANAGER_DEVICE_FQDN = arg
elif opt in ("-e", "--es"): elif opt in ("-e", "--es"):
evt_subscriber_device_fqdn = arg EVT_SUBSCRIBER_DEVICE_FQDN = arg
elif opt in ("-a", "--attrfile"): elif opt in ("-a", "--attrfile"):
attr_list_file = arg ATTR_LIST_FILE = arg
conf_manager_proxy = DeviceProxy(conf_manager_device_fqdn) conf_manager_proxy = DeviceProxy(CONF_MANAGER_DEVICE_FQDN)
evt_subscriber_proxy = DeviceProxy(evt_subscriber_device_fqdn) evt_subscriber_proxy = DeviceProxy(EVT_SUBSCRIBER_DEVICE_FQDN)
sleep_time = 6 SLEEP_TIME = 6
max_retries = 10 MAX_RETRIES = 10
for x in range(0, max_retries): for x in range(0, MAX_RETRIES):
try: try:
configure_success_count, configure_fail_count, already_configured_count, total_attrib_count, attribute_started_count, error_starting_attrib_count = cm_configure_attributes() configure_success_count, configure_fail_count, already_configured_count, \
print("Configured successfully: ", configure_success_count, "Failed: ", configure_fail_count, "Already configured: ", total_attrib_count, attribute_started_count, error_starting_attrib_count = \
already_configured_count, "Total attributes: ", total_attrib_count, "Attribute started: ", attribute_started_count, cm_configure_attributes()
print("Configured successfully: ", configure_success_count, "Failed: ",
configure_fail_count, "Already configured: ",
already_configured_count, "Total attributes: ",
total_attrib_count, "Attribute started: ", attribute_started_count,
"Error starting attribute: ", error_starting_attrib_count) "Error starting attribute: ", error_starting_attrib_count)
break break
except: except:
print("configure_attribute exception: " + str(sys.exc_info())) print("configure_attribute exception: " + str(sys.exc_info()))
if(x == (max_retries - 1)): if x == (MAX_RETRIES - 1):
sys.exit(-1) sys.exit(-1)
try: try:
deviceAdm = DeviceProxy("dserver/hdbppcm-srv/01") DEVICE_ADM = None
deviceAdm.RestartServer() DEVICE_ADM = DeviceProxy("dserver/hdbppcm-srv/01")
DEVICE_ADM.RestartServer()
except: except:
print("reset_conf_manager exception: " + str(sys.exc_info()[0])) print("reset_conf_manager exception: " + str(sys.exc_info()[0]))
sleep(sleep_time) sleep(SLEEP_TIME)
if configure_fail_count > 0: if configure_fail_count > 0:
exit(-1) sys.exit(-1)
evt_subscriber_proxy.Start() evt_subscriber_proxy.Start()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment