From e3addd1252a46b7414bf6fa152079a47ccd0c305 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Tue, 26 Feb 2019 14:32:01 -0800 Subject: [PATCH] lorax-composer: Delete workspace copy when deleting blueprint Also extends the blueprint delete test to also check the workspace. (cherry picked from commit da6e22875359c88a1c1d6619408d413e65dc2c3a) Related: rhbz#1682992 --- src/pylorax/api/v0.py | 4 +++- tests/pylorax/test_server.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index 283a9134..9172a0cc 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -201,7 +201,8 @@ DELETE `/api/v0/blueprints/delete/` Delete a blueprint. The blueprint is deleted from the branch, and will no longer be listed by the `list` route. A blueprint can be undeleted using the `undo` route - to revert to a previous commit. + to revert to a previous commit. This will also delete the workspace copy of the + blueprint. The response will be a status response with `status` set to true, or an error response with it set to false and an error message included. @@ -1206,6 +1207,7 @@ def v0_api(api): try: with api.config["GITLOCK"].lock: + workspace_delete(api.config["GITLOCK"].repo, branch, blueprint_name) delete_recipe(api.config["GITLOCK"].repo, branch, blueprint_name) except Exception as e: log.error("(v0_blueprints_delete) %s", str(e)) diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index 4ab8ec48..e411b8ec 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -361,6 +361,25 @@ class ServerTestCase(unittest.TestCase): def test_10_blueprints_delete(self): """Test DELETE /api/v0/blueprints/delete/""" + + # Push a new workspace blueprint first + test_blueprint = {"description": "An example GlusterFS server with samba, ws version", + "name":"example-glusterfs", + "version": "1.4.0", + "modules":[{"name":"glusterfs", "version":"4.0.*"}, + {"name":"glusterfs-cli", "version":"4.0.*"}], + "packages":[{"name":"samba", "version":"4.*.*"}, + {"name":"tmux", "version":"2.8"}], + "groups": []} + resp = self.server.post("/api/v0/blueprints/workspace", + data=json.dumps(test_blueprint), + content_type="application/json") + data = json.loads(resp.data) + self.assertEqual(data, {"status":True}) + # Make sure the workspace file is present + self.assertEqual(os.path.exists(joinpaths(self.repo_dir, "git/workspace/master/example-glusterfs.toml")), True) + + # This should delete the git blueprint and the workspace copy resp = self.server.delete("/api/v0/blueprints/delete/example-glusterfs") data = json.loads(resp.data) self.assertEqual(data, {"status":True}) @@ -372,6 +391,9 @@ class ServerTestCase(unittest.TestCase): blueprints = data.get("blueprints") self.assertEqual("example-glusterfs" in blueprints, False) + # Make sure the workspace file is gone + self.assertEqual(os.path.exists(joinpaths(self.repo_dir, "git/workspace/master/example-glusterfs.toml")), False) + def test_11_blueprints_undo(self): """Test POST /api/v0/blueprints/undo//""" resp = self.server.get("/api/v0/blueprints/changes/example-glusterfs")