def test_can_restart_node(self): adapter = DockerAdapter() containers = adapter.find_all_containers('brady/firefox-node:latest') if len(containers) == 0: print "Not Found" return container = containers.pop(0) adapter.restart(container)
def test_can_restart_node(self): adapter = DockerAdapter() containers = adapter.find_all_containers("brady/firefox-node:latest") if len(containers) == 0: print "Not Found" return container = containers.pop(0) adapter.restart(container)
class GridHub: VALID_BROWSERS = ('firefox', 'phantomjs', 'chrome') def __init__(self): self.adapter = DockerAdapter() def get_container_info(self): container = self.adapter.find_container('dsgrid/selenium-hub:latest') if not container: # raise exception container not found return False container_info = self.adapter.inspect(container['Id']) container = dict(container.items() + container_info.items()) return container def get_nodes(self): nodes = [] containers = self.adapter.client.containers() for container in containers: if "node" in container['Image']: nodes.append(container) return nodes def is_running(self): container = self.get_container_info() if not container: # raise exception container not found return False return "Up" in container['Status'] def start(self): response = self.adapter.client.create_container('dsgrid/selenium-hub', ports={"4444/tcp": {}}) if response['Id']: self.adapter.client.start(response, None, {'4444/tcp': ('', '49044')}) def get_ip(self): container = self.get_container_info() return container['NetworkSettings']['IPAddress'] def add_node(self, browser): if not browser in self.VALID_BROWSERS: return False ip = self.get_ip() response = self.adapter.client.create_container( 'dsgrid/' + browser + '-node', [], environment={"GRID_IP": ip}) if response['Id']: self.adapter.client.start(response) return True def restart_nodes(self, browser=None): containers = self.get_nodes() nodes_to_stop = [] for container in containers: if browser is not None and browser not in container['Image']: continue nodes_to_stop.append(container) if len(nodes_to_stop) == 0: return False for container in nodes_to_stop: self.adapter.restart(container) return True def stop_nodes(self, by_browser=None): if by_browser is not None and not by_browser in self.VALID_BROWSERS: # raise exception return False browser = '' if by_browser in self.VALID_BROWSERS: browser = by_browser + '-' containers = self.adapter.client.containers() for container in containers: if browser + "node" in container['Image']: self.adapter.client.stop(container['Id']) self.adapter.client.remove_container(container['Id']) return True def shutdown(self): self.stop_nodes() container = self.adapter.find_container('dsgrid/selenium-hub:latest') if not container: # raise exception container not found return False self.adapter.client.stop(container) self.adapter.client.remove_container(container)
class GridHub: VALID_BROWSERS = ('firefox', 'phantomjs') def __init__(self): self.adapter = DockerAdapter() def get_container_info(self): container = self.adapter.find_container('dsgrid/selenium-hub:latest') if not container: # raise exception container not found return False container_info = self.adapter.inspect(container['Id']) container = dict(container.items() + container_info.items()) return container def get_nodes(self): nodes = [] containers = self.adapter.client.containers() for container in containers: if "node" in container['Image']: nodes.append(container) return nodes def is_running(self): container = self.get_container_info() if not container: # raise exception container not found return False return "Up" in container['Status'] def start(self): response = self.adapter.client.create_container('dsgrid/selenium-hub', [], ports=["49044:4444"]) if response['Id']: self.adapter.client.start(response) def get_ip(self): container = self.get_container_info() return container['NetworkSettings']['IPAddress'] def add_node(self, browser): if not browser in self.VALID_BROWSERS: return False ip = self.get_ip() response = self.adapter.client.create_container('dsgrid/'+browser+'-node', [], environment={"GRID_IP": ip}) if response['Id']: self.adapter.client.start(response) return True def restart_nodes(self, browser=None): containers = self.get_nodes() nodes_to_stop = [] for container in containers: if browser is not None and browser not in container['Image']: continue nodes_to_stop.append(container) if len(nodes_to_stop) == 0: return False for container in nodes_to_stop: self.adapter.restart(container) return True def stop_nodes(self, by_browser=None): if by_browser is not None and not by_browser in self.VALID_BROWSERS: # raise exception return False browser = '' if by_browser in self.VALID_BROWSERS: browser = by_browser + '-' containers = self.adapter.client.containers() for container in containers: if browser + "node" in container['Image']: self.adapter.client.stop(container['Id']) self.adapter.client.remove_container(container['Id']) return True def shutdown(self): self.stop_nodes() container = self.adapter.find_container('dsgrid/selenium-hub:latest') if not container: # raise exception container not found return False self.adapter.client.stop(container) self.adapter.client.remove_container(container)
class GridHub: VALID_BROWSERS = ("firefox", "phantomjs", "chrome") def __init__(self): self.adapter = DockerAdapter() def get_container_info(self): container = self.adapter.find_container("dsgrid/selenium-hub:latest") if not container: # raise exception container not found return False container_info = self.adapter.inspect(container["Id"]) container = dict(container.items() + container_info.items()) return container def get_nodes(self): nodes = [] containers = self.adapter.client.containers() for container in containers: if "node" in container["Image"]: nodes.append(container) return nodes def is_running(self): container = self.get_container_info() if not container: # raise exception container not found return False return "Up" in container["Status"] def start(self): response = self.adapter.client.create_container("dsgrid/selenium-hub", ports={"4444/tcp": {}}) if response["Id"]: self.adapter.client.start(response, None, {"4444/tcp": ("", "49044")}) def get_ip(self): container = self.get_container_info() return container["NetworkSettings"]["IPAddress"] def add_node(self, browser): if not browser in self.VALID_BROWSERS: return False ip = self.get_ip() response = self.adapter.client.create_container("dsgrid/" + browser + "-node", [], environment={"GRID_IP": ip}) if response["Id"]: self.adapter.client.start(response) return True def restart_nodes(self, browser=None): containers = self.get_nodes() nodes_to_stop = [] for container in containers: if browser is not None and browser not in container["Image"]: continue nodes_to_stop.append(container) if len(nodes_to_stop) == 0: return False for container in nodes_to_stop: self.adapter.restart(container) return True def stop_nodes(self, by_browser=None): if by_browser is not None and not by_browser in self.VALID_BROWSERS: # raise exception return False browser = "" if by_browser in self.VALID_BROWSERS: browser = by_browser + "-" containers = self.adapter.client.containers() for container in containers: if browser + "node" in container["Image"]: self.adapter.client.stop(container["Id"]) self.adapter.client.remove_container(container["Id"]) return True def shutdown(self): self.stop_nodes() container = self.adapter.find_container("dsgrid/selenium-hub:latest") if not container: # raise exception container not found return False self.adapter.client.stop(container) self.adapter.client.remove_container(container)