Beispiel #1
0
def test_get_image_informations(project, manager, loop):
    response = {
    }
    with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
        vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
        loop.run_until_complete(asyncio.async(vm._get_image_informations()))
        mock.assert_called_with("GET", "images/ubuntu:latest/json")
Beispiel #2
0
def test_get_image_informations(project, manager, loop):
    response = {}
    with asyncio_patch("gns3server.modules.docker.Docker.query",
                       return_value=response) as mock:
        vm = DockerVM("test", str(uuid.uuid4()), project, manager,
                      "ubuntu:latest")
        loop.run_until_complete(asyncio. async (vm._get_image_informations()))
        mock.assert_called_with("GET", "images/ubuntu:latest/json")
Beispiel #3
0
def test_create_image_not_available(loop, project, manager):

    call = 0

    @asyncio.coroutine
    def informations():
        nonlocal call
        if call == 0:
            call += 1
            raise DockerHttp404Error("missing")
        else:
            return {}

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

    vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
    vm._get_image_informations = MagicMock()
    vm._get_image_informations.side_effect = informations

    with asyncio_patch("gns3server.modules.docker.DockerVM.pull_image", return_value=True) as mock_pull:
        with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
            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"))
                        ],
                        "Privileged": True
                    },
                "Volumes": {},
                "NetworkDisabled": True,
                "Name": "test",
                "Hostname": "test",
                "Image": "ubuntu:latest",
                "Env": [
                    "container=docker",
                    "GNS3_MAX_ETHERNET=eth0",
                    "GNS3_VOLUMES=/etc/network"
                ],
                "Entrypoint": ["/gns3/init.sh"],
                "Cmd": ["/bin/sh"]
            })
        assert vm._cid == "e90e34656806"
        mock_pull.assert_called_with("ubuntu:latest")
Beispiel #4
0
def test_create_image_not_available(loop, project, manager):

    call = 0

    @asyncio.coroutine
    def informations():
        nonlocal call
        if call == 0:
            call += 1
            raise DockerHttp404Error("missing")
        else:
            return {}

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

    vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
    vm._get_image_informations = MagicMock()
    vm._get_image_informations.side_effect = informations

    with asyncio_patch("gns3server.modules.docker.DockerVM.pull_image",
                       return_value=True) as mock_pull:
        with asyncio_patch("gns3server.modules.docker.Docker.query",
                           return_value=response) as mock:
            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"))
                        ],
                        "Privileged":
                        True
                    },
                    "Volumes": {},
                    "NetworkDisabled":
                    True,
                    "Name":
                    "test",
                    "Hostname":
                    "test",
                    "Image":
                    "ubuntu:latest",
                    "Env": [
                        "container=docker", "GNS3_MAX_ETHERNET=eth0",
                        "GNS3_VOLUMES=/etc/network"
                    ],
                    "Entrypoint": ["/gns3/init.sh"],
                    "Cmd": ["/bin/sh"]
                })
        assert vm._cid == "e90e34656806"
        mock_pull.assert_called_with("ubuntu:latest")