Merge "Add test-scheduler dir to verity"
[bottlenecks.git] / test-scheduler / server / src / step / workload.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 import json
11 import os
12 from src.step.test_step import TestStep
13
14
15 class WorkloadStep(TestStep):
16     __step_type__ = 'workload'
17
18     def __init__(self, id, name, service, action, args):
19         super(WorkloadStep, self).__init__(
20             self.__step_type__, id, name, service, action, args)
21         self._argsParse()
22         self._action()
23
24     def _argsParse(self):
25         if self._callType == "REST":
26             currentDirPath = os.path.dirname(os.path.abspath(__file__))
27             envDirPath = os.path.abspath(
28                 os.path.join(currentDirPath, os.pardir, os.pardir, 'env'))
29             envFilePath = os.path.join(
30                 envDirPath, "%s.json" % self._service['name'])
31             with open(envFilePath) as f:
32                 propDict = json.load(f)
33                 self._args['ip'] = propDict['ip']
34                 self._args['port'] = propDict['port']
35                 self._args['api'] = "%s/%s" % (
36                     propDict['api_map']['workload'], self._args['command'])
37                 exclude = {'ip', 'port', 'api', 'command', 'method'}
38                 self._args['req_body'] = {
39                     key: value for key, value in
40                     self._args.items() if key not in exclude}
41
42     def _start(self):
43         print "workload start"
44
45     def _stop(self):
46         print "workload stop"