Update the remote IOU initial config

This commit is contained in:
Julien Duponchelle committed 2015-02-13 22:16:43 +01:00
1 parent 83edc649d2
commit e082cd8b1a
5 files changed
+148 -11

No files matched your search

+11 -3
View File
@@ -46,6 +46,9 @@ def vm(server, project, base_params):
return response.json
def initial_config_file(project, vm):
return os.path.join(project.path, "project-files", "iou", vm["vm_id"], "initial-config.cfg")
def test_iou_create(server, project, base_params):
response = server.post("/projects/{project_id}/iou/vms".format(project_id=project.id), base_params)
assert response.status == 201
@@ -66,6 +69,7 @@ def test_iou_create_with_params(server, project, base_params):
params["serial_adapters"] = 4
params["ethernet_adapters"] = 0
params["l1_keepalives"] = True
params["initial_config"] = "hostname test"
response = server.post("/projects/{project_id}/iou/vms".format(project_id=project.id), params, example=True)
assert response.status == 201
@@ -77,6 +81,8 @@ def test_iou_create_with_params(server, project, base_params):
assert response.json["ram"] == 1024
assert response.json["nvram"] == 512
assert response.json["l1_keepalives"] == True
with open(initial_config_file(project, response.json)) as f:
assert f.read() == params["initial_config"]
def test_iou_get(server, project, vm):
@@ -120,7 +126,7 @@ def test_iou_delete(server, vm):
assert response.status == 204
def test_iou_update(server, vm, tmpdir, free_console_port):
def test_iou_update(server, vm, tmpdir, free_console_port, project):
params = {
"name": "test",
"console": free_console_port,
@@ -128,7 +134,8 @@ def test_iou_update(server, vm, tmpdir, free_console_port):
"nvram": 2048,
"ethernet_adapters": 4,
"serial_adapters": 0,
"l1_keepalives": True
"l1_keepalives": True,
"initial_config": "hostname test"
}
response = server.put("/projects/{project_id}/iou/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), params)
assert response.status == 200
@@ -139,7 +146,8 @@ def test_iou_update(server, vm, tmpdir, free_console_port):
assert response.json["ram"] == 512
assert response.json["nvram"] == 2048
assert response.json["l1_keepalives"] == True
with open(initial_config_file(project, response.json)) as f:
assert f.read() == "hostname test"
def test_iou_nio_create_udp(server, vm):
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp",
+51 -1
View File
@@ -69,6 +69,12 @@ def test_vm(project, manager):
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
def test_vm_initial_config(project, manager):
vm = IOUVM("test", "00010203-0405-0607-0808-0a0b0c0d0e0f", project, manager, initial_config="hostname %h")
assert vm.name == "test"
assert vm.initial_config == "hostname test"
assert vm.id == "00010203-0405-0607-0808-0a0b0c0d0e0f"
@patch("gns3server.config.Config.get_section_config", return_value={"iouyap_path": "/bin/test_fake"})
def test_vm_invalid_iouyap_path(project, manager, loop):
with pytest.raises(IOUError):
@@ -179,4 +185,48 @@ def test_create_netmap_config(vm):
def test_build_command(vm):
assert vm._build_command() == [vm.path, '-L', str(vm.application_id)]
assert vm._build_command() == [vm.path, "-L", str(vm.application_id)]
def test_build_command_initial_config(vm):
filepath = os.path.join(vm.working_dir, "initial-config.cfg")
with open(filepath, "w+") as f:
f.write("service timestamps debug datetime msec\nservice timestamps log datetime msec\nno service password-encryption")
assert vm._build_command() == [vm.path, "-L", "-c", vm.initial_config_file, str(vm.application_id)]
def test_get_initial_config(vm):
content = "service timestamps debug datetime msec\nservice timestamps log datetime msec\nno service password-encryption"
vm.initial_config = content
assert vm.initial_config == content
def test_update_initial_config(vm):
content = "service timestamps debug datetime msec\nservice timestamps log datetime msec\nno service password-encryption"
vm.initial_config = content
filepath = os.path.join(vm.working_dir, "initial-config.cfg")
assert os.path.exists(filepath)
with open(filepath) as f:
assert f.read() == content
def test_update_initial_config_h(vm):
content = "hostname %h\n"
vm.name = "pc1"
vm.initial_config = content
with open(vm.initial_config_file) as f:
assert f.read() == "hostname pc1\n"
def test_change_name(vm, tmpdir):
path = os.path.join(vm.working_dir, "initial-config.cfg")
vm.name = "world"
with open(path, 'w+') as f:
f.write("hostname world")
vm.name = "hello"
assert vm.name == "hello"
with open(path) as f:
assert f.read() == "hostname hello"