Created
November 5, 2014 17:43
-
-
Save hh/2085e5c88a4ab0278451 to your computer and use it in GitHub Desktop.
Load impact scenario download/upload/validate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/env python2.7 | |
| import sys | |
| import loadimpact | |
| import json | |
| from loadimpact import LoadZone | |
| from loadimpact import UserScenarioValidation | |
| client = loadimpact.ApiTokenClient() | |
| def usage(): | |
| print "\nUSAGE: ", sys.argv[0], ' download SCENARIO_ID SCENARIO_FILE.lua' | |
| print " ", sys.argv[0], ' validate SCENARIO_ID SCENARIO_FILE.lua' | |
| if len(sys.argv) < 2: | |
| for scenario in client.list_user_scenarios(): | |
| print scenario.id, scenario.name | |
| usage() | |
| exit(0) | |
| if sys.argv[1] == 'download': | |
| text=client.get_user_scenario(sys.argv[2]).load_script | |
| f=open(sys.argv[3],'w') | |
| f.write(text) | |
| f.close() | |
| print "Scenario " + sys.argv[2] + " written to " + sys.argv[3] | |
| elif sys.argv[1] == 'validate': | |
| user_scenario=client.get_user_scenario(sys.argv[2]) | |
| luacode=open(sys.argv[3]).read() | |
| user_scenario.load_script=luacode | |
| user_scenario.update() | |
| print sys.argv[3] + "uploaded as scenario " + sys.argv[2] | |
| # Validation starting | |
| validation = user_scenario.validate() | |
| stream = validation.result_stream() | |
| print("Starting validation #%d..." % (validation.id,)) | |
| for result in stream: | |
| if 'stack_trace' in result: | |
| print('[%s]: %s @ line %s' | |
| % (result['timestamp'], result['message'], | |
| result['line_number'])) | |
| print('Stack trace:') | |
| for filename, line, function in result['stack_trace']: | |
| print('\t%s:%s in %s' % (function, line, filename)) | |
| else: | |
| print('[%s]: %s' % (result['timestamp'], result['message'])) | |
| print("Validation completed with status '%s'" | |
| % (UserScenarioValidation.status_code_to_text(validation.status))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment