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
import sys, getopt
import sys
import getopt
import json
from tango import DeviceProxy, DevFailed, AttributeProxy
from time import sleep
import os
from tango import DeviceProxy, DevFailed, AttributeProxy
def cm_configure_attributes():
"""Method to configure an attribute."""
configure_success_count = 0
configure_fail_count = 0
already_configured_count = 0
total_attrib_count = 0
attribute_started_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)
for cb in configuration_blocks:
attribute_list = cb['attributes']
polling_period = cb['polling_period']
period_event = cb['period_event']
for c_b in configuration_blocks:
attribute_list = c_b['attributes']
polling_period = c_b['polling_period']
period_event = c_b['period_event']
for attribute in attribute_list:
total_attrib_count += 1
......@@ -31,7 +34,9 @@ def cm_configure_attributes():
print("Attribute " + attribute + " already configured.")
is_already_archived = True
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
if not is_already_archived:
......@@ -39,30 +44,33 @@ def cm_configure_attributes():
max_retries = 5
sleep_time = 1
not_online = False
for x in range(0, max_retries):
for loop_cnt in range(0, max_retries):
try:
att = AttributeProxy(attribute_fqdn)
att.read()
break
except DevFailed as df:
if(x == (max_retries -1)):
except DevFailed as dev_failed:
if loop_cnt == (max_retries -1):
print("Attribute " + attribute + " not online. Skipping it.")
not_online = True
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)
if (not_online):
if not_online:
continue
try:
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("SetPollingPeriod", int(polling_period))
conf_manager_proxy.write_attribute("SetPeriodEvent", int(period_event))
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
continue
......@@ -70,14 +78,17 @@ def cm_configure_attributes():
conf_manager_proxy.AttributeAdd()
configure_success_count += 1
print ("attribute_fqdn " + attribute_fqdn + " " + " added successfuly")
except DevFailed as df:
except DevFailed as dev_failed:
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):
"""Method to start archiving an attribute."""
try:
conf_manager_proxy.command_inout("AttributeStart", str_attribute)
attribute_started_count +=1
......@@ -88,9 +99,9 @@ def start_archiving(str_attribute, attribute_started_count, error_starting_attri
return attribute_started_count, error_starting_attrib_count
# Main entrypoint of the script.
conf_manager_device_fqdn = ""
evt_subscriber_device_fqdn = ""
attr_list_file = ""
CONF_MANAGER_DEVICE_FQDN = ""
EVT_SUBSCRIBER_DEVICE_FQDN = ""
ATTR_LIST_FILE = ""
## parse arguments
try:
opts, args = getopt.getopt(sys.argv[1:], "c:e:a:", ["cm=", "es=", "attrfile="])
......@@ -105,39 +116,44 @@ except getopt.GetoptError:
sys.exit(2)
for opt, arg in opts:
if opt in ("-c", "--cm"):
conf_manager_device_fqdn = arg
CONF_MANAGER_DEVICE_FQDN = arg
elif opt in ("-e", "--es"):
evt_subscriber_device_fqdn = arg
EVT_SUBSCRIBER_DEVICE_FQDN = arg
elif opt in ("-a", "--attrfile"):
attr_list_file = arg
ATTR_LIST_FILE = arg
conf_manager_proxy = DeviceProxy(conf_manager_device_fqdn)
evt_subscriber_proxy = DeviceProxy(evt_subscriber_device_fqdn)
conf_manager_proxy = DeviceProxy(CONF_MANAGER_DEVICE_FQDN)
evt_subscriber_proxy = DeviceProxy(EVT_SUBSCRIBER_DEVICE_FQDN)
sleep_time = 6
max_retries = 10
for x in range(0, max_retries):
SLEEP_TIME = 6
MAX_RETRIES = 10
for x in range(0, MAX_RETRIES):
try:
configure_success_count, configure_fail_count, already_configured_count, total_attrib_count, attribute_started_count, error_starting_attrib_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,
configure_success_count, configure_fail_count, already_configured_count, \
total_attrib_count, attribute_started_count, error_starting_attrib_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)
break
except:
print("configure_attribute exception: " + str(sys.exc_info()))
if(x == (max_retries - 1)):
if x == (MAX_RETRIES - 1):
sys.exit(-1)
try:
deviceAdm = DeviceProxy("dserver/hdbppcm-srv/01")
deviceAdm.RestartServer()
DEVICE_ADM = None
DEVICE_ADM = DeviceProxy("dserver/hdbppcm-srv/01")
DEVICE_ADM.RestartServer()
except:
print("reset_conf_manager exception: " + str(sys.exc_info()[0]))
sleep(sleep_time)
sleep(SLEEP_TIME)
if configure_fail_count > 0:
exit(-1)
sys.exit(-1)
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