Merge "Add test-scheduler dir to verity"
[bottlenecks.git] / test-scheduler / server / src / step / monitor.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 MonitorStep(TestStep):
16     __step_type__ = 'monitor'
17
18     def __init__(self, name, service, action, args):
19         super(MonitorStep, self).__init__(name, service, action, args)
20         self._argsParse()
21         self.action()
22
23     def _argsParse(self):
24         if self._call == "REST":
25             currentDirPath = os.path.dirname(os.path.abspath(__file__))
26             envDirPath = os.path.abspath(os.path.join(
27                 currentDirPath, os.pardir, os.pardir, 'env'))
28             envFilePath = os.path.join(
29                 envDirPath, "%s.json" % self._service['name'])
30             with open(envFilePath) as f:
31                 propDict = json.load(f)
32                 self._args['ip'] = propDict['ip']
33                 self._args['port'] = propDict['port']
34                 self._args['api'] = "%s/%s" % (
35                     propDict['api_map']['workload'], self._args['command'])
36                 exclude = {'ip', 'port', 'api', 'command', 'method'}
37                 self._args['req_body'] = {
38                     key: value for key, value in
39                     self._args.items() if key not in exclude}
40
41     def setUp(self):
42         print "monitor setUp"
43
44     def uninstall(self):
45         print "monitor uninstall"
46
47     def start(self):
48         print "monitor start...."
49
50     def stop(self):
51         print "monitor stop"
52
53
54 if __name__ == "__main__":
55     service = {"name": "ansible", "call": "REST"}
56     monitor = MonitorStep(
57         "monitor_cpu", service, "start", **{"target": "abc:qq"})