From 7b881698d7c2e5fca7fc38d9bb6b51165bd8ec36 Mon Sep 17 00:00:00 2001 From: Assaf Admi <90143867+assafad@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:47:13 +0200 Subject: [PATCH] Collect running VMs count (#191) Signed-off-by: assafad --- collection-scripts/gather | 1 + collection-scripts/gather_virtualization | 15 +++++++++++++++ tests/validate_must_gather_test.go | 14 ++++++++++++++ 3 files changed, 30 insertions(+) create mode 100755 collection-scripts/gather_virtualization diff --git a/collection-scripts/gather b/collection-scripts/gather index 00002a81..a2af278c 100755 --- a/collection-scripts/gather +++ b/collection-scripts/gather @@ -18,6 +18,7 @@ function main() { "virtualmachines" "webhooks" "instancetypes" + "virtualization" ) declare requested_scripts=("${mandatory_scripts[@]}") diff --git a/collection-scripts/gather_virtualization b/collection-scripts/gather_virtualization new file mode 100755 index 00000000..ef8c9739 --- /dev/null +++ b/collection-scripts/gather_virtualization @@ -0,0 +1,15 @@ +#!/bin/bash -x + +DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${DIR_NAME}/common.sh" +check_command + +VIRTUALIZATION_PATH="${BASE_COLLECTION_PATH}/virtualization" +mkdir -p "${VIRTUALIZATION_PATH}" + +function collect_running_vms_count() { + /usr/bin/oc get vmi --all-namespaces -o=jsonpath='{.items[?(@.status.phase=="Running")].metadata.name}' | wc -w > "${VIRTUALIZATION_PATH}/running_vms_count.txt" +} + +collect_running_vms_count + diff --git a/tests/validate_must_gather_test.go b/tests/validate_must_gather_test.go index a0c4aa4f..e2da7ff1 100644 --- a/tests/validate_must_gather_test.go +++ b/tests/validate_must_gather_test.go @@ -337,6 +337,20 @@ var _ = Describe("validate the must-gather output", func() { Entry("should gather resources in ns005", "ns005"), ) }) + + Context("[level:product]validate the virtualization directory", Label("level:product"), func() { + virtualizationDir := "virtualization" + + // This test assumes, according to automation/create_workloads.sh, that there are 5 running VMs in the cluster. + It("should validate the running VMs count", func() { + runningVmsCountPath := path.Join(outputDir, virtualizationDir, "running_vms_count.txt") + countBytes, err := os.ReadFile(runningVmsCountPath) + Expect(err).ToNot(HaveOccurred()) + + count := strings.TrimSpace(string(countBytes)) + Expect(count).To(Equal("5")) + }) + }) }) func validateVmFile(vm, ns, vmPath string) {