--- /dev/null
+##############################################################################\r
+# Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.\r
+#\r
+# All rights reserved. This program and the accompanying materials\r
+# are made available under the terms of the Apache License, Version 2.0\r
+# which accompanies this distribution, and is available at\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+##############################################################################\r
+\r
+import json\r
+import os\r
+from src.step.test_step import TestStep\r
+\r
+\r
+class MonitorStep(TestStep):\r
+ __step_type__ = 'monitor'\r
+\r
+ def __init__(self, name, service, action, args):\r
+ super(MonitorStep, self).__init__(name, service, action, args)\r
+ self._argsParse()\r
+ self.action()\r
+\r
+ def _argsParse(self):\r
+ if self._call == "REST":\r
+ currentDirPath = os.path.dirname(os.path.abspath(__file__))\r
+ envDirPath = os.path.abspath(os.path.join(\r
+ currentDirPath, os.pardir, os.pardir, 'env'))\r
+ envFilePath = os.path.join(\r
+ envDirPath, "%s.json" % self._service['name'])\r
+ with open(envFilePath) as f:\r
+ propDict = json.load(f)\r
+ self._args['ip'] = propDict['ip']\r
+ self._args['port'] = propDict['port']\r
+ self._args['api'] = "%s/%s" % (\r
+ propDict['api_map']['workload'], self._args['command'])\r
+ exclude = {'ip', 'port', 'api', 'command', 'method'}\r
+ self._args['req_body'] = {\r
+ key: value for key, value in\r
+ self._args.items() if key not in exclude}\r
+\r
+ def setUp(self):\r
+ print "monitor setUp"\r
+\r
+ def uninstall(self):\r
+ print "monitor uninstall"\r
+\r
+ def start(self):\r
+ print "monitor start...."\r
+\r
+ def stop(self):\r
+ print "monitor stop"\r
+\r
+\r
+if __name__ == "__main__":\r
+ service = {"name": "ansible", "call": "REST"}\r
+ monitor = MonitorStep(\r
+ "monitor_cpu", service, "start", **{"target": "abc:qq"})\r