From 377f0fb453444b798a08864ec0320c0b74f016da Mon Sep 17 00:00:00 2001 From: akumari Date: Wed, 21 May 2025 01:10:22 +0530 Subject: [PATCH 1/6] Add initial tmt test plan --- .fmf/version | 1 + plans/rex-uptime.fmf | 4 ++++ tests/rex-uptime/main.fmf | 3 +++ tests/rex-uptime/test.sh | 10 ++++++++++ 4 files changed, 18 insertions(+) create mode 100644 .fmf/version create mode 100644 plans/rex-uptime.fmf create mode 100644 tests/rex-uptime/main.fmf create mode 100755 tests/rex-uptime/test.sh diff --git a/.fmf/version b/.fmf/version new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/plans/rex-uptime.fmf b/plans/rex-uptime.fmf new file mode 100644 index 000000000..d37c237ef --- /dev/null +++ b/plans/rex-uptime.fmf @@ -0,0 +1,4 @@ +summary: Run uptime command via remote execution +execute: + how: tmt + test: rex-uptime diff --git a/tests/rex-uptime/main.fmf b/tests/rex-uptime/main.fmf new file mode 100644 index 000000000..ed6e8ee78 --- /dev/null +++ b/tests/rex-uptime/main.fmf @@ -0,0 +1,3 @@ +summary: Run uptime command via remote execution +test: ./test.sh +framework: shell diff --git a/tests/rex-uptime/test.sh b/tests/rex-uptime/test.sh new file mode 100755 index 000000000..616084ad0 --- /dev/null +++ b/tests/rex-uptime/test.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -euo pipefail + +echo "Running remote execution test: uptime" + +hammer job-invocation create \ + --job-template 'Run Command - Script Default' \ + --inputs 'command=uptime' \ + --search-query "name ~ $(hostname -f)" + From 94ce037f972477635c86d58b260b98ae4ffddfee Mon Sep 17 00:00:00 2001 From: akumari Date: Mon, 9 Jun 2025 15:31:43 +0530 Subject: [PATCH 2/6] enhance tmt test with smart proxy org setup using hammer --- tests/rex-uptime/test.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/rex-uptime/test.sh b/tests/rex-uptime/test.sh index 616084ad0..da305aa51 100755 --- a/tests/rex-uptime/test.sh +++ b/tests/rex-uptime/test.sh @@ -3,8 +3,19 @@ set -euo pipefail echo "Running remote execution test: uptime" +job_template='Run Command - Script Default' +SMART_PROXY_NAME=$(hostname -f) +REX_ORG="Remote Execution Org $$" + +OLD_ORGS=$(hammer --output csv --no-headers --show-ids proxy info --name "${SMART_PROXY_NAME}" --fields Organizations) + +hammer organization create --name "${REX_ORG}" +hammer host update --name "${SMART_PROXY_NAME}" --new-organization "${REX_ORG}" +hammer proxy update --name "${SMART_PROXY_NAME}" --organizations "${OLD_ORGS},${REX_ORG}" + hammer job-invocation create \ - --job-template 'Run Command - Script Default' \ + --job-template "${job_template}" \ --inputs 'command=uptime' \ - --search-query "name ~ $(hostname -f)" + --search-query "name = ${SMART_PROXY_NAME}" +echo "Test completed successfully." From 9f966e1ca8591a5e8509276a255f41ff4f0f98db Mon Sep 17 00:00:00 2001 From: akumari Date: Mon, 9 Jun 2025 15:33:59 +0530 Subject: [PATCH 3/6] configure packit test --- .packit.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.packit.yaml b/.packit.yaml index c0adce2da..48e504669 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -35,6 +35,11 @@ jobs: - https://yum.theforeman.org/plugins/nightly/el9/x86_64/ module_hotfixes: true + - job: tests + trigger: pull_request + targets: + - epel-9 + srpm_build_deps: - wget - rubygems From 3d31ee5c82d3bbca157e5d428f0d19f350ce34a3 Mon Sep 17 00:00:00 2001 From: akumari Date: Mon, 9 Jun 2025 15:58:33 +0530 Subject: [PATCH 4/6] configure tmt to provision virtual guest --- main.fmf | 1 + plans/rex-uptime.fmf | 10 +++++++++- tests/rex-uptime/test.sh | 12 ++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 main.fmf diff --git a/main.fmf b/main.fmf new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/main.fmf @@ -0,0 +1 @@ + diff --git a/plans/rex-uptime.fmf b/plans/rex-uptime.fmf index d37c237ef..e413e1362 100644 --- a/plans/rex-uptime.fmf +++ b/plans/rex-uptime.fmf @@ -1,4 +1,12 @@ summary: Run uptime command via remote execution + +discover: + how: fmf + directory: ./tests + execute: how: tmt - test: rex-uptime + +provision: + how: virtual + image: centos-stream-9 diff --git a/tests/rex-uptime/test.sh b/tests/rex-uptime/test.sh index da305aa51..6ce57e939 100755 --- a/tests/rex-uptime/test.sh +++ b/tests/rex-uptime/test.sh @@ -5,6 +5,7 @@ echo "Running remote execution test: uptime" job_template='Run Command - Script Default' SMART_PROXY_NAME=$(hostname -f) +ORG="Test Org" REX_ORG="Remote Execution Org $$" OLD_ORGS=$(hammer --output csv --no-headers --show-ids proxy info --name "${SMART_PROXY_NAME}" --fields Organizations) @@ -18,4 +19,15 @@ hammer job-invocation create \ --inputs 'command=uptime' \ --search-query "name = ${SMART_PROXY_NAME}" +JOB_ID=$(hammer --csv job-invocation list | grep "${job_template}" | head -n1 | cut -d',' -f1) + +STATUS=$(hammer --csv job-invocation info --id "$JOB_ID" | grep '^Status,' | cut -d',' -f2) + +if [[ "$STATUS" == "Succeeded" || "$STATUS" == "Finished" ]]; then + echo "Remote job succeeded" +else + echo "Remote job failed with status: $STATUS" + exit 1 +fi + echo "Test completed successfully." From 446712a68ab7e15ce42dda3bd8c4686d5af3cd28 Mon Sep 17 00:00:00 2001 From: akumari Date: Thu, 10 Jul 2025 02:54:45 +0530 Subject: [PATCH 5/6] update file structure --- main.fmf | 1 - plans/rex-uptime.fmf | 12 -------- tests/rex-uptime/main.fmf | 3 -- tests/rex-uptime/test.sh | 33 -------------------- tests/rex/rex-uptime/main.fmf | 3 ++ tests/rex/rex-uptime/test.sh | 6 ++++ tests/rex/tmt/main.fmf | 2 ++ tests/rex/tmt/plans/rex-uptime.fmf | 49 ++++++++++++++++++++++++++++++ 8 files changed, 60 insertions(+), 49 deletions(-) delete mode 100644 main.fmf delete mode 100644 plans/rex-uptime.fmf delete mode 100644 tests/rex-uptime/main.fmf delete mode 100755 tests/rex-uptime/test.sh create mode 100644 tests/rex/rex-uptime/main.fmf create mode 100755 tests/rex/rex-uptime/test.sh create mode 100644 tests/rex/tmt/main.fmf create mode 100644 tests/rex/tmt/plans/rex-uptime.fmf diff --git a/main.fmf b/main.fmf deleted file mode 100644 index 8b1378917..000000000 --- a/main.fmf +++ /dev/null @@ -1 +0,0 @@ - diff --git a/plans/rex-uptime.fmf b/plans/rex-uptime.fmf deleted file mode 100644 index e413e1362..000000000 --- a/plans/rex-uptime.fmf +++ /dev/null @@ -1,12 +0,0 @@ -summary: Run uptime command via remote execution - -discover: - how: fmf - directory: ./tests - -execute: - how: tmt - -provision: - how: virtual - image: centos-stream-9 diff --git a/tests/rex-uptime/main.fmf b/tests/rex-uptime/main.fmf deleted file mode 100644 index ed6e8ee78..000000000 --- a/tests/rex-uptime/main.fmf +++ /dev/null @@ -1,3 +0,0 @@ -summary: Run uptime command via remote execution -test: ./test.sh -framework: shell diff --git a/tests/rex-uptime/test.sh b/tests/rex-uptime/test.sh deleted file mode 100755 index 6ce57e939..000000000 --- a/tests/rex-uptime/test.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -set -euo pipefail - -echo "Running remote execution test: uptime" - -job_template='Run Command - Script Default' -SMART_PROXY_NAME=$(hostname -f) -ORG="Test Org" -REX_ORG="Remote Execution Org $$" - -OLD_ORGS=$(hammer --output csv --no-headers --show-ids proxy info --name "${SMART_PROXY_NAME}" --fields Organizations) - -hammer organization create --name "${REX_ORG}" -hammer host update --name "${SMART_PROXY_NAME}" --new-organization "${REX_ORG}" -hammer proxy update --name "${SMART_PROXY_NAME}" --organizations "${OLD_ORGS},${REX_ORG}" - -hammer job-invocation create \ - --job-template "${job_template}" \ - --inputs 'command=uptime' \ - --search-query "name = ${SMART_PROXY_NAME}" - -JOB_ID=$(hammer --csv job-invocation list | grep "${job_template}" | head -n1 | cut -d',' -f1) - -STATUS=$(hammer --csv job-invocation info --id "$JOB_ID" | grep '^Status,' | cut -d',' -f2) - -if [[ "$STATUS" == "Succeeded" || "$STATUS" == "Finished" ]]; then - echo "Remote job succeeded" -else - echo "Remote job failed with status: $STATUS" - exit 1 -fi - -echo "Test completed successfully." diff --git a/tests/rex/rex-uptime/main.fmf b/tests/rex/rex-uptime/main.fmf new file mode 100644 index 000000000..087895715 --- /dev/null +++ b/tests/rex/rex-uptime/main.fmf @@ -0,0 +1,3 @@ +summary: Run uptime command check on the provisioned guest +test: ./test.sh +framework: shell diff --git a/tests/rex/rex-uptime/test.sh b/tests/rex/rex-uptime/test.sh new file mode 100755 index 000000000..b757319be --- /dev/null +++ b/tests/rex/rex-uptime/test.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -euo pipefail + +echo "Running uptime check on the TMT guest" +uptime +echo "Uptime test on guest completed successfully." diff --git a/tests/rex/tmt/main.fmf b/tests/rex/tmt/main.fmf new file mode 100644 index 000000000..91b27804f --- /dev/null +++ b/tests/rex/tmt/main.fmf @@ -0,0 +1,2 @@ +plans: + name: /plans/rex-uptime.fmf diff --git a/tests/rex/tmt/plans/rex-uptime.fmf b/tests/rex/tmt/plans/rex-uptime.fmf new file mode 100644 index 000000000..9a72f3cad --- /dev/null +++ b/tests/rex/tmt/plans/rex-uptime.fmf @@ -0,0 +1,49 @@ +name: /plans/rex-uptime +summary: Test Foreman Remote Execution for uptime command + +provision: + how: virtual + image: centos-stream-9 + +discover: + how: fmf + directory: ../../rex-uptime + +execute: + how: tmt + prepare: + - how: shell + name: trigger-and-verify-remote-execution + where: localhost + script: + - | + #!/bin/bash + set -euo pipefail + + echo "Foreman Remote Execution Test from TMT Host" + job_template='Run Command - Script Default' + GUEST_IP=$(tmt --root $(tmt _root) guest --id default-0 | grep 'primary address' | awk '{print $NF}') + echo "TMT Guest IP: ${GUEST_IP}" + + echo "Triggering 'uptime' command on guest IP ${GUEST_IP} via Foreman" + JOB_INFO=$(hammer job-invocation create \ + --job-template "${job_template}" \ + --inputs 'command=uptime' \ + --search-query "facts.ip_address = ${GUEST_IP}" \ + --json) + + JOB_ID=$(echo "${JOB_INFO}" | jq -r '.id') + echo "Foreman Job ID: ${JOB_ID}" + + echo "Waiting for Foreman job ${JOB_ID} to complete" + for i in $(seq 1 120); do + JOB_STATUS=$(hammer job-invocation info --id "${JOB_ID}" --json | jq -r '.state') + echo "Job status: ${JOB_STATUS} (Attempt ${i})" + [[ "$JOB_STATUS" == "finished" ]] && break + [[ "$JOB_STATUS" == "error" || "$JOB_STATUS" == "failed" ]] && exit 1 + sleep 5 + done + + echo "Foreman job ${JOB_ID} completed successfully." + hammer job-invocation info --id "$JOB_ID" + echo "Foreman Remote Execution Test PASSED" From e59a3717328f83a001991c6937dabe49b347d0e4 Mon Sep 17 00:00:00 2001 From: akumari Date: Mon, 14 Jul 2025 14:08:32 +0530 Subject: [PATCH 6/6] add additional modules and repos --- .packit.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.packit.yaml b/.packit.yaml index 48e504669..45bc30e40 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -28,11 +28,12 @@ jobs: - job: copr_build trigger: pull_request targets: - rhel-9: + rhel-9: &additional_repos additional_modules: "foreman-devel:el9" additional_repos: - https://yum.theforeman.org/releases/nightly/el9/x86_64/ - https://yum.theforeman.org/plugins/nightly/el9/x86_64/ + epel-9: *additional_repos module_hotfixes: true - job: tests