Skip to content
Snippets Groups Projects
Commit 5a118f19 authored by Jan David Mol's avatar Jan David Mol
Browse files

SW-610: Upgrade ObservationControl2 to use Fabric v2+

parent 0a24689d
No related branches found
No related tags found
No related merge requests found
......@@ -21,16 +21,8 @@ import os
import logging
from optparse import OptionParser
from fabric.exceptions import NetworkError
try:
# WARNING: This code only works with Fabric Version 1
from fabric import tasks
from fabric.api import env, run, settings
except ImportError as e:
print(str(e))
print('Please install python3 package fabric: sudo apt-get install fabric')
exit(1)
# WARNING: This code only works with Fabric Version 2
from fabric.connection import Connection
from lofar.messaging import Service
from lofar.messaging import setQpidLogLevel
......@@ -48,15 +40,18 @@ class ObservationControlHandler(MessageHandlerInterface):
'AbortObservation': self.abort_observation
}
env.hosts = ["localhost"]
host = "localhost"
if "LOFARENV" in os.environ:
lofar_environment = os.environ['LOFARENV']
if lofar_environment == "PRODUCTION":
env.hosts = [config.PRODUCTION_OBSERVATION_CONTROL_HOST]
host = config.PRODUCTION_OBSERVATION_CONTROL_HOST
elif lofar_environment == "TEST":
env.hosts = [config.TEST_OBSERVATION_CONTROL_HOST]
host = config.TEST_OBSERVATION_CONTROL_HOST
self.connection = Connection(host)
def _abort_observation_task(self, sas_id):
logger.info("trying to abort ObservationControl for SAS ID: %s", sas_id)
......@@ -64,25 +59,21 @@ class ObservationControlHandler(MessageHandlerInterface):
killed = False
with settings(warn_only = True):
pid_line = run('pidof ObservationControl')
pid_line = self.connection.run('pidof ObservationControl').stdout
pids = pid_line.split(' ')
for pid in pids:
pid_sas_id = run("ps -p %s --no-heading -o command | awk -F[{}] '{ printf $2; }'" % pid)
pid_sas_id = self.connection.run("ps -p %s --no-heading -o command | awk -F[{}] '{ printf $2; }'" % pid).stdout
if str(pid_sas_id) == str(sas_id):
logger.info("Killing ObservationControl with PID: %s for SAS ID: %s", pid, sas_id)
run('kill -SIGINT %s' % pid)
self.connection.run('kill -SIGINT %s' % pid)
killed = True
return killed
def abort_observation(self, sas_id):
""" aborts an observation for a single sas_id """
try:
result = tasks.execute(self._abort_observation_task, sas_id)
aborted = True in list(result.values())
except NetworkError:
aborted = False
aborted = self._abort_observation_task(sas_id)
return {'aborted': aborted}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment