From ac73c72727599ea0d29397ed54abd4abb4be32e2 Mon Sep 17 00:00:00 2001 From: ziajka Date: Wed, 13 Jun 2018 18:55:47 +0200 Subject: [PATCH] Don't send variables to computes where are empty, Ref: #1340 --- gns3server/controller/project.py | 19 +++++++++++-------- tests/handlers/api/compute/test_project.py | 10 ++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 6c707f9b..ece3d328 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -500,18 +500,21 @@ class Project: if compute not in self._project_created_on_compute: # For a local server we send the project path if compute.id == "local": - yield from compute.post("/projects", data={ + data = { "name": self._name, "project_id": self._id, - "path": self._path, - "variables": self._variables - }) + "path": self._path + } else: - yield from compute.post("/projects", data={ + data = { "name": self._name, - "project_id": self._id, - "variables": self._variables - }) + "project_id": self._id + } + + if self._variables: + data["variables"] = self._variables + + yield from compute.post("/projects", data=data) self._project_created_on_compute.add(compute) yield from node.create() diff --git a/tests/handlers/api/compute/test_project.py b/tests/handlers/api/compute/test_project.py index 1fc92e85..90acd72d 100644 --- a/tests/handlers/api/compute/test_project.py +++ b/tests/handlers/api/compute/test_project.py @@ -36,6 +36,16 @@ def test_create_project_with_path(http_compute, tmpdir): assert response.json["project_id"] == "00010203-0405-0607-0809-0a0b0c0d0e0f" +def test_create_project_with_path_and_empty_variables(http_compute, tmpdir): + with patch("gns3server.compute.project.Project.is_local", return_value=True): + response = http_compute.post("/projects", { + "name": "test", + "path": str(tmpdir), "project_id": "00010203-0405-0607-0809-0a0b0c0d0e0f", + "variables": None}) + assert response.status == 201 + assert response.json["project_id"] == "00010203-0405-0607-0809-0a0b0c0d0e0f" + + def test_create_project_without_dir(http_compute): query = {"name": "test", "project_id": "10010203-0405-0607-0809-0a0b0c0d0e0f"} response = http_compute.post("/projects", query, example=True)