Beispiel #1
0
def test_create_vnc(loop, project, manager):

    response = {
        "Id": "e90e34656806",
        "Warnings": []
    }

    with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu:latest"}]) as mock_list_images:
        with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
            vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest", console_type="vnc", console=5900)
            vm._start_vnc = MagicMock()
            vm._display = 42
            loop.run_until_complete(asyncio.async(vm.create()))
            mock.assert_called_with("POST", "containers/create", data={
                "Tty": True,
                "OpenStdin": True,
                "StdinOnce": False,
                "HostConfig":
                    {
                        "CapAdd": ["ALL"],
                        "Binds": [
                            "{}:/gns3:ro".format(get_resource("modules/docker/resources")),
                            "{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")),
                            '/tmp/.X11-unix/:/tmp/.X11-unix/'
                        ],
                        "Privileged": True
                    },
                "Volumes": {},
                "NetworkDisabled": True,
                "Name": "test",
                "Hostname": "test",
                "Image": "ubuntu:latest",
                "Env": [
                    "container=docker",
                    "GNS3_MAX_ETHERNET=eth0",
                    "GNS3_VOLUMES=/etc/network",
                    "QT_GRAPHICSSYSTEM=native",
                    "DISPLAY=:42"
                ],
                "Entrypoint": ["/gns3/init.sh"],
                "Cmd": ["/bin/sh"]
            })
        assert vm._start_vnc.called
        assert vm._cid == "e90e34656806"
        assert vm._console_type == "vnc"
Beispiel #2
0
def test_create_vnc(loop, project, manager):

    response = {"Id": "e90e34656806", "Warnings": []}

    with asyncio_patch("gns3server.modules.docker.Docker.list_images",
                       return_value=[{
                           "image": "ubuntu:latest"
                       }]) as mock_list_images:
        with asyncio_patch("gns3server.modules.docker.Docker.query",
                           return_value=response) as mock:
            vm = DockerVM("test",
                          str(uuid.uuid4()),
                          project,
                          manager,
                          "ubuntu:latest",
                          console_type="vnc",
                          console=5900)
            vm._start_vnc = MagicMock()
            vm._display = 42
            loop.run_until_complete(asyncio. async (vm.create()))
            mock.assert_called_with(
                "POST",
                "containers/create",
                data={
                    "Tty":
                    True,
                    "OpenStdin":
                    True,
                    "StdinOnce":
                    False,
                    "HostConfig": {
                        "CapAdd": ["ALL"],
                        "Binds": [
                            "{}:/gns3:ro".format(
                                get_resource("modules/docker/resources")),
                            "{}:/gns3volumes/etc/network:rw".format(
                                os.path.join(vm.working_dir, "etc",
                                             "network")),
                            '/tmp/.X11-unix/:/tmp/.X11-unix/'
                        ],
                        "Privileged":
                        True
                    },
                    "Volumes": {},
                    "NetworkDisabled":
                    True,
                    "Name":
                    "test",
                    "Hostname":
                    "test",
                    "Image":
                    "ubuntu:latest",
                    "Env": [
                        "container=docker", "GNS3_MAX_ETHERNET=eth0",
                        "GNS3_VOLUMES=/etc/network",
                        "QT_GRAPHICSSYSTEM=native", "DISPLAY=:42"
                    ],
                    "Entrypoint": ["/gns3/init.sh"],
                    "Cmd": ["/bin/sh"]
                })
        assert vm._start_vnc.called
        assert vm._cid == "e90e34656806"
        assert vm._console_type == "vnc"