summaryrefslogtreecommitdiffstats
path: root/deploy/status_callback.py
diff options
context:
space:
mode:
authorHarry Huang <huangxiangyu5@huawei.com>2017-11-07 15:30:51 +0800
committerHarry Huang <huangxiangyu5@huawei.com>2017-12-21 15:35:12 +0800
commita360411cb8c775dffa24a4157cec2b566cbde6f3 (patch)
tree400e879a6f6779c294d7f2113c05b29d5578cff3 /deploy/status_callback.py
parent4074d39e93d7e7697dd2aaad2e08433ca0a60221 (diff)
Add compass-docker-compose
1. Add ansible for docker compose containerized compass 2. deploy/conf/compass.conf no longer specify image tags for runtime. build.yaml now is added into compass tarball to be the only place determine image tags 3. This patch is based on patch: https://gerrit.opnfv.org/gerrit/#/c/47393/ use merged compass-tasks 4. Tempoarily using private docker repo for compass-tasks. Switch to opnfv repo when patch https://gerrit.opnfv.org/gerrit/#/c/47329/ is merged 5. Modify ansible callback module accrodingly Change-Id: I0728a9002a1cc7804c9e8f13bd1afdccb684a159 Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
Diffstat (limited to 'deploy/status_callback.py')
-rw-r--r--deploy/status_callback.py76
1 files changed, 41 insertions, 35 deletions
diff --git a/deploy/status_callback.py b/deploy/status_callback.py
index 4bbbc321..f0615f3f 100644
--- a/deploy/status_callback.py
+++ b/deploy/status_callback.py
@@ -16,13 +16,13 @@ from ansible.plugins.callback import CallbackBase
COMPASS_HOST = "compass-deck"
-def task_error(display, host, data):
- display.display("task_error: host=%s,data=%s" % (host, data))
-
-# if isinstance(data, dict):
-# invocation = data.pop('invocation', {})
-
- notify_host(display, COMPASS_HOST, host, "failed")
+# def task_error(display, host, data):
+# display.display("task_error: host=%s,data=%s" % (host, data))
+#
+# if isinstance(data, dict):
+# invocation = data.pop('invocation', {})
+#
+# notify_host(display, COMPASS_HOST, host, "failed")
class CallbackModule(CallbackBase):
@@ -101,39 +101,47 @@ class CallbackModule(CallbackBase):
def v2_playbook_on_stats(self, stats):
self._display.display("playbook_on_stats enter")
+ all_vars = self.play.get_variable_manager().get_vars(self.loader)
+ host_vars = all_vars["hostvars"]
hosts = sorted(stats.processed.keys())
- failures = False
- unreachable = False
-
- for host in hosts:
- summary = stats.summarize(host)
- # self._display.display("host: %s \nsummary: %s\n" % (host, summary)) # noqa
-
- if summary['failures'] > 0:
- failures = True
- if summary['unreachable'] > 0:
- unreachable = True
+ cluster_name = host_vars[hosts[0]]['cluster_name']
headers = {"Content-type": "application/json",
"Accept": "*/*"}
-
conn = httplib.HTTPConnection(COMPASS_HOST, 80)
token = auth(conn)
headers["X-Auth-Token"] = token
- get_url = "/api/hosts"
+ get_url = "/api/clusterhosts"
conn.request("GET", get_url, "", headers)
resp = conn.getresponse()
raise_for_status(resp)
- host_data = json.loads(resp.read())
- clusterhosts = [item["name"] for item in host_data]
-
- if failures or unreachable:
- host_status = "error"
- else:
- host_status = "succ"
+ clusterhost_data = json.loads(resp.read())
+ clusterhost_mapping = {}
+ for item in clusterhost_data:
+ if item["clustername"] == cluster_name:
+ clusterhost_mapping.update({item["hostname"]:
+ item["clusterhost_id"]})
+
+ force_error = False
+ if "localhost" in hosts:
+ summary = stats.summarize("localhost")
+ if summary['failures'] > 0 or summary['unreachable'] > 0:
+ force_error = True
+
+ for hostname, hostid in clusterhost_mapping.iteritems():
+ if hostname not in hosts:
+ continue
+
+ summary = stats.summarize(hostname)
+ # self._display.display("host: %s \nsummary: %s\n" % (host, summary)) # noqa
- for host in clusterhosts:
- notify_host(self._display, "compass-deck", host, host_status)
+ if summary['failures'] > 0 or summary['unreachable'] > 0 \
+ or force_error:
+ status = "error"
+ else:
+ status = "succ"
+ self._display.display("hostname: %s" % hostname)
+ notify_host(self._display, COMPASS_HOST, hostid, status)
def raise_for_status(resp):
@@ -157,17 +165,15 @@ def auth(conn):
return json.loads(resp.read())["token"]
-def notify_host(display, compass_host, host, status):
- display.display("hostname: %s" % host)
- host = host.strip("host")
- url = "/api/clusterhosts/%s/state" % host
+def notify_host(display, compass_host, hostid, status):
+ url = "/api/clusterhosts/%s/state" % hostid
if status == "succ":
body = {"state": "SUCCESSFUL"}
elif status == "error":
body = {"state": "ERROR"}
else:
- display.error("notify_host: host %s with status %s is not supported"
- % (host, status))
+ display.error("notify_host: hostid %s with status %s is not supported"
+ % (hostid, status))
return
headers = {"Content-type": "application/json",