def test_tell_manager(self): worker = NowcastWorker("test_worker", "description") worker._parsed_args = Mock(debug=False) worker._socket = Mock(name="_socket") worker.logger = Mock(name="logger") config = Config() config.file = "nowcast.yaml" worker.config._dict = { "message registry": { "manager": { "ack": "message acknowledged" }, "workers": { "test_worker": { "success": "successful test" } }, } } mgr_msg = Message(source="manager", type="ack") worker._socket.recv_string.return_value = mgr_msg.serialize() response = worker.tell_manager("success", "payload") worker._socket.send_string.assert_called_once_with( Message(source="test_worker", type="success", payload="payload").serialize()) worker._socket.recv_string.assert_called_once_with() assert worker.logger.debug.call_count == 2 assert response == mgr_msg
def test_remote_host(self, m_subprocess): config = Config() config._dict = { "run": { "enabled hosts": { "remotehost": { "envvars": "envvars.sh", "config file": "nowcast.yaml", "python": "nowcast-env/bin/python3", } } } } next_worker = NextWorker("nowcast.workers.test_worker", ["--debug"], "remotehost") next_worker.launch(config, "test_runner") cmd = m_subprocess.Popen.call_args_list[0] expected = call([ "ssh", "remotehost", "source", "envvars.sh", ";", "nowcast-env/bin/python3", "-m", "nowcast.workers.test_worker", "nowcast.yaml", "--debug", ]) assert cmd == expected
def test_unregistered_worker(self): worker = NowcastWorker("test_worker", "description") worker._parsed_args = Mock(debug=True) worker.logger = Mock(name="logger") config = Config() config.file = "nowcast.yaml" worker.config._dict = {"message registry": {"workers": {}}} with pytest.raises(WorkerError): worker.tell_manager("success", "payload")
def test_no_cmdline_args(self, m_subprocess): config = Config() config.file = "nowcast.yaml" config._dict = {"python": "nowcast-env/bin/python3"} next_worker = NextWorker("nowcast.workers.test_worker") next_worker.launch(config, "test_runner") cmd = m_subprocess.Popen.call_args_list[0] expected = call([ "nowcast-env/bin/python3", "-m", "nowcast.workers.test_worker", "nowcast.yaml", ]) assert cmd == expected
def main(): """Set up and run the nowcast system message broker. Set-up includes: * Building the command-line parser, and parsing the command-line used to launch the message broker * Reading and parsing the configuration file given on the command-line * Configuring the logging system as specified in the configuration file * Log the message broker's PID, and the file path/name that was used to configure it. The set-up is repeated if the message broker process receives a HUP signal so that the configuration can be re-loaded without having to stop and re-start the message broker. After the set-up is complete, launch the broker message queuing process. See :command:`python -m nemo_nowcast.message_broker --help` for details of the command-line interface. """ cli = CommandLineInterface(NAME, package="nemo_nowcast", description=__doc__) cli.build_parser() parsed_args = cli.parser.parse_args() config = Config() config.load(parsed_args.config_file) msg = _configure_logging(config) logger.info(f"running in process {os.getpid()}") logger.info(f"read config from {config.file}") logger.info(msg) run(config)
def test_debug_mode(self): worker = NowcastWorker("test_worker", "description") worker._parsed_args = Mock(debug=True) worker.logger = Mock(name="logger") config = Config() config.file = "nowcast.yaml" worker.config._dict = { "message registry": { "workers": { "test_worker": { "success": "successful test" } } } } response_payload = worker.tell_manager("success", "payload") assert worker.logger.debug.call_count == 1 assert response_payload is None
def test_unregistered_manager_message_type(self): worker = NowcastWorker("test_worker", "description") worker._parsed_args = Mock(debug=False) worker._socket = Mock(name="_socket") worker.logger = Mock(name="logger") config = Config() config.file = "nowcast.yaml" worker.config._dict = { "message registry": { "manager": { "ack": "message acknowledged" }, "workers": { "test_worker": { "success": "successful test" } }, } } mgr_msg = Message(source="manager", type="foo") worker._socket.recv_string.return_value = mgr_msg.serialize() with pytest.raises(WorkerError): worker.tell_manager("success", "payload")
def test_config(self): worker = NowcastWorker("worker_name", "description") assert worker.config == Config()
def test_config(self): mgr = manager.NowcastManager() assert mgr.config == Config()