Handle ENOENT during license removal

This commit is contained in:
James Laska
2015-06-15 19:24:51 -04:00
parent c7e2c333d4
commit 3f9c2cf465

View File

@@ -10,6 +10,7 @@ import dateutil
import time import time
import socket import socket
import sys import sys
import errno
# Django # Django
from django.conf import settings from django.conf import settings
@@ -270,19 +271,21 @@ class ApiV1ConfigView(APIView):
return Response(None, status=status.HTTP_404_NOT_FOUND) return Response(None, status=status.HTTP_404_NOT_FOUND)
# Remove license file # Remove license file
has_error = False errno = None
for fname in (TEMPORARY_TASK_FILE, TASK_FILE): for fname in (TEMPORARY_TASK_FILE, TASK_FILE):
try: try:
os.remove(fname) os.remove(fname)
except OSError: except OSError, e:
has_error = True if e.errno != errno.ENOENT
errno = e.errno
break
# Only stop mongod if license removal succeeded # Only stop mongod if license removal succeeded
if has_error: if errno is None:
return Response({"error": "Failed to remove license"}, status=status.HTTP_400_BAD_REQUEST)
else:
mongodb_control.delay('stop') mongodb_control.delay('stop')
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
else:
return Response({"error": "Failed to remove license (%s)" % errno}, status=status.HTTP_400_BAD_REQUEST)
class DashboardView(APIView): class DashboardView(APIView):