From f2a5fc19a4aa99e2246d16b50f01dbe494b1e31c Mon Sep 17 00:00:00 2001 From: David Murphy Date: Mon, 11 Nov 2024 15:18:55 -0700 Subject: [PATCH] Update testing --- bootstrap-salt.sh | 120 ++++++++++++++++++++++++- tests/integration/test_installation.py | 29 ++++-- 2 files changed, 140 insertions(+), 9 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index ab94e5f..958e303 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -936,6 +936,10 @@ fi # DESCRIPTION: Retrieves a URL and writes it to a given path #---------------------------------------------------------------------------------------------------------------------- __fetch_url() { + # DGM debug + set -v + set -x + # shellcheck disable=SC2086 curl $_CURL_ARGS -L -s -f -o "$1" "$2" >/dev/null 2>&1 || wget $_WGET_ARGS -q -O "$1" "$2" >/dev/null 2>&1 || @@ -950,6 +954,10 @@ __fetch_url() { # DESCRIPTION: Retrieves a URL, verifies its content and writes it to standard output #---------------------------------------------------------------------------------------------------------------------- __fetch_verify() { + # DGM debug + set -v + set -x + fetch_verify_url="$1" fetch_verify_sum="$2" @@ -972,6 +980,10 @@ __fetch_verify() { # DESCRIPTION: Checks if a URL exists #---------------------------------------------------------------------------------------------------------------------- __check_url_exists() { + # DGM debug + set -v + set -x + _URL="$1" if curl --output /dev/null --silent --fail "${_URL}"; then @@ -1940,6 +1952,10 @@ __function_defined() { # process is finished so the script doesn't exit on a locked proc. #---------------------------------------------------------------------------------------------------------------------- __wait_for_apt(){ + # DGM debug + set -v + set -x + # Timeout set at 15 minutes WAIT_TIMEOUT=900 @@ -1977,6 +1993,10 @@ __wait_for_apt(){ # PARAMETERS: packages #---------------------------------------------------------------------------------------------------------------------- __apt_get_install_noinput() { + # DGM debug + set -v + set -x + __wait_for_apt apt-get install -y -o DPkg::Options::=--force-confold "${@}"; return $? } # ---------- end of function __apt_get_install_noinput ---------- @@ -1987,6 +2007,9 @@ __apt_get_install_noinput() { # DESCRIPTION: (DRY) apt-get upgrade with noinput options #---------------------------------------------------------------------------------------------------------------------- __apt_get_upgrade_noinput() { + # DGM debug + set -v + set -x __wait_for_apt apt-get upgrade -y -o DPkg::Options::=--force-confold; return $? } # ---------- end of function __apt_get_upgrade_noinput ---------- @@ -2018,7 +2041,9 @@ __temp_gpg_pub() { # PARAMETERS: url #---------------------------------------------------------------------------------------------------------------------- __apt_key_fetch() { - + # DGM debug + set -v + set -x url=$1 @@ -2627,6 +2652,10 @@ __activate_virtualenv() { #---------------------------------------------------------------------------------------------------------------------- __install_pip_pkgs() { + # DGM debug + set -v + set -x + _pip_pkgs="$1" _py_exe="$2" _py_pkg=$(echo "$_py_exe" | sed -E "s/\\.//g") @@ -2668,6 +2697,10 @@ __install_pip_pkgs() { # PARAMETERS: requirements_file #---------------------------------------------------------------------------------------------------------------------- __install_pip_deps() { + # DGM debug + set -v + set -x + # Install virtualenv to system pip before activating virtualenv if thats going to be used # We assume pip pkg is installed since that is distro specific if [ "$_VIRTUALENV_DIR" != "null" ]; then @@ -2704,6 +2737,9 @@ __install_pip_deps() { # PARAMETERS: py_exe #---------------------------------------------------------------------------------------------------------------------- __install_salt_from_repo() { + # DGM debug + set -v + set -x _py_exe="$1" @@ -2952,6 +2988,9 @@ fi # Ubuntu Install Functions # __enable_universe_repository() { + # DGM debug + set -v + set -x if [ "$(grep -R universe /etc/apt/sources.list /etc/apt/sources.list.d/ | grep -v '#')" != "" ]; then # The universe repository is already enabled @@ -2966,6 +3005,10 @@ __enable_universe_repository() { } __install_saltstack_ubuntu_repository() { + # DGM debug + set -v + set -x + # Workaround for latest non-LTS Ubuntu echodebug "__install_saltstack_ubuntu_repository() entry" @@ -3024,6 +3067,9 @@ __install_saltstack_ubuntu_repository() { } __install_saltstack_ubuntu_onedir_repository() { + # DGM debug + set -v + set -x echodebug "__install_saltstack_ubuntu_onedir_repository() entry" # Workaround for latest non-LTS Ubuntu @@ -3075,6 +3121,9 @@ __install_saltstack_ubuntu_onedir_repository() { } install_ubuntu_deps() { + # DGM debug + set -v + set -x echodebug "install_ubuntu_deps() entry" if [ "$_DISABLE_REPOS" -eq $BS_FALSE ]; then @@ -3133,6 +3182,9 @@ install_ubuntu_deps() { } install_ubuntu_stable_deps() { + # DGM debug + set -v + set -x echodebug "install_ubuntu_stable_deps() entry" @@ -3168,6 +3220,9 @@ install_ubuntu_stable_deps() { } install_ubuntu_git_deps() { + # DGM debug + set -v + set -x echodebug "install_ubuntu_git_deps() entry" @@ -3211,6 +3266,9 @@ install_ubuntu_git_deps() { } install_ubuntu_onedir_deps() { + # DGM debug + set -v + set -x if [ "$_START_DAEMONS" -eq $BS_FALSE ]; then echowarn "Not starting daemons on Debian based distributions is not working mostly because starting them is the default behaviour." @@ -3244,6 +3302,9 @@ install_ubuntu_onedir_deps() { } install_ubuntu_stable() { + # DGM debug + set -v + set -x __PACKAGES="" @@ -3271,6 +3332,9 @@ install_ubuntu_stable() { } install_ubuntu_git() { + # DGM debug + set -v + set -x # Activate virtualenv before install if [ "${_VIRTUALENV_DIR}" != "null" ]; then @@ -3301,6 +3365,9 @@ install_ubuntu_git() { } install_ubuntu_onedir() { + # DGM debug + set -v + set -x __PACKAGES="" @@ -3328,6 +3395,9 @@ install_ubuntu_onedir() { } install_ubuntu_stable_post() { + # DGM debug + set -v + set -x for fname in api master minion syndic; do # Skip salt-api since the service should be opt-in and not necessarily started on boot @@ -3356,6 +3426,9 @@ install_ubuntu_stable_post() { } install_ubuntu_git_post() { + # DGM debug + set -v + set -x for fname in api master minion syndic; do # Skip if not meant to be installed @@ -3401,6 +3474,9 @@ install_ubuntu_git_post() { } install_ubuntu_restart_daemons() { + # DGM debug + set -v + set -x [ "$_START_DAEMONS" -eq $BS_FALSE ] && return @@ -3443,6 +3519,9 @@ install_ubuntu_restart_daemons() { } install_ubuntu_check_services() { + # DGM debug + set -v + set -x for fname in api master minion syndic; do # Skip salt-api since the service should be opt-in and not necessarily started on boot @@ -4159,6 +4238,9 @@ install_fedora_onedir_post() { # CentOS Install Functions # __install_saltstack_rhel_onedir_repository() { + # DGM debug + set -v + set -x if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -ne 3 ]; then echoerror "Python version is no longer supported, only Python 3" @@ -4191,6 +4273,9 @@ __install_saltstack_rhel_onedir_repository() { } install_centos_stable_deps() { + # DGM debug + set -v + set -x if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then yum -y update || return 1 @@ -4229,6 +4314,9 @@ install_centos_stable_deps() { } install_centos_stable() { + # DGM debug + set -v + set -x __PACKAGES="" @@ -4263,6 +4351,9 @@ install_centos_stable() { } install_centos_stable_post() { + # DGM debug + set -v + set -x SYSTEMD_RELOAD=$BS_FALSE @@ -4295,6 +4386,9 @@ install_centos_stable_post() { } install_centos_git_deps() { + # DGM debug + set -v + set -x # First try stable deps then fall back to onedir deps if that one fails # if we're installing on a Red Hat based host that doesn't have the classic @@ -4341,6 +4435,9 @@ install_centos_git_deps() { } install_centos_git() { + # DGM debug + set -v + set -x if [ "${_PY_EXE}" != "" ]; then _PYEXE=${_PY_EXE} @@ -4357,6 +4454,9 @@ install_centos_git() { } install_centos_git_post() { + # DGM debug + set -v + set -x SYSTEMD_RELOAD=$BS_FALSE @@ -4399,6 +4499,9 @@ install_centos_git_post() { } install_centos_onedir_deps() { + # DGM debug + set -v + set -x if [ "$_UPGRADE_SYS" -eq "$BS_TRUE" ]; then yum -y update || return 1 @@ -4436,6 +4539,9 @@ install_centos_onedir_deps() { } install_centos_onedir() { + # DGM debug + set -v + set -x __PACKAGES="" @@ -4463,6 +4569,9 @@ install_centos_onedir() { } install_centos_onedir_post() { + # DGM debug + set -v + set -x SYSTEMD_RELOAD=$BS_FALSE @@ -4495,6 +4604,9 @@ install_centos_onedir_post() { } install_centos_restart_daemons() { + # DGM debug + set -v + set -x [ "$_START_DAEMONS" -eq $BS_FALSE ] && return @@ -4525,6 +4637,9 @@ install_centos_restart_daemons() { } install_centos_testing_deps() { + # DGM debug + set -v + set -x install_centos_stable_deps || return 1 return 0 @@ -4543,6 +4658,9 @@ install_centos_testing_post() { } install_centos_check_services() { + # DGM debug + set -v + set -x for fname in api master minion syndic; do # Skip salt-api since the service should be opt-in and not necessarily started on boot diff --git a/tests/integration/test_installation.py b/tests/integration/test_installation.py index 9a37498..65294a1 100644 --- a/tests/integration/test_installation.py +++ b/tests/integration/test_installation.py @@ -3,6 +3,7 @@ import logging import os import platform import subprocess +import tempfile import pytest @@ -24,14 +25,26 @@ def run_salt_call(cmd): Runs salt call command and returns a dictionary Accepts cmd as a list """ - cmd.append("--out=json") - result = subprocess.run(cmd, capture_output=True, text=True) - print( - f"DGM run_salt_call, cmd '{cmd}', result '{result}', stdout '{result.stdout}'", - flush=True, - ) - json_data = json.loads(result.stdout) - return json_data["local"] + tmpf = tempfile.NamedTemporaryFile(delete=False) + json_data = {"local": {}} + + try: + cmd.append("--out=json") + cmd.append(f"--log-file={tmpf.name}") + result = subprocess.run(cmd, capture_output=True, text=True) + print( + f"DGM run_salt_call, cmd '{cmd}', result '{result}', stdout '{result.stdout}'", + flush=True, + ) + if 0 == result.returncode: + json_data = json.loads(result.stdout) + else: + log.error(f"failed to produce output result, '{result}'") + + finally: + tmpf.close() + os.unlink(tmpf.name) + return json_data["local"] def test_ping(path):