mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Merge pull request #158 from GNS3/keep_iou_config
Do not erase the IOU initial-config if there is one when creating the IOU VM.
This commit is contained in:
commit
4f021054e0
@ -58,6 +58,8 @@ class IOUHandler:
|
|||||||
|
|
||||||
for name, value in request.json.items():
|
for name, value in request.json.items():
|
||||||
if hasattr(vm, name) and getattr(vm, name) != value:
|
if hasattr(vm, name) and getattr(vm, name) != value:
|
||||||
|
if name == "initial_config_content" and (vm.initial_config_content and len(vm.initial_config_content) > 0):
|
||||||
|
continue
|
||||||
setattr(vm, name, value)
|
setattr(vm, name, value)
|
||||||
response.set_status(201)
|
response.set_status(201)
|
||||||
response.json(vm)
|
response.json(vm)
|
||||||
|
@ -973,7 +973,7 @@ class IOUVM(BaseVM):
|
|||||||
if len(initial_config) == 0 and os.path.exists(initial_config_path):
|
if len(initial_config) == 0 and os.path.exists(initial_config_path):
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(initial_config_path, "w+", encoding="utf-8") as f:
|
with open(initial_config_path, 'w+', encoding='utf-8') as f:
|
||||||
if len(initial_config) == 0:
|
if len(initial_config) == 0:
|
||||||
f.write('')
|
f.write('')
|
||||||
else:
|
else:
|
||||||
|
@ -19,6 +19,7 @@ import pytest
|
|||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
|
import uuid
|
||||||
|
|
||||||
from tests.utils import asyncio_patch
|
from tests.utils import asyncio_patch
|
||||||
from unittest.mock import patch, MagicMock, PropertyMock
|
from unittest.mock import patch, MagicMock, PropertyMock
|
||||||
@ -94,11 +95,32 @@ def test_iou_create_with_params(server, project, base_params):
|
|||||||
|
|
||||||
assert "initial-config.cfg" in response.json["initial_config"]
|
assert "initial-config.cfg" in response.json["initial_config"]
|
||||||
with open(initial_config_file(project, response.json)) as f:
|
with open(initial_config_file(project, response.json)) as f:
|
||||||
assert f.read() == params["initial_config_content"]
|
assert f.read() == "hostname test"
|
||||||
|
|
||||||
assert "iourc" in response.json["iourc_path"]
|
assert "iourc" in response.json["iourc_path"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_iou_create_initial_config_already_exist(server, project, base_params):
|
||||||
|
"""We don't erase an initial config if already exist at project creation"""
|
||||||
|
|
||||||
|
vm_id = str(uuid.uuid4())
|
||||||
|
initial_config_file_path = initial_config_file(project, {'vm_id': vm_id})
|
||||||
|
with open(initial_config_file_path, 'w+') as f:
|
||||||
|
f.write("echo hello")
|
||||||
|
|
||||||
|
params = base_params
|
||||||
|
params["vm_id"] = vm_id
|
||||||
|
params["initial_config_content"] = "hostname test"
|
||||||
|
|
||||||
|
response = server.post("/projects/{project_id}/iou/vms".format(project_id=project.id), params, example=True)
|
||||||
|
assert response.status == 201
|
||||||
|
assert response.route == "/projects/{project_id}/iou/vms"
|
||||||
|
|
||||||
|
assert "initial-config.cfg" in response.json["initial_config"]
|
||||||
|
with open(initial_config_file(project, response.json)) as f:
|
||||||
|
assert f.read() == "echo hello"
|
||||||
|
|
||||||
|
|
||||||
def test_iou_get(server, project, vm):
|
def test_iou_get(server, project, vm):
|
||||||
response = server.get("/projects/{project_id}/iou/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
|
response = server.get("/projects/{project_id}/iou/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
|
Loading…
Reference in New Issue
Block a user