Create API to run test cases
[yardstick.git] / api / utils / common.py
1 import collections
2
3 from api.utils.daemonthread import DaemonThread
4 from yardstick.cmd.cli import YardstickCLI
5
6
7 def translate_to_str(object):
8     if isinstance(object, collections.Mapping):
9         return {str(k): translate_to_str(v) for k, v in object.items()}
10     elif isinstance(object, list):
11         return [translate_to_str(ele) for ele in object]
12     elif isinstance(object, unicode):
13         return str(object)
14     return object
15
16
17 def get_command_list(command_list, opts, args):
18
19     command_list.append(args)
20
21     command_list.extend(('--{}'.format(k) for k in opts if 'task-args' != k))
22
23     task_args = opts.get('task_args', '')
24     if task_args:
25         command_list.extend(['--task-args', task_args])
26
27     return command_list
28
29
30 def exec_command_task(command_list, task_id):   # pragma: no cover
31     daemonthread = DaemonThread(YardstickCLI().api, (command_list, task_id))
32     daemonthread.start()
33
34
35 class Url(object):
36
37     def __init__(self, url, resource, endpoint):
38         super(Url, self).__init__()
39         self.url = url
40         self.resource = resource
41         self.endpoint = endpoint