Skip to content

Commit 27db914

Browse files
committed
Add SCENARIO_* variables to unify VM config between static and dynamic scenarios
1 parent 3ba45d0 commit 27db914

File tree

62 files changed

+321
-556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+321
-556
lines changed

test/bin/common.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ VM_POOL_BASENAME="vm-storage"
3636
# The location for storage for the VMs.
3737
export VM_DISK_BASEDIR="${IMAGEDIR}/${VM_POOL_BASENAME}"
3838

39+
# Default VM resource settings (shared by scenario.sh and vm_scheduler.sh)
40+
# These can be overridden per-scenario via launch_vm args or dynamic_schedule_requirements()
41+
DEFAULT_VM_VCPUS=2
42+
DEFAULT_VM_MEMORY=4096
43+
DEFAULT_VM_DISKSIZE=20
44+
DEFAULT_VM_NETWORK="default"
45+
46+
# Scenarios can override defaults by setting SCENARIO_* variables at the top of the file:
47+
# SCENARIO_VCPUS - Number of vCPUs (default: DEFAULT_VM_VCPUS)
48+
# SCENARIO_MEMORY - Memory in MB (default: DEFAULT_VM_MEMORY)
49+
# SCENARIO_DISKSIZE - Disk size in GB (default: DEFAULT_VM_DISKSIZE)
50+
# SCENARIO_NETWORKS - Network(s) to use, comma-separated (default: DEFAULT_VM_NETWORK)
51+
# SCENARIO_FIPS - Enable FIPS mode: "true" or "false" (default: "false")
52+
#
53+
# These are automatically used by both launch_vm() and get_scenario_requirements()
54+
# so you only need to define them once per scenario.
55+
3956
# The isolated network name used by some VMs.
4057
export VM_ISOLATED_NETWORK="isolated"
4158

test/bin/scenario.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,12 +848,18 @@ setup_vm_properties_from_existing() {
848848
# [--fips]: Enable FIPS mode for the VM.
849849
launch_vm() {
850850
# Set default values for the optional arguments
851+
# Check SCENARIO_* variables first, then fall back to shared defaults from common.sh
852+
# This allows scenarios to define SCENARIO_VCPUS=4 once and have it used by both
853+
# launch_vm and dynamic_schedule_requirements
851854
local vmname="host1"
852-
local network="default"
853-
local vm_memory=4096
854-
local vm_vcpus=2
855-
local vm_disksize=20
855+
local _net="${SCENARIO_NETWORKS:-${DEFAULT_VM_NETWORK}}"
856+
local network="${_net//,/ }"
857+
local vm_memory="${SCENARIO_MEMORY:-${DEFAULT_VM_MEMORY}}"
858+
local vm_vcpus="${SCENARIO_VCPUS:-${DEFAULT_VM_VCPUS}}"
859+
local vm_disksize="${SCENARIO_DISKSIZE:-${DEFAULT_VM_DISKSIZE}}"
860+
# Convert SCENARIO_FIPS (true/false) to fips_mode (1/0)
856861
local fips_mode=0
862+
[[ "${SCENARIO_FIPS:-false}" == "true" ]] && fips_mode=1
857863
local kernel_location="images/pxeboot"
858864

859865
# Parse the mandatory arguments

test/bin/vm_scheduler.sh

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ init_scheduler() {
148148
}
149149

150150
# Default VM resources when not specified in launch_vm
151-
DEFAULT_VM_VCPUS=2
152-
DEFAULT_VM_MEMORY=4096
151+
# DEFAULT_VM_VCPUS, DEFAULT_VM_MEMORY, DEFAULT_VM_DISKSIZE defined in common.sh
153152

154153
parse_static_scenario_resources() {
155154
local scenario_script="$1"
@@ -344,7 +343,18 @@ get_scenario_requirements() {
344343
(
345344
source "${scenario_script}"
346345
if type dynamic_schedule_requirements &>/dev/null; then
346+
# Get explicit requirements from function
347347
dynamic_schedule_requirements > "${output_file}"
348+
349+
# Fill in missing values from SCENARIO_* variables or defaults
350+
# This allows scenarios to define SCENARIO_VCPUS=4 and have it picked up
351+
# without needing to echo it in dynamic_schedule_requirements()
352+
grep -q "^min_vcpus=" "${output_file}" || echo "min_vcpus=${SCENARIO_VCPUS:-${DEFAULT_VM_VCPUS}}" >> "${output_file}"
353+
grep -q "^min_memory=" "${output_file}" || echo "min_memory=${SCENARIO_MEMORY:-${DEFAULT_VM_MEMORY}}" >> "${output_file}"
354+
grep -q "^min_disksize=" "${output_file}" || echo "min_disksize=${SCENARIO_DISKSIZE:-${DEFAULT_VM_DISKSIZE}}" >> "${output_file}"
355+
grep -q "^networks=" "${output_file}" || echo "networks=${SCENARIO_NETWORKS:-}" >> "${output_file}"
356+
grep -q "^fips=" "${output_file}" || echo "fips=${SCENARIO_FIPS:-false}" >> "${output_file}"
357+
grep -q "^boot_image=" "${output_file}" || echo "boot_image=${start_image:-}" >> "${output_file}"
348358
else
349359
# This shouldn't happen if scenario_is_dynamic was checked first
350360
echo "ERROR: dynamic_schedule_requirements not found" >&2
@@ -413,21 +423,21 @@ vm_satisfies_requirements() {
413423
local vm_state="${VM_REGISTRY}/${vm_name}/state"
414424
[ -f "${vm_state}" ] || return 1
415425

416-
# Get VM capabilities
426+
# Get VM capabilities (defaults from common.sh)
417427
local vm_vcpus vm_memory vm_disksize vm_networks vm_fips vm_boot_image
418-
vm_vcpus=$(get_req_value "${vm_state}" "vcpus" "2")
419-
vm_memory=$(get_req_value "${vm_state}" "memory" "4096")
420-
vm_disksize=$(get_req_value "${vm_state}" "disksize" "20")
421-
vm_networks=$(get_req_value "${vm_state}" "networks" "default")
428+
vm_vcpus=$(get_req_value "${vm_state}" "vcpus" "${DEFAULT_VM_VCPUS}")
429+
vm_memory=$(get_req_value "${vm_state}" "memory" "${DEFAULT_VM_MEMORY}")
430+
vm_disksize=$(get_req_value "${vm_state}" "disksize" "${DEFAULT_VM_DISKSIZE}")
431+
vm_networks=$(get_req_value "${vm_state}" "networks" "${DEFAULT_VM_NETWORK}")
422432
vm_fips=$(get_req_value "${vm_state}" "fips" "false")
423433
vm_boot_image=$(get_req_value "${vm_state}" "boot_image" "")
424434

425-
# Get scenario requirements
435+
# Get scenario requirements (defaults from common.sh)
426436
local req_vcpus req_memory req_disksize req_networks req_fips req_boot_image
427437
req_vcpus=$(get_req_value "${scenario_reqs}" "min_vcpus" "${DEFAULT_VM_VCPUS}")
428438
req_memory=$(get_req_value "${scenario_reqs}" "min_memory" "${DEFAULT_VM_MEMORY}")
429-
req_disksize=$(get_req_value "${scenario_reqs}" "min_disksize" "20")
430-
req_networks=$(get_req_value "${scenario_reqs}" "networks" "default")
439+
req_disksize=$(get_req_value "${scenario_reqs}" "min_disksize" "${DEFAULT_VM_DISKSIZE}")
440+
req_networks=$(get_req_value "${scenario_reqs}" "networks" "${DEFAULT_VM_NETWORK}")
431441
req_fips=$(get_req_value "${scenario_reqs}" "fips" "false")
432442
req_boot_image=$(get_req_value "${scenario_reqs}" "boot_image" "")
433443

@@ -525,12 +535,12 @@ register_vm() {
525535
# Copy requirements as VM state with status
526536
cp "${scenario_reqs}" "${vm_dir}/state"
527537

528-
# Add vcpus/memory/disksize from min_* values and set status
538+
# Add vcpus/memory/disksize from min_* values and set status (defaults from common.sh)
529539
local vcpus memory disksize networks fips boot_image
530540
vcpus=$(get_req_value "${scenario_reqs}" "min_vcpus" "${DEFAULT_VM_VCPUS}")
531541
memory=$(get_req_value "${scenario_reqs}" "min_memory" "${DEFAULT_VM_MEMORY}")
532-
disksize=$(get_req_value "${scenario_reqs}" "min_disksize" "20")
533-
networks=$(get_req_value "${scenario_reqs}" "networks" "default")
542+
disksize=$(get_req_value "${scenario_reqs}" "min_disksize" "${DEFAULT_VM_DISKSIZE}")
543+
networks=$(get_req_value "${scenario_reqs}" "networks" "${DEFAULT_VM_NETWORK}")
534544
fips=$(get_req_value "${scenario_reqs}" "fips" "false")
535545
boot_image=$(get_req_value "${scenario_reqs}" "boot_image" "")
536546

test/scenarios-bootc/el9/presubmits/el98-src@auto-recovery-extra.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
# Sourced from scenario.sh and uses functions defined there.
44

5+
start_image="rhel98-bootc-source"
6+
SCENARIO_VCPUS=4
7+
58
# Opt-in to dynamic VM scheduling by declaring requirements
69
dynamic_schedule_requirements() {
710
cat <<EOF
8-
min_vcpus=4
9-
min_memory=4096
10-
min_disksize=20
11-
networks=
12-
boot_image=rhel98-bootc-source
13-
fips=false
11+
boot_image=${start_image}
1412
slow=true
1513
EOF
1614
}
1715

1816
scenario_create_vms() {
19-
prepare_kickstart host1 kickstart-bootc.ks.template rhel98-bootc-source
20-
launch_vm rhel98-bootc --vm_vcpus 4
17+
prepare_kickstart host1 kickstart-bootc.ks.template "${start_image}"
18+
launch_vm rhel98-bootc
2119
}
2220

2321
scenario_remove_vms() {

test/scenarios-bootc/el9/presubmits/el98-src@auto-recovery.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
# Sourced from scenario.sh and uses functions defined there.
44

5+
start_image="rhel98-bootc-source"
6+
SCENARIO_VCPUS=4
7+
58
# Opt-in to dynamic VM scheduling by declaring requirements
69
dynamic_schedule_requirements() {
710
cat <<EOF
8-
min_vcpus=4
9-
min_memory=4096
10-
min_disksize=20
11-
networks=
12-
boot_image=rhel98-bootc-source
13-
fips=false
11+
boot_image=${start_image}
1412
fast=true
1513
EOF
1614
}
1715

1816
scenario_create_vms() {
19-
prepare_kickstart host1 kickstart-bootc.ks.template rhel98-bootc-source
20-
launch_vm rhel98-bootc --vm_vcpus 4
17+
prepare_kickstart host1 kickstart-bootc.ks.template "${start_image}"
18+
launch_vm rhel98-bootc
2119
}
2220

2321
scenario_remove_vms() {

test/scenarios-bootc/el9/presubmits/el98-src@backups.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
# Sourced from scenario.sh and uses functions defined there.
44

5+
start_image="rhel98-bootc-source"
6+
SCENARIO_VCPUS=4
7+
58
# Opt-in to dynamic VM scheduling by declaring requirements
69
dynamic_schedule_requirements() {
710
cat <<EOF
8-
min_vcpus=4
9-
min_memory=4096
10-
min_disksize=20
11-
networks=
12-
boot_image=rhel98-bootc-source
13-
fips=false
11+
boot_image=${start_image}
1412
fast=true
1513
EOF
1614
}
1715

1816
scenario_create_vms() {
19-
prepare_kickstart host1 kickstart-bootc.ks.template rhel98-bootc-source
20-
launch_vm rhel98-bootc --vm_vcpus 4
17+
prepare_kickstart host1 kickstart-bootc.ks.template "${start_image}"
18+
launch_vm rhel98-bootc
2119
}
2220

2321
scenario_remove_vms() {

test/scenarios-bootc/el9/presubmits/el98-src@configuration.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
# Sourced from scenario.sh and uses functions defined there.
44

5+
start_image="rhel98-bootc-source"
6+
SCENARIO_VCPUS=4
7+
58
# Opt-in to dynamic VM scheduling by declaring requirements
69
dynamic_schedule_requirements() {
710
cat <<EOF
8-
min_vcpus=4
9-
min_memory=4096
10-
min_disksize=20
11-
networks=
12-
boot_image=rhel98-bootc-source
13-
fips=false
11+
boot_image=${start_image}
1412
slow=true
1513
EOF
1614
}
1715

1816
scenario_create_vms() {
19-
prepare_kickstart host1 kickstart-bootc.ks.template rhel98-bootc-source
20-
launch_vm rhel98-bootc --vm_vcpus 4
17+
prepare_kickstart host1 kickstart-bootc.ks.template "${start_image}"
18+
launch_vm rhel98-bootc
2119
}
2220

2321
scenario_remove_vms() {

test/scenarios-bootc/el9/presubmits/el98-src@dns.sh

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22

33
# Sourced from scenario.sh and uses functions defined there.
44

5+
start_image="rhel98-bootc-source"
6+
SCENARIO_VCPUS=4
7+
58
# Opt-in to dynamic VM scheduling by declaring requirements
69
dynamic_schedule_requirements() {
7-
cat <<EOF
8-
min_vcpus=4
9-
min_memory=4096
10-
min_disksize=20
11-
networks=default
12-
boot_image=rhel98-bootc-source
13-
fips=false
14-
EOF
10+
echo "boot_image=${start_image}"
1511
}
1612

1713
scenario_create_vms() {
18-
prepare_kickstart host1 kickstart-bootc.ks.template rhel98-bootc-source
19-
launch_vm rhel98-bootc --vm_vcpus 4
14+
prepare_kickstart host1 kickstart-bootc.ks.template "${start_image}"
15+
launch_vm rhel98-bootc
2016
}
2117

2218
scenario_remove_vms() {

test/scenarios-bootc/el9/presubmits/el98-src@etcd.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22

33
# Sourced from scenario.sh and uses functions defined there.
44

5+
start_image="rhel98-bootc-source"
6+
SCENARIO_VCPUS=4
7+
58
# Opt-in to dynamic VM scheduling by declaring requirements
69
dynamic_schedule_requirements() {
7-
cat <<EOF
8-
min_vcpus=4
9-
min_memory=4096
10-
min_disksize=20
11-
networks=default
12-
boot_image=rhel98-bootc-source
13-
fips=false
14-
EOF
10+
echo "boot_image=${start_image}"
1511
}
1612

1713
scenario_create_vms() {
18-
prepare_kickstart host1 kickstart-bootc.ks.template rhel98-bootc-source
19-
launch_vm rhel98-bootc --vm_vcpus 4
14+
prepare_kickstart host1 kickstart-bootc.ks.template "${start_image}"
15+
launch_vm rhel98-bootc
2016
}
2117

2218
scenario_remove_vms() {
@@ -27,3 +23,4 @@ scenario_run_tests() {
2723
run_tests host1 \
2824
suites/standard1/etcd.robot
2925
}
26+

test/scenarios-bootc/el9/presubmits/el98-src@feature-gates.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22

33
# Sourced from scenario.sh and uses functions defined there.
44

5+
start_image="rhel98-bootc-source"
6+
SCENARIO_VCPUS=4
7+
58
# Opt-in to dynamic VM scheduling by declaring requirements
69
dynamic_schedule_requirements() {
7-
cat <<EOF
8-
min_vcpus=4
9-
min_memory=4096
10-
min_disksize=20
11-
networks=
12-
boot_image=rhel98-bootc-source
13-
fips=false
14-
EOF
10+
echo "boot_image=${start_image}"
1511
}
1612

1713
scenario_create_vms() {
18-
prepare_kickstart host1 kickstart-bootc.ks.template rhel98-bootc-source
19-
launch_vm rhel98-bootc --vm_vcpus 4
14+
prepare_kickstart host1 kickstart-bootc.ks.template "${start_image}"
15+
launch_vm rhel98-bootc
2016
}
2117

2218
scenario_remove_vms() {
@@ -26,3 +22,4 @@ scenario_remove_vms() {
2622
scenario_run_tests() {
2723
run_tests host1 suites/standard2/feature-gates.robot
2824
}
25+

0 commit comments

Comments
 (0)