mirror of
https://github.com/GNS3/gns3-server
synced 2025-02-17 18:42:00 +00:00
parent
49f1931e95
commit
c333e9451f
@ -150,6 +150,11 @@ class DockerVM(BaseVM):
|
|||||||
def create(self):
|
def create(self):
|
||||||
"""Creates the Docker container."""
|
"""Creates the Docker container."""
|
||||||
|
|
||||||
|
try:
|
||||||
|
image_infos = yield from self._get_image_informations()
|
||||||
|
except DockerHttp404Error:
|
||||||
|
log.info("Image %s is missing pulling it from docker hub", self._image)
|
||||||
|
yield from self.pull_image(self._image)
|
||||||
image_infos = yield from self._get_image_informations()
|
image_infos = yield from self._get_image_informations()
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
@ -173,11 +178,6 @@ class DockerVM(BaseVM):
|
|||||||
if self._environment:
|
if self._environment:
|
||||||
params.update({"Env": [e.strip() for e in self._environment.split("\n")]})
|
params.update({"Env": [e.strip() for e in self._environment.split("\n")]})
|
||||||
|
|
||||||
images = [i["image"] for i in (yield from self.manager.list_images())]
|
|
||||||
if self._image not in images:
|
|
||||||
log.info("Image %s is missing pulling it from docker hub", self._image)
|
|
||||||
yield from self.pull_image(self._image)
|
|
||||||
|
|
||||||
result = yield from self.manager.query("POST", "containers/create", data=params)
|
result = yield from self.manager.query("POST", "containers/create", data=params)
|
||||||
self._cid = result['Id']
|
self._cid = result['Id']
|
||||||
log.info("Docker container '{name}' [{id}] created".format(
|
log.info("Docker container '{name}' [{id}] created".format(
|
||||||
|
@ -23,7 +23,7 @@ from tests.utils import asyncio_patch
|
|||||||
|
|
||||||
from gns3server.ubridge.ubridge_error import UbridgeNamespaceError
|
from gns3server.ubridge.ubridge_error import UbridgeNamespaceError
|
||||||
from gns3server.modules.docker.docker_vm import DockerVM
|
from gns3server.modules.docker.docker_vm import DockerVM
|
||||||
from gns3server.modules.docker.docker_error import DockerError
|
from gns3server.modules.docker.docker_error import *
|
||||||
from gns3server.modules.docker import Docker
|
from gns3server.modules.docker import Docker
|
||||||
|
|
||||||
|
|
||||||
@ -161,14 +161,28 @@ def test_create_environment(loop, project, manager):
|
|||||||
|
|
||||||
def test_create_image_not_available(loop, project, manager):
|
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 = {
|
response = {
|
||||||
"Id": "e90e34656806",
|
"Id": "e90e34656806",
|
||||||
"Warnings": []
|
"Warnings": []
|
||||||
}
|
}
|
||||||
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[]) as mock_list_images:
|
|
||||||
|
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
|
||||||
|
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.DockerVM.pull_image", return_value=True) as mock_pull:
|
||||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
|
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.async(vm.create()))
|
||||||
mock.assert_called_with("POST", "containers/create", data={
|
mock.assert_called_with("POST", "containers/create", data={
|
||||||
"Tty": True,
|
"Tty": True,
|
||||||
|
Loading…
Reference in New Issue
Block a user