aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/status_callback.py
diff options
context:
space:
mode:
authormeimei <meimei@huawei.com>2016-11-29 18:05:01 +0800
committermeimei <meimei@huawei.com>2016-11-29 18:09:16 +0800
commit6b2eccf0350f7f053e18ea2ac190489b00960809 (patch)
tree8968b2871c4bfc23bfa7077e857dae4d151e53d2 /deploy/status_callback.py
parentfcd0eefae931bb7bed0380574c1c7acaa31ffa28 (diff)
Improve compass ci verification, clear all the warnnings
JIRA: COMPASS-494 MODIFY BY HAOJINGBO Change-Id: I2b95d84157c860254b3b3f68f7b2a54393caf8f4 Signed-off-by: meimei <meimei@huawei.com>
Diffstat (limited to 'deploy/status_callback.py')
-rwxr-xr-xdeploy/status_callback.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/deploy/status_callback.py b/deploy/status_callback.py
index e430326b..aaca05b5 100755
--- a/deploy/status_callback.py
+++ b/deploy/status_callback.py
@@ -3,15 +3,14 @@ import json
import sys
import logging
+
def task_error(host, data):
logging.info("task_error: host=%s,data=%s" % (host, data))
-
- if type(data) == dict:
- invocation = data.pop('invocation', {})
-
notify_host("localhost", host, "failed")
+
class CallbackModule(object):
+
"""
logs playbook results, per host, in /var/log/ansible/hosts
"""
@@ -58,7 +57,8 @@ class CallbackModule(object):
def playbook_on_task_start(self, name, is_conditional):
pass
- def playbook_on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
+ def playbook_on_vars_prompt(self, varname, private=True, prompt=None,
+ encrypt=None, confirm=False, salt_size=None, salt=None, default=None): # noqa: E501
pass
def playbook_on_setup(self):
@@ -101,7 +101,10 @@ class CallbackModule(object):
def raise_for_status(resp):
if resp.status < 200 or resp.status > 300:
- raise RuntimeError("%s, %s, %s" % (resp.status, resp.reason, resp.read()))
+ raise RuntimeError(
+ "%s, %s, %s" %
+ (resp.status, resp.reason, resp.read()))
+
def auth(conn):
credential = {}
@@ -116,6 +119,7 @@ def auth(conn):
raise_for_status(resp)
return json.loads(resp.read())["token"]
+
def notify_host(compass_host, host, status):
if status == "succ":
body = {"ready": True}
@@ -125,8 +129,8 @@ def notify_host(compass_host, host, status):
host = host.strip("host")
url = "/api/clusterhosts/%s/state" % host
else:
- logging.error("notify_host: host %s with status %s is not supported" \
- % (host, status))
+ logging.error("notify_host: host %s with status %s is not supported"
+ % (host, status))
return
headers = {"Content-type": "application/json",
@@ -135,12 +139,16 @@ def notify_host(compass_host, host, status):
conn = httplib.HTTPConnection(compass_host, 80)
token = auth(conn)
headers["X-Auth-Token"] = token
- logging.info("host=%s,url=%s,body=%s,headers=%s" % (compass_host,url,json.dumps(body),headers))
+ logging.info(
+ "host=%s,url=%s,body=%s,headers=%s" %
+ (compass_host, url, json.dumps(body), headers))
conn.request("POST", url, json.dumps(body), headers)
resp = conn.getresponse()
try:
raise_for_status(resp)
- logging.info("notify host status success!!! status=%s, body=%s" % (resp.status, resp.read()))
+ logging.info(
+ "notify host status success!!! status=%s, body=%s" %
+ (resp.status, resp.read()))
except Exception as e:
logging.error("http request failed %s" % str(e))
raise