1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Merge branch '1.5' into 2.0

This commit is contained in:
Julien Duponchelle 2016-05-19 13:32:30 +02:00
commit 00f80f54e8
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
3 changed files with 69 additions and 25 deletions

View File

@ -68,6 +68,9 @@ class DockerVM(BaseNode):
console_resolution="1024x768", console_http_port=80, console_http_path="/"): console_resolution="1024x768", console_http_port=80, console_http_path="/"):
super().__init__(name, node_id, project, manager, console=console, aux=aux, allocate_aux=True, console_type=console_type) super().__init__(name, node_id, project, manager, console=console, aux=aux, allocate_aux=True, console_type=console_type)
# If no version is specified force latest
if ":" not in image:
image = "{}:latest".format(image)
self._image = image self._image = image
self._start_command = start_command self._start_command = start_command
self._environment = environment self._environment = environment
@ -541,11 +544,16 @@ class DockerVM(BaseNode):
try: try:
if self.console_type == "vnc": if self.console_type == "vnc":
if self._x11vnc_process: if self._x11vnc_process:
try:
self._x11vnc_process.terminate() self._x11vnc_process.terminate()
self._xvfb_process.terminate()
yield from self._x11vnc_process.wait() yield from self._x11vnc_process.wait()
except ProcessLookupError:
pass
try:
self._xvfb_process.terminate()
yield from self._xvfb_process.wait() yield from self._xvfb_process.wait()
except ProcessLookupError:
pass
state = yield from self._get_container_state() state = yield from self._get_container_state()
if state == "paused" or state == "running": if state == "paused" or state == "running":
yield from self.stop() yield from self.stop()

View File

@ -41,7 +41,7 @@ def manager(port_manager):
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def vm(project, manager): def vm(project, manager):
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
vm._cid = "e90e34656842" vm._cid = "e90e34656842"
vm.allocate_aux = False vm.allocate_aux = False
return vm return vm
@ -50,7 +50,7 @@ def vm(project, manager):
def test_json(vm, project): def test_json(vm, project):
assert vm.__json__() == { assert vm.__json__() == {
'container_id': 'e90e34656842', 'container_id': 'e90e34656842',
'image': 'ubuntu', 'image': 'ubuntu:latest',
'name': 'test', 'name': 'test',
'project_id': project.id, 'project_id': project.id,
'node_id': vm.id, 'node_id': vm.id,
@ -84,7 +84,7 @@ def test_create(loop, project, manager):
} }
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
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,
@ -103,7 +103,44 @@ def test_create(loop, project, manager):
"NetworkDisabled": True, "NetworkDisabled": True,
"Name": "test", "Name": "test",
"Hostname": "test", "Hostname": "test",
"Image": "ubuntu", "Image": "ubuntu:latest",
"Env": [
"GNS3_MAX_ETHERNET=eth0"
],
"Entrypoint": ["/gns3/init.sh"],
"Cmd": ["/bin/sh"]
})
assert vm._cid == "e90e34656806"
def test_create_with_tag(loop, project, manager):
response = {
"Id": "e90e34656806",
"Warnings": []
}
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:16.04")
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("compute/docker/resources")),
"{}:/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network"))
],
"Privileged": True
},
"Volumes": {},
"NetworkDisabled": True,
"Name": "test",
"Hostname": "test",
"Image": "ubuntu:16.04",
"Env": [ "Env": [
"GNS3_MAX_ETHERNET=eth0" "GNS3_MAX_ETHERNET=eth0"
], ],
@ -144,7 +181,7 @@ def test_create_vnc(loop, project, manager):
"NetworkDisabled": True, "NetworkDisabled": True,
"Name": "test", "Name": "test",
"Hostname": "test", "Hostname": "test",
"Image": "ubuntu", "Image": "ubuntu:latest",
"Env": [ "Env": [
"GNS3_MAX_ETHERNET=eth0", "GNS3_MAX_ETHERNET=eth0",
"DISPLAY=:42" "DISPLAY=:42"
@ -165,7 +202,7 @@ def test_create_start_cmd(loop, project, manager):
} }
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
vm._start_command = "/bin/ls" vm._start_command = "/bin/ls"
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={
@ -187,7 +224,7 @@ def test_create_start_cmd(loop, project, manager):
"NetworkDisabled": True, "NetworkDisabled": True,
"Name": "test", "Name": "test",
"Hostname": "test", "Hostname": "test",
"Image": "ubuntu", "Image": "ubuntu:latest",
"Env": [ "Env": [
"GNS3_MAX_ETHERNET=eth0" "GNS3_MAX_ETHERNET=eth0"
] ]
@ -228,7 +265,7 @@ def test_create_environment(loop, project, manager):
"NetworkDisabled": True, "NetworkDisabled": True,
"Name": "test", "Name": "test",
"Hostname": "test", "Hostname": "test",
"Image": "ubuntu", "Image": "ubuntu:latest",
"Entrypoint": ["/gns3/init.sh"], "Entrypoint": ["/gns3/init.sh"],
"Cmd": ["/bin/sh"] "Cmd": ["/bin/sh"]
}) })
@ -256,7 +293,6 @@ def test_create_image_not_available(loop, project, manager):
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
vm._get_image_information = MagicMock() vm._get_image_information = MagicMock()
vm._get_image_information.side_effect = information vm._get_image_information.side_effect = information
with asyncio_patch("gns3server.compute.docker.DockerVM.pull_image", return_value=True) as mock_pull: with asyncio_patch("gns3server.compute.docker.DockerVM.pull_image", return_value=True) as mock_pull:
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
loop.run_until_complete(asyncio.async(vm.create())) loop.run_until_complete(asyncio.async(vm.create()))
@ -277,7 +313,7 @@ def test_create_image_not_available(loop, project, manager):
"NetworkDisabled": True, "NetworkDisabled": True,
"Name": "test", "Name": "test",
"Hostname": "test", "Hostname": "test",
"Image": "ubuntu", "Image": "ubuntu:latest",
"Env": [ "Env": [
"GNS3_MAX_ETHERNET=eth0" "GNS3_MAX_ETHERNET=eth0"
], ],
@ -285,7 +321,7 @@ def test_create_image_not_available(loop, project, manager):
"Cmd": ["/bin/sh"] "Cmd": ["/bin/sh"]
}) })
assert vm._cid == "e90e34656806" assert vm._cid == "e90e34656806"
mock_pull.assert_called_with("ubuntu") mock_pull.assert_called_with("ubuntu:latest")
def test_get_container_state(loop, vm): def test_get_container_state(loop, vm):
@ -494,7 +530,7 @@ def test_update(loop, vm):
"NetworkDisabled": True, "NetworkDisabled": True,
"Name": "test", "Name": "test",
"Hostname": "test", "Hostname": "test",
"Image": "ubuntu", "Image": "ubuntu:latest",
"Env": [ "Env": [
"GNS3_MAX_ETHERNET=eth0" "GNS3_MAX_ETHERNET=eth0"
], ],
@ -561,7 +597,7 @@ def test_update_running(loop, vm):
"NetworkDisabled": True, "NetworkDisabled": True,
"Name": "test", "Name": "test",
"Hostname": "test", "Hostname": "test",
"Image": "ubuntu", "Image": "ubuntu:latest",
"Env": [ "Env": [
"GNS3_MAX_ETHERNET=eth0" "GNS3_MAX_ETHERNET=eth0"
], ],
@ -814,7 +850,7 @@ def test_get_image_informations(project, manager, loop):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
loop.run_until_complete(asyncio.async(vm._get_image_information())) loop.run_until_complete(asyncio.async(vm._get_image_information()))
mock.assert_called_with("GET", "images/ubuntu/json") mock.assert_called_with("GET", "images/ubuntu:latest/json")
def test_mount_binds(vm, tmpdir): def test_mount_binds(vm, tmpdir):

View File

@ -62,7 +62,7 @@ def test_docker_create(http_compute, project, base_params):
assert response.json["name"] == "PC TEST 1" assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id assert response.json["project_id"] == project.id
assert response.json["container_id"] == "8bd8153ea8f5" assert response.json["container_id"] == "8bd8153ea8f5"
assert response.json["image"] == "nginx" assert response.json["image"] == "nginx:latest"
assert response.json["adapters"] == 2 assert response.json["adapters"] == 2
assert response.json["environment"] == "YES=1\nNO=0" assert response.json["environment"] == "YES=1\nNO=0"
assert response.json["console_resolution"] == "1280x1024" assert response.json["console_resolution"] == "1280x1024"