[MobLab] Moblab Setup page.
* Adds a new page located at /moblab_setup
* 2 are on this page: 1 to upload a Boto Key and 1 to edit the config values.
* Link to /moblab_setup is visible only on a moblab system.
* RPC's that execute moblab_setup's actions are gated by a decorator that
limits them to only run on a moblab_system.
* Unittests for new RPC's.
* Editting the config values, writes the full config to shadow_config.ini and
reboots the system so changes takes effort.
* Resetting the config values, makes shadow_config.ini an empty file and
reboots the system so it is restored.
* Uploading the boto key uses shutil.copyfile to write in the new boto file's
contents to the boto file location.
BUG=chromium:396694
TEST=unittests, Uploaded a boto key and successfully ran a suite, editted
config and ensured changes were written into shadow_config, & reset config
and ensured that the default settings were restored.
DEPLOY=afe,apache
CQ-DEPEND=CL:212322
CQ-DEPEND=CL:212323
CQ-DEPEND=CL:212295
Change-Id: Ie354a2df310393045f3116e93004f58ea671de36
Reviewed-on: https://chromium-review.googlesource.com/209685
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Simran Basi <sbasi@chromium.org>
Tested-by: Simran Basi <sbasi@chromium.org>
diff --git a/frontend/afe/views.py b/frontend/afe/views.py
index f304bcb..44feef0 100644
--- a/frontend/afe/views.py
+++ b/frontend/afe/views.py
@@ -1,4 +1,4 @@
-import httplib2, sys, traceback, cgi
+import httplib2, os, sys, traceback, cgi
from django.http import HttpResponse, HttpResponsePermanentRedirect
from django.http import HttpResponseServerError
@@ -62,3 +62,25 @@
'traceback': cgi.escape(trace)
})
return HttpResponseServerError(t.render(context))
+
+
+def handle_file_upload(request):
+ """Handler for uploading files.
+
+ Saves the files to /tmp and returns the resulting paths on disk.
+
+ @param request: request containing the file data.
+
+ @returns HttpResponse: with the paths of the saved files.
+ """
+ if request.method == 'POST':
+ TEMPT_DIR = '/tmp/'
+ file_paths = []
+ for file_name, upload_file in request.FILES.iteritems():
+ file_path = os.path.join(
+ TEMPT_DIR, '_'.join([file_name, upload_file.name]))
+ with open(file_path, 'wb+') as destination:
+ for chunk in upload_file.chunks():
+ destination.write(chunk)
+ file_paths.append(file_path)
+ return HttpResponse(rpc_utils.prepare_for_serialization(file_paths))