lorax-composer: Delete workspace copy when deleting blueprint

Also extends the blueprint delete test to also check the workspace.

(cherry picked from commit 26bd2c1378)
(cherry picked from commit 5c0f127b3c)
This commit is contained in:
Brian C. Lane 2019-02-26 14:32:01 -08:00
parent 21975b44da
commit d0458750df
2 changed files with 25 additions and 1 deletions

View File

@ -201,7 +201,8 @@ DELETE `/api/v0/blueprints/delete/<blueprint_name>`
Delete a blueprint. The blueprint is deleted from the branch, and will no longer 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 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 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. error response with it set to false and an error message included.
@ -1212,6 +1213,7 @@ def v0_api(api):
try: try:
with api.config["GITLOCK"].lock: with api.config["GITLOCK"].lock:
workspace_delete(api.config["GITLOCK"].repo, branch, blueprint_name)
delete_recipe(api.config["GITLOCK"].repo, branch, blueprint_name) delete_recipe(api.config["GITLOCK"].repo, branch, blueprint_name)
except Exception as e: except Exception as e:
log.error("(v0_blueprints_delete) %s", str(e)) log.error("(v0_blueprints_delete) %s", str(e))

View File

@ -370,6 +370,25 @@ class ServerTestCase(unittest.TestCase):
def test_10_blueprints_delete(self): def test_10_blueprints_delete(self):
"""Test DELETE /api/v0/blueprints/delete/<blueprint_name>""" """Test DELETE /api/v0/blueprints/delete/<blueprint_name>"""
# 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":"5.*"},
{"name":"glusterfs-cli", "version":"5.*"}],
"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") resp = self.server.delete("/api/v0/blueprints/delete/example-glusterfs")
data = json.loads(resp.data) data = json.loads(resp.data)
self.assertEqual(data, {"status":True}) self.assertEqual(data, {"status":True})
@ -381,6 +400,9 @@ class ServerTestCase(unittest.TestCase):
blueprints = data.get("blueprints") blueprints = data.get("blueprints")
self.assertEqual("example-glusterfs" in blueprints, False) 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): def test_11_blueprints_undo(self):
"""Test POST /api/v0/blueprints/undo/<blueprint_name>/<commit>""" """Test POST /api/v0/blueprints/undo/<blueprint_name>/<commit>"""
resp = self.server.get("/api/v0/blueprints/changes/example-glusterfs") resp = self.server.get("/api/v0/blueprints/changes/example-glusterfs")