From 41a619f3d473df79d88c1331b795604e48d222a8 Mon Sep 17 00:00:00 2001 From: Patrik Koncity Date: Mon, 9 Oct 2023 10:42:17 +0200 Subject: [PATCH] DRAFT: Prepare CI for tang operator --- .packit.yaml | 13 + Sanity/runnotest.sh | 38 --- Sanity/runtest.sh | 14 +- Sanity/{ => scripts}/mount_image.sh | 0 Sanity/{ => scripts}/umount_image.sh | 0 Sanity/tang_operator_test.sh | 49 ---- Sanity/tools/dependency_install.sh | 357 ----------------------- Setup/install_dependecies/main.fmf | 18 ++ Setup/install_dependecies/runtest-old.sh | 141 +++++++++ Setup/install_dependecies/runtest.sh | 91 ++++++ packit-ci.fmf | 21 ++ 11 files changed, 291 insertions(+), 451 deletions(-) create mode 100644 .packit.yaml delete mode 100755 Sanity/runnotest.sh rename Sanity/{ => scripts}/mount_image.sh (100%) rename Sanity/{ => scripts}/umount_image.sh (100%) delete mode 100755 Sanity/tang_operator_test.sh delete mode 100755 Sanity/tools/dependency_install.sh create mode 100644 Setup/install_dependecies/main.fmf create mode 100755 Setup/install_dependecies/runtest-old.sh create mode 100755 Setup/install_dependecies/runtest.sh create mode 100644 packit-ci.fmf diff --git a/.packit.yaml b/.packit.yaml new file mode 100644 index 0000000..ae5e370 --- /dev/null +++ b/.packit.yaml @@ -0,0 +1,13 @@ +jobs: +- job: tests + trigger: pull_request + branch: main + targets: + - fedora-all + skip_build: true + tf_extra_params: + environments: + - tmt: + context: + target_PR_branch: "main" + diff --git a/Sanity/runnotest.sh b/Sanity/runnotest.sh deleted file mode 100755 index 2de9243..0000000 --- a/Sanity/runnotest.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# runtest.sh of /CoreOS/tang-operator/Sanity -# Description: Deployment and basic functionality of the tang operator -# Author: Martin Zeleny -# -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# Copyright (c) 2021 Red Hat, Inc. -# -# This program is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation, either version 2 of -# the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied -# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see http://www.gnu.org/licenses/. -# -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -# Include Beaker environment -. /usr/share/beakerlib/beakerlib.sh || exit 1 - -UNSUPPORTED_RELEASE=$(awk -F "release" '{print $2}' < /etc/redhat-release\ - | sed -e 's/^[ /t]*//g' | awk '{print $1}' | awk -F '.' '{print $1}') - -rlJournalStart - rlPhaseStartTest "Check tang-operator controller is running" - rlRun "true" 0 "No test is executed (unsupported release:${UNSUPPORTED_RELEASE})" - rlPhaseEnd -rlJournalEnd diff --git a/Sanity/runtest.sh b/Sanity/runtest.sh index 3f30af9..4d70845 100755 --- a/Sanity/runtest.sh +++ b/Sanity/runtest.sh @@ -612,9 +612,9 @@ bundleStart() { fi if [ "${V}" == "1" ] || [ "${VERBOSE}" == "1" ]; then - operator-sdk run bundle --timeout ${TO_BUNDLE} ${IMAGE_VERSION} ${RUN_BUNDLE_PARAMS} --namespace ${OPERATOR_NAMESPACE} + operator-sdk_linux_amd64 run bundle --timeout ${TO_BUNDLE} ${IMAGE_VERSION} ${RUN_BUNDLE_PARAMS} --namespace ${OPERATOR_NAMESPACE} else - operator-sdk run bundle --timeout ${TO_BUNDLE} ${IMAGE_VERSION} ${RUN_BUNDLE_PARAMS} --namespace ${OPERATOR_NAMESPACE} 2>/dev/null + operator-sdk_linux_amd64 run bundle --timeout ${TO_BUNDLE} ${IMAGE_VERSION} ${RUN_BUNDLE_PARAMS} --namespace ${OPERATOR_NAMESPACE} 2>/dev/null fi return $? } @@ -626,9 +626,9 @@ bundleStop() { fi if [ "${V}" == "1" ] || [ "${VERBOSE}" == "1" ]; then - operator-sdk cleanup tang-operator --namespace ${OPERATOR_NAMESPACE} + operator-sdk_linux_amd64 cleanup tang-operator --namespace ${OPERATOR_NAMESPACE} else - operator-sdk cleanup tang-operator --namespace ${OPERATOR_NAMESPACE} 2>/dev/null + operator-sdk_linux_amd64 cleanup tang-operator --namespace ${OPERATOR_NAMESPACE} 2>/dev/null fi if [ $? -eq 0 ]; then @@ -750,7 +750,7 @@ getVersion() { analyzeVersion() { dumpVerbose "DETECTING MALWARE ON VERSION:[${1}]" "${CONTAINER_MGR}" pull "${1}" - dir_mount=$("${CONTAINER_MGR}" unshare ./mount_image.sh -v "${1}" -c "${CONTAINER_MGR}") + dir_mount=$("${CONTAINER_MGR}" unshare ./scripts/mount_image.sh -v "${1}" -c "${CONTAINER_MGR}") rlAssertEquals "Checking image could be mounted appropriately" "$?" "0" analyzed_dir=$(echo "${dir_mount}" | sed -e 's@/merged@@g') dumpVerbose "Analyzing directory:[${analyzed_dir}]" @@ -763,7 +763,7 @@ analyzeVersion() { rlLogWarning "${infected_files} Infected Files Detected!" rlLogWarning "Please, review Malware Detection log file: ${tmpdir}/${prefix}_malware.log" fi - "${CONTAINER_MGR}" unshare ./umount_image.sh -v "${1}" -c "${CONTAINER_MGR}" + "${CONTAINER_MGR}" unshare ./scripts/umount_image.sh -v "${1}" -c "${CONTAINER_MGR}" rlAssertEquals "Checking image could be umounted appropriately" "$?" "0" } @@ -775,7 +775,7 @@ rlJournalStart rlPhaseStartSetup rlRun "tmpdir=\$(mktemp -d)" 0 "Creating tmp directory" rlRun "dumpOpenShiftClientStatus" 0 "Checking OpenshiftClient installation" - rlRun "operator-sdk version > /dev/null" 0 "Checking operator-sdk installation" + rlRun "operator-sdk_linux_amd64 version > /dev/null" 0 "Checking operator-sdk installation" rlRun "checkClusterStatus" 0 "Checking cluster status" # In case previous execution was abruptelly stopped: rlRun "bundleStop" 0 "Cleaning already installed tang-operator (if any)" diff --git a/Sanity/mount_image.sh b/Sanity/scripts/mount_image.sh similarity index 100% rename from Sanity/mount_image.sh rename to Sanity/scripts/mount_image.sh diff --git a/Sanity/umount_image.sh b/Sanity/scripts/umount_image.sh similarity index 100% rename from Sanity/umount_image.sh rename to Sanity/scripts/umount_image.sh diff --git a/Sanity/tang_operator_test.sh b/Sanity/tang_operator_test.sh deleted file mode 100755 index 4e590f2..0000000 --- a/Sanity/tang_operator_test.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# Copyright (c) 2021 Red Hat, Inc. -# -# This program is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation, either version 2 of -# the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied -# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see http://www.gnu.org/licenses/. -# -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo "================ INFO ================" -echo "DATE:$(date)" -echo "HOSTNAME:$(hostname)" -echo "================ /INFO ===============" - -result=1 -./tools/dependency_install.sh -dep_res=$? -echo "Dependency installation result:${dep_res}" -echo "======= DIRECTORY:$(pwd) ========" - -if [ ${dep_res} -eq 255 ]; -then - # Architecture unsupported, just let it go in this arch - echo "Architecture execution bypassed" - ./runnotest.sh - result=$? -elif [ ${dep_res} -eq 0 ]; -then - chown minikube.minikube -R "$(pwd)" - # Ugly, but the way paths are managed (root dir not directory where running): - chown minikube.minikube -R "$(pwd)/../../../../../.." - # User minikube should have been installed, execute test as minikube user - su minikube -c '. ~/.bashrc && ./runtest.sh' - run_result=$? - echo "TEST EXECUTION RESULT:[${run_result}]" - result=${run_result} -fi -echo "RESULT:[${result}]" -exit "${result}" diff --git a/Sanity/tools/dependency_install.sh b/Sanity/tools/dependency_install.sh deleted file mode 100755 index d1510c6..0000000 --- a/Sanity/tools/dependency_install.sh +++ /dev/null @@ -1,357 +0,0 @@ -#!/bin/bash -# Copyright 2021. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# Uncomment next line to dump verbose information in script execution: -# set -x - -SM="subscription-manager" -OC_PATH=http://download.eng.bos.redhat.com/brewroot/vol/rhel-8/packages/openshift-clients/4.9.0/202109020218.p0.git.96e95ce.assembly.stream.el8/x86_64 -OC_FILE=openshift-clients-4.9.0-202109020218.p0.git.96e95ce.assembly.stream.el8.x86_64.rpm -OC_OUTPUT_FILE=openshift-clients-4.9.0.rpm -TMPDIR=$(mktemp -d) -TMPDIR_NON_TMPFS="${TMPDIR//\/tmp/}" -OC_INSTALL_FILE="${TMPDIR}/${OC_OUTPUT_FILE}" -CRC_PATH=https://developers.redhat.com/content-gateway/rest/mirror/pub/openshift-v4/clients/crc/latest -CRC_FILE=crc-linux-amd64.tar.xz -CRC_OUTPUT_FILE=crc-linux-amd64.tar.xz -CRC_INSTALL_FILE="${TMPDIR_NON_TMPFS}/${CRC_OUTPUT_FILE}" -CRC_PREFIX="crc-linux-[0-9]" -CRC_EXEC="crc" -CRC_VIRSH_DOMAIN="crc" -HOME_BASHRC="${HOME}/.bashrc" -CRC_USER="crc" -CRC_PASSWORD="crc1234crc5678" -CRC_HOME="/home/${CRC_USER}" -CRC_HOME_BIN="${CRC_HOME}/bin" -CRC_HOME_BASHRC="${CRC_HOME}/.bashrc" -CRC_EXEC_PATH="${CRC_HOME_BIN}/${CRC_EXEC}" -PULL_SECRET_PATH="$(dirname $(readlink -f $0))" -PULL_SECRET_FILENAME="public_pull_secret.txt" -PULL_SECRET_FILE="${PULL_SECRET_PATH}/${PULL_SECRET_FILENAME}" -PULL_SECRET_INSTALL_FILE="${TMPDIR}/${PULL_SECRET_FILENAME}" -MINIKUBE_URL="https://storage.googleapis.com/minikube/releases/latest" -MINIKUBE_FILE="minikube-latest.x86_64.rpm" -MINIKUBE_URL_FILE="${MINIKUBE_URL}/${MINIKUBE_FILE}" -RH_INSTALL=0 -RELEASE_K8S_URL="https://dl.k8s.io/release/" -STABLE_K8S_URL_FILE="https://dl.k8s.io/release/stable.txt" -BIN_LINUX_PATH="bin/linux/amd64" -MINIKUBE_USER="minikube" -MINIKUBE_HOME="/home/${MINIKUBE_USER}" -MINIKUBE_HOME_BIN="${MINIKUBE_HOME}/bin" -MINIKUBE_HOME_BASHRC="${MINIKUBE_HOME}/.bashrc" -MINIKUBE_CLIENT="kubectl" -OLM_INSTALL_TIMEOUT="5m" - -usage() { - echo "" - echo "Usage: $1 [-r redhat_installation (oc, crc)]" - echo "" - echo " -r: install RedHat tools (CRC, oc) instead of Minikube and kubectl" - echo "" - exit "$2" -} - -#### OC Installation -get_oc_rpm_adding_repo() { - POOL_ID=$("${SM}" list --available --matches 'Red Hat OpenShift Container Platform' | grep -i 'Pool ID' | awk -F ':' '{print $2}' | tr -d ' ' | head -1) - for pool_id in $("${SM}" list --available --matches 'Red Hat OpenShift Container Platform' | grep -i 'Pool ID' | awk -F ':' '{print $2}' | tr -d ' ') - do - "${SM}" attach --pool="${pool_id}" - echo "POOL_ID=${pool_id}" - for repo in $(subscription-manager repos --list | grep 'Repo ID:' | awk -F ':' '{print $2}'); - do - "${SM}" repos --enable="${repo}" - #"${SM}" repos --enable="rhocp-4.7-for-rhel-8-x86_64-rpms" - yum update - yum install openshift-clients - done - done - # - "${SM}" attach --pool="${POOL_ID}" - "${SM}" repos --enable="rhocp-4.8-for-rhel-8-x86_64-rpms" - yum install openshift-clients -} - -get_oc_rpm_with_wget() { - type oc && return 0 - wget "${OC_PATH}/${OC_FILE}" -O "${OC_INSTALL_FILE}" -} - -get_crc_tgz_with_wget() { - mkdir "${TMPDIR_NON_TMPFS}" - wget "${CRC_PATH}/${CRC_FILE}" -O "${CRC_INSTALL_FILE}" -} - -install_podman() { - type podman && return 0 - yum install -y podman -} - -install_jq() { - type jq && return 0 - yum install -y jq -} - -install_wget() { - type wget && return 0 - yum install -y wget -} - -install_network_manager() { - yum install -y NetworkManager - systemctl enable --now NetworkManager -} - -install_libvirtd() { - yum install -y libvirt-daemon - yum install -y libvirt-client -# yum install -y dbus-x11 - systemctl enable --now libvirt-daemon -} - -install_oc() { - type oc && return 0 - yum install -y "${OC_INSTALL_FILE}" -} - -install_crc() { - sudo -u "${CRC_USER}" /home/crc/bin/crc status && return 0 - test -f "${CRC_HOME_BIN}/${CRC_EXEC}" && return 0 - get_crc_tgz_with_wget - pushd "${TMPDIR_NON_TMPFS}" || exit - tar Jxvf "${CRC_OUTPUT_FILE}" - CRC_DIR=$(ls -d ${CRC_PREFIX}*) - pushd "${CRC_DIR}" || exit - rm -fr "${CRC_USER}"/.crc "${CRC_USER}"/.kube - virsh destroy "${CRC_VIRSH_DOMAIN}" - virsh undefine "${CRC_VIRSH_DOMAIN}" - cp "${CRC_EXEC}" "${CRC_HOME_BIN}" - cp "${HOME_BASHRC}" "${CRC_HOME_BASHRC}" - cat<>"${CRC_HOME_BASHRC}" - -# CRC installation PATH update -EOF - printf 'export PATH="${PATH}:' >> "${CRC_HOME_BASHRC}" - printf "%s\"\n" "${CRC_HOME_BIN}" >> "${CRC_HOME_BASHRC}" - popd || exit - popd || exit - # AVOID issues with systemctl and network manager - sudo loginctl enable-linger - sudo -u "${CRC_USER}" "${CRC_EXEC_PATH}" config set skip-check-daemon-systemd-unit true - sudo -u "${CRC_USER}" "${CRC_EXEC_PATH}" config set skip-check-daemon-systemd-sockets true - sudo -u "${CRC_USER}" "${CRC_EXEC_PATH}" config set skip-check-network-manager-running true - sudo -u "${CRC_USER}" "${CRC_EXEC_PATH}" config set skip-check-network-manager-installed true - sudo -u "${CRC_USER}" "${CRC_EXEC_PATH}" config set skip-check-network-manager-config true - - - ### 34 2021-09-07 12:41:44 sudo -u crc XDG_RUNTIME_DIR=/run/user/$(id -u $otherUser) systemctl --user - sudo -u "${CRC_USER}" XDG_RUNTIME_DIR="/run/user/$(id -u ${CRC_USER})" "${CRC_EXEC_PATH}" setup</dev/null || useradd "${CRC_USER}" - passwd "${CRC_USER}"<>/etc/sudoers - -### Add crc user to sudoers -"${CRC_USER}" ALL=(ALL) NOPASSWD:ALL -EOF - fi - test -d "${CRC_HOME_BIN}" || mkdir -p "${CRC_HOME_BIN}" - chown -R "${CRC_USER}.${CRC_USER}" "${CRC_HOME}" -} - -create_minikube_user() { - sudo -u "${MINIKUBE_USER}" true 2>/dev/null || useradd "${MINIKUBE_USER}" - mkdir -p "${MINIKUBE_HOME_BIN}" - chown -R "${MINIKUBE_USER}.${MINIKUBE_USER}" "${MINIKUBE_HOME}" - cp "${HOME_BASHRC}" "${MINIKUBE_HOME_BASHRC}" - printf 'export XDG_RUNTIME_DIR="' >> "${MINIKUBE_HOME_BASHRC}" - printf "%s\"\n\n" "/run/user/$(id -u ${MINIKUBE_USER})" >> "${MINIKUBE_HOME_BASHRC}" - grep -R "Add minikube user to sudoers" /etc/sudoers - if [ $? -ne 0 ]; - then - cat<>/etc/sudoers - -### Add minikube user to sudoers -"${MINIKUBE_USER}" ALL=(ALL) NOPASSWD:ALL -EOF - fi -} - -install_operator_sdk() { - ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n "$(uname -m)" ;; esac) - OS=$(uname | awk '{print tolower($0)}') - OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.12.0 - curl -LO "${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH}" - if [ ${RH_INSTALL} -eq 1 ]; - then - chmod +x "operator-sdk_${OS}_${ARCH}" && sudo mv "operator-sdk_${OS}_${ARCH}" "${CRC_HOME_BIN}/operator-sdk" - else - chmod +x "operator-sdk_${OS}_${ARCH}" && sudo mv "operator-sdk_${OS}_${ARCH}" "${MINIKUBE_HOME_BIN}/operator-sdk" - fi -} - -setup_crc() { - sudo -u "${CRC_USER}" oc adm policy add-scc-to-group anyuid system:authenticated -} - -install_minikube() { - curl -LO "${MINIKUBE_URL_FILE}" - rpm -Uvh "${MINIKUBE_FILE}" - rm "${MINIKUBE_FILE}" -} - -setup_minikube() { - minikube_user_id=$(id "${MINIKUBE_USER}" | awk {'print $1'} | egrep -E "[0-9]{1,}" -o) - loginctl enable-linger ${minikube_user_id} - pushd /tmp - sudo -u "${MINIKUBE_USER}" XDG_RUNTIME_DIR="/run/user/$(id -u ${MINIKUBE_USER})" podman ps - sudo -u "${MINIKUBE_USER}" XDG_RUNTIME_DIR="/run/user/$(id -u ${MINIKUBE_USER})" minikube start - sudo -u "${MINIKUBE_USER}" XDG_RUNTIME_DIR="/run/user/$(id -u ${MINIKUBE_USER})" podman ps - sudo -u "${MINIKUBE_USER}" XDG_RUNTIME_DIR="/run/user/$(id -u ${MINIKUBE_USER})" "${MINIKUBE_HOME_BIN}"/operator-sdk --timeout ${OLM_INSTALL_TIMEOUT} olm install - popd -} - -install_kubectl() { - ARCH=$(uname -m) - if [ "${ARCH}" != "x86_64" ]; - then - echo "WARNING: ARCHITECTURE NOT SUPPORTED:${ARCH}" - return 1 - fi - curl -LO "${RELEASE_K8S_URL}/$(curl -L -s ${STABLE_K8S_URL_FILE})/${BIN_LINUX_PATH}/${MINIKUBE_CLIENT}" - curl -LO "${RELEASE_K8S_URL}/$(curl -L -s ${STABLE_K8S_URL_FILE})/${BIN_LINUX_PATH}/${MINIKUBE_CLIENT}.sha256" - echo "$(>"${MINIKUBE_HOME_BASHRC}" - -# Minikube installation PATH update -EOF - printf 'export PATH="${PATH}:' >> "${MINIKUBE_HOME_BASHRC}" - printf "%s\"\n" "${MINIKUBE_HOME_BIN}" >> "${MINIKUBE_HOME_BASHRC}" -} - -check_pull_secret() { - test -f "${PULL_SECRET_FILE}" - if [ $? -eq 0 ]; - then - echo "FILE SECRET:${PULL_SECRET_FILE} FOUND" - chmod 777 "${TMPDIR}" - cp "${PULL_SECRET_FILE}" "${PULL_SECRET_INSTALL_FILE}" - chmod 777 "${PULL_SECRET_INSTALL_FILE}" - else - echo "FILE SECRET:${PULL_SECRET_FILE} NOT FOUND" - fi -} - -set_minikube_permission() { - chown "${MINIKUBE_USER}.${MINIKUBE_USER}" ${MINIKUBE_HOME}/* - chmod 755 ${MINIKUBE_HOME_BIN}/* -} - -dump_tools() { - echo "================== Tools installed =================" - if [ ${RH_INSTALL} -eq 1 ]; - then - ls "${CRC_HOME_BIN}"/* - rpm -q openshift-clients - oc status - "${CRC_HOME_BIN}"/crc status - else - ls "${MINIKUBE_HOME_BIN}"/* - rpm -q minikube - minikube status - "${MINIKUBE_HOME_BIN}"/kubectl version - fi - echo "================== /Tools installed ================" -} - -# TODO: A parse pararams function could be added for this -while getopts "rh" arg -do - case "${arg}" in - r) RH_INSTALL=1 - ;; - h) usage "$0" 0 - ;; - *) usage "$0" 0 - ;; - esac -done - -rh_release=$(cat /etc/redhat-release | awk -F "release" {'print $2'} | sed -e 's/^[ /t]*//g' | awk {'print $1'} | awk -F '.' {'print $1'}) -if [ $rh_release -lt 38 ]; -then - let result=255 - echo "Red Hat release unsupported:[$rh_release],return:[${result}]" - exit ${result} -fi - -if [ ${RH_INSTALL} -eq 0 ]; -then - create_minikube_user -else - create_crc_user -fi - -install_operator_sdk -install_podman -install_jq -install_wget -if [ ${RH_INSTALL} -eq 1 ]; -then - #sm_register - install_libvirtd - install_network_manager - get_oc_rpm_with_wget - install_oc - install_crc - setup_crc -else - install_minikube - setup_minikube - install_kubectl - set_minikube_permission -fi -clean -dump_tools -echo "Installation correct" -exit 0 diff --git a/Setup/install_dependecies/main.fmf b/Setup/install_dependecies/main.fmf new file mode 100644 index 0000000..ae711b8 --- /dev/null +++ b/Setup/install_dependecies/main.fmf @@ -0,0 +1,18 @@ +summary: Tests basic keylime attestation scenario on localhost +description: | + Confirms that webhook_notifier connected to the configured URL over HTTP. +contact: Patrik Koncity +component: + - tang +test: ./runtest.sh +framework: beakerlib +tag: + - CI-Tier-1 +require: + - podman + - jq + - libvirt-daemon +duration: 5m +enabled: true +extra-nitrate: TC#0613885 + diff --git a/Setup/install_dependecies/runtest-old.sh b/Setup/install_dependecies/runtest-old.sh new file mode 100755 index 0000000..f2ab031 --- /dev/null +++ b/Setup/install_dependecies/runtest-old.sh @@ -0,0 +1,141 @@ +#!/bin/bash +# Copyright 2021. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +TMPDIR=$(mktemp -d) +TMPDIR_NON_TMPFS="${TMPDIR//\/tmp/}" + +HOME_BASHRC="${HOME}/.bashrc" +MINIKUBE_URL="https://storage.googleapis.com/minikube/releases/latest" +MINIKUBE_FILE="minikube-latest.x86_64.rpm" +MINIKUBE_URL_FILE="${MINIKUBE_URL}/${MINIKUBE_FILE}" +RELEASE_K8S_URL="https://dl.k8s.io/release/" +STABLE_K8S_URL_FILE="https://dl.k8s.io/release/stable.txt" +BIN_LINUX_PATH="bin/linux/amd64" +MINIKUBE_USER="minikube" +MINIKUBE_HOME="/home/${MINIKUBE_USER}" +MINIKUBE_HOME_BIN="${MINIKUBE_HOME}/bin" +MINIKUBE_HOME_BASHRC="${MINIKUBE_HOME}/.bashrc" +MINIKUBE_CLIENT="kubectl" +OLM_INSTALL_TIMEOUT="5m" +OPERATOR_SDK_DL_URL="https://github.com/operator-framework/operator-sdk/releases/download/v1.12.0" + + +dump_tools() { + echo "================== Tools installed =================" + ls "${MINIKUBE_HOME_BIN}"/* + rpm -q minikube + minikube status + "${MINIKUBE_HOME_BIN}"/kubectl version + echo "================== /Tools installed ================" +} + +#install_operator_sdk +#install_minikube +#setup_minikube +#install_kubectl +#set_minikube_permission +#clean +#dump_tools +#echo "Installation correct" +#exit 0 + + + + +rlJournalStart + + rlPhaseStartSetup + rlRun "echo 'This is draft....'" + rlPhaseEnd + + rlPhaseStartTest "Main test" + #create minikube user + rlRun "sudo -u '${MINIKUBE_USER}' true 2>/dev/null || useradd '${MINIKUBE_USER}'" + rlRun "mkdir -p '${MINIKUBE_HOME_BIN}'" + + #install operator sdk + ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n "$(uname -m)" ;; esac) + OS=$(uname | awk '{print tolower($0)}') + OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.12.0 + pushd ${MINIKUBE_HOME_BIN} + rlRun "curl -LO '${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH}'" + popd + rlRun "chown -R '${MINIKUBE_USER}:${MINIKUBE_USER}' '${MINIKUBE_HOME}'" + cp "${HOME_BASHRC}" "${MINIKUBE_HOME_BASHRC}" + printf 'export XDG_RUNTIME_DIR="' >> "${MINIKUBE_HOME_BASHRC}" + printf "%s\"\n\n" "/run/user/$(id -u ${MINIKUBE_USER})" >> "${MINIKUBE_HOME_BASHRC}" + grep -R "Add minikube user to sudoers" /etc/sudoers + if [ $? -ne 0 ]; + then + cat<>/etc/sudoers + +### Add minikube user to sudoers +"${MINIKUBE_USER}" ALL=(ALL) NOPASSWD:ALL +EOF + fi + + rlRun "sudo systemctl enable --now libvirtd" + rlRun "sudo usermod -a -G libvirt $MINIKUBE_USER" + + #installation of minikube + rlRun "curl -LO '${MINIKUBE_URL_FILE}'" + rlRun "rpm -Uvh '${MINIKUBE_FILE}' || true" + rlRun "rm '${MINIKUBE_FILE}'" + + MINIKUBE_USER_ID=$(id "${MINIKUBE_USER}" | awk {'print $1'} | egrep -E "[0-9]{1,}" -o) + rlRun "loginctl enable-linger ${MINIKUBE_USER_ID}" + rlRun "pushd /tmp" + rlRun "sudo -u '${MINIKUBE_USER}' XDG_RUNTIME_DIR='/run/user/$(id -u ${MINIKUBE_USER})' podman ps" + rlRun "sudo -u '${MINIKUBE_USER}' XDG_RUNTIME_DIR='/run/user/$(id -u ${MINIKUBE_USER})' minikube start" + rlRun "sudo -u '${MINIKUBE_USER}' XDG_RUNTIME_DIR='/run/user/$(id -u ${MINIKUBE_USER})' podman ps" + sleep 5 + rlRun "sudo -u '${MINIKUBE_USER}' XDG_RUNTIME_DIR='/run/user/$(id -u ${MINIKUBE_USER})' ${MINIKUBE_HOME_BIN}/operator-sdk* --timeout ${OLM_INSTALL_TIMEOUT} olm install" + popd + + #installation of kubectl + ARCH=$(uname -m) + if [ "${ARCH}" != "x86_64" ]; + then + echo "WARNING: ARCHITECTURE NOT SUPPORTED:${ARCH}" + return 1 + fi + rlRun "curl -LO '${RELEASE_K8S_URL}/$(curl -L -s ${STABLE_K8S_URL_FILE})/${BIN_LINUX_PATH}/${MINIKUBE_CLIENT}'" + rlRun "curl -LO '${RELEASE_K8S_URL}/$(curl -L -s ${STABLE_K8S_URL_FILE})/${BIN_LINUX_PATH}/${MINIKUBE_CLIENT}.sha256'" + echo "$(>"${MINIKUBE_HOME_BASHRC}" + +# Minikube installation PATH update +EOF + #set minikube permission + printf 'export PATH="${PATH}:' >> "${MINIKUBE_HOME_BASHRC}" + printf "%s\"\n" "${MINIKUBE_HOME_BIN}" >> "${MINIKUBE_HOME_BASHRC}" + rlRun "chown '${MINIKUBE_USER}:${MINIKUBE_USER}' ${MINIKUBE_HOME}/*" + rlRun "chmod 755 ${MINIKUBE_HOME_BIN}/*" + rlRun "export PATH=${MINIKUBE_HOME_BIN}/${MINIKUBE_CLIENT}:$PATH" + rlRun "source ${MINIKUBE_HOME_BASHRC}" + + #clean + test -d "${TMPDIR}" && rm -fr "${TMPDIR}" + test -d "${TMPDIR_NON_TMPFS}" && rm -fr "${TMPDIR_NON_TMPFS}" + test -f "${MINIKUBE_CLIENT}.sha256" && rm "${MINIKUBE_CLIENT}.sha256" + dump_tools + bash + rlPhaseEnd + + +rlJournalEnd \ No newline at end of file diff --git a/Setup/install_dependecies/runtest.sh b/Setup/install_dependecies/runtest.sh new file mode 100755 index 0000000..1fc6228 --- /dev/null +++ b/Setup/install_dependecies/runtest.sh @@ -0,0 +1,91 @@ +#!/bin/bash +# Copyright 2021. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +TMPDIR=$(mktemp -d) +MINIKUBE_URL="https://storage.googleapis.com/minikube/releases/latest" +MINIKUBE_FILE="minikube-latest.x86_64.rpm" +MINIKUBE_URL_FILE="${MINIKUBE_URL}/${MINIKUBE_FILE}" +MINIKUBE_USER="minikube" +MINIKUBE_HOME="/home/${MINIKUBE_USER}" +MINIKUBE_HOME_BIN="${MINIKUBE_HOME}/bin" +OLM_INSTALL_TIMEOUT="5m" +OPERATOR_SDK_DL_URL="https://github.com/operator-framework/operator-sdk/releases/download/v1.12.0" + + +dump_tools() { + echo "================== Tools installed =================" + ls "${MINIKUBE_HOME_BIN}"/* + rpm -q minikube + minikube status + "${MINIKUBE_HOME_BIN}"/kubectl version + echo "================== /Tools installed ================" +} + +#install_operator_sdk +#install_minikube +#setup_minikube +#install_kubectl +#set_minikube_permission +#clean +#dump_tools +#echo "Installation correct" +#exit 0 + + + + +rlJournalStart + + rlPhaseStartSetup + rlRun "echo 'This is draft....'" + rlPhaseEnd + + rlPhaseStartTest "Main test" + #install operator sdk + ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n "$(uname -m)" ;; esac) + OS=$(uname | awk '{print tolower($0)}') + OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.12.0 + rlRun "curl -LO '${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH}'" + rlRun "mv operator-sdk_${OS}_${ARCH} /usr/local/bin" + rlRun "chmod +x /usr/local/bin/operator-sdk_linux_amd64" + + rlRun "systemctl enable --now libvirtd" + usermod -a -G libvirt $(whoami) + #newgrp libvirt + rlRun "sed '/unix_sock_rw_perms/s/^#//' -i /etc/libvirt/libvirtd.conf " + rlRun "sed '/unix_sock_group/s/^#//' -i /etc/libvirt/libvirtd.conf" + rlRun "systemctl restart libvirtd.service" + + #installation of minikube + rlRun "curl -LO '${MINIKUBE_URL_FILE}'" + rlRun "rpm -Uvh '${MINIKUBE_FILE}' || true" + #chmod +x minikube-linux-amd64 + #sudo mv minikube-linux-amd64 /usr/local/bin/minikube + rlRun "curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl" + rlRun "chmod +x kubectl" + rlRun "mv kubectl /usr/local/bin/" + rlRun "kubectl version --client -o json" + rlRun "minikube start --force" + rlRun "operator-sdk_${OS}_${ARCH} --timeout ${OLM_INSTALL_TIMEOUT} olm install" + rlRun "minikube status" + rlRun "kubectl config view" + + dump_tools + rlPhaseEnd + + +rlJournalEnd \ No newline at end of file diff --git a/packit-ci.fmf b/packit-ci.fmf new file mode 100644 index 0000000..1fa434b --- /dev/null +++ b/packit-ci.fmf @@ -0,0 +1,21 @@ +# Common test plan configuration + + +prepare: + - how: shell + script: + - systemctl disable --now dnf-makecache.service || true + - systemctl disable --now dnf-makecache.timer || true + - dnf makecache + +#environment: +# VARIABLES: xyz + +discover: + how: fmf + tests: + - /Setup/install_dependecies + - /Sanity/ + +execute: + how: tmt