Skip to content
Snippets Groups Projects
Commit 58db975d authored by Auke Klazema's avatar Auke Klazema
Browse files

Task #9898: Moved duplicate strings out to config file

parent dbe546ba
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ from lofar.messaging import Service ...@@ -27,7 +27,7 @@ from lofar.messaging import Service
from lofar.messaging import setQpidLogLevel from lofar.messaging import setQpidLogLevel
from lofar.common.util import waitForInterrupt from lofar.common.util import waitForInterrupt
from lofar.messaging.Service import MessageHandlerInterface from lofar.messaging.Service import MessageHandlerInterface
from lofar.mac.config import DEFAULT_OBSERVATION_CONTROL_BUS_NAME, DEFAULT_OBSERVATION_CONTROL_SERVICE_NAME import lofar.mac.config as config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -46,9 +46,9 @@ class ObservationControlHandler(MessageHandlerInterface): ...@@ -46,9 +46,9 @@ class ObservationControlHandler(MessageHandlerInterface):
lofar_environment = os.environ['LOFARENV'] lofar_environment = os.environ['LOFARENV']
if lofar_environment == "PRODUCTION": if lofar_environment == "PRODUCTION":
env.hosts = ["mcu001.control.lofar"] env.hosts = [config.PRODUCTION_OBSERVATION_CONTROL_HOST]
elif lofar_environment == "TEST": elif lofar_environment == "TEST":
env.hosts = ["mcu099.control.lofar"] env.hosts = [config.TEST_OBSERVATION_CONTROL_HOST]
def abort_observation_task(self, sas_id): def abort_observation_task(self, sas_id):
logger.info("trying to abort ObservationControl for SAS ID: %s", sas_id) logger.info("trying to abort ObservationControl for SAS ID: %s", sas_id)
...@@ -76,7 +76,8 @@ class ObservationControlHandler(MessageHandlerInterface): ...@@ -76,7 +76,8 @@ class ObservationControlHandler(MessageHandlerInterface):
pass pass
def create_service(bus_name=DEFAULT_OBSERVATION_CONTROL_BUS_NAME, service_name=DEFAULT_OBSERVATION_CONTROL_SERVICE_NAME, def create_service(bus_name=config.DEFAULT_OBSERVATION_CONTROL_BUS_NAME,
service_name=config.DEFAULT_OBSERVATION_CONTROL_SERVICE_NAME,
broker=None, verbose=False): broker=None, verbose=False):
return Service(service_name, return Service(service_name,
ObservationControlHandler, ObservationControlHandler,
...@@ -97,8 +98,8 @@ def main(): ...@@ -97,8 +98,8 @@ def main():
parser = OptionParser("%prog [options]", parser = OptionParser("%prog [options]",
description='runs the observationcontrol service') description='runs the observationcontrol service')
parser.add_option('-q', '--broker', dest='broker', type='string', default=None, help='Address of the qpid broker, default: localhost') parser.add_option('-q', '--broker', dest='broker', type='string', default=None, help='Address of the qpid broker, default: localhost')
parser.add_option("-b", "--busname", dest="busname", type="string", default=DEFAULT_OBSERVATION_CONTROL_BUS_NAME, help="Name of the bus exchange on the qpid broker, default: %s" % DEFAULT_OBSERVATION_CONTROL_BUS_NAME) parser.add_option("-b", "--busname", dest="busname", type="string", default=config.DEFAULT_OBSERVATION_CONTROL_BUS_NAME, help="Name of the bus exchange on the qpid broker, default: %s" % config.DEFAULT_OBSERVATION_CONTROL_BUS_NAME)
parser.add_option("-s", "--servicename", dest="servicename", type="string", default=DEFAULT_OBSERVATION_CONTROL_SERVICE_NAME, help="Name for this service, default: %s" % DEFAULT_OBSERVATION_CONTROL_SERVICE_NAME) parser.add_option("-s", "--servicename", dest="servicename", type="string", default=config.DEFAULT_OBSERVATION_CONTROL_SERVICE_NAME, help="Name for this service, default: %s" % config.DEFAULT_OBSERVATION_CONTROL_SERVICE_NAME)
parser.add_option('-V', '--verbose', dest='verbose', action='store_true', help='verbose logging') parser.add_option('-V', '--verbose', dest='verbose', action='store_true', help='verbose logging')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
......
...@@ -22,3 +22,5 @@ from lofar.messaging import adaptNameToEnvironment ...@@ -22,3 +22,5 @@ from lofar.messaging import adaptNameToEnvironment
DEFAULT_OBSERVATION_CONTROL_BUS_NAME = adaptNameToEnvironment('lofar.mac.command') DEFAULT_OBSERVATION_CONTROL_BUS_NAME = adaptNameToEnvironment('lofar.mac.command')
DEFAULT_OBSERVATION_CONTROL_SERVICE_NAME = 'ObservationControl2' DEFAULT_OBSERVATION_CONTROL_SERVICE_NAME = 'ObservationControl2'
PRODUCTION_OBSERVATION_CONTROL_HOST = "mcu001.control.lofar"
TEST_OBSERVATION_CONTROL_HOST = "mcu099.control.lofar"
...@@ -7,6 +7,7 @@ import os ...@@ -7,6 +7,7 @@ import os
import time import time
from lofar.mac.ObservationControl2 import ObservationControlHandler, create_service from lofar.mac.ObservationControl2 import ObservationControlHandler, create_service
from qpid.messaging.message import Message as QpidMessage from qpid.messaging.message import Message as QpidMessage
import lofar.mac.config as config
class TestObservationControlHandler(unittest.TestCase): class TestObservationControlHandler(unittest.TestCase):
pid1 = "1000" pid1 = "1000"
...@@ -14,10 +15,6 @@ class TestObservationControlHandler(unittest.TestCase): ...@@ -14,10 +15,6 @@ class TestObservationControlHandler(unittest.TestCase):
sas_id = "100" sas_id = "100"
test_host = "mcu099.control.lofar"
production_host = "mcu001.control.lofar"
local_host = "localhost"
def _run_side_effect(self, cmd): def _run_side_effect(self, cmd):
if cmd.startswith("ps -p %s" % self.pid1): if cmd.startswith("ps -p %s" % self.pid1):
return self.sas_id return self.sas_id
...@@ -71,18 +68,18 @@ class TestObservationControlHandler(unittest.TestCase): ...@@ -71,18 +68,18 @@ class TestObservationControlHandler(unittest.TestCase):
def test_observation_control_should_select_test_host_if_lofar_environment_is_test(self): def test_observation_control_should_select_test_host_if_lofar_environment_is_test(self):
ObservationControlHandler() ObservationControlHandler()
self.assertEqual(self.fabric_env_mock.hosts, [self.test_host]) self.assertEqual(self.fabric_env_mock.hosts, [config.TEST_OBSERVATION_CONTROL_HOST])
@mock.patch.dict(os.environ, {'LOFARENV': 'PRODUCTION'}) @mock.patch.dict(os.environ, {'LOFARENV': 'PRODUCTION'})
def test_observation_control_should_select_production_host_if_lofar_environment_is_production(self): def test_observation_control_should_select_production_host_if_lofar_environment_is_production(self):
ObservationControlHandler() ObservationControlHandler()
self.assertEqual(self.fabric_env_mock.hosts, [self.production_host]) self.assertEqual(self.fabric_env_mock.hosts, [config.PRODUCTION_OBSERVATION_CONTROL_HOST])
def test_observation_control_should_select_local_host_if_no_lofar_environment_is_set(self): def test_observation_control_should_select_local_host_if_no_lofar_environment_is_set(self):
ObservationControlHandler() ObservationControlHandler()
self.assertEqual(self.fabric_env_mock.hosts, [self.local_host]) self.assertEqual(self.fabric_env_mock.hosts, ["localhost"])
def test_abort_observation_should_execute_abort_observation_task_on_localhost(self): def test_abort_observation_should_execute_abort_observation_task_on_localhost(self):
self.observation_control_handler.abort_observation(self.sas_id) self.observation_control_handler.abort_observation(self.sas_id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment