Change naming and veriy test-scheduler function
[bottlenecks.git] / test-scheduler / server / src / step / step_manager.py
1 ##############################################################################
2 # Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 from src.step.test_step import TestStep
11 import os
12 import sys
13
14
15 class TestStepManager(object):
16     def __init__(self, context):
17         self._context = context
18
19         currentDirPath = os.path.dirname(os.path.abspath(__file__))
20         sys.path.append(currentDirPath)
21
22         excludeFiles = ('__init__.py', 'step_manager.py', 'test_step.py')
23         for fileName in os.listdir(currentDirPath):
24             if os.path.isfile(os.path.join(currentDirPath, fileName)) and \
25                 os.path.splitext(fileName)[1] == '.py' and \
26                     fileName not in excludeFiles:
27                 __import__(os.path.splitext(fileName)[0])
28
29     def getStepObj(self, type, id, name, service, action, args):
30         for subclass in TestStep.__subclasses__():
31             if type == subclass.__step_type__:
32                 return subclass(id, name, service, action, args, self._context)
33
34
35 if __name__ == "__main__":
36     tsMgr = TestStepManager()
37     args = {'command': 'greet', 'method': 'POST', 'args': {'name': 'leo'}}
38     stepObj = tsMgr.getStepObj('test', 1, 'test_cpu', {
39         'name': 'greet', 'call': 'REST'}, 'start', args)
40     print stepObj
41     print stepObj.__class__.__mro__