diff options
Diffstat (limited to 'ci')
-rwxr-xr-x | ci/deploy/deploy.sh | 143 | ||||
-rwxr-xr-x | ci/kolla-build.sh | 202 |
2 files changed, 306 insertions, 39 deletions
diff --git a/ci/deploy/deploy.sh b/ci/deploy/deploy.sh index 6d7addd2..a2d18496 100755 --- a/ci/deploy/deploy.sh +++ b/ci/deploy/deploy.sh @@ -10,23 +10,89 @@ ############################################################################## #daisy host discover ######exit before finish test####### -exit 0 +# exit 0 ##########TODO after test########## -DHA=$1 -NETWORK=$2 -tempest_path=$WORKSPACE/deploy +DHA=$WORKSPACE/$1 +NETWORK=$WORKSPACE/$2 +deploy_path=$WORKSPACE/deploy +create_qcow2_path=$WORKSPACE/tools +net_daisy1=$WORKSPACE/templates/virtual_environment/networks/daisy.xml +net_daisy2=$WORKSPACE/templates/virtual_environment/networks/os-all_in_one.xml +pod_daisy=$WORKSPACE/templates/virtual_environment/vms/daisy.xml +pod_all_in_one=$WORKSPACE/templates/virtual_environment/vms/all_in_one.xml -echo "====== clean && install daisy===========" -.$WORKSPACE/opnfv.bin clean -rc=$? -if [ $rc -ne 0 ]; then - echo "daisy clean failed" - exit 1 -else - echo "daisy clean successfully" -fi -.$WORKSPACE/opnfv.bin install +parameter_from_deploy=`python $WORKSPACE/deploy/get_para_from_deploy.py --dha $DHA` + +daisyserver_size=`echo $parameter_from_deploy | cut -d " " -f 1` +controller_node_size=`echo $parameter_from_deploy | cut -d " " -f 2` +compute_node_size=`echo $parameter_from_deploy | cut -d " " -f 3` +daisy_passwd=`echo $parameter_from_deploy | cut -d " " -f 4` +daisy_ip=`echo $parameter_from_deploy | cut -d " " -f 5` +daisy_gateway=`echo $parameter_from_deploy | cut -d " " -f 6` + +function execute_on_jumpserver +{ + ssh $1 -o UserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no $2 +} + +function create_node +{ + virsh net-define $1 + virsh net-autostart $2 + virsh net-start $2 + virsh define $3 + virsh start $4 +} + +#update key = value config option in an conf or ini file +function update_config +{ + local file=$1 + local key=$2 + local value=$3 + + [ ! -e $file ] && return + + #echo update key $key to value $value in file $file ... + local exist=`grep "^[[:space:]]*[^#]" $file | grep -c "$key[[:space:]]*=[[:space:]]*.*"` + #action:If a line is a comment, the beginning of the first character must be a #!!! + local comment=`grep -c "^[[:space:]]*#[[:space:]]*$key[[:space:]]*=[[:space:]]*.*" $file` + + if [[ $value == "#" ]];then + if [ $exist -gt 0 ];then + sed -i "/^[^#]/s/$key[[:space:]]*=/\#$key=/" $file + fi + return + fi + + if [ $exist -gt 0 ];then + #if there have been a effective configuration line did not comment, update value directly + sed -i "/^[^#]/s#$key[[:space:]]*=.*#$key=$value#" $file + + elif [ $comment -gt 0 ];then + #if there is a configuration line has been commented out, then remove the comments, update the value + sed -i "s@^[[:space:]]*#[[:space:]]*$key[[:space:]]*=[[:space:]]*.*@$key=$value@" $file + else + #add effective configuration line at the end + echo "$key=$value" >> $file + fi +} + +echo "=======create daisy node================" +$create_qcow2_path/daisy-img-modify.sh -c $create_qcow2_path/centos-img-modify.sh -a $daisy_ip -g $daisy_gateway -s $daisyserver_size +#qemu-img resize centos7.qcow2 100G +create_node $net_daisy1 daisy1 $pod_daisy daisy +sleep 20 + +echo "====== install daisy===========" +$deploy_path/trustme.sh $daisy_ip $daisy_passwd +scp -r $WORKSPACE root@$daisy_ip:/home + +execute_on_jumpserver $daisy_ip "mkdir -p /home/daisy_install" +update_config $WORKSPACE/deploy/daisy.conf daisy_management_ip $daisy_ip +scp $WORKSPACE/deploy/daisy.conf root@$daisy_ip:/home/daisy_install +execute_on_jumpserver $daisy_ip "$WORKSPACE/opnfv.bin install" rc=$? if [ $rc -ne 0 ]; then echo "daisy install failed" @@ -35,29 +101,28 @@ else echo "daisy install successfully" fi -source ~/daisyrc_admin - -echo "======prepare install openstack===========" -python $tempest_path/tempest.py --dha $DHA --network $NETWORK - -echo "======daisy install kolla(openstack)===========" -cluster_id=`daisy cluster-list | awk -F "|" '{print $2}' | sed -n '4p'` -daisy install $cluster_id -echo "check installing process..." -var=1 -while [ $var -eq 1 ]; do - echo "loop for judge openstack installing progress..." - openstack_install_active=`daisy host-list --cluster-id $cluster_id | awk -F "|" '{print $12}' | grep -c "active" ` - openstack_install_failed=`daisy host-list --cluster-id $cluster_id | awk -F "|" '{print $12}' | grep -c "install-failed" ` - if [ $openstack_install_active -eq 1 ]; then - echo "openstack installing successful ..." - break - elif [ $openstack_install_failed -gt 0 ]; then - echo "openstack installing have failed..." - tail -n 200 /var/log/daisy/kolla_$cluster_id* - exit 1 - else - echo " openstack in installing , please waiting ..." - fi -done +echo "====== add relate config of kolla===========" +execute_on_jumpserver $daisy_ip "mkdir -p /etc/kolla/config/nova" +execute_on_jumpserver $daisy_ip "echo -e "[libvirt]\nvirt_type=qemu" > /etc/kolla/config/nova/nova-compute.conf" + +echo "===prepare cluster and pxe===" +execute_on_jumpserver $daisy_ip "python $WORKSPACE/deploy/tempest.py --dha $DHA --network $NETWORK --cluster "yes"" + +echo "=====create all-in-one node======" +qemu-img create -f qcow2 $WORKSPACE/../qemu/vms/all_in_one.qcow2 200G +create_node $net_daisy2 daisy2 $pod_all_in_one all_in_one +sleep 20 + +echo "======prepare host and pxe===========" +execute_on_jumpserver $daisy_ip "python $WORKSPACE/deploy/tempest.py --dha $DHA --network $NETWORK --host "yes"" + +echo "======daisy deploy os and openstack===========" +virsh destroy all_in_one +virsh start all_in_one + +echo "===========check install progress===========" +execute_on_jumpserver $daisy_ip "$WORKSPACE/deploy/check_os_progress.sh" +virsh reboot all_in_one +execute_on_jumpserver $daisy_ip "$WORKSPACE/deploy/check_openstack_progress.sh" + exit 0 diff --git a/ci/kolla-build.sh b/ci/kolla-build.sh new file mode 100755 index 00000000..39828ece --- /dev/null +++ b/ci/kolla-build.sh @@ -0,0 +1,202 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2016 ZTE Coreporation and others. +# hu.zhijiang@zte.com.cn +# lu.yao135@zte.com.cn +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# Build OpenStack container images as well as extension images. +# Parameters: $1 kolla git url, for example, +# https://git.openstack.org/openstack/kolla +# $2 kolla branch, for example, stable/newton + +set -o errexit +set -o nounset +set -o pipefail + +KOLLA_GIT=$1 +KOLLA_BRANCH=$2 +KOLLA_GIT_VERSION= +KOLLA_GIT_DIR=/tmp/kolla-git +REGISTRY_VOLUME_DIR=/tmp/registry +BUILD_OUTPUT_DIR=/tmp/kolla-build-output +REGISTRY_SERVER_NAME=daisy-registry + +function pre_check { + echo "Pre setup" + if [ $KOLLA_BRANCH == "stable/mitaka" ] ; then + RPM_REQUIRES="python-docker-py:1.6 python-pbr:1.6 python-jinja2:2.8 \ + python-gitdb:0.6.4 GitPython:1.0.1 python-six:1.9.0 \ + python2-oslo-config:3.7.0 python-beautifulsoup4:4.4.1 \ + python2-setuptools:16.0.0 python2-crypto:2.6 docker-engine:1.12" + elif [ $KOLLA_BRANCH == "stable/newton" ] ; then + RPM_REQUIRES="python-docker-py:1.6 python-pbr:1.6 python-jinja2:2.8 \ + python-gitdb:0.6.4 GitPython:1.0.1 python-six:1.9.0 \ + python2-oslo-config:3.14.0 python-netaddr:0.7.13 \ + python2-setuptools:16.0.0 python2-crypto:2.6 docker-engine:1.12 \ + centos-release-openstack-newton:1 epel-release:7" + else + exit 1 + fi + + for package_version in $RPM_REQUIRES + do + package=`echo $package_version | awk -F: '{print $1}'` + expversion=`echo $package_version | awk -F: '{print $2}'` + + echo "Step:1 Check if $package existed" + rpm -q $package &> /dev/null + if [ "$?" != "0" ] ; then + echo "$package not installed" + exit 1 + fi + + echo "Step:2 Check if $package version meets the requirement" + realversion=$(rpm -q --queryformat '%{VERSION}' $package) + smallestversion=`printf "$realversion\n$expversion\n" | sort -V | head -1` + if [ "$smallestversion" != "$expversion" ] ; then + echo "$package version $realversion DOES NOT meet the \ + requirement verion $expversion" + exit 1 + fi + done + + # Some packages must be installed by pip. + # TODO: Check version of packages installed by pip just like what we do for RPM above. + rpm -e tox || true + rpm -e python-virtualenv || true + rpm -e python-py || true + pip install tox + + # Just make sure docker is working. + service docker restart +} + +function cleanup_registry_server { + echo "Cleaning registry server" + containers_to_kill=$(sudo docker ps --filter "name=$REGISTRY_SERVER_NAME" \ + --format "{{.Names}}" -a) + + if [[ ! -z "$containers_to_kill" ]]; then + volumes_to_remove=$(sudo docker inspect -f \ + '{{range .Mounts}} {{printf "%s\n" .Name }}{{end}}' \ + ${containers_to_kill} | egrep -v '(^\s*$)' | sort | uniq) + + echo "Stopping containers... $containers_to_kill" + (sudo docker stop -t 2 ${containers_to_kill} 2>&1) > /dev/null + echo "Removing containers... $containers_to_kill" + (sudo docker rm -v -f ${containers_to_kill} 2>&1) > /dev/null + + if [[ ! -z "$containers_to_kill" ]]; then + echo "Removing volumes... $volumes_to_remove" + (sudo docker volume rm ${volumes_to_remove} 2>&1) || true > /dev/null + fi + fi +} + +function cleanup_registry_data { + echo "Cleaning registry data dir" + rm -rf $REGISTRY_VOLUME_DIR + mkdir -p $REGISTRY_VOLUME_DIR +} + +function cleanup_kolla_image { + echo "Cleaning Kolla images" + if [ -d $KOLLA_GIT_DIR ] ; then + pushd $KOLLA_GIT_DIR/kolla + (./tools/cleanup-images 2>&1) || true > /dev/null; + popd + fi +} + +function start_registry_server { + echo "Starting registry server" + sudo docker run -d -p 5000:5000 --restart=always \ + -e REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/tmp/registry \ + -v $REGISTRY_VOLUME_DIR:/tmp/registry \ + --name $REGISTRY_SERVER_NAME registry:2 +} + +function pack_registry_data { + echo "Packaging registry data" + datetag=$(date +%y%m%d%H%M%S) + version=$(echo $KOLLA_BRANCH | awk -F'/' '{print $2}') + + if [ ! -d $BUILD_OUTPUT_DIR ] ; then + mkdir -p $BUILD_OUTPUT_DIR + fi + + pushd $BUILD_OUTPUT_DIR + echo $KOLLA_GIT_VERSION > registry-$version-$datetag.version + tar czf kolla-image-$version-$datetag.tgz $REGISTRY_VOLUME_DIR \ + registry-$version-$datetag.version + rm -rf registry-$version-$datetag.version + popd +} + +function update_kolla_code { + echo "Updating Kolla code" + if [ ! -d $KOLLA_GIT_DIR ] ; then + mkdir -p $KOLLA_GIT_DIR + fi + + if [ ! -d $KOLLA_GIT_DIR/kolla ] ; then + pushd $KOLLA_GIT_DIR + git clone $KOLLA_GIT + git checkout $KOLLA_BRANCH + popd + else + pushd $KOLLA_GIT_DIR/kolla + git remote update + git checkout $KOLLA_BRANCH + git pull --ff-only + popd + fi + + pushd $KOLLA_GIT_DIR/kolla + KOLLA_GIT_VERSION=`git log -1 --pretty="%H"` + tox -e genconfig + popd +} + +function start_build { + echo "Start to build Kolla image" + REGISTRY_PARAM="--registry 127.0.0.1:5000 --push" + pushd $KOLLA_GIT_DIR/kolla + + # Some of the images may be failed to built out but is OK + # so we use "|| true" here. + # TODO: We can impl. some checks to see if the images that + # we really care are built successfully. + tools/build.py $REGISTRY_PARAM || true; + popd +} + +function usage { + echo "Usage: $0 https://git.openstack.org/openstack/kolla stable/newton" +} + +if [ "$1" == "" -o "$2" == "" ] ; then + usage + exit 1 +fi + +pre_check +# Try to cleanup images of the last failed run, if any. +cleanup_kolla_image +update_kolla_code + +# Make sure there is no garbage in the registry server. +cleanup_registry_server +cleanup_registry_data +start_registry_server + +start_build +cleanup_kolla_image +pack_registry_data + +# TODO: Upload to OPNFV artifacts repo. |