improve: display ansible install log on client side 43/5443/2
authorcarey.xu <carey.xuhan@huawei.com>
Mon, 4 Jan 2016 07:21:16 +0000 (15:21 +0800)
committercarey.xu <carey.xuhan@huawei.com>
Mon, 4 Jan 2016 08:30:17 +0000 (16:30 +0800)
JIRA: COMPASS-219

Change-Id: Id134c312a25a48ee32ab8755def35b8041f47f62
Signed-off-by: carey.xu <carey.xuhan@huawei.com>
deploy/client.py
deploy/deploy_host.sh

index b9cfd7f..9bb0c5e 100644 (file)
@@ -25,6 +25,7 @@ import netaddr
 import requests
 import json
 import itertools
+import threading
 from collections import defaultdict
 from restful import Client
 
@@ -231,6 +232,9 @@ opts = [
     cfg.StrOpt('deploy_flag',
               help='deploy flag',
               default='deploy'),
+    cfg.StrOpt('rsa_file',
+              help='ssh rsa key file',
+              default=''),
 ]
 CONF.register_cli_opts(opts)
 
@@ -836,31 +840,40 @@ class CompassClient(object):
         deployment_timeout = time.time() + 60 * float(
             CONF.deployment_timeout)
 
-        current_time = time.time()
+        current_time = time.time
         deployment_failed = True
-        while current_time < deployment_timeout:
+        while current_time() < deployment_timeout:
             status, cluster_state = self.client.get_cluster_state(cluster_id)
-            LOG.info(
-                'get cluster %s state status %s: %s',
-                cluster_id, status, cluster_state
-            )
             if not self.is_ok(status):
                 raise RuntimeError("can not get cluster state")
 
             if cluster_state['state'] in ['UNINITIALIZED', 'INITIALIZED']:
-                if current_time >= action_timeout:
+                if current_time() >= action_timeout:
                     deployment_failed = True
+                    LOG.info(
+                         'get cluster %s state status %s: %s, successful',
+                         cluster_id, status, cluster_state
+                    )
                     break
                 else:
                     continue
 
             elif cluster_state['state'] == 'SUCCESSFUL':
                 deployment_failed = False
+                LOG.info(
+                     'get cluster %s state status %s: %s, successful',
+                     cluster_id, status, cluster_state
+                )
                 break
             elif cluster_state['state'] == 'ERROR':
                 deployment_failed = True
+                LOG.info(
+                     'get cluster %s state status %s: %s, error',
+                     cluster_id, status, cluster_state
+                )
                 break
 
+        kill_print_proc()
         if deployment_failed:
             raise RuntimeError("deploy cluster failed")
 
@@ -886,6 +899,12 @@ class CompassClient(object):
             raise Exception(msg)
 
 
+def print_ansible_log():
+    os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i %s root@192.168.200.2 \
+              'while ! tail -f /var/ansible/run/openstack_liberty-opnfv2/ansible.log 2>/dev/null; do :; sleep 1; done'" % CONF.rsa_file)
+
+def kill_print_proc():
+    os.system("ps aux|grep -v grep|grep -E 'ssh.+root@192.168.200.2'|awk '{print $2}'|xargs kill -9")
 
 def deploy():
     client = CompassClient()
@@ -907,7 +926,9 @@ def deploy():
     client.set_all_hosts_roles(cluster_id)
     client.deploy_clusters(cluster_id)
 
-    client.get_installing_progress(cluster_id)
+    threading.Thread(target=client.get_installing_progress, args=(cluster_id,)).start()
+    LOG.info("compass OS installtion is begin")
+    print_ansible_log()
     client.check_dashboard_links(cluster_id)
 
 def redeploy():
index b87a74d..f8feacb 100755 (executable)
@@ -1,4 +1,5 @@
 #!/bin/bash
+rsa_file=$compass_vm_dir/boot.rsa
 function deploy_host(){
 
     ssh $ssh_args root@${MGMT_IP} mkdir -p /opt/compass/bin/ansible_callbacks
@@ -30,6 +31,7 @@ function deploy_host(){
     --machines=${machines//\'} --switch_credential="${SWITCH_CREDENTIAL}" --deploy_type="${TYPE}" \
     --deployment_timeout="${DEPLOYMENT_TIMEOUT}" --${POLL_SWITCHES_FLAG} --dashboard_url="${DASHBOARD_URL}" \
     --cluster_vip="${VIP}" --network_cfg="$NETWORK" --neutron_cfg="$NEUTRON" \
-    --enable_secgroup="${ENABLE_SECGROUP}" --enable_fwaas="${ENABLE_FWAAS}" --enable_vpnaas="${ENABLE_VPNAAS}"
+    --enable_secgroup="${ENABLE_SECGROUP}" --enable_fwaas="${ENABLE_FWAAS}" \
+    --rsa_file="$rsa_file" --enable_vpnaas="${ENABLE_VPNAAS}"
 
 }