diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 189: support the inclusion of a auth token in the job file and use it when submitting results

Message ID 20120112231113.21882.15062.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson Jan. 12, 2012, 11:11 p.m. UTC
Merge authors:
  Michael Hudson-Doyle (mwhudson)
Related merge proposals:
  https://code.launchpad.net/~mwhudson/lava-dispatcher/support-submit_job-token/+merge/87893
  proposed by: Michael Hudson-Doyle (mwhudson)
  review: Approve - Paul Larson (pwlars)
  review: Approve - Zygmunt Krynicki (zkrynicki)
  https://code.launchpad.net/~mwhudson/lava-dispatcher/custom-connection-command/+merge/87890
  proposed by: Michael Hudson-Doyle (mwhudson)
------------------------------------------------------------
revno: 189 [merge]
committer: Michael Hudson-Doyle <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Fri 2012-01-13 12:08:03 +1300
message:
  support the inclusion of a auth token in the job file and use it when submitting results
  this means that it is now possible to submit a job to a private bundle stream
modified:
  lava_dispatcher/actions/launch_control.py
  lava_dispatcher/connection.py
  lava_dispatcher/default-config/lava-dispatcher/device-defaults.conf
  setup.py


--
lp:lava-dispatcher
https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk

You are subscribed to branch lp:lava-dispatcher.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_dispatcher/actions/launch_control.py'
--- lava_dispatcher/actions/launch_control.py	2011-11-24 03:00:54 +0000
+++ lava_dispatcher/actions/launch_control.py	2012-01-09 23:20:01 +0000
@@ -24,6 +24,9 @@ 
 import shutil
 import tarfile
 import logging
+import urlparse
+
+from lava_tool.authtoken import AuthenticatingServerProxy, MemoryAuthBackend
 
 from lava_dispatcher.actions import BaseAction
 from lava_dispatcher.client.base import OperationFailed
@@ -44,8 +47,8 @@ 
             test_runs += bundle['test_runs']
         return main_bundle
 
-    def submit_combine_bundles(self, status='pass', err_msg='', server=None, stream=None):
-        dashboard = _get_dashboard(server)
+    def submit_combine_bundles(self, status='pass', err_msg='', server=None, stream=None, token=None):
+        dashboard = _get_dashboard(server, token)
         main_bundle = self.combine_bundles()
         self.context.test_data.add_seriallog(
             self.context.client.get_seriallog())
@@ -67,7 +70,7 @@ 
             logging.warning("Fault string: %s" % err.faultString)
 
 class cmd_submit_results_on_host(SubmitResultAction):
-    def run(self, server, stream):
+    def run(self, server, stream, token=None):
         #Upload bundle files to dashboard
         logging.info("Executing submit_results_on_host command")
         bundlename_list = []
@@ -87,7 +90,7 @@ 
             status = 'fail'
             err_msg = err_msg + " Some test case result appending failed."
 
-        self.submit_combine_bundles(status, err_msg, server, stream)
+        self.submit_combine_bundles(status, err_msg, server, stream, token)
 
         for bundle in bundlename_list:
             os.remove(bundle)
@@ -98,7 +101,7 @@ 
 
 class cmd_submit_results(SubmitResultAction):
 
-    def run(self, server, stream, result_disk="testrootfs"):
+    def run(self, server, stream, result_disk="testrootfs", token=None):
         """Submit test results to a lava-dashboard server
         :param server: URL of the lava-dashboard server RPC endpoint
         :param stream: Stream on the lava-dashboard server to save the result to
@@ -126,12 +129,12 @@ 
         if err_msg is None:
             err_msg = ''
 
-        self.submit_combine_bundles(status, err_msg, server, stream)
+        self.submit_combine_bundles(status, err_msg, server, stream, token)
         if status == 'fail':
             raise OperationFailed(err_msg)
 
 #util function, see if it needs to be part of utils.py
-def _get_dashboard(server):
+def _get_dashboard(server, token):
     if not server.endswith("/"):
         server = ''.join([server, "/"])
 
@@ -141,7 +144,23 @@ 
         server = ''.join([server, "xml-rpc/"])
         logging.warn("Please use whole endpoint URL not just end with 'dashboard/', 'xml-rpc/' is added automatically now!!!")
 
-    srv = xmlrpclib.ServerProxy(server, allow_none=True, use_datetime=True)
+    parsed_server = urlparse.urlparse(server)
+    auth_backend = MemoryAuthBackend([])
+    if parsed_server.username:
+        if token:
+            userless_server = '%s://%s%s' % (
+                parsed_server.scheme, parsed_server.hostname, parsed_server.path)
+            auth_backend = MemoryAuthBackend([(parsed_server.username, userless_server, token)])
+        else:
+            logging.warn(
+                "specifying a user without a token is unlikely to work")
+    else:
+        if token:
+            logging.warn(
+                "specifying a token without a user is probably useless")
+
+    srv = AuthenticatingServerProxy(
+        server, allow_none=True, use_datetime=True, auth_backend=auth_backend)
     if server.endswith("xml-rpc/"):
         logging.warn("Please use RPC2 endpoint instead, xml-rpc is deprecated!!!")
         dashboard = srv

=== modified file 'lava_dispatcher/connection.py'
--- lava_dispatcher/connection.py	2012-01-12 20:38:57 +0000
+++ lava_dispatcher/connection.py	2012-01-12 23:08:03 +0000
@@ -102,7 +102,7 @@ 
 class LavaConmuxConnection(LavaConnection):
 
     def _make_connection(self, sio):
-        cmd = "conmux-console %s" % self.device_option("hostname")
+        cmd = self.device_option("connection_command")
         proc = pexpect.spawn(cmd, timeout=1200, logfile=sio)
         #serial can be slow, races do funny things if you don't increase delay
         proc.delaybeforesend=1

=== modified file 'lava_dispatcher/default-config/lava-dispatcher/device-defaults.conf'
--- lava_dispatcher/default-config/lava-dispatcher/device-defaults.conf	2011-11-30 01:12:17 +0000
+++ lava_dispatcher/default-config/lava-dispatcher/device-defaults.conf	2012-01-09 03:16:32 +0000
@@ -12,6 +12,8 @@ 
 # 'qemu' is the other possible value at this time.
 client_type = master
 
+connection_command = conmux-console %(hostname)s
+
 # The bootloader commands to boot the device into the test image (we
 # assume that the device boots into the master image without bootloader
 # intervention).

=== modified file 'setup.py'
--- setup.py	2011-11-14 04:24:37 +0000
+++ setup.py	2012-01-09 03:08:37 +0000
@@ -22,6 +22,7 @@ 
         },
     install_requires=[
         "pexpect >= 2.3",
+        "lava-tool",
         "json-schema-validator",
     ],
     setup_requires=[