From aeab9780d8e841be1683493097bee1eaaf262933 Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 15 Apr 2015 19:49:40 -0600 Subject: [PATCH 1/5] Fixes initial-configs that were not restored when opening a project containing IOU VMs. --- gns3server/handlers/api/iou_handler.py | 4 ---- gns3server/modules/iou/iou_vm.py | 12 ++++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/gns3server/handlers/api/iou_handler.py b/gns3server/handlers/api/iou_handler.py index 98bd4cf7..acf3b5b1 100644 --- a/gns3server/handlers/api/iou_handler.py +++ b/gns3server/handlers/api/iou_handler.py @@ -59,8 +59,6 @@ class IOUHandler: for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: setattr(vm, name, value) - if "initial_config_content" in request.json: - vm.initial_config = request.json.get("initial_config_content") response.set_status(201) response.json(vm) @@ -108,8 +106,6 @@ class IOUHandler: for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: setattr(vm, name, value) - if "initial_config_content" in request.json: - vm.initial_config = request.json.get("initial_config_content") response.json(vm) @classmethod diff --git a/gns3server/modules/iou/iou_vm.py b/gns3server/modules/iou/iou_vm.py index 305250e0..5edf33a9 100644 --- a/gns3server/modules/iou/iou_vm.py +++ b/gns3server/modules/iou/iou_vm.py @@ -317,9 +317,9 @@ class IOUVM(BaseVM): """ if self.initial_config_file: - content = self.initial_config + content = self.initial_config_content content = content.replace(self._name, new_name) - self.initial_config = content + self.initial_config_content = content super(IOUVM, IOUVM).name.__set__(self, new_name) @@ -939,7 +939,7 @@ class IOUVM(BaseVM): log.warn("could not determine if layer 1 keepalive messages are supported by {}: {}".format(os.path.basename(self._path), e)) @property - def initial_config(self): + def initial_config_content(self): """ Returns the content of the current initial-config file. """ @@ -952,10 +952,10 @@ class IOUVM(BaseVM): with open(config_file) as f: return f.read() except OSError as e: - raise IOUError("Can't read configuration file '{}'".format(config_file)) + raise IOUError("Can't read configuration file '{}': {}".format(config_file, e)) - @initial_config.setter - def initial_config(self, initial_config): + @initial_config_content.setter + def initial_config_content(self, initial_config): """ Update the initial config From 4136c29b0ff875ae53ea03188d8136b63e4a6d36 Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 15 Apr 2015 19:50:40 -0600 Subject: [PATCH 2/5] Config paths are not used when updating Dynamips or IOU VM settings. --- gns3server/schemas/dynamips_vm.py | 10 ---------- gns3server/schemas/iou.py | 4 ---- 2 files changed, 14 deletions(-) diff --git a/gns3server/schemas/dynamips_vm.py b/gns3server/schemas/dynamips_vm.py index 934646c8..8888f6a6 100644 --- a/gns3server/schemas/dynamips_vm.py +++ b/gns3server/schemas/dynamips_vm.py @@ -284,20 +284,10 @@ VM_UPDATE_SCHEMA = { "type": "string", "minLength": 1, }, - "startup_config": { - "description": "path to the IOS startup configuration file", - "type": "string", - "minLength": 1, - }, "startup_config_content": { "description": "Content of IOS startup configuration file", "type": "string", }, - "private_config": { - "description": "path to the IOS private configuration file", - "type": "string", - "minLength": 1, - }, "private_config_content": { "description": "Content of IOS private configuration file", "type": "string", diff --git a/gns3server/schemas/iou.py b/gns3server/schemas/iou.py index 743dfcfc..011607ba 100644 --- a/gns3server/schemas/iou.py +++ b/gns3server/schemas/iou.py @@ -127,10 +127,6 @@ IOU_UPDATE_SCHEMA = { "description": "Always up ethernet interface", "type": ["boolean", "null"] }, - "initial_config": { - "description": "Path to the initial configuration of IOU", - "type": ["string", "null"] - }, "initial_config_content": { "description": "Initial configuration of IOU", "type": ["string", "null"] From 343e007809a1f1915407fb1d4135122b94027bde Mon Sep 17 00:00:00 2001 From: grossmj Date: Thu, 16 Apr 2015 20:17:06 -0600 Subject: [PATCH 3/5] Ignore the "OSError: [WinError 0] The operation completed successfully" exception in Windows. --- gns3server/server.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gns3server/server.py b/gns3server/server.py index dca8ff29..0dd5d641 100644 --- a/gns3server/server.py +++ b/gns3server/server.py @@ -225,6 +225,11 @@ class Server: try: self._loop.run_forever() + except OSError as e: + # This is to ignore OSError: [WinError 0] The operation completed successfully + # exception on Windows. + if not sys.platform.startswith("win") and not e.winerror == 0: + raise except TypeError as e: # This is to ignore an asyncio.windows_events exception # on Windows when the process gets the SIGBREAK signal From 3926390d307a67689936d7f1104c9cd03446e820 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Sat, 18 Apr 2015 09:22:37 +0200 Subject: [PATCH 4/5] Fix tests broken by a previous commit --- gns3server/handlers/api/iou_handler.py | 2 +- tests/modules/iou/test_iou_vm.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gns3server/handlers/api/iou_handler.py b/gns3server/handlers/api/iou_handler.py index acf3b5b1..3314e580 100644 --- a/gns3server/handlers/api/iou_handler.py +++ b/gns3server/handlers/api/iou_handler.py @@ -305,4 +305,4 @@ class IOUHandler: vm = iou_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"]) response.set_status(200) - response.json({"content": vm.initial_config}) + response.json({"content": vm.initial_config_content}) diff --git a/tests/modules/iou/test_iou_vm.py b/tests/modules/iou/test_iou_vm.py index 731f6974..c66cfb99 100644 --- a/tests/modules/iou/test_iou_vm.py +++ b/tests/modules/iou/test_iou_vm.py @@ -81,11 +81,11 @@ def test_vm(project, manager): assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f" -def test_vm_initial_config(project, manager): +def test_vm_initial_config_content(project, manager): vm = IOUVM("test", "00010203-0405-0607-0808-0a0b0c0d0e0f", project, manager) - vm.initial_config = "hostname %h" + vm.initial_config_content = "hostname %h" assert vm.name == "test" - assert vm.initial_config == "hostname test" + assert vm.initial_config_content == "hostname test" assert vm.id == "00010203-0405-0607-0808-0a0b0c0d0e0f" @@ -287,10 +287,10 @@ def test_update_initial_config_empty(vm): assert f.read() == content -def test_update_initial_config_h(vm): +def test_update_initial_config_content_hostname(vm): content = "hostname %h\n" vm.name = "pc1" - vm.initial_config = content + vm.initial_config_content = content with open(vm.initial_config_file) as f: assert f.read() == "hostname pc1\n" From 531e95463cea6a37310a7512a311c91eb973b5dc Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 20 Apr 2015 10:12:17 +0200 Subject: [PATCH 5/5] Add qemu-kvm to the list of binary --- gns3server/modules/qemu/__init__.py | 2 +- tests/modules/qemu/test_qemu_manager.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gns3server/modules/qemu/__init__.py b/gns3server/modules/qemu/__init__.py index e5bf698a..510f6aab 100644 --- a/gns3server/modules/qemu/__init__.py +++ b/gns3server/modules/qemu/__init__.py @@ -67,7 +67,7 @@ class Qemu(BaseManager): for path in paths: try: for f in os.listdir(path): - if (f.startswith("qemu-system") or f == "qemu" or f == "qemu.exe") and \ + if (f.startswith("qemu-system") or f.startswith("qemu-kvm") or f == "qemu" or f == "qemu.exe") and \ os.access(os.path.join(path, f), os.X_OK) and \ os.path.isfile(os.path.join(path, f)): qemu_path = os.path.join(path, f) diff --git a/tests/modules/qemu/test_qemu_manager.py b/tests/modules/qemu/test_qemu_manager.py index ee732d11..fcdfe477 100644 --- a/tests/modules/qemu/test_qemu_manager.py +++ b/tests/modules/qemu/test_qemu_manager.py @@ -32,7 +32,7 @@ def test_get_qemu_version(loop): def test_binary_list(loop): - files_to_create = ["qemu-system-x86", "qemu-system-x42", "hello"] + files_to_create = ["qemu-system-x86", "qemu-system-x42", "qemu-kvm", "hello"] for file_to_create in files_to_create: path = os.path.join(os.environ["PATH"], file_to_create) @@ -44,6 +44,7 @@ def test_binary_list(loop): qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list())) assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": "2.2.0"} in qemus + assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": "2.2.0"} in qemus assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": "2.2.0"} in qemus assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": "2.2.0"} not in qemus