Skip to content
Snippets Groups Projects
Commit 0e0a0ee1 authored by BRONES Romain's avatar BRONES Romain
Browse files

feat(force): Allow force action in Utils and CLI

parent 7f800c7b
No related branches found
No related tags found
No related merge requests found
......@@ -15,13 +15,13 @@ import FofbTool.Operation
# Get the module logger
logger = logging.getLogger("FofbTool")
def init_opcua():
def init_opcua(force=False):
"""
Run init on all OPCUA devices. Catch DevFailed and inform via log.
Does nothing if Fofb is running.
"""
if not check_fofbnotrunning():
if not check_fofbnotrunning(force):
logger.warning("Not running configuration of combpm because FOFB seems to be running.")
return
......@@ -33,13 +33,13 @@ def init_opcua():
logger.error("Could not perform init() '{}', got DevFailed.".format(p))
logger.debug(str(e))
def init_watcher():
def init_watcher(force=False):
"""
Run init on Fofb-Watcher, waiting for its completion then init on the FofbCommand.
Does nothing if Fofb is running.
"""
if not check_fofbnotrunning():
if not check_fofbnotrunning(force):
logger.warning("Not running configuration of combpm because FOFB seems to be running.")
return
......@@ -89,7 +89,7 @@ def confds_opcua():
logger.debug(str(e))
def check_fofbnotrunning():
def check_fofbnotrunning(force=False):
"""
Check if the FOFB is not running.
If it fails to know, return False and log error.
......@@ -100,6 +100,10 @@ def check_fofbnotrunning():
True if FOFB is not running
"""
if force:
logger.warning("Forced action even if FOFB might be running")
return True
p=FofbTool.Configuration.config["tangopath"]["fofb-watcher"]
try:
prx = tango.DeviceProxy(p)
......@@ -115,7 +119,7 @@ def check_fofbnotrunning():
logger.debug(str(e))
return False
def conf_all_combpm():
def conf_all_combpm(force=False):
"""
Run default configuration of all combpm blocks.
Check beforehand that the FOFB is not running.
......@@ -126,7 +130,7 @@ def conf_all_combpm():
True if FOFB is not running
"""
if not check_fofbnotrunning():
if not check_fofbnotrunning(force):
logger.warning("Not running configuration of combpm because FOFB seems to be running.")
return False
......@@ -139,7 +143,7 @@ def conf_all_combpm():
return success
def conf_all_comcorr(enable=True):
def conf_all_comcorr(force=False, enable=True):
"""
Run default configuration of all comcorr blocks.
Check beforehand that the FOFB is not running.
......@@ -155,7 +159,7 @@ def conf_all_comcorr(enable=True):
True if FOFB is not running
"""
if not check_fofbnotrunning():
if not check_fofbnotrunning(force):
logger.warning("Not running configuration of comcorr because FOFB seems to be running.")
return False
......@@ -168,7 +172,7 @@ def conf_all_comcorr(enable=True):
return success
def conf_all_ccn():
def conf_all_ccn(force=False):
"""
Run default configuration of all comcellnode blocks.
Check beforehand that the FOFB is not running.
......@@ -179,7 +183,7 @@ def conf_all_ccn():
True if FOFB is not running
"""
if not check_fofbnotrunning():
if not check_fofbnotrunning(force):
logger.warning("Not running configuration of comcorr because FOFB seems to be running.")
return False
......@@ -224,14 +228,14 @@ def get_prx_from_nodename(nodename):
return prx
def stop_all_combpm():
def stop_all_combpm(force=False):
"""
Apply stop command on all Cellnodes.
Check beforehand that the FOFB is not running. Display warning if.
"""
if not check_fofbnotrunning():
if not check_fofbnotrunning(force):
logger.warning("Not running stop combpm because FOFB seems to be running.")
for n,p in FofbTool.Configuration.config["tangopath.fofbnodes"].items():
......@@ -239,14 +243,14 @@ def stop_all_combpm():
FofbTool.Operation.stop_combpm(n)
def stop_all_ccn():
def stop_all_ccn(force=False):
"""
Apply stop and reset commands on all fofbnodes.
Check beforehand that the FOFB is not running. Display warning if.
"""
if not check_fofbnotrunning():
if not check_fofbnotrunning(force):
logger.warning("Not running stop combpm because FOFB seems to be running.")
for n,p in FofbTool.Configuration.config["tangopath.fofbnodes"].items():
......
......@@ -86,35 +86,31 @@ if __name__ == '__main__':
## Check running
if not FofbTool.Utils.check_fofbnotrunning():
logger.warning("FOFB is running")
if not args.force:
logger.warning("Stoping here")
if not FofbTool.Utils.check_fofbnotrunning(force=args.force):
logger.warning("FOFB is running, Stopping here")
exit(1)
else:
logger.warning("Action forced")
## Device Server related commands
if args.DS_init_opcua:
FofbTool.Utils.init_opcua()
FofbTool.Utils.init_opcua(force=args.force)
if args.DS_init_watcher:
FofbTool.Utils.init_watcher()
FofbTool.Utils.init_watcher(force=args.force)
if args.DS_conf:
FofbTool.Utils.confds_opcua()
if args.stop or args.stop_combpm:
FofbTool.Utils.stop_all_combpm()
FofbTool.Utils.stop_all_combpm(force=args.force)
if args.stop or args.stop_ccn:
FofbTool.Utils.stop_all_ccn()
FofbTool.Utils.stop_all_ccn(force=args.force)
if args.configure in ("combpm", "all"):
FofbTool.Utils.conf_all_combpm()
FofbTool.Utils.conf_all_combpm(force=args.force)
if args.configure in ("comcorr", "all"):
FofbTool.Utils.conf_all_comcorr()
FofbTool.Utils.conf_all_comcorr(force=args.force)
if args.configure in ("ccn", "all"):
FofbTool.Utils.conf_all_ccn()
FofbTool.Utils.conf_all_ccn(force=args.force)
if args.configure in ("corr", "all"):
FofbTool.Configuration.centralnode_configure_corr()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment