def test_nodes_from_config(self): config = { 'MACDASH_NODES': [{ 'name': 'test-node', 'host': 'remotehost.org', 'port': 5000 }] } r = PsDashRunner(config) self.assertEqual(len(r.get_nodes()), 2) self.assertIn('remotehost.org:5000', r.get_nodes()) self.assertEqual(r.get_nodes()['remotehost.org:5000'].name, 'test-node') self.assertEqual(r.get_nodes()['remotehost.org:5000'].host, 'remotehost.org') self.assertEqual(r.get_nodes()['remotehost.org:5000'].port, 5000)
def test_register_agent_to_auth_protected_host(self): r = PsDashRunner({ 'MACDASH_AUTH_USERNAME': '******', 'MACDASH_AUTH_PASSWORD': '******' }) agent = PsDashRunner({ 'MACDASH_AGENT': True, 'MACDASH_PORT': 5001, 'MACDASH_REGISTER_TO': 'http://localhost:5000', 'MACDASH_AUTH_USERNAME': '******', 'MACDASH_AUTH_PASSWORD': '******' }) jobs = [] jobs.append(gevent.spawn(r.run)) gevent.sleep(0.3) jobs.append(gevent.spawn(agent.run)) gevent.sleep(0.3) self.assertIn('127.0.0.1:5001', r.get_nodes()) self.assertEquals( r.get_node('127.0.0.1:5001').name, socket.gethostname()) self.assertEquals(r.get_node('127.0.0.1:5001').port, 5001) r.server.close() agent.server.close() gevent.killall(jobs)
def test_register_agent_without_name_defaults_to_hostname(self): agent_options = { 'MACDASH_AGENT': True, 'MACDASH_PORT': 5001, 'MACDASH_REGISTER_TO': 'http://localhost:5000' } r = PsDashRunner() agent = PsDashRunner(agent_options) jobs = [] jobs.append(gevent.spawn(r.run)) gevent.sleep(0.3) jobs.append(gevent.spawn(agent.run)) gevent.sleep(0.3) self.assertIn('127.0.0.1:5001', r.get_nodes()) self.assertEquals( r.get_node('127.0.0.1:5001').name, socket.gethostname()) self.assertEquals(r.get_node('127.0.0.1:5001').port, 5001) r.server.close() agent.server.close() gevent.killall(jobs)
def test_get_all_nodes(self): r = PsDashRunner() r.register_node('examplehost', 'example.org', 5000) self.assertEqual(len(r.get_nodes()), 2) # local + registered