summaryrefslogtreecommitdiffstats
path: root/testing-scheduler/server/src/step
diff options
context:
space:
mode:
Diffstat (limited to 'testing-scheduler/server/src/step')
-rw-r--r--testing-scheduler/server/src/step/__init__.py8
-rw-r--r--testing-scheduler/server/src/step/general_test_step.py87
-rw-r--r--testing-scheduler/server/src/step/monitor.py57
-rw-r--r--testing-scheduler/server/src/step/step_manager.py41
-rw-r--r--testing-scheduler/server/src/step/test_step.py56
-rw-r--r--testing-scheduler/server/src/step/workload.py46
6 files changed, 0 insertions, 295 deletions
diff --git a/testing-scheduler/server/src/step/__init__.py b/testing-scheduler/server/src/step/__init__.py
deleted file mode 100644
index e8198009..00000000
--- a/testing-scheduler/server/src/step/__init__.py
+++ /dev/null
@@ -1,8 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
diff --git a/testing-scheduler/server/src/step/general_test_step.py b/testing-scheduler/server/src/step/general_test_step.py
deleted file mode 100644
index 2f9e8bcc..00000000
--- a/testing-scheduler/server/src/step/general_test_step.py
+++ /dev/null
@@ -1,87 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-from src.step.test_step import TestStep
-import os
-import yaml
-import re
-
-
-class GeneralTestStep(TestStep):
- __step_type__ = "test"
-
- def __init__(self, id, name, service, action, args, context):
- super(GeneralTestStep, self).__init__(
- self.__step_type__, id, name, service, action, args, context)
- self._stepParse()
- self.action()
-
- def _contextTransform(self, argsDict):
- for (k, v) in argsDict.items():
- if isinstance(v, str):
- if re.match('^\(\(context\..*\)\)', v):
- v = v[10:-2]
- layers = v.split(".")
- contextData = self._context
- for layer in layers:
- contextData = contextData[layer]
- argsDict[k] = contextData
- elif isinstance(v, dict):
- self._contextTransform(v)
-
- def _stepParse(self):
- self._args_temp = self._args
- self._args = {}
-
- # transform the service config
- envFilePath = os.path.join(
- self._getCurrentDir(), "..", "env",
- "service", self._serviceName + ".yaml")
- requestParam = {}
- with open(envFilePath, 'r') as f:
- conf = yaml.load(f)
- conf = conf[self._serviceName]
- for apiItem in conf["apis"]:
- if apiItem['name'] == self._serviceInterface:
- interfaceConf = apiItem
- if interfaceConf is None:
- return
-
- # transform the args config
- self._contextTransform(self._args_temp)
-
- interfaceUri = interfaceConf['baseuri'] + \
- interfaceConf['template']['uri'][11:]
- interfaceUri = "http://%s:%s/%s" % (
- conf['ip'], conf['port'], interfaceUri)
- requestParam['uri'] = self._uriTransform(interfaceUri)
-
- requestParam['method'] = interfaceConf['method']
- if requestParam["method"] == "POST":
- requestParam['body'] = interfaceConf['template']['body']
- self._paramTransform(requestParam['body'], self._args_temp)
- self._args['http_request'] = requestParam
-
- def _uriTransform(self, uri):
- return re.sub("\(\(.*?\)\)", self._uriResReplace, uri)
-
- def _uriResReplace(self, match):
- matchTrim = match.group()[2:-2]
- return self._args_temp[matchTrim]
-
- def _paramTransform(self, argsTemplate, argsDict):
- for (k, v) in argsTemplate.items():
- if isinstance(v, str):
- if re.match('^\(\(.*\)\)', v):
- argsTemplate[k] = argsDict[v[2:-2]]
- elif isinstance(v, dict):
- self._paramTransform(v, argsDict)
-
- def start(self):
- pass
diff --git a/testing-scheduler/server/src/step/monitor.py b/testing-scheduler/server/src/step/monitor.py
deleted file mode 100644
index 6deb9e2e..00000000
--- a/testing-scheduler/server/src/step/monitor.py
+++ /dev/null
@@ -1,57 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-import json
-import os
-from src.step.test_step import TestStep
-
-
-class MonitorStep(TestStep):
- __step_type__ = 'monitor'
-
- def __init__(self, name, service, action, args):
- super(MonitorStep, self).__init__(name, service, action, args)
- self._argsParse()
- self.action()
-
- def _argsParse(self):
- if self._call == "REST":
- currentDirPath = os.path.dirname(os.path.abspath(__file__))
- envDirPath = os.path.abspath(os.path.join(
- currentDirPath, os.pardir, os.pardir, 'env'))
- envFilePath = os.path.join(
- envDirPath, "%s.json" % self._service['name'])
- with open(envFilePath) as f:
- propDict = json.load(f)
- self._args['ip'] = propDict['ip']
- self._args['port'] = propDict['port']
- self._args['api'] = "%s/%s" % (
- propDict['api_map']['workload'], self._args['command'])
- exclude = {'ip', 'port', 'api', 'command', 'method'}
- self._args['req_body'] = {
- key: value for key, value in
- self._args.items() if key not in exclude}
-
- def setUp(self):
- print "monitor setUp"
-
- def uninstall(self):
- print "monitor uninstall"
-
- def start(self):
- print "monitor start...."
-
- def stop(self):
- print "monitor stop"
-
-
-if __name__ == "__main__":
- service = {"name": "ansible", "call": "REST"}
- monitor = MonitorStep(
- "monitor_cpu", service, "start", **{"target": "abc:qq"})
diff --git a/testing-scheduler/server/src/step/step_manager.py b/testing-scheduler/server/src/step/step_manager.py
deleted file mode 100644
index 8d76c67c..00000000
--- a/testing-scheduler/server/src/step/step_manager.py
+++ /dev/null
@@ -1,41 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-from src.step.test_step import TestStep
-import os
-import sys
-
-
-class TestStepManager(object):
- def __init__(self, context):
- self._context = context
-
- currentDirPath = os.path.dirname(os.path.abspath(__file__))
- sys.path.append(currentDirPath)
-
- excludeFiles = ('__init__.py', 'step_manager.py', 'test_step.py')
- for fileName in os.listdir(currentDirPath):
- if os.path.isfile(os.path.join(currentDirPath, fileName)) and \
- os.path.splitext(fileName)[1] == '.py' and \
- fileName not in excludeFiles:
- __import__(os.path.splitext(fileName)[0])
-
- def getStepObj(self, type, id, name, service, action, args):
- for subclass in TestStep.__subclasses__():
- if type == subclass.__step_type__:
- return subclass(id, name, service, action, args, self._context)
-
-
-if __name__ == "__main__":
- tsMgr = TestStepManager()
- args = {'command': 'greet', 'method': 'POST', 'args': {'name': 'leo'}}
- stepObj = tsMgr.getStepObj('test', 1, 'test_cpu', {
- 'name': 'greet', 'call': 'REST'}, 'start', args)
- print stepObj
- print stepObj.__class__.__mro__
diff --git a/testing-scheduler/server/src/step/test_step.py b/testing-scheduler/server/src/step/test_step.py
deleted file mode 100644
index 363c4800..00000000
--- a/testing-scheduler/server/src/step/test_step.py
+++ /dev/null
@@ -1,56 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-import os
-
-
-class TestStep(object):
- def __init__(self, type, id, name, service, action, args, context):
- self._type = type
- self._id = id
- self._name = name
- self._serviceName = service['name']
- self._serviceInterface = service['interface']
- self._action = action
- self._args = args
- self._context = context
-
- def getId(self):
- return self._id
-
- def getName(self):
- return self._name
-
- def getServiceName(self):
- return self._serviceName
-
- def getCallFunction(self):
- return self._callType
-
- def getArgs(self):
- return self._args
-
- def action(self):
- f = getattr(self, self._action)
- f()
-
- def _argsParse(self):
- pass
-
- def _getCurrentDir(self):
- return os.path.dirname(__file__)
-
- def __str__(self):
- return str(self.__dict__)
-
-
-if __name__ == "__main__":
- args = {'command': 'start'}
- stepObj = TestStep('test_cpu', 'ansible', 'REST', **args)
- print stepObj
diff --git a/testing-scheduler/server/src/step/workload.py b/testing-scheduler/server/src/step/workload.py
deleted file mode 100644
index 265b9a6b..00000000
--- a/testing-scheduler/server/src/step/workload.py
+++ /dev/null
@@ -1,46 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-import json
-import os
-from src.step.test_step import TestStep
-
-
-class WorkloadStep(TestStep):
- __step_type__ = 'workload'
-
- def __init__(self, id, name, service, action, args):
- super(WorkloadStep, self).__init__(
- self.__step_type__, id, name, service, action, args)
- self._argsParse()
- self._action()
-
- def _argsParse(self):
- if self._callType == "REST":
- currentDirPath = os.path.dirname(os.path.abspath(__file__))
- envDirPath = os.path.abspath(
- os.path.join(currentDirPath, os.pardir, os.pardir, 'env'))
- envFilePath = os.path.join(
- envDirPath, "%s.json" % self._service['name'])
- with open(envFilePath) as f:
- propDict = json.load(f)
- self._args['ip'] = propDict['ip']
- self._args['port'] = propDict['port']
- self._args['api'] = "%s/%s" % (
- propDict['api_map']['workload'], self._args['command'])
- exclude = {'ip', 'port', 'api', 'command', 'method'}
- self._args['req_body'] = {
- key: value for key, value in
- self._args.items() if key not in exclude}
-
- def _start(self):
- print "workload start"
-
- def _stop(self):
- print "workload stop"