1 ##############################################################################
2 # Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
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 ##############################################################################
12 from src.step.test_step import TestStep
15 class MonitorStep(TestStep):
16 __step_type__ = 'monitor'
18 def __init__(self, name, service, action, args):
19 super(MonitorStep, self).__init__(name, service, action, args)
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}
45 print "monitor uninstall"
48 print "monitor start...."
54 if __name__ == "__main__":
55 service = {"name": "ansible", "call": "REST"}
56 monitor = MonitorStep(
57 "monitor_cpu", service, "start", **{"target": "abc:qq"})