baremetal, virtual: Bump kernel to hwe-18.04 (5.0)
[fuel.git] / ci / deploy.sh
index a61946e..de631e8 100755 (executable)
@@ -16,9 +16,9 @@ do_exit () {
     local RC=$?
     cleanup_mounts > /dev/null 2>&1
     if [ ${RC} -eq 0 ]; then
-        notify_n "[OK] MCP: Openstack installation finished succesfully!" 2
+        notify_n "[OK] MCP: Installation of $DEPLOY_SCENARIO finished succesfully!" 2
     else
-        notify_n "[ERROR] MCP: Openstack installation threw a fatal error!"
+        notify_n "[ERROR] MCP: Installation  of $DEPLOY_SCENARIO threw a fatal error!"
     fi
 }
 #
@@ -38,19 +38,21 @@ $(notify "USAGE:" 2)
   $(basename "$0") -l lab-name -p pod-name -s deploy-scenario \\
     [-b Lab Config Base URI] \\
     [-S storage-dir] [-L /path/to/log/file.tar.gz] \\
-    [-f] [-F] [-e | -E[E]] [-d] [-D] [-N] [-m]
+    [-f] [-F[F]] [-e[e] | -E[E]] [-d] [-D] [-N] [-m] \\
+    [-o operating-system]
 
 $(notify "OPTIONS:" 2)
   -b  Base-uri for the stack-configuration structure
   -d  Dry-run
   -D  Debug logging
-  -e  Do not launch environment deployment
+  -e  Do not launch environment deployment (use twice to skip cloud setup)
   -E  Remove existing VCP VMs (use twice to redeploy baremetal nodes)
   -f  Deploy on existing Salt master (use twice or more to skip states)
   -F  Same as -e, do not launch environment deployment (legacy option)
   -h  Print this message and exit
   -l  Lab-name
   -p  Pod-name
+  -o  Use specified operating system for jumpserver/VCP VMs
   -P  Skip installation of package dependencies
   -s  Deploy-scenario short-name
   -S  Storage dir for VM images and other deploy artifacts
@@ -77,10 +79,15 @@ $(notify_i "Input parameters to the build script are:" 2)
 -d Dry-run - Produce deploy config files, but do not execute deploy
 -D Debug logging - Enable extra logging in sh deploy scripts (set -x)
 -e Do not launch environment deployment
+   If specified twice (e.g. -e -e), only the operating system and networks
+   will be provisioned, skipping cloud installation.
 -E Remove existing VCP VMs. It will destroy and undefine all VCP VMs
    currently defined on cluster KVM nodes. If specified twice (e.g. -E -E),
    baremetal nodes (VCP too, implicitly) will be removed, then reprovisioned.
    Only applicable for baremetal deploys.
+   If specified 3 times, a complete uninstallation (cleanup) will be performed
+   on the jumpserver (even for virtual deploys): VMs, virsh networks,
+   containers, networks, services etc.
 -f Deploy on existing Salt master. It will skip infrastructure VM creation,
    but it will still sync reclass configuration from current repo to Salt
    Master node.
@@ -96,6 +103,9 @@ $(notify_i "Input parameters to the build script are:" 2)
    single guest CPU socket.
 -N Experimental: Instead of virtualizing the control plane (VCP), deploy
    control plane directly on baremetal nodes
+-o Operating system to be preinstalled on jumpserver VMs (for virtual/hybrid
+   deployments) and/or VCP VMs (for baremetal deployments).
+   Defaults to 'ubuntu1804' (Bionic).
 -P Skip installing dependency distro packages on current host
    This flag should only be used if you have kept back older packages that
    would be upgraded and that is undesirable on the current system.
@@ -131,16 +141,19 @@ DEPLOY_DIR=$(cd "${MCP_REPO_ROOT_PATH}/mcp/scripts"; pwd)
 MCP_STORAGE_DIR='/var/lib/opnfv/tmpdir'
 URI_REGEXP='(file|https?|ftp)://.*'
 BASE_CONFIG_URI="file://${MCP_REPO_ROOT_PATH}/mcp/scripts/pharos"
+OPNFV_BRANCH=$(sed -ne 's/defaultbranch=//p' "${MCP_REPO_ROOT_PATH}/.gitreview")
+DEF_DOCKER_TAG=$(basename "${OPNFV_BRANCH/master/latest}")
 
 # Customize deploy workflow
 DRY_RUN=${DRY_RUN:-0}
 USE_EXISTING_PKGS=${USE_EXISTING_PKGS:-0}
 USE_EXISTING_INFRA=${USE_EXISTING_INFRA:-0}
-NO_DEPLOY_ENVIRONMENT=${NO_DEPLOY_ENVIRONMENT:-0}
+MCP_NO_DEPLOY_ENVIRONMENT=${MCP_NO_DEPLOY_ENVIRONMENT:-0}
 ERASE_ENV=${ERASE_ENV:-0}
 MCP_VCP=${MCP_VCP:-1}
-MCP_DOCKER_TAG=${MCP_DOCKER_TAG:-latest}
+MCP_DOCKER_TAG=${MCP_DOCKER_TAG:-${DEF_DOCKER_TAG}}
 MCP_CMP_SS=${MCP_CMP_SS:-0}
+MCP_OS=${MCP_OS:-ubuntu1804}
 
 source "${DEPLOY_DIR}/globals.sh"
 source "${DEPLOY_DIR}/lib.sh"
@@ -156,7 +169,7 @@ source "${DEPLOY_DIR}/lib_jump_deploy.sh"
 # BEGIN of main
 #
 set +x
-while getopts "b:dDfEFl:L:Np:Ps:S:he" OPTION
+while getopts "b:dDfEFl:L:No:p:Ps:S:he" OPTION
 do
     case $OPTION in
         b)
@@ -177,7 +190,7 @@ do
             ((USE_EXISTING_INFRA+=1))
             ;;
         F|e)
-            NO_DEPLOY_ENVIRONMENT=1
+            ((MCP_NO_DEPLOY_ENVIRONMENT+=1))
             ;;
         E)
             ((ERASE_ENV+=1))
@@ -194,6 +207,9 @@ do
         N)
             MCP_VCP=0
             ;;
+        o)
+            MCP_OS=${OPTARG}
+            ;;
         p)
             TARGET_POD=${OPTARG}
             ;;
@@ -251,6 +267,10 @@ else
     jumpserver_pkg_install 'deploy'
     docker_install "${MCP_STORAGE_DIR}"
     virtinst_install "${MCP_STORAGE_DIR}"
+    # Ubuntu 18.04 cloud image requires newer e2fsprogs
+    if [[ "${MCP_OS:-}" =~ ubuntu1804 ]]; then
+        e2fsprogs_install "${MCP_STORAGE_DIR}"
+    fi
 fi
 
 if ! ${VIRSH} list >/dev/null 2>&1; then
@@ -277,7 +297,8 @@ export MAAS_SSH_KEY="$(cat "$(basename "${SSH_KEY}").pub")"
 # Expand jinja2 templates based on PDF data and env vars
 [[ "${DEPLOY_SCENARIO}" =~ -ha$ ]] || MCP_VCP=0
 export MCP_REPO_ROOT_PATH MCP_VCP MCP_STORAGE_DIR MCP_DOCKER_TAG MCP_CMP_SS \
-       MCP_JUMP_ARCH=$(uname -i) MCP_DEPLOY_SCENARIO="${DEPLOY_SCENARIO}"
+       MCP_JUMP_ARCH=$(uname -i) MCP_DEPLOY_SCENARIO="${DEPLOY_SCENARIO}" \
+       MCP_NO_DEPLOY_ENVIRONMENT MCP_OS
 do_templates_scenario "${MCP_STORAGE_DIR}" "${TARGET_LAB}" "${TARGET_POD}" \
                       "${BASE_CONFIG_URI}" "${SCENARIO_DIR}" \
                       "${SCENARIO_DIR}/${DEPLOY_SCENARIO}.yaml"
@@ -290,23 +311,26 @@ source "${DEPLOY_DIR}/xdf_data.sh"
 
 # Jumpserver prerequisites check
 notify "[NOTE] Using bridges: ${OPNFV_BRIDGES[*]}" 2
-jumpserver_check_requirements "${virtual_nodes[*]}" "${OPNFV_BRIDGES[@]}"
+jumpserver_check_requirements "${cluster_states[*]}" "${virtual_nodes[*]}" \
+                              "${OPNFV_BRIDGES[@]}"
 
 # Infra setup
 if [ ${DRY_RUN} -eq 1 ]; then
     notify "[NOTE] Dry run, skipping all deployment tasks" 2
     exit 0
+elif [ ${ERASE_ENV} -gt 2 ]; then
+    notify "[NOTE] Uninstall / cleanup all jumpserver Fuel resources" 2
+    cleanup_all "${MCP_STORAGE_DIR}" "${OPNFV_BRIDGES[@]}"
+    exit 0
 elif [ ${USE_EXISTING_INFRA} -gt 0 ]; then
     notify "[NOTE] Use existing infra: skip first ${USE_EXISTING_INFRA} states" 2
     notify "[STATE] Skipping: ${cluster_states[*]::${USE_EXISTING_INFRA}}" 2
 else
-    prepare_vms "${base_image}" "${MCP_STORAGE_DIR}" "${virtual_repos_pkgs}" \
-      "${virtual_nodes[@]}"
+    prepare_vms "${base_image}" "${MCP_STORAGE_DIR}" "${virtual_repos_pkgs}"
     create_networks "${OPNFV_BRIDGES[@]}"
     do_sysctl_cfg
     do_udev_cfg
     create_vms "${MCP_STORAGE_DIR}" "${virtual_nodes_data}" "${OPNFV_BRIDGES[@]}"
-    update_mcpcontrol_network
     start_vms "${virtual_nodes[@]}"
 
     # https://github.com/docker/libnetwork/issues/1743
@@ -320,7 +344,7 @@ check_connection
 
 # Openstack cluster setup
 set +x
-if [ ${NO_DEPLOY_ENVIRONMENT} -eq 1 ]; then
+if [ ${MCP_NO_DEPLOY_ENVIRONMENT} -eq 1 ]; then
     notify "[NOTE] Skip openstack cluster setup" 2
 else
     for state in "${cluster_states[@]:${USE_EXISTING_INFRA}}"; do