[libvirt] [jenkins-ci PATCH 1/8] lcitool: Drop shell implementation

Andrea Bolognani abologna at redhat.com
Wed Jul 11 15:54:29 UTC 2018


We're going to rewrite the script completely, and getting
the current implementation out of the way firts will make
the diffs more reasonable.

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 guests/lcitool | 227 -------------------------------------------------
 1 file changed, 227 deletions(-)
 delete mode 100755 guests/lcitool

diff --git a/guests/lcitool b/guests/lcitool
deleted file mode 100755
index 0c1520e..0000000
--- a/guests/lcitool
+++ /dev/null
@@ -1,227 +0,0 @@
-#!/bin/sh
-
-# -------------------
-#  Utility functions
-# -------------------
-
-# die MESSAGE
-#
-# Abort the program after displaying $MESSAGE on standard error.
-die() {
-    echo "$1" >&2
-    exit 1
-}
-
-# hash_file PASS_FILE
-#
-# Generate a password hash from the contents of PASS_FILE.
-hash_file() {
-    PASS_FILE="$1"
-
-    perl -le '
-        my @chars = ("A".."Z", "a".."z", "0".."9");
-        my $salt; $salt .= $chars[rand @chars] for 1..16;
-        my $handle; open($handle, "'"$PASS_FILE"'");
-        my $pass = <$handle>; chomp($pass);
-        print crypt("$pass", "\$6\$$salt\$");'
-}
-
-# yaml_var FILE VAR
-#
-# Read $FILE and output the value of YAML variable $VAR. Only trivial YAML
-# values are supported, eg. strings and numbers that don't depend on the
-# value of other variables. That's enough for our use case.
-yaml_var() {
-    grep "^$2:\\s*" "$1" 2>/dev/null | tail -1 | sed "s/$2:\\s*//g"
-}
-
-# load_install_config FILE
-#
-# Read all known configuration variables from $FILE and set them in the
-# environment. Configuration variables that have already been set in
-# the environment will not be updated.
-load_install_config() {
-    INSTALL_URL=${INSTALL_URL:-$(yaml_var "$1" install_url)}
-    INSTALL_CONFIG=${INSTALL_CONFIG:-$(yaml_var "$1" install_config)}
-    INSTALL_VIRT_TYPE=${INSTALL_VIRT_TYPE:-$(yaml_var "$1" install_virt_type)}
-    INSTALL_ARCH=${INSTALL_ARCH:-$(yaml_var "$1" install_arch)}
-    INSTALL_MACHINE=${INSTALL_MACHINE:-$(yaml_var "$1" install_machine)}
-    INSTALL_CPU_MODEL=${INSTALL_CPU_MODEL:-$(yaml_var "$1" install_cpu_model)}
-    INSTALL_VCPUS=${INSTALL_VCPUS:-$(yaml_var "$1" install_vcpus)}
-    INSTALL_MEMORY_SIZE=${INSTALL_MEMORY_SIZE:-$(yaml_var "$1" install_memory_size)}
-    INSTALL_DISK_SIZE=${INSTALL_DISK_SIZE:-$(yaml_var "$1" install_disk_size)}
-    INSTALL_STORAGE_POOL=${INSTALL_STORAGE_POOL:-$(yaml_var "$1" install_storage_pool)}
-    INSTALL_NETWORK=${INSTALL_NETWORK:-$(yaml_var "$1" install_network)}
-}
-
-# load_config
-#
-# Read tool configuration and perform the necessary validation.
-load_config() {
-    CONFIG_DIR="$HOME/.config/$PROGRAM_NAME"
-
-    mkdir -p "$CONFIG_DIR" >/dev/null 2>&1 || {
-        die "$PROGRAM_NAME: $CONFIG_DIR: Unable to create config directory"
-    }
-
-    FLAVOR_FILE="$CONFIG_DIR/flavor"
-    VAULT_PASS_FILE="$CONFIG_DIR/vault-password"
-    ROOT_PASS_FILE="$CONFIG_DIR/root-password"
-
-    # Two flavors are supported: test (default) and jenkins. Read the
-    # flavor from configuration, validate it and write it back in case
-    # it was not present
-    FLAVOR="$(cat "$FLAVOR_FILE" 2>/dev/null)"
-    FLAVOR=${FLAVOR:-test}
-    test "$FLAVOR" = test || test "$FLAVOR" = jenkins || {
-        die "$PROGRAM_NAME: Invalid flavor '$FLAVOR'"
-    }
-    echo "$FLAVOR" >"$FLAVOR_FILE" || {
-        die "$PROGRAM_NAME: $FLAVOR_FILE: Unable to save flavor"
-    }
-
-    test "$FLAVOR" = jenkins && {
-        # The vault password is only needed for the jenkins flavor, so only
-        # validate it in that case
-        test -f "$VAULT_PASS_FILE" && test "$(cat "$VAULT_PASS_FILE")" || {
-            die "$PROGRAM_NAME: $VAULT_PASS_FILE: Missing or invalid password"
-        }
-    } || {
-        # For other flavors, undefine the variable so that Ansible
-        # will not try to read the file at all
-        VAULT_PASS_FILE=
-    }
-
-    # Make sure the root password has been configured properly
-    test -f "$ROOT_PASS_FILE" && test "$(cat "$ROOT_PASS_FILE")" || {
-        die "$PROGRAM_NAME: $ROOT_PASS_FILE: Missing or invalid password"
-    }
-
-    ROOT_HASH_FILE="$CONFIG_DIR/.root-password.hash"
-
-    # Regenerate root password hash. Ansible expects passwords as hashes but
-    # doesn't provide a built-in facility to generate one from plain text
-    hash_file "$ROOT_PASS_FILE" >"$ROOT_HASH_FILE" || {
-        die "$PROGRAM_NAME: Failure while hashing root password"
-    }
-}
-
-# ----------------------
-#  User-visible actions
-# ----------------------
-
-do_help() {
-    echo "\
-Usage: $CALL_NAME ACTION [OPTIONS]
-
-Actions:
-  list                 List known guests
-  install GUEST        Install GUEST
-  prepare GUEST|all    Prepare or update GUEST. Can be run multiple times
-  update  GUEST|all    Alias for prepare
-  help                 Display this help"
-}
-
-do_list() {
-    # List all guests present in the inventory. Skip group names,
-    # comments and empty lines
-    grep -vE '^#|^\[|^$' inventory | sort -u
-}
-
-do_install()
-{
-    GUEST="$1"
-
-    test "$GUEST" || {
-        die "$(do_help)"
-    }
-    do_list | grep -q "$GUEST" || {
-        die "$PROGRAM_NAME: $GUEST: Unknown guest"
-    }
-    test -f "host_vars/$GUEST/install.yml" || {
-        die "$PROGRAM_NAME: $GUEST: Missing configuration, guest must be installed manually"
-    }
-
-    load_config
-
-    # Load configuration files. Values don't get overwritten after being
-    # set the first time, so loading the host-specific configuration before
-    # the group configuration ensures overrides work as expected
-    load_install_config "host_vars/$GUEST/install.yml"
-    load_install_config "group_vars/all/install.yml"
-
-    # Both memory size and disk size use GiB as unit, but virt-install wants
-    # disk size in GiB and memory size in *MiB*, so perform conversion here
-    INSTALL_MEMORY_SIZE=$(expr "$INSTALL_MEMORY_SIZE" \* 1024 2>/dev/null)
-
-    # preseed files must use a well-known name to be picked up by d-i;
-    # for kickstart files, we can use whatever name we please but we need
-    # to point anaconda in the right direction through a kernel argument
-    case "$INSTALL_CONFIG" in
-        *kickstart*|*ks*) EXTRA_ARGS="ks=file:/${INSTALL_CONFIG##*/}" ;;
-    esac
-
-    # Only configure autostart for the guest for the jenkins flavor
-    test "$FLAVOR" = jenkins && {
-        AUTOSTART="--autostart"
-    }
-
-    virt-install \
-        --name "$GUEST" \
-        --location "$INSTALL_URL" \
-        --virt-type "$INSTALL_VIRT_TYPE" \
-        --arch "$INSTALL_ARCH" \
-        --machine "$INSTALL_MACHINE"  \
-        --cpu "$INSTALL_CPU_MODEL" \
-        --vcpus "$INSTALL_VCPUS" \
-        --memory "$INSTALL_MEMORY_SIZE" \
-        --disk "size=$INSTALL_DISK_SIZE,pool=$INSTALL_STORAGE_POOL,bus=virtio" \
-        --network "network=$INSTALL_NETWORK,model=virtio" \
-        --graphics none \
-        --console pty \
-        --sound none \
-        --initrd-inject "$INSTALL_CONFIG" \
-        --extra-args "console=ttyS0 $EXTRA_ARGS" \
-        $AUTOSTART \
-        --wait 0
-}
-
-do_prepare() {
-    GUEST="$1"
-
-    test "$GUEST" || {
-        die "$(do_help)"
-    }
-    do_list | grep -q "$GUEST" || test "$GUEST" = all || {
-        die "$PROGRAM_NAME: $GUEST: Unknown guest"
-    }
-
-    load_config
-
-    EXTRA_VARS="flavor=$FLAVOR root_password_file=$ROOT_HASH_FILE"
-
-    ansible-playbook \
-        --vault-password-file "$VAULT_PASS_FILE" \
-        --extra-vars "$EXTRA_VARS" \
-        -l "$GUEST" \
-        site.yml
-}
-
-# ---------------------
-#  Program entry point
-# ---------------------
-
-CALL_NAME="$0"
-PROGRAM_NAME="${0##*/}"
-
-test -f "$PROGRAM_NAME" || {
-    die "$PROGRAM_NAME: Must be run from the source directory"
-}
-
-case "$1" in
-    list)           do_list ;;
-    install)        do_install "$2" ;;
-    prepare|update) do_prepare "$2" ;;
-    *help)          do_help ;;
-    *)              die "$(do_help)" ;;
-esac
-- 
2.17.1




More information about the libvir-list mailing list