summaryrefslogtreecommitdiffstats
path: root/testing-scheduler/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'testing-scheduler/server/src')
-rw-r--r--testing-scheduler/server/src/__init__.py8
-rw-r--r--testing-scheduler/server/src/env/context/context.yaml75
-rw-r--r--testing-scheduler/server/src/env/service/ansible.yaml65
-rw-r--r--testing-scheduler/server/src/env/service/greet.yaml68
-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
-rw-r--r--testing-scheduler/server/src/test_parser.py315
11 files changed, 826 insertions, 0 deletions
diff --git a/testing-scheduler/server/src/__init__.py b/testing-scheduler/server/src/__init__.py
new file mode 100644
index 0000000..e819800
--- /dev/null
+++ b/testing-scheduler/server/src/__init__.py
@@ -0,0 +1,8 @@
+##############################################################################
+# 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/env/context/context.yaml b/testing-scheduler/server/src/env/context/context.yaml
new file mode 100644
index 0000000..58ed461
--- /dev/null
+++ b/testing-scheduler/server/src/env/context/context.yaml
@@ -0,0 +1,75 @@
+##############################################################################
+# 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
+##############################################################################
+
+---
+
+hosts:
+ node26:
+ name: node26
+ ip: 192.168.1.26
+ port: 22
+ user: root
+ password: 123456
+
+ node27:
+ name: node27
+ ip: 192.168.1.27
+ port: 22
+ user: root
+ password: 123456
+
+ node28:
+ name: node28
+ ip: 192.168.1.28
+ port: 22
+ user: root
+ password: 123456
+
+ node29:
+ name: node29
+ ip: 192.168.1.29
+ port: 22
+ user: root
+ password: 123456
+
+ node30:
+ name: node30
+ ip: 192.168.1.30
+ port: 22
+ user: root
+ password: 123456
+
+ node31:
+ name: node31
+ ip: 192.168.1.31
+ port: 22
+ user: root
+ password: 123456
+
+ node32:
+ name: node32
+ ip: 192.168.1.32
+ port: 22
+ user: root
+ password: 123456
+
+
+cassandra:
+ name: node24
+ ip: 192.168.1.24
+ port: 22
+ user: root
+ password: 123456
+
+sprout:
+ name: node32
+ ip: 192.168.1.32
+ port: 22
+ user: root
+ password: 123456 \ No newline at end of file
diff --git a/testing-scheduler/server/src/env/service/ansible.yaml b/testing-scheduler/server/src/env/service/ansible.yaml
new file mode 100644
index 0000000..7b97602
--- /dev/null
+++ b/testing-scheduler/server/src/env/service/ansible.yaml
@@ -0,0 +1,65 @@
+##############################################################################
+# 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
+##############################################################################
+
+---
+
+ansible:
+ apis:
+ - method: POST
+ name: faultload
+ params:
+ - description: call user count
+ name: call_user
+ - description: workload time
+ name: duration
+ - description: faultload time
+ name: fault_duration
+ - description: register speed
+ name: initial_reg_rate
+ - description: multiplier
+ name: multiplier
+ - description: register user count
+ name: reg_user
+ baseuri: faultload
+ template:
+ uri: ((baseuri))
+ body:
+ call_user: ((call_user))
+ duration: ((duration))
+ fault_duration: ((fault_duration))
+ initial_reg_rate: ((initial_reg_rate))
+ multiplier: ((multiplier))
+ reg_user: ((reg_user))
+
+ - method: POST
+ name: workload
+ params:
+ - description: call user count
+ name: call_user
+ - description: workload time
+ name: duration
+ - description: register speed
+ name: initial_reg_rate
+ - description: multiplier
+ name: multiplier
+ - description: register user count
+ name: reg_user
+ baseuri: workload
+ template:
+ uri: ((baseuri))
+ body:
+ call_user: ((call_user))
+ duration: ((duration))
+ fault_duration: ((fault_duration))
+ initial_reg_rate: ((initial_reg_rate))
+ multiplier: ((multiplier))
+ reg_user: ((reg_user))
+
+ ip: 100.64.227.222
+ port: 9006
diff --git a/testing-scheduler/server/src/env/service/greet.yaml b/testing-scheduler/server/src/env/service/greet.yaml
new file mode 100644
index 0000000..1b21f41
--- /dev/null
+++ b/testing-scheduler/server/src/env/service/greet.yaml
@@ -0,0 +1,68 @@
+##############################################################################
+# 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
+##############################################################################
+
+---
+
+greet:
+ ip: t-scheduler-server
+ port: 5312
+ apis:
+ -
+ name: greet
+ method: GET
+ baseuri: greet
+ params:
+ - name: name
+ description: user name
+ template:
+ uri: ((baseuri))?name=((name))
+ response:
+ result: int
+ next:
+ aa: str
+ bb: int
+ -
+ name: answer
+ method: POST
+ baseuri: answer
+ params:
+ - name: ping
+ description: param ping
+ template:
+ uri: ((baseuri))
+ body:
+ ping: ((ping))
+
+ -
+ name: ten
+ method: GET
+ baseuri: ten
+ template:
+ uri: ((baseuri))
+
+
+ -
+ name: switch
+ method: GET
+ baseuri: switch
+ template:
+ uri: ((baseuri))
+ return:
+ -
+ result
+
+ -
+ name: switch_2
+ method: GET
+ baseuri: switch_2
+ template:
+ uri: ((baseuri))
+ return:
+ -
+ result
diff --git a/testing-scheduler/server/src/step/__init__.py b/testing-scheduler/server/src/step/__init__.py
new file mode 100644
index 0000000..e819800
--- /dev/null
+++ b/testing-scheduler/server/src/step/__init__.py
@@ -0,0 +1,8 @@
+##############################################################################
+# 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
new file mode 100644
index 0000000..2f9e8bc
--- /dev/null
+++ b/testing-scheduler/server/src/step/general_test_step.py
@@ -0,0 +1,87 @@
+##############################################################################
+# 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
new file mode 100644
index 0000000..6deb9e2
--- /dev/null
+++ b/testing-scheduler/server/src/step/monitor.py
@@ -0,0 +1,57 @@
+##############################################################################
+# 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
new file mode 100644
index 0000000..8d76c67
--- /dev/null
+++ b/testing-scheduler/server/src/step/step_manager.py
@@ -0,0 +1,41 @@
+##############################################################################
+# 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
new file mode 100644
index 0000000..363c480
--- /dev/null
+++ b/testing-scheduler/server/src/step/test_step.py
@@ -0,0 +1,56 @@
+##############################################################################
+# 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
new file mode 100644
index 0000000..265b9a6
--- /dev/null
+++ b/testing-scheduler/server/src/step/workload.py
@@ -0,0 +1,46 @@
+##############################################################################
+# 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"
diff --git a/testing-scheduler/server/src/test_parser.py b/testing-scheduler/server/src/test_parser.py
new file mode 100644
index 0000000..7b47151
--- /dev/null
+++ b/testing-scheduler/server/src/test_parser.py
@@ -0,0 +1,315 @@
+#!/usr/bin/env python
+
+##############################################################################
+# 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 click
+import os
+import yaml
+import json
+import collections
+from src.step.step_manager import TestStepManager
+from src.conductor_processor.workflow import WorkflowFile
+from conductorclient.run_new_workflow import WorkflowMgr
+
+BASE_DIR = os.path.dirname(os.path.abspath(__file__))
+CONDUCTOR_SERVER_ADDR = "http://conductor_conductor-server_1:8080"
+STORE_TASK_PATH = "/tmp/generate_task.json"
+STORE_WF_PATH = "/tmp/generate_workflow.json"
+
+
+@click.command()
+@click.option("--filepath", help="file path of test case")
+def cmdParse(filepath):
+ parse(filepath)
+
+
+def parse(filepath):
+ filePrefix, fileName = os.path.split(filepath)
+ print '------------ start to parse the test case:' + \
+ '%s ----------------' % fileName
+ with open(filepath) as f:
+ yaml_file = yaml.load(f)
+ parseTestcase(yaml_file['schema'], fileName)
+
+ workflowId = runWorkFlow()
+ print '------------------- parse executes end -------------------------'
+
+ return workflowId
+
+
+def parseTestcase(schema, tcName='testcase0'):
+ if schema is None:
+ return parseLog(False, reason='schema not found.')
+ steps = schema['steps']
+ if steps is None:
+ return parseLog(False, reason='steps is invalid.')
+ flows = schema['flows']
+ if flows is None:
+ return parseLog(False, reasion='flows is invalid.')
+ # steps is a list, step is dict. no json here.
+ # steps = sorted(steps, sortById)
+
+ # load context
+ contextDict = {}
+ contextDir = os.path.join(BASE_DIR, "env", "context", "context.yaml")
+ with open(contextDir, "r") as f:
+ contextDict = yaml.load(f)
+ #
+ testStepMgr = TestStepManager(contextDict)
+
+ stepObjArr = []
+ for step in steps:
+ if 'args' not in step:
+ step['args'] = {}
+ # type and action can be extended, default couple is 'test' & 'start'.
+ if 'type' not in step:
+ step['type'] = 'test'
+ step['action'] = 'start'
+
+ stepObj = testStepMgr.getStepObj(
+ step['type'], step['id'], step['name'], step['service'],
+ step['action'], step['args'])
+ stepObjArr.append(stepObj)
+
+ # generate workflow by 'flow' and 'step'
+ tcName = os.path.splitext(tcName)[0]
+ wfFileObj = WorkflowFile(tcName)
+ workflowDict, taskMetaList = wfFileObj.generateMetaData(flows, stepObjArr)
+
+ with open(STORE_TASK_PATH, 'w') as f:
+ f.write(json.dumps({'task_group': taskMetaList}, indent=True))
+ with open(STORE_WF_PATH, 'w') as f:
+ f.write(json.dumps(workflowDict, indent=True))
+
+
+def parseWebTestcase(webTestcase):
+ print 'parseWebTestcase----------------------------'
+
+ stepList = webTestcase['stepList']
+ mainOrdersList = webTestcase['mainOrdersList']
+ subflowList = webTestcase['subflowList']
+
+ parseData = collections.OrderedDict()
+ parseData['schema'] = collections.OrderedDict()
+ parseData['schema']['steps'] = []
+ parseData['schema']['flows'] = []
+
+ parseStepList = parseData['schema']['steps']
+ parseFlowList = parseData['schema']['flows']
+ stepIndexDict = {}
+ # parse stepList
+ for index in range(len(stepList)):
+ stepItem = stepList[index]
+ parseStep = collections.OrderedDict()
+
+ parseStep['id'] = index + 1
+ parseStep['name'] = stepItem['name']
+ parseStep['service'] = collections.OrderedDict()
+ parseStep['service']['name'] = stepItem['service']
+ parseStep['service']['interface'] = stepItem['action']
+ parseStep['action'] = 'start'
+ parseStep['args'] = {}
+ for paramItem in stepItem['params']:
+ parseStep['args'][paramItem['key']] = transParamString(
+ paramItem['value'])
+
+ parseStepList.append(parseStep)
+ stepIndexDict[parseStep['name']] = parseStep['id']
+ # parse flows
+ # parse mainflow
+ print stepIndexDict
+ typeDict = {1: 'normal', 2: 'switch', 3: 'parallel'}
+ mainFlow = collections.OrderedDict()
+ mainFlow['name'] = 'main'
+ mainFlow['orders'] = []
+ mainFlow['orders'] = parseOrderList(
+ mainOrdersList, stepIndexDict, typeDict)
+ parseFlowList.append(mainFlow)
+
+ # parse subflow
+ for subflowItem in subflowList:
+ replaceSubflow = collections.OrderedDict()
+ replaceSubflow['name'] = subflowItem['name']
+ replaceSubflow['orders'] = parseOrderList(
+ subflowItem['orderList'], stepIndexDict, typeDict)
+ parseFlowList.append(replaceSubflow)
+
+ print 'END parseWebTestcase----------------------------'
+ return parseData
+
+
+# parse orderlist from web edition to server edition
+def parseOrderList(orderList, stepIndexDict, typeDict):
+ replaceList = []
+ for orderItem in orderList:
+ replaceOrder = collections.OrderedDict()
+ orderType = typeDict[orderItem['type']]
+ replaceOrder['type'] = orderType
+ if orderType == 'normal':
+ stepId = stepIndexDict[orderItem['step']]
+ replaceOrder['step'] = stepId
+ elif orderType == 'switch':
+ replaceOrder['value'] = orderItem['value']
+ replaceOrder['cases'] = collections.OrderedDict()
+ for caseItem in orderItem['cases']:
+ caseValue = caseItem['value']
+ caseOrderType = caseItem['orderType']
+ caseOrderValue = caseItem['orderValue']
+ if caseOrderType == "step":
+ orderInCase = collections.OrderedDict()
+ orderInCase['type'] = 'normal'
+ orderInCase['step'] = stepIndexDict[caseOrderValue]
+ replaceOrder['cases'][caseValue] = [orderInCase]
+ else:
+ replaceOrder['cases'][caseValue] = caseOrderValue
+ else:
+ replaceOrder['parallel'] = collections.OrderedDict()
+ pIndex = 1
+ for branchItem in orderItem['branches']:
+ pKey = 'p' + str(pIndex)
+ branchOrderType = branchItem['orderType']
+ branchOrderValue = branchItem['orderValue']
+ if branchOrderType == "step":
+ replaceBranchItem = collections.OrderedDict()
+ replaceBranchItem['type'] = 'normal'
+ replaceBranchItem['step'] = stepIndexDict[branchOrderValue]
+ replaceOrder['parallel'][pKey] = [replaceBranchItem]
+ else:
+ replaceOrder['parallel'][pKey] = branchOrderValue
+ pIndex += 1
+ replaceList.append(replaceOrder)
+ return replaceList
+
+
+def transParamString(val):
+ if type(val) != str:
+ return val
+ if '.' not in val:
+ if val.isdigit():
+ return int(val)
+ try:
+ f = float(val)
+ return f
+ except ValueError:
+ return val
+
+
+def getWebTestcase(originTcDict):
+ print "getWebTestcase----------------------------------"
+ webTcDict = {
+ "stepList": [],
+ "mainOrdersList": [],
+ "subflowList": []
+ }
+ stepList = webTcDict['stepList']
+ subflowList = webTcDict['subflowList']
+ if originTcDict is None:
+ return webTcDict
+ originContent = originTcDict['schema']
+ originSteps = originContent['steps']
+ stepIndexDict = {}
+ # transform steps to stepList
+ for stepItem in originSteps:
+ replaceStep = {}
+ replaceStep['name'] = stepItem['name']
+ replaceStep['service'] = stepItem['service']['name']
+ replaceStep['action'] = stepItem['service']['interface']
+ replaceStep['params'] = []
+ if 'args' in stepItem:
+ for (key, value) in stepItem['args'].items():
+ replaceParam = {}
+ replaceParam['key'] = key
+ replaceParam['value'] = value
+ replaceStep['params'].append(replaceParam)
+ stepList.append(replaceStep)
+ stepIndexDict[stepItem['id']] = stepItem['name']
+
+ # transform main flow
+ originFlows = originContent['flows']
+ originMainflow = {}
+ for flowIndex in range(len(originFlows)):
+ flowItem = originFlows[flowIndex]
+ if flowItem['name'] == 'main':
+ originMainflow = flowItem
+ originFlows.pop(flowIndex)
+ break
+ typeDict = {'normal': 1, 'switch': 2, 'parallel': 3}
+ webTcDict['mainOrdersList'] = getOrderList(
+ originMainflow['orders'], stepIndexDict, typeDict)
+
+ # transform subflows
+ for originSubflow in originFlows:
+ replaceSubflow = {}
+ replaceSubflow['name'] = originSubflow['name']
+ replaceSubflow['orderList'] = getOrderList(
+ originSubflow['orders'], stepIndexDict, typeDict)
+ subflowList.append(replaceSubflow)
+
+ # return web edition of testcase
+ print "END getWebTestcase----------------------------------"
+ return webTcDict
+
+
+def getOrderList(originOrderList, stepIndexDict, typeDict):
+ replaceOrderList = []
+ for orderItem in originOrderList:
+ replaceOrderItem = {}
+ orderType = orderItem['type']
+ replaceOrderItem['type'] = typeDict[orderType]
+ if orderType == 'normal':
+ stepName = stepIndexDict[orderItem['step']]
+ replaceOrderItem['step'] = stepName
+ elif orderType == 'switch':
+ replaceOrderItem['value'] = orderItem['value']
+ replaceOrderItem['cases'] = []
+ for (caseValue, ordersInCase) in orderItem['cases'].items():
+ replaceCase = {}
+ replaceCase['value'] = caseValue
+ if type(ordersInCase) == list:
+ replaceCase['orderType'] = 'step'
+ caseStepName = stepIndexDict[ordersInCase[0]['step']]
+ replaceCase['orderValue'] = caseStepName
+ else:
+ replaceCase['orderType'] = 'flow'
+ replaceCase['orderValue'] = ordersInCase
+ replaceOrderItem['cases'].append(replaceCase)
+ else:
+ replaceOrderItem['branches'] = []
+ for paraIndex in orderItem['parallel']:
+ paraItem = orderItem['parallel'][paraIndex]
+ replaceBranch = {}
+ if type(paraItem) == list:
+ replaceBranch['orderType'] = 'step'
+ branchStepName = stepIndexDict[paraItem[0]['step']]
+ replaceBranch['orderValue'] = branchStepName
+ else:
+ replaceBranch['orderType'] = 'flow'
+ replaceBranch['orderValue'] = paraItem
+ replaceOrderItem['branches'].append(replaceBranch)
+ replaceOrderList.append(replaceOrderItem)
+
+ return replaceOrderList
+
+
+def runWorkFlow():
+ wfMgr = WorkflowMgr(CONDUCTOR_SERVER_ADDR)
+ wfMgr.setTaskDefFromFile(STORE_TASK_PATH)
+ wfMgr.setWorkflowFromFile(STORE_WF_PATH)
+ inputParam = {'input': 'fake'}
+ workflowId = wfMgr.startWorkflow(inputParam)
+ return workflowId
+
+
+def parseLog(flag, **msg):
+ return {'result': flag, 'message': msg}
+
+
+if __name__ == "__main__":
+ cmdParse()