2 # Copyright (c) 2015 Orange
3 # guyrodrigue.koffi@orange.com
4 # morgan.richomme@orange.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
11 import re, json, os, sys
13 def get_task_id(cmd_raw):
15 get task id from command rally result
17 :return: task_id as string
19 taskid_re = re.compile('^Task +(.*): started$')
20 for line in cmd_raw.splitlines(True):
22 match = taskid_re.match(line)
27 def task_succeed(json_raw):
29 Parse JSON from rally JSON results
33 rally_report = json.loads(json_raw)
34 rally_report = rally_report[0]
35 if rally_report is None:
37 if rally_report.get('result') is None:
40 for result in rally_report.get('result'):
41 if len(result.get('error')) > 0:
47 def run_task(test_name):
49 the "main" function of the script who lunch rally for a task
50 :param test_name: name for the rally test
55 cmd = os.popen("date '+%d%m%Y_%H%M'")
56 test_date = cmd.read().rstrip()
58 """ directory for test scenarios files"""
59 test_dir = '/home/ubuntu/rally/samples/tasks/scenarios/opnfv'
60 test_file_name = "/home/ubuntu/rally/samples/tasks/scenarios/opnfv/opnfv-%s.json" % test_name
63 cmd = os.popen("rally task start --abort-on-sla-failure %s" % test_file_name)
64 task_id = get_task_id(cmd.read())
67 print "./run_rally : failed to retrieve task_id"
70 report_file_name = "/home/ubuntu/rally/opnfv-%s-%s.html" % (test_name, test_date)
72 os.popen("rally task report %s --out %s" % (task_id, report_file_name))
73 cmd = os.popen("rally task results %s" % task_id)
74 if task_succeed(cmd.read()):
81 """ configure script """
82 tests = ('authenticate','glance','heat','keystone','neutron','nova','tempest','vm', 'all',)
85 if len(sys.argv) != 2:
86 print "./run_rally [", tests, "]"
88 test_name = sys.argv[1]
90 if not (test_name in tests):
91 print "argument not valid"
94 if test_name == "all":
95 #run test for all tests
101 if __name__ == '__main__':