示例#1
0
 def test_can_get_grid_ip(self):
     adapter = DockerAdapter()
     container = adapter.find_container("brady/selenium-grid:latest")
     if not container:
         print "Not Found"
         return
     container_info = adapter.inspect(container["Id"])
     container = dict(container.items() + container_info.items())
     print container["NetworkSettings"]["IPAddress"]
示例#2
0
 def test_can_get_grid_ip(self):
     adapter = DockerAdapter()
     container = adapter.find_container('brady/selenium-grid:latest')
     if not container:
         print "Not Found"
         return
     container_info = adapter.inspect(container['Id'])
     container = dict(container.items() + container_info.items())
     print container['NetworkSettings']['IPAddress']
示例#3
0
 def test_can_check_if_grid_running(self):
     adapter = DockerAdapter()
     container = adapter.find_container('brady/selenium-grid:latest')
     if not container:
         print "Not Found"
     print "Found"
     #print container['Status']
     #print container['Ports']
     #print container['Id']
     if "Up" in container['Status']:
         print "Grid is Running"
     else:
         print "Grid is not Running"
示例#4
0
 def test_can_check_if_grid_running(self):
     adapter = DockerAdapter()
     container = adapter.find_container("brady/selenium-grid:latest")
     if not container:
         print "Not Found"
     print "Found"
     # print container['Status']
     # print container['Ports']
     # print container['Id']
     if "Up" in container["Status"]:
         print "Grid is Running"
     else:
         print "Grid is not Running"
示例#5
0
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)
示例#6
0
文件: hub.py 项目: MEDBEDb/dsgrid
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)
示例#7
0
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)