Commit 914e9efc authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

fix integrity issue

because django sets a foreign key constraint on sandbox_version_id
we may have issues if it refers to a version we want to delete
parent 77e60e80
......@@ -332,6 +332,11 @@ class WebappSandboxPanel(LoginRequiredMixin, TemplateView):
webapp = self.get_object()
action = request.POST["action"]
def stop_sandbox():
webapp.sandbox_state = Webapp.STOPPING
webapp.sandbox_version_id = None
webapp.save()
log.info("action %r", request.POST["action"])
if action == "start":
if webapp.sandbox_state != Webapp.IDLE:
......@@ -383,16 +388,14 @@ class WebappSandboxPanel(LoginRequiredMixin, TemplateView):
description=request.POST["description"],
url="http://WTF",
**extra)
webapp.sandbox_state = Webapp.STOPPING;
webapp.save()
stop_sandbox()
messages.success(request, "committing sandbox %r version %r"
% (webapp.name, number))
elif action == "rollback":
if webapp.sandbox_state == Webapp.RUNNING:
webapp.sandbox_state = Webapp.STOPPING
webapp.save()
stop_sandbox()
messages.success(request, "rolling back sandbox %r" % webapp.name)
else:
messages.error(request, "unable to roll back, sandbox %r is not running"
......@@ -400,8 +403,7 @@ class WebappSandboxPanel(LoginRequiredMixin, TemplateView):
elif action == "abort":
if webapp.sandbox_state == Webapp.START_ERROR:
webapp.sandbox_state = Webapp.STOPPING
webapp.save()
stop_sandbox()
messages.success(request, "reset sandbox %r" % webapp.name)
elif action == "retry":
......@@ -410,8 +412,7 @@ class WebappSandboxPanel(LoginRequiredMixin, TemplateView):
webapp.save()
messages.success(request, "starting sandbox %r" % webapp.name)
elif webapp.sandbox_state == Webapp.STOP_ERROR:
webapp.sandbox_state = Webapp.STOPPING
webapp.save()
stop_sandbox()
messages.success(request, "stopping sandbox %r" % webapp.name)
log.debug("new sandbox state: %r -> %r",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment