6deb9e2ef61a305fdd860cc406c2d34ca1527139
[bottlenecks.git] / testing-scheduler / server / src / step / monitor.py
1 ##############################################################################\r
2 # Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.\r
3 #\r
4 # All rights reserved. This program and the accompanying materials\r
5 # are made available under the terms of the Apache License, Version 2.0\r
6 # which accompanies this distribution, and is available at\r
7 # http://www.apache.org/licenses/LICENSE-2.0\r
8 ##############################################################################\r
9 \r
10 import json\r
11 import os\r
12 from src.step.test_step import TestStep\r
13 \r
14 \r
15 class MonitorStep(TestStep):\r
16     __step_type__ = 'monitor'\r
17 \r
18     def __init__(self, name, service, action, args):\r
19         super(MonitorStep, self).__init__(name, service, action, args)\r
20         self._argsParse()\r
21         self.action()\r
22 \r
23     def _argsParse(self):\r
24         if self._call == "REST":\r
25             currentDirPath = os.path.dirname(os.path.abspath(__file__))\r
26             envDirPath = os.path.abspath(os.path.join(\r
27                 currentDirPath, os.pardir, os.pardir, 'env'))\r
28             envFilePath = os.path.join(\r
29                 envDirPath, "%s.json" % self._service['name'])\r
30             with open(envFilePath) as f:\r
31                 propDict = json.load(f)\r
32                 self._args['ip'] = propDict['ip']\r
33                 self._args['port'] = propDict['port']\r
34                 self._args['api'] = "%s/%s" % (\r
35                     propDict['api_map']['workload'], self._args['command'])\r
36                 exclude = {'ip', 'port', 'api', 'command', 'method'}\r
37                 self._args['req_body'] = {\r
38                     key: value for key, value in\r
39                     self._args.items() if key not in exclude}\r
40 \r
41     def setUp(self):\r
42         print "monitor setUp"\r
43 \r
44     def uninstall(self):\r
45         print "monitor uninstall"\r
46 \r
47     def start(self):\r
48         print "monitor start...."\r
49 \r
50     def stop(self):\r
51         print "monitor stop"\r
52 \r
53 \r
54 if __name__ == "__main__":\r
55     service = {"name": "ansible", "call": "REST"}\r
56     monitor = MonitorStep(\r
57         "monitor_cpu", service, "start", **{"target": "abc:qq"})\r