parser script and step class in backend code of testing-scheduler
[bottlenecks.git] / testing-scheduler / server / src / step / step_manager.py
diff --git a/testing-scheduler/server/src/step/step_manager.py b/testing-scheduler/server/src/step/step_manager.py
new file mode 100644 (file)
index 0000000..8d76c67
--- /dev/null
@@ -0,0 +1,41 @@
+##############################################################################\r
+# Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.\r
+#\r
+# All rights reserved. This program and the accompanying materials\r
+# are made available under the terms of the Apache License, Version 2.0\r
+# which accompanies this distribution, and is available at\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+##############################################################################\r
+\r
+from src.step.test_step import TestStep\r
+import os\r
+import sys\r
+\r
+\r
+class TestStepManager(object):\r
+    def __init__(self, context):\r
+        self._context = context\r
+\r
+        currentDirPath = os.path.dirname(os.path.abspath(__file__))\r
+        sys.path.append(currentDirPath)\r
+\r
+        excludeFiles = ('__init__.py', 'step_manager.py', 'test_step.py')\r
+        for fileName in os.listdir(currentDirPath):\r
+            if os.path.isfile(os.path.join(currentDirPath, fileName)) and \\r
+                os.path.splitext(fileName)[1] == '.py' and \\r
+                    fileName not in excludeFiles:\r
+                __import__(os.path.splitext(fileName)[0])\r
+\r
+    def getStepObj(self, type, id, name, service, action, args):\r
+        for subclass in TestStep.__subclasses__():\r
+            if type == subclass.__step_type__:\r
+                return subclass(id, name, service, action, args, self._context)\r
+\r
+\r
+if __name__ == "__main__":\r
+    tsMgr = TestStepManager()\r
+    args = {'command': 'greet', 'method': 'POST', 'args': {'name': 'leo'}}\r
+    stepObj = tsMgr.getStepObj('test', 1, 'test_cpu', {\r
+        'name': 'greet', 'call': 'REST'}, 'start', args)\r
+    print stepObj\r
+    print stepObj.__class__.__mro__\r