1 ##############################################################################
\r
2 # Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
\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
12 from src.step.test_step import TestStep
\r
15 class MonitorStep(TestStep):
\r
16 __step_type__ = 'monitor'
\r
18 def __init__(self, name, service, action, args):
\r
19 super(MonitorStep, self).__init__(name, service, action, args)
\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
42 print "monitor setUp"
\r
44 def uninstall(self):
\r
45 print "monitor uninstall"
\r
48 print "monitor start...."
\r
51 print "monitor stop"
\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