Dave Pigott has proposed merging lp:~dpigott/lava-scheduler-tool/fix821400-add-token-file into lp:lava-scheduler-tool.
Requested reviews: Linaro Validation Team (linaro-validation) Related bugs: Bug #821400 in LAVA Scheduler Tool: "add --token-file to submit-job" https://bugs.launchpad.net/lava-scheduler-tool/+bug/821400 For more details, see: https://code.launchpad.net/~dpigott/lava-scheduler-tool/fix821400-add-token-file/+merge/74197 Added code to support --token-file to the submit-job command. In the process realised that cancel-job requires the same functionality and that there is now code duplication between auth-add and submit-job. Will open that work as a separate bug. -- https://code.launchpad.net/~dpigott/lava-scheduler-tool/fix821400-add-token-file/+merge/74197 Your team Linaro Validation Team is requested to review the proposed merge of lp:~dpigott/lava-scheduler-tool/fix821400-add-token-file into lp:lava-scheduler-tool.
=== modified file 'lava_scheduler_tool/commands.py' --- lava_scheduler_tool/commands.py 2011-08-19 04:32:11 +0000 +++ lava_scheduler_tool/commands.py 2011-09-06 10:45:24 +0000 @@ -16,11 +16,27 @@ # You should have received a copy of the GNU Lesser General Public License # along with lava-scheduler-tool. If not, see <http://www.gnu.org/licenses/>. +import getpass +import urlparse +import xmlrpclib -from lava_tool.authtoken import AuthenticatingServerProxy, KeyringAuthBackend -from lava_tool.interface import Command +from lava_tool.authtoken import ( + AuthenticatingServerProxy, + KeyringAuthBackend, + MemoryAuthBackend, + ) +from lava_tool.interface import Command, LavaCommandError from lava_tool.commands import ExperimentalCommandMixIn +def normalize_xmlrpc_url(uri): + if '://' not in uri: + uri = 'http://' + uri + if not uri.endswith('/'): + uri += '/' + if not uri.endswith('/RPC2/'): + uri += 'RPC2/' + return uri + class submit_job(ExperimentalCommandMixIn, Command): """ @@ -32,11 +48,51 @@ super(submit_job, cls).register_arguments(parser) parser.add_argument("SERVER") parser.add_argument("JSON_FILE") + parser.add_argument( + "--token-file", default=None, + help="Read the password from a file rather than prompting for it.") def invoke(self): + uri = normalize_xmlrpc_url(self.args.SERVER) + parsed_host = urlparse.urlparse(uri) + + if parsed_host.username: + username = parsed_host.username + else: + username = getpass.getuser() + + host = parsed_host.hostname + if parsed_host.port: + host += ':' + str(parsed_host.port) + + if self.args.token_file: + if parsed_host.password: + raise LavaCommandError( + "Token specified in url but --token-file also passed."); + else: + try: + token_file = open(self.args.token_file) + except IOError as ex: + raise LavaCommandError( + "opening %r failed: %s" % (self.args.token_file, ex)) + token = token_file.read().strip() + else: + if parsed_host.password: + token = parsed_host.password + else: + token = getpass.getpass("Paste token for %s: " % uri) + + userless_uri = '%s://%s%s' % ( + parsed_host.scheme, host, parsed_host.path) + self.print_experimental_notice() + server = AuthenticatingServerProxy( - self.args.SERVER, auth_backend=KeyringAuthBackend()) + uri, auth_backend = MemoryAuthBackend( + [(username, userless_uri, token)])) +# server = AuthenticatingServerProxy( +# self.args.SERVER, auth_backend=KeyringAuthBackend()) + with open(self.args.JSON_FILE, 'rb') as stream: command_text = stream.read() print "submitted as job id:", server.scheduler.submit_job(command_text)
_______________________________________________ Mailing list: https://launchpad.net/~linaro-release Post to : [email protected] Unsubscribe : https://launchpad.net/~linaro-release More help : https://help.launchpad.net/ListHelp

