def test_extract_hosts(self): '''Test simple extract hosts''' hosts = "localhost" result = server.extract_hosts(hosts) self.assertEquals(list(result), ["localhost"]) hosts = "localhost, host2" result = server.extract_hosts(hosts) self.assertEquals(sorted(list(result)), ["host2", "localhost"]) hosts = ["localhost", "host2"] result = server.extract_hosts(hosts) self.assertEquals(sorted(list(result)), ["host2", "localhost"]) hosts = "localhost, host[2-4]" result = server.extract_hosts(hosts) self.assertEquals(sorted(list(result)), ["host2", "host3", "host4", "localhost"])
def test_choose_host(self): """Test choose host""" host_choice = server._choose_host(None) self.assertEquals(host_choice, None) host_choice = server._choose_host([]) self.assertEquals(host_choice, None) hosts = "localhost, host[2-4]" result = server.extract_hosts(hosts) self.assertEquals(sorted(list(result)), ["host2", "host3", "host4", "localhost"])
def test_extract_hosts_from_config(self): '''Test extract hosts from configobj''' sio = StringIO() sio.write(""" server_port = 5050 hosts = "localhost, host[2-4]" [profiles] [[prof1]] vtype = "docker" img = "myimage" """) sio.flush() sio.seek(0) conf = ConfigObj(sio, unrepr=True) result = server.extract_hosts(conf["hosts"]) self.assertEquals(sorted(list(result)), ["host2", "host3", "host4", "localhost"]) sio.close() sio = StringIO() sio.write(""" server_port = 5050 hosts = "localhost", "host[2-4]" [profiles] [[prof1]] vtype = "docker" img = "myimage" """) sio.flush() sio.seek(0) conf = ConfigObj(sio, unrepr=True) result = server.extract_hosts(conf["hosts"]) self.assertEquals(sorted(list(result)), ["host2", "host3", "host4", "localhost"]) sio.close()