diff --git a/MAC/Services/src/ObservationControl2.py b/MAC/Services/src/ObservationControl2.py index c44044d30dbdc2eae471ab30f336b936af2a312b..c9f6f0e1c83980ea8efc39e6e407609b614f8842 100644 --- a/MAC/Services/src/ObservationControl2.py +++ b/MAC/Services/src/ObservationControl2.py @@ -27,7 +27,7 @@ from lofar.messaging import Service from lofar.messaging import setQpidLogLevel from lofar.common.util import waitForInterrupt 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__) @@ -46,9 +46,9 @@ class ObservationControlHandler(MessageHandlerInterface): lofar_environment = os.environ['LOFARENV'] if lofar_environment == "PRODUCTION": - env.hosts = ["mcu001.control.lofar"] + env.hosts = [config.PRODUCTION_OBSERVATION_CONTROL_HOST] elif lofar_environment == "TEST": - env.hosts = ["mcu099.control.lofar"] + env.hosts = [config.TEST_OBSERVATION_CONTROL_HOST] def abort_observation_task(self, sas_id): logger.info("trying to abort ObservationControl for SAS ID: %s", sas_id) @@ -76,7 +76,8 @@ class ObservationControlHandler(MessageHandlerInterface): 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): return Service(service_name, ObservationControlHandler, @@ -97,8 +98,8 @@ def main(): parser = OptionParser("%prog [options]", 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("-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("-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("-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=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') (options, args) = parser.parse_args() diff --git a/MAC/Services/src/config.py b/MAC/Services/src/config.py index 9a72a7e412a9de1436828f4026e5cb36c3947865..a4976653ef12279087991940956c1981292e2ad7 100644 --- a/MAC/Services/src/config.py +++ b/MAC/Services/src/config.py @@ -22,3 +22,5 @@ from lofar.messaging import adaptNameToEnvironment DEFAULT_OBSERVATION_CONTROL_BUS_NAME = adaptNameToEnvironment('lofar.mac.command') DEFAULT_OBSERVATION_CONTROL_SERVICE_NAME = 'ObservationControl2' +PRODUCTION_OBSERVATION_CONTROL_HOST = "mcu001.control.lofar" +TEST_OBSERVATION_CONTROL_HOST = "mcu099.control.lofar" diff --git a/MAC/Services/test/tObservationControl2.py b/MAC/Services/test/tObservationControl2.py index 66ae8a74b3dc50d033f518f2b953f97c369b3a2e..f3e127b7ec6162d55b9096c27b15f65863085a1c 100644 --- a/MAC/Services/test/tObservationControl2.py +++ b/MAC/Services/test/tObservationControl2.py @@ -7,6 +7,7 @@ import os import time from lofar.mac.ObservationControl2 import ObservationControlHandler, create_service from qpid.messaging.message import Message as QpidMessage +import lofar.mac.config as config class TestObservationControlHandler(unittest.TestCase): pid1 = "1000" @@ -14,10 +15,6 @@ class TestObservationControlHandler(unittest.TestCase): sas_id = "100" - test_host = "mcu099.control.lofar" - production_host = "mcu001.control.lofar" - local_host = "localhost" - def _run_side_effect(self, cmd): if cmd.startswith("ps -p %s" % self.pid1): return self.sas_id @@ -71,18 +68,18 @@ class TestObservationControlHandler(unittest.TestCase): def test_observation_control_should_select_test_host_if_lofar_environment_is_test(self): 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'}) def test_observation_control_should_select_production_host_if_lofar_environment_is_production(self): 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): 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): self.observation_control_handler.abort_observation(self.sas_id)