support redeploy 91/5291/4
authorbaigk <baiguoku@huawei.com>
Sun, 27 Dec 2015 13:23:33 +0000 (21:23 +0800)
committerbaigk <baiguoku@huawei.com>
Mon, 28 Dec 2015 06:45:58 +0000 (06:45 +0000)
JIRA: COMPASS-216

Change-Id: Ide78ac82c1615259eeb7093c7a4485fbe493c6d9
Signed-off-by: baigk <baiguoku@huawei.com>
15 files changed:
build/make_repo.sh
deploy.sh
deploy/client.py
deploy/compass_vm.sh
deploy/deploy_host.sh
deploy/host_baremetal.sh
deploy/host_virtual.sh
deploy/launch.sh
deploy/prepare.sh
deploy/restful.py
deploy_compass.sh [new file with mode: 0755]
deploy_compass_only.sh [deleted file]
deploy_host.sh [new file with mode: 0755]
deploy_host_only.sh [deleted file]
redeploy_host.sh [new file with mode: 0755]

index 67f2e2f..c165c99 100755 (executable)
@@ -163,8 +163,8 @@ function make_all_repo()
 
     make_repo --os-ver rhel7 --package-tag compass \
               --tmpl "${WORK_PATH}/build/templates/compass_core.tmpl" \
-              --default-package "kernel-devel epel-release wget libxml2 glibc gcc perl openssl-libs mkisofs createrepo \
-                                 python-yaml python-jinja2 python-paramiko elasticsearch logstash bind-license vim \
+              --default-package "kernel-devel epel-release wget libxml2 glibc gcc perl openssl-libs mkisofs createrepo lsof \
+                                 python-yaml python-jinja2 python-paramiko elasticsearch logstash bind-license vim nmap-ncat \
                                  yum cobbler cobbler-web createrepo mkisofs syslinux pykickstart bind rsync fence-agents \
                                  dhcp xinetd tftp-server httpd libselinux-python python-setuptools python-devel mysql-devel \
                                  mysql-server mysql MySQL-python redis mod_wsgi net-tools rabbitmq-server nfs-utils" \
index b95475b..653eec8 100755 (executable)
--- a/deploy.sh
+++ b/deploy.sh
@@ -2,18 +2,16 @@
 COMPASS_DIR=`cd ${BASH_SOURCE[0]%/*}/;pwd`
 export COMPASS_DIR
 
-if [[ -z "$DEPLOY_STEP" ]]; then
-    export DEPLOY_STEP="all"
+if [[ -z $DEPLOY_COMPASS && -z $DEPLOY_HOST && -z $REDEPLOY_HOST ]]; then
+    export DEPLOY_COMPASS="true"
+    export DEPLOY_HOST="true"
 fi
 
-for i in python-cheetah python-yaml screen; do
+for i in python-cheetah python-yaml; do
     if [[ `dpkg-query -l $i` == 0 ]]; then
         continue
     fi
     sudo apt-get install -y --force-yes  $i
 done
 
-screen -ls |grep deploy|awk -F. '{print $1}'|xargs kill -9
-screen -wipe
-#screen -dmSL deploy bash $COMPASS_DIR/ci/launch.sh $*
 $COMPASS_DIR/deploy/launch.sh $*
index 1952b3a..b9cfd7f 100644 (file)
@@ -228,6 +228,9 @@ opts = [
     cfg.StrOpt('deploy_type',
               help='deploy type',
               default='virtual'),
+    cfg.StrOpt('deploy_flag',
+              help='deploy flag',
+              default='deploy'),
 ]
 CONF.register_cli_opts(opts)
 
@@ -279,9 +282,9 @@ class CompassClient(object):
 
     def get_machines(self):
         status, resp = self.client.list_machines()
-        LOG.info(
-            'get all machines status: %s, resp: %s', status, resp)
         if not self.is_ok(status):
+            LOG.error(
+                'get all machines status: %s, resp: %s', status, resp)
             raise RuntimeError('failed to get machines')
 
         machines_to_add = list(set([
@@ -289,12 +292,21 @@ class CompassClient(object):
             if machine
         ]))
 
-        LOG.info('machines to add: %s', machines_to_add)
         machines_db = [str(m["mac"]) for m in resp]
-        LOG.info('machines in db: %s', machines_db)
-        assert(set(machines_db) == set(machines_to_add))
+        LOG.info('machines in db: %s\n to add: %s', machines_db, machines_to_add)
+        if not set(machines_to_add).issubset(set(machines_db)):
+            raise RuntimeError('unidentify machine to add')
+
+        return [m["id"] for m in resp if str(m["mac"]) in machines_to_add]
+
+    def list_clusters(self):
+        status, resp = self.client.list_clusters(name=CONF.cluster_name)
+        if not self.is_ok(status) or not resp:
+            raise RuntimeError('failed to list cluster')
+
+        cluster = resp[0]
 
-        return [m["id"] for m in resp]
+        return cluster['id']
 
     def get_adapter(self):
         """get adapter."""
@@ -806,6 +818,18 @@ class CompassClient(object):
         if not self.is_ok(status):
             raise RuntimeError("deploy cluster failed")
 
+    def redeploy_clusters(self, cluster_id):
+        status, response = self.client.redeploy_cluster(
+            cluster_id
+        )
+
+        if not self.is_ok(status):
+            LOG.info(
+                'deploy cluster %s status %s: %s',
+                cluster_id, status, response
+            )
+            raise RuntimeError("redeploy cluster failed")
+
     def get_installing_progress(self, cluster_id):
         """get intalling progress."""
         action_timeout = time.time() + 60 * float(CONF.action_timeout)
@@ -862,7 +886,8 @@ class CompassClient(object):
             raise Exception(msg)
 
 
-def main():
+
+def deploy():
     client = CompassClient()
     machines = client.get_machines()
 
@@ -885,6 +910,23 @@ def main():
     client.get_installing_progress(cluster_id)
     client.check_dashboard_links(cluster_id)
 
+def redeploy():
+    client = CompassClient()
+
+    cluster_id = client.list_clusters()
+
+    client.redeploy_clusters(cluster_id)
+
+    client.get_installing_progress(cluster_id)
+    client.check_dashboard_links(cluster_id)
+
+def main():
+    if CONF.deploy_flag == "redeploy":
+        redeploy()
+    else:
+        deploy()
+
+
 if __name__ == "__main__":
     CONF(args=sys.argv[1:])
     main()
index 71d9ad6..5b94b60 100644 (file)
@@ -14,14 +14,26 @@ function tear_down_compass() {
 }
 
 function install_compass_core() {
+    install_compass "compass_nodocker.yml"
+}
+
+function set_compass_machine() {
+    local config_file=$WORK_DIR/installer/compass-install/install/group_vars/all
+
+    sed -i -e '/test: true/d' -e '/pxe_boot_macs/d' $config_file
+    echo "test: true" >> $config_file
+    echo "pxe_boot_macs: [${machines}]" >> $config_file
+
+    install_compass "compass_machine.yml"
+}
+
+function install_compass() {
     local inventory_file=$compass_vm_dir/inventory.file
-    log_info "install_compass_core enter"
     sed -i "s/mgmt_next_ip:.*/mgmt_next_ip: ${COMPASS_SERVER}/g" $WORK_DIR/installer/compass-install/install/group_vars/all
     echo "compass_nodocker ansible_ssh_host=$MGMT_IP ansible_ssh_port=22" > $inventory_file
-    PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o ControlMaster=auto -o ControlPersist=60s' python /usr/local/bin/ansible-playbook -e pipeline=true --private-key=$rsa_file --user=root --connection=ssh --inventory-file=$inventory_file $WORK_DIR/installer/compass-install/install/compass_nodocker.yml
+    PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o ControlMaster=auto -o ControlPersist=60s' python /usr/local/bin/ansible-playbook -e pipeline=true --private-key=$rsa_file --user=root --connection=ssh --inventory-file=$inventory_file $WORK_DIR/installer/compass-install/install/$1
     exit_status=$?
     rm $inventory_file
-    log_info "install_compass_core exit"
     if [[ $exit_status != 0 ]];then
         /bin/false
     fi
index e7dedb8..be392d7 100644 (file)
@@ -5,7 +5,13 @@ function deploy_host(){
 
     reboot_hosts
 
-    python ${COMPASS_DIR}/deploy/client.py --compass_server="${HTTP_SERVER_URL}" \
+    if [[ "$REDEPLOY_HOST" == true ]]; then
+        deploy_flag="redeploy"
+    else
+        deploy_flag="deploy"
+    fi
+
+    python ${COMPASS_DIR}/deploy/client.py --deploy_flag=$deploy_flag --compass_server="${HTTP_SERVER_URL}" \
     --compass_user_email="${COMPASS_USER_EMAIL}" --compass_user_password="${COMPASS_USER_PASSWORD}" \
     --cluster_name="${CLUSTER_NAME}" --language="${LANGUAGE}" --timezone="${TIMEZONE}" \
     --hostnames="${HOSTNAMES}" --partitions="${PARTITIONS}" --subnets="${SUBNETS}" \
index 9e25c98..0210cee 100644 (file)
@@ -6,10 +6,6 @@ function reboot_hosts() {
 }
 
 function get_host_macs() {
-    local config_file=$WORK_DIR/installer/compass-install/install/group_vars/all
-    echo "test: true" >> $config_file
-    machine=`echo $HOST_MACS | sed -e 's/,/'\',\''/g' -e 's/^/'\''/g' -e 's/$/'\''/g'`
-    echo "pxe_boot_macs: [$machine]" >> $config_file
-
-    echo $machine
+    machines=`echo $HOST_MACS | sed -e 's/,/'\',\''/g' -e 's/^/'\''/g' -e 's/$/'\''/g'`
+    echo $machines
 }
index 4cb3361..c7e5f84 100644 (file)
@@ -1,10 +1,13 @@
 host_vm_dir=$WORK_DIR/vm
 function tear_down_machines() {
+    old_ifs=$IFS
+    IFS=,
     for i in $HOSTNAMES; do
         sudo virsh destroy $i
         sudo virsh undefine $i
         rm -rf $host_vm_dir/$i
     done
+    IFS=$old_ifs
 }
 
 function reboot_hosts() {
@@ -14,7 +17,6 @@ function reboot_hosts() {
 function launch_host_vms() {
     old_ifs=$IFS
     IFS=,
-    tear_down_machines
     #function_bod
     mac_array=($machines)
     log_info "bringing up pxe boot vms"
@@ -44,16 +46,18 @@ function launch_host_vms() {
 }
 
 function get_host_macs() {
-    local config_file=$WORK_DIR/installer/compass-install/install/group_vars/all
     local mac_generator=${COMPASS_DIR}/deploy/mac_generator.sh
     local machines=
 
-    chmod +x $mac_generator
-    mac_array=`$mac_generator $VIRT_NUMBER`
-    machines=`echo $mac_array|sed 's/ /,/g'`
+    if [[ $REDEPLOY_HOST == "true" ]]; then
+        mac_array=`cat $WORK_DIR/switch_machines`
+    else
+        chmod +x $mac_generator
+        mac_array=`$mac_generator $VIRT_NUMBER`
+        echo $mac_array > $WORK_DIR/switch_machines
+    fi
 
-    echo "test: true" >> $config_file
-    echo "pxe_boot_macs: [${machines}]" >> $config_file
+    machines=`echo $mac_array|sed 's/ /,/g'`
 
     echo $machines
 }
index 273e27a..7160612 100755 (executable)
@@ -18,67 +18,56 @@ source ${COMPASS_DIR}/deploy/compass_vm.sh
 source ${COMPASS_DIR}/deploy/deploy_host.sh
 
 ######################### main process
-old_ifs=$IFS
-IFS=,
-tear_down_machines
-IFS=$old_ifs
+print_logo
 
-if [[ "$DEPLOY_STEP" == "compass_only" || "$DEPLOY_STEP" == "all" ]]
-then
-if ! prepare_env;then
-    echo "prepare_env failed"
-    exit 1
+if [[ ! -z $VIRT_NUMBER ]];then
+    tear_down_machines
 fi
 
 log_info "########## get host mac begin #############"
 machines=`get_host_macs`
-if [[ -z $machines ]];then
+if [[ -z $machines ]]; then
     log_error "get_host_macs failed"
     exit 1
 fi
 
-log_info "deploy host macs: $machines"
 export machines
-echo "export machines=\""$machines"\"" > $WORK_DIR/switch_machines
-log_info "########## set up network begin #############"
-if ! create_nets;then
-    log_error "create_nets failed"
-    exit 1
-fi
 
-if ! launch_compass;then
-    log_error "launch_compass failed"
-    exit 1
-fi
+if [[ "$DEPLOY_COMPASS" == "true" ]]; then
+    if ! prepare_env;then
+        echo "prepare_env failed"
+        exit 1
+    fi
 
-else
+    log_info "########## set up network begin #############"
+    if ! create_nets;then
+        log_error "create_nets failed"
+        exit 1
+    fi
 
-# test code
-if [[ -f $WORK_DIR/switch_machines ]]; then
-    echo "using last generated machines"
-    source $WORK_DIR/switch_machines
-else
-    export machines="'00:00:3d:a4:ee:4c','00:00:63:35:3c:2b','00:00:f2:f2:b7:a5','00:00:2f:d3:88:28','00:00:46:67:11:e7'"
+    if ! launch_compass;then
+        log_error "launch_compass failed"
+        exit 1
+    fi
 fi
 
+if [[ -z "$REDEPLOY_HOST" || "$REDEPLOY_HOST" == "false" ]]; then
+    if ! set_compass_machine; then
+        log_error "set_compass_machine fail"
+    fi
 fi
 
-if [[ "$DEPLOY_STEP" == "host_only" || "$DEPLOY_STEP" == "all" ]]; then
+if [[ "$DEPLOY_HOST" == "true" || $REDEPLOY_HOST == "true" ]]; then
+    if [[ ! -z $VIRT_NUMBER ]];then
+        if ! launch_host_vms;then
+            log_error "launch_host_vms failed"
+            exit 1
+        fi
+    fi
 
-if [[ ! -z $VIRT_NUMBER ]];then
-    if ! launch_host_vms;then
-        log_error "launch_host_vms failed"
-        exit 1
+    if ! deploy_host;then
+         exit 1
     fi
 fi
-if ! deploy_host;then
-    #tear_down_machines
-    #tear_down_compass
-    exit 1
-else
-    #tear_down_machines
-    #tear_down_compass
-    exit 0
-fi
 
-fi
+figlet -ctf slant Installation Complete!
index e8b2103..f1aacd9 100755 (executable)
@@ -1,4 +1,16 @@
 
+function print_logo()
+{
+    if ! apt --installed list 2>/dev/null | grep "figlet"
+    then
+        sudo apt-get update -y
+        sudo apt-get install -y --force-yes figlet
+    fi
+
+    figlet -ctf slant Compass Installer
+    set +x; sleep 2; set -x
+}
+
 function download_iso()
 {
     iso_name=`basename $ISO_URL`
@@ -15,7 +27,6 @@ function download_iso()
     curl --connect-timeout 10 -o $WORK_DIR/cache/$iso_name $ISO_URL
 }
 
-
 function prepare_env() {
     export PYTHONPATH=/usr/lib/python2.7/dist-packages:/usr/local/lib/python2.7/dist-packages
     sudo apt-get update -y
index 4d86da8..44e461c 100644 (file)
@@ -647,6 +647,11 @@ class Client(object):
         data['deploy'] = deploy
         return self._post('/clusters/%s/action' % cluster_id, data=data)
 
+    def redeploy_cluster(self, cluster_id):
+        data = {}
+        data['redeploy'] = {}
+        return self._post('/clusters/%s/action' % cluster_id, data=data)
+
     def get_cluster_state(self, cluster_id):
         return self._get('/clusters/%s/state' % cluster_id)
 
diff --git a/deploy_compass.sh b/deploy_compass.sh
new file mode 100755 (executable)
index 0000000..a92ecea
--- /dev/null
@@ -0,0 +1,3 @@
+export DEPLOY_COMPASS=${DEPLOY_COMPASS-"true"}
+
+./deploy.sh $*
diff --git a/deploy_compass_only.sh b/deploy_compass_only.sh
deleted file mode 100755 (executable)
index 8cb31eb..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-export DEPLOY_STEP="compass_only"
-
-./deploy.sh $*
diff --git a/deploy_host.sh b/deploy_host.sh
new file mode 100755 (executable)
index 0000000..1272aee
--- /dev/null
@@ -0,0 +1,3 @@
+export DEPLOY_HOST=${DEPLOY_HOST-"true"}
+
+./deploy.sh $*
diff --git a/deploy_host_only.sh b/deploy_host_only.sh
deleted file mode 100755 (executable)
index accade3..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-export DEPLOY_STEP="host_only"
-
-./deploy.sh $*
diff --git a/redeploy_host.sh b/redeploy_host.sh
new file mode 100755 (executable)
index 0000000..9ae02fc
--- /dev/null
@@ -0,0 +1,3 @@
+export REDEPLOY_HOST=${REDEPLOY_HOST-"true"}
+
+./deploy.sh $*