diff --git a/src/radical/pilot/agent/agent_0.py b/src/radical/pilot/agent/agent_0.py index 7537754901..2fb1005d22 100644 --- a/src/radical/pilot/agent/agent_0.py +++ b/src/radical/pilot/agent/agent_0.py @@ -386,8 +386,8 @@ def _services_startup_cb(self, cb_data): service_urls[idx] = url if service_urls: - key = cb_data[tid]['name'] for idx, url in service_urls.items(): + key = cb_data[tid]['name'] if idx: key += '.%s' % idx key += '.url' diff --git a/tests/unit_tests/test_agent_0/test_agent_0.py b/tests/unit_tests/test_agent_0/test_agent_0.py index 1b8637a91a..3185a9eda7 100755 --- a/tests/unit_tests/test_agent_0/test_agent_0.py +++ b/tests/unit_tests/test_agent_0/test_agent_0.py @@ -268,6 +268,40 @@ def test_ctrl_service_up(self, mocked_init): self.assertTrue(agent_0._services_setup.is_set()) + # -------------------------------------------------------------------------- + # + @mock.patch.object(Agent_0, '__init__', return_value=None) + def test_services_startup_cb(self, mocked_init): + + fd, startup_file = tempfile.mkstemp() + self._cleanup_files.append(startup_file) + + uri_0 = 'ofi+verbs;ofi_rxm://10.41.0.103:35298' + uri_1 = 'ofi+verbs;ofi_rxm://10.41.0.104:38112' + with os.fdopen(fd, 'w') as f: + f.write('2\n0 %s\n1 %s' % (uri_0, uri_1)) + + reg = ru.zmq.Registry() + reg.start() + + agent_0 = Agent_0() + agent_0._session = self._session + agent_0._session._reg = ru.zmq.RegistryClient(url=reg.addr) + + agent_0.publish = mock.Mock() + + cb_data = {'service.0000': {'name' : 'service.monit', + 'startup_file': startup_file}} + agent_0._services_startup_cb(cb_data=cb_data) + + self.assertEqual(agent_0._session._reg['service.monit.0.url'], uri_0) + self.assertEqual(agent_0._session._reg['service.monit.1.url'], uri_1) + + agent_0._session._reg.close() + reg.stop() + reg.wait() + + # ------------------------------------------------------------------------------ # if __name__ == '__main__':