summaryrefslogtreecommitdiffstats
path: root/deploy/adapters/ansible/roles
diff options
context:
space:
mode:
authorQiLiang <liangqi1@huawei.com>2016-09-13 20:42:02 +0800
committerqi liang <liangqi1@huawei.com>2016-09-14 03:11:22 +0000
commit77ed8a151a33caf50c1bb2ac7edf60b55fab9e06 (patch)
treee163db931e9d7d66c12f36376df604aaa3574010 /deploy/adapters/ansible/roles
parenta2fc2124740877d26061ecd9b1d3f573771e683c (diff)
Add network connectivity check
JIRA: COMPASS-485 Change-Id: I3ca177118dec362ca2350c746519b83889ec3f83 Signed-off-by: QiLiang <liangqi1@huawei.com>
Diffstat (limited to 'deploy/adapters/ansible/roles')
-rw-r--r--deploy/adapters/ansible/roles/setup-network/files/setup_networks/check_network.py56
-rw-r--r--deploy/adapters/ansible/roles/setup-network/tasks/main.yml14
2 files changed, 70 insertions, 0 deletions
diff --git a/deploy/adapters/ansible/roles/setup-network/files/setup_networks/check_network.py b/deploy/adapters/ansible/roles/setup-network/files/setup_networks/check_network.py
new file mode 100644
index 00000000..72a5db97
--- /dev/null
+++ b/deploy/adapters/ansible/roles/setup-network/files/setup_networks/check_network.py
@@ -0,0 +1,56 @@
+import yaml
+import sys
+import subprocess
+
+import log as logging
+
+LOG = logging.getLogger("net-check")
+
+def is_ip_reachable(ip):
+ cmd = "ping -c 2 %s" % ip
+ process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=None, shell=True)
+
+ output = process.communicate()[0]
+ if " 0% packet loss" in output:
+ LOG.info("%s is reachable", ip)
+ elif "100% packet loss" in output:
+ LOG.error("%s is unreachable" % (ip))
+ return False
+ else:
+ LOG.warn("%r", output)
+
+ return True
+
+def is_host_ips_reachable(settings):
+ external = settings["br-prv"]["ip"]
+ external_gw = settings["br-prv"]["gw"]
+ storage = settings["storage"]["ip"]
+ mgmt = settings["mgmt"]["ip"]
+
+ return is_ip_reachable(external) \
+ and is_ip_reachable(external_gw) \
+ and is_ip_reachable(storage) \
+ and is_ip_reachable(mgmt)
+
+def main(hostname, config):
+ LOG.info("host is %s", hostname)
+
+ result = True
+
+ for host, settings in config.iteritems():
+ LOG.info("check %s network connectivity start", host)
+ result = result and is_host_ips_reachable(settings)
+
+ if result:
+ LOG.info("All hosts ips are reachable")
+ else:
+ LOG.error("Some hosts ips are unreachable !!!")
+ sys.exit(-1)
+
+if __name__ == "__main__":
+ hostname = yaml.load(sys.argv[1])
+ config = yaml.load(sys.argv[2])
+ config.pop(hostname, None)
+
+ main(hostname, config)
+
diff --git a/deploy/adapters/ansible/roles/setup-network/tasks/main.yml b/deploy/adapters/ansible/roles/setup-network/tasks/main.yml
index 7873c073..e1fdf925 100644
--- a/deploy/adapters/ansible/roles/setup-network/tasks/main.yml
+++ b/deploy/adapters/ansible/roles/setup-network/tasks/main.yml
@@ -38,6 +38,9 @@
with_items:
- setup_networks/log.py
- setup_networks/setup_networks.py
+ - setup_networks/check_network.py
+ tags:
+ - network_check
- name: copy boot scripts
copy: src={{ item }} dest=/etc/init.d/ mode=0755
@@ -58,7 +61,18 @@
tags:
- recovery
+- name: check basic network connectivity
+ shell: >
+ python /opt/setup_networks/check_network.py \
+ "{{ inventory_hostname }}" \
+ "{{ ip_settings }}"
+ tags:
+ - network_check
+ retries: 3
+ delay: 2
+
- name: add to boot scripts
service: name=net_init enabled=yes
- meta: flush_handlers
+