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

Do not erase the IOU config

This commit is contained in:
Julien Duponchelle 2015-04-24 15:12:58 +02:00
parent d5ae4750e9
commit 324a4f73d0
3 changed files with 26 additions and 2 deletions

View File

@ -58,6 +58,8 @@ class IOUHandler:
for name, value in request.json.items():
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)
response.set_status(201)
response.json(vm)

View File

@ -973,7 +973,7 @@ class IOUVM(BaseVM):
if len(initial_config) == 0 and os.path.exists(initial_config_path):
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:
f.write('')
else:

View File

@ -19,6 +19,7 @@ import pytest
import os
import stat
import sys
import uuid
from tests.utils import asyncio_patch
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"]
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"]
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):
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