From 039ef4620198a444878fc3c864bebeda74f97378 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Tue, 7 May 2024 09:42:53 +0100 Subject: [PATCH] Add RH based script to do some testing --- do_sos_avocado_rh.sh | 100 +++++++++++++++++++++++++++++++++++++++++++ lxd_profile_rh.yaml | 62 +++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100755 do_sos_avocado_rh.sh create mode 100644 lxd_profile_rh.yaml diff --git a/do_sos_avocado_rh.sh b/do_sos_avocado_rh.sh new file mode 100755 index 0000000..069ebcc --- /dev/null +++ b/do_sos_avocado_rh.sh @@ -0,0 +1,100 @@ +#!/bin/bash + +#set -ax + +script_cmd=${0##*/} + +declare -A all_series + +all_series=( + ['centos8']="centos/8-Stream/cloud" + ['centos9']="centos/9-Stream/cloud" +) + +project_name="sos-testing-rh" +project="--project ${project_name}" +lxc="lxc ${project}" +lxc_exec="${lxc} exec" + +sos_location="$HOME/gitRepos/sos" + +lxc project create ${project_name} + +${lxc} profile edit default < lxd_profile_rh.yaml + +for distro in "${!all_series[@]}" +do + + inst_name=sos-avocado01-${distro} + + ${lxc} delete ${inst_name} --force + + image="images:${all_series[${distro}]}" + + ${lxc} launch ${image} ${inst_name} --vm -c limits.cpu=4 -c limits.memory=4GiB + + + if [[ "${script_cmd}" == "do_sos_avocado_rh.sh" ]] ; then + cd ${sos_location} + find . -type f -name "*.pyc" -exec sudo rm -f {} \; + rm -rf .tox *.snap *.deb + tar cfz /tmp/sos.tgz . + cd - + fi + + echo -n "Checking VM status of ${inst_name} " + + while true ; do + num_of_procs=$(${lxc} info ${inst_name} | yq .Resources.Processes) + [[ ${num_of_procs} -gt 0 ]] && break + sleep 3 + echo -n "." + done + + echo done + + if [[ "${script_cmd}" == "do_sos_avocado_rh.sh" ]] ; then + ${lxc} file push /tmp/sos.tgz ${inst_name}/root/sos.tgz + fi + + echo -n "Checking cloud-init status of ${inst_name} " + + while true ; do + status=$(${lxc_exec} ${inst_name} -- cloud-init status | grep status | awk '{print $2}') + [[ "${status}" == "done" ]] && break + [[ "${status}" == "error" ]] && break + sleep 3 + echo -n "." + done + + echo done + + if [[ "${script_cmd}" == "do_sos_testing.sh" ]] ; then + ${lxc_exec} ${inst_name} -- sudo add-apt-repository -y ppa:${ppa_user}/${ppa_name} + if [[ "${distro}" == "${latest_dev_series}" ]] ; then + filename="$(echo ${ppa_name} | sed 's/\./_/g')" + ${lxc_exec} ${inst_name} -- sed -i s/i${latest_sup_series}/${latest_dev_series}/g /etc/apt/sources.list.d/${ppa_user}-ubuntu-${filename}-${latest_sup_series}.list + fi + cat > setup_sos.sh << EOF +#!/bin/bash + +sos_type="${sos_type}" + +if [[ "\${sos_type}" == "deb" ]] ; then + apt -y install sosreport +elif [[ "\${sos_type}" == "snap" ]] ; then + snap install sosreport --channel ${sos_channel} --classic +fi +EOF + ${lxc} file push setup_sos.sh ${inst_name}/root/setup_sos.sh + fi + + if [[ "${script_cmd}" == "do_sos_avocado_rh.sh" ]] ; then + ${lxc_exec} ${inst_name} -- bash /root/run_avocado.sh + elif [[ "${script_cmd}" == "do_sos_testing.sh" ]] ; then + ${lxc_exec} ${inst_name} -- bash /root/setup_sos.sh + ${lxc_exec} ${inst_name} -- bash /root/run_sos.sh + fi + ${lxc} stop ${inst_name} + +done diff --git a/lxd_profile_rh.yaml b/lxd_profile_rh.yaml new file mode 100644 index 0000000..be79171 --- /dev/null +++ b/lxd_profile_rh.yaml @@ -0,0 +1,62 @@ +devices: + eth0: + name: eth0 + network: lxdbr0 + type: nic + root: + path: / + pool: virtual + type: disk +config: + user.user-data: | + #cloud-config + packages: + - tar + - git + - python3-pip + - ethtool + - dnf-plugins-core + write_files: + - path: /root/setup.sh + permissions: '0755' + owner: root:root + content: | + #!bin/bash + dnf remove sos + pip3 install tox==2.5.0 + - path: /root/run_avocado.sh + permissions: '0755' + owner: root:root + content: | + #!bin/bash + + mkdir -p /root/sos + cd /root/sos + tar xfz ../sos.tgz + + git config --global --add safe.directory /root/sos + + mkdir -p /etc/sos + cp sos.conf /etc/sos/sos.conf + + echo "Cleaning up any old .tox environments ..." + rm -rf .tox + + echo "Running Unit Tests ..." + tox -e unit_tests + + echo "Running Stage One Tests ..." + tox -e stageone_tests + + echo "Running Stage Two Tests ..." + tox -e stagetwo_tests + - path: /root/run_sos.sh + permissions: '0755' + owner: root:root + content: | + #!bin/bash + + sos report -a --all-logs --batch + + runcmd: + - [ /root/setup.sh ]