X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=blobdiff_plain;f=shell%2Fjenkins-configure-clouds.sh;h=78e233e7c2c2d5c47f363b3b53095ac90d83b1ac;hb=b55451a53da28d40c62de5cae462302a32fe4c31;hp=29a20de18496f1e3341180b594ecf0b93247ad7f;hpb=6ac3df63c1e23932be9ed1e5c1810d5e9bf3cf18;p=releng%2Fglobal-jjb.git diff --git a/shell/jenkins-configure-clouds.sh b/shell/jenkins-configure-clouds.sh index 29a20de1..78e233e7 100644 --- a/shell/jenkins-configure-clouds.sh +++ b/shell/jenkins-configure-clouds.sh @@ -43,9 +43,21 @@ mkdir -p "$SCRIPT_DIR" silos="${jenkins_silos:-jenkins}" + set -eu -o pipefail -version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; } +testversion() { + local current_val="$1" operator="$2" test_value="$3" + awk -vv1="$current_val" -vv2="$test_value" 'BEGIN { + split(v1, a, /\:/); + if (a[2] == '"$test_value"') { + exit (a[2] == '"$test_value"') ? 0 : 1 + } + else { + exit (a[2] '"$operator"' '"$test_value"') ? 0 : 1 + } + }' +} get_cfg() { if [ -z ${3+x} ]; then @@ -68,8 +80,9 @@ get_cfg() { } export get_cfg + get_cloud_cfg() { - if [ -z $1 ]; then + if [ -z "$1" ]; then >&2 echo "Usage: get_cloud_cfg CFG_DIR" exit 1 fi @@ -99,8 +112,9 @@ get_cloud_cfg() { echo ")" } + get_launcher_factory() { - if [ -z $1 ]; then + if [ -z "$1" ]; then >&2 echo "Usage: get_launcher_factory JNLP|SSH" exit 1 fi @@ -117,8 +131,9 @@ get_launcher_factory() { fi } + get_minion_options() { - if [ -z $1 ]; then + if [ -z "$1" ]; then >&2 echo "Usage: get_minion_options CFG_FILE" exit 1 fi @@ -133,6 +148,7 @@ get_minion_options() { # Fails on first instance of each different associatve array prefix # Fails when using single/double/no quotes, all of which are valid bash # shellcheck disable=SC2154 + flavors["acumos-highcpu-4-avx"]="c720c1f8-62e9-4695-823d-f7f54db46c86" flavors["lf-highcpu-2"]="1051d06a-61ea-45e3-b9b4-93de92880b27" flavors["lf-highcpu-4"]="35eb8e11-490f-4d1a-9f19-76091fc04547" flavors["lf-highcpu-8"]="68af673f-54ee-4255-871c-158c18e4f643" @@ -173,86 +189,82 @@ get_minion_options() { flavors["v2-standard-16"]="9e4b01cd-6744-4120-aafe-1b5e17584919" flavors["v2-standard-360"]="f0d27f44-a410-4f0f-9781-d722f5b5489e" + image_name=$(get_cfg "$cfg_file" IMAGE_NAME "") volume_size=$(get_cfg "$cfg_file" VOLUME_SIZE "") hardware_id=$(get_cfg "$cfg_file" HARDWARE_ID "") network_id=$(get_cfg "$cfg_file" NETWORK_ID "") - - udi_default="$(get_cfg "$(dirname $cfg_file)/cloud.cfg" USER_DATA_ID "jenkins-init-script")" + udi_default="$(get_cfg "$(dirname "$cfg_file")/cloud.cfg" USER_DATA_ID "jenkins-init-script")" user_data_id=$(get_cfg "$cfg_file" USER_DATA_ID "$udi_default") # Handle Sandbox systems that might have a different cap. - instance_cap=$(get_cfg "$cfg_file" INSTANCE_CAP "null") if [ "$silo" == "sandbox" ]; then instance_cap=$(get_cfg "$cfg_file" SANDBOX_CAP "null") + else + instance_cap=$(get_cfg "$cfg_file" INSTANCE_CAP "null") fi - min_instance_cap=$(get_cfg "$cfg_file" MIN_INSTANCE_CAP "null") floating_ip_pool=$(get_cfg "$cfg_file" FLOATING_IP_POOL "") security_groups=$(get_cfg "$cfg_file" SECURITY_GROUPS "default") availability_zone=$(get_cfg "$cfg_file" AVAILABILITY_ZONE "") start_timeout=$(get_cfg "$cfg_file" START_TIMEOUT "600000") - - kpn_default="$(get_cfg "$(dirname $cfg_file)/cloud.cfg" KEY_PAIR_NAME "jenkins-ssh")" + kpn_default="$(get_cfg "$(dirname "$cfg_file")/cloud.cfg" KEY_PAIR_NAME "jenkins-ssh")" key_pair_name=$(get_cfg "$cfg_file" KEY_PAIR_NAME "$kpn_default") - num_executors=$(get_cfg "$cfg_file" NUM_EXECUTORS "1") jvm_options=$(get_cfg "$cfg_file" JVM_OPTIONS "") fs_root=$(get_cfg "$cfg_file" FS_ROOT "/w") - retention_time=$(get_cfg "$cfg_file" RETENTION_TIME "0") connection_type=$(get_cfg "$cfg_file" CONNECTION_TYPE "SSH") launcher_factory=$(get_launcher_factory "$connection_type") + node_properties=$(get_cfg "$cfg_file" NODE_PROPERTIES, "null") + retention_time=$(get_cfg "$cfg_file" RETENTION_TIME "0") + config_drive=$(get_cfg "$cfg_file" CONFIG_DRIVE, "null") + - OS_PLUGIN_VER="$(lftools jenkins plugins list \ - | grep -i 'OpenStack Cloud Plugin' \ - | awk -F':' '{print $2}' | awk -F' ' '{print $1}')" - if version_ge "$OS_PLUGIN_VER" "2.35"; then - if [ ! -z "$volume_size" ]; then - echo " new BootSource.VolumeFromImage(\"$image_name\", $volume_size)," - else - echo " new BootSource.Image(\"$image_name\")," - fi - echo " \"${flavors[${hardware_id}]}\"," - echo " \"$network_id\"," - echo " \"$user_data_id\"," - echo " $instance_cap," - echo " $min_instance_cap," - echo " \"$floating_ip_pool\"," - echo " \"$security_groups\"," - echo " \"$availability_zone\"," - echo " $start_timeout," - echo " \"$key_pair_name\"," - echo " $num_executors," - echo " \"$jvm_options\"," - echo " \"$fs_root\"," - echo " $launcher_factory," - echo " $retention_time" - - else # SlaveOptions() structure for versions <= 2.34 - if [ ! -z "$volume_size" ]; then - echo " new BootSource.VolumeFromImage(\"$image_name\", $volume_size)," - else - echo " new BootSource.Image(\"$image_name\")," - fi - echo " \"${flavors[${hardware_id}]}\"," - echo " \"$network_id\"," - echo " \"$user_data_id\"," - echo " $instance_cap," - echo " \"$floating_ip_pool\"," - echo " \"$security_groups\"," - echo " \"$availability_zone\"," - echo " $start_timeout," - echo " \"$key_pair_name\"," - echo " $num_executors," - echo " \"$jvm_options\"," - echo " \"$fs_root\"," - echo " $launcher_factory," - echo " $retention_time" + if [ -n "$volume_size" ]; then + echo " new BootSource.VolumeFromImage(\"$image_name\", $volume_size)," + else + echo " new BootSource.Image(\"$image_name\")," fi + + echo " \"${flavors[${hardware_id}]}\"," + echo " \"$network_id\"," + echo " \"$user_data_id\"," + echo " $instance_cap," + + # Handle specifying the minimum instance count across different versions + if testversion "$os_plugin_version" '>=' '2.47' + then + instance_min=$(get_cfg "$cfg_file" INSTANCE_MIN "null") + echo " $instance_min," + else + instance_min=$(get_cfg "$cfg_file" INSTANCE_MIN_CAPMAX "null") + echo " $instance_min," + fi + + echo " \"$floating_ip_pool\"," + echo " \"$security_groups\"," + echo " \"$availability_zone\"," + echo " $start_timeout," + echo " \"$key_pair_name\"," + echo " $num_executors," + echo " \"$jvm_options\"," + echo " \"$fs_root\"," + echo " $launcher_factory," + + if testversion "$os_plugin_version" '>=' '2.47' + then + echo " $node_properties," + echo " $retention_time", + echo " $config_drive" + else + echo " $retention_time" + fi + + } get_template_cfg() { - if [ -z $2 ]; then + if [ -z "$2" ]; then >&2 echo "Usage: get_template_cfg CFG_FILE SILO [MINION_PREFIX]" exit 1 fi @@ -262,7 +274,7 @@ get_template_cfg() { local minion_prefix="${3:-}" - template_name=$(basename $cfg_file .cfg) + template_name=$(basename "$cfg_file" .cfg) labels=$(get_cfg "$cfg_file" LABELS "") echo "minion_options = new SlaveOptions(" @@ -277,7 +289,8 @@ get_template_cfg() { echo ")" } -mapfile -t clouds < <(ls -d1 $OS_CLOUD_DIR/*/) + +mapfile -t clouds < <(ls -d1 "$OS_CLOUD_DIR"/*/) for silo in $silos; do @@ -303,22 +316,30 @@ for silo in $silos; do export JENKINS_USER export JENKINS_PASSWORD + # JENKINS_{URL,USER,PASSWORD} env vars are required for the "lftools jenkins + # plugins list" call + os_plugin_version="$(lftools jenkins plugins list \ + | grep -i 'OpenStack Cloud Plugin')" + echo "-----> Groovy script $script_file" for cloud in "${clouds[@]}"; do cfg_dir="${cloud}" echo "Processing $cfg_dir" - insert_file="$SCRIPT_DIR/$silo/$(basename $cloud)/cloud-cfg.txt" - mkdir -p "$(dirname $insert_file)" + insert_file="$SCRIPT_DIR/$silo/$(basename "$cloud")/cloud-cfg.txt" + mkdir -p "$(dirname "$insert_file")" rm -f "$insert_file" - echo "" >> "$insert_file" - echo "//////////////////////////////////////////////////" >> "$insert_file" - echo "// Cloud config for $(basename $cloud)" >> "$insert_file" - echo "//////////////////////////////////////////////////" >> "$insert_file" - echo "" >> "$insert_file" + { + echo "" + echo "//////////////////////////////////////////////////" + echo "// Cloud config for $(basename "$cloud")" + echo "//////////////////////////////////////////////////" + echo "" + } >> "$insert_file" + - echo "templates = []" >> $insert_file - mapfile -t templates < <(find $cfg_dir -maxdepth 1 -not -type d -not -name "cloud.cfg") + echo "templates = []" >> "$insert_file" + mapfile -t templates < <(find "$cfg_dir" -maxdepth 1 -not -type d -not -name "cloud.cfg") for template in "${templates[@]}"; do get_template_cfg "$template" "$silo" "$node_prefix" >> "$insert_file" echo "templates.add(template)" >> "$insert_file"