Skip to content

Commit 76a2bcb

Browse files
authored
Merge pull request #509 from KaiyiLiu1234/remove-env
tests(power-monitor): replace enable_vm_test env variable with command-line flag
2 parents 5456bb9 + efd05ad commit 76a2bcb

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

tests/e2e/main_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var (
2323
testKeplerImage string
2424
testKeplerRebootImage string
2525
vmAnnotationKey string
26-
enableVMEnv string
26+
enableVMTest bool
2727
)
2828

2929
func TestMain(m *testing.M) {
@@ -33,12 +33,7 @@ func TestMain(m *testing.M) {
3333
flag.StringVar(&testKeplerImage, "kepler-image", keplerImage, "Kepler image to use when running Internal tests")
3434
flag.StringVar(&testKeplerRebootImage, "kepler-reboot-image", keplerRebootImage, "Kepler image to use when running PowerMonitorInternal tests")
3535
flag.StringVar(&vmAnnotationKey, "vm-annotation-key", ciTestVMEnvKey, "VM Annotation Key set to enable vm test environment")
36-
enableFakeMeter := "false"
37-
if os.Getenv("ENABLE_VM_TEST") == "true" {
38-
enableFakeMeter = "true"
39-
}
40-
flag.StringVar(&enableVMEnv, "enable-vm-env", enableFakeMeter, "Flag to set when enabling vm test environment")
41-
36+
flag.BoolVar(&enableVMTest, "enable-vm-test", false, "Enable VM test environment")
4237
flag.Parse()
4338

4439
if *openshift {

tests/e2e/power_monitor_internal_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package e2e
55

66
import (
7+
"strconv"
78
"testing"
89
"time"
910

@@ -31,7 +32,7 @@ func TestPowerMonitorInternal_Reconciliation(t *testing.T) {
3132
b.WithNamespace(testNs),
3233
b.WithKeplerImage(testKeplerRebootImage),
3334
b.WithCluster(Cluster),
34-
b.WithAnnotation(vmAnnotationKey, enableVMEnv),
35+
b.WithAnnotation(vmAnnotationKey, strconv.FormatBool(enableVMTest)),
3536
)
3637

3738
// then the following resources will be created

tests/e2e/power_monitor_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package e2e
55

66
import (
7+
"strconv"
78
"testing"
89
"time"
910

@@ -22,7 +23,7 @@ func TestPowerMonitor_Deletion(t *testing.T) {
2223
f := test.NewFramework(t)
2324

2425
// pre-condition: ensure powermonitor exists
25-
f.CreatePowerMonitor("power-monitor", f.WithPowerMonitorAnnotation(vmAnnotationKey, enableVMEnv))
26+
f.CreatePowerMonitor("power-monitor", f.WithPowerMonitorAnnotation(vmAnnotationKey, strconv.FormatBool(enableVMTest)))
2627
pm := f.WaitUntilPowerMonitorCondition("power-monitor", v1alpha1.Available, v1alpha1.ConditionTrue)
2728

2829
//
@@ -48,7 +49,7 @@ func TestPowerMonitor_Reconciliation(t *testing.T) {
4849
f.AssertNoResourceExists("power-monitor", "", &v1alpha1.PowerMonitor{})
4950

5051
// when
51-
pm := f.CreatePowerMonitor("power-monitor", f.WithPowerMonitorAnnotation(vmAnnotationKey, enableVMEnv))
52+
pm := f.CreatePowerMonitor("power-monitor", f.WithPowerMonitorAnnotation(vmAnnotationKey, strconv.FormatBool(enableVMTest)))
5253

5354
// then
5455
f.AssertResourceExists(controller.PowerMonitorDeploymentNS, "", &corev1.Namespace{})
@@ -95,7 +96,7 @@ func TestPowerMonitorNodeSelector(t *testing.T) {
9596

9697
pm := f.CreatePowerMonitor("power-monitor",
9798
f.WithPowerMonitorNodeSelector(labels),
98-
f.WithPowerMonitorAnnotation(vmAnnotationKey, enableVMEnv))
99+
f.WithPowerMonitorAnnotation(vmAnnotationKey, strconv.FormatBool(enableVMTest)))
99100

100101
f.AssertResourceExists(controller.PowerMonitorDeploymentNS, "", &corev1.Namespace{})
101102
ds := appsv1.DaemonSet{}
@@ -119,7 +120,7 @@ func TestPowerMonitorNodeSelectorUnavailableLabel(t *testing.T) {
119120

120121
pm := f.CreatePowerMonitor("power-monitor",
121122
f.WithPowerMonitorNodeSelector(unavailableLabels),
122-
f.WithPowerMonitorAnnotation(vmAnnotationKey, enableVMEnv))
123+
f.WithPowerMonitorAnnotation(vmAnnotationKey, strconv.FormatBool(enableVMTest)))
123124

124125
f.AssertResourceExists(controller.PowerMonitorDeploymentNS, "", &corev1.Namespace{})
125126
ds := appsv1.DaemonSet{}
@@ -155,7 +156,7 @@ func TestPowerMonitorTaint_WithToleration(t *testing.T) {
155156

156157
pm := f.CreatePowerMonitor("power-monitor",
157158
f.WithPowerMonitorTolerations(append(node.Spec.Taints, e2eTestTaint)),
158-
f.WithPowerMonitorAnnotation(vmAnnotationKey, enableVMEnv))
159+
f.WithPowerMonitorAnnotation(vmAnnotationKey, strconv.FormatBool(enableVMTest)))
159160
f.AssertResourceExists(controller.PowerMonitorDeploymentNS, "", &corev1.Namespace{})
160161
ds := appsv1.DaemonSet{}
161162
f.AssertResourceExists(pm.Name, controller.PowerMonitorDeploymentNS, &ds)
@@ -193,7 +194,7 @@ func TestBadPowerMonitorTaint_WithToleration(t *testing.T) {
193194

194195
pm := f.CreatePowerMonitor("power-monitor",
195196
f.WithPowerMonitorTolerations(append(node.Spec.Taints, badTestTaint)),
196-
f.WithPowerMonitorAnnotation(vmAnnotationKey, enableVMEnv))
197+
f.WithPowerMonitorAnnotation(vmAnnotationKey, strconv.FormatBool(enableVMTest)))
197198

198199
f.AssertResourceExists(controller.PowerMonitorDeploymentNS, "", &corev1.Namespace{})
199200
ds := appsv1.DaemonSet{}

tests/run-e2e.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ declare -r OPERATOR_CSV="bundle/manifests/$OPERATOR.clusterserviceversion.yaml"
1818
declare -r OPERATOR_DEPLOY_NAME="kepler-operator-controller"
1919
declare -r OPERATOR_RELEASED_BUNDLE="quay.io/sustainable_computing_io/$OPERATOR-bundle"
2020
declare -r TEST_IMAGES_YAML="tests/images.yaml"
21-
declare ENABLE_VM_TEST
2221

2322
declare IMG_BASE="${IMG_BASE:-localhost:5001/$OPERATOR}"
2423
# NOTE: this vars are initialized in init_operator_img
@@ -29,6 +28,7 @@ declare CI_MODE=false
2928
declare NO_DEPLOY=false
3029
declare NO_BUILDS=false
3130
declare SHOW_USAGE=false
31+
declare ENABLE_VM_TEST=false
3232
declare LOGS_DIR="tmp/e2e"
3333
declare OPERATORS_NS="operators"
3434
declare TEST_TIMEOUT="15m"
@@ -213,6 +213,7 @@ run_e2e() {
213213
local ret=0
214214
run go test -v -failfast -timeout $TEST_TIMEOUT \
215215
./tests/e2e/... "$@" \
216+
-enable-vm-test=$ENABLE_VM_TEST \
216217
2>&1 | tee "$LOGS_DIR/e2e.log" || ret=1
217218

218219
# terminate both log_events
@@ -261,8 +262,7 @@ parse_args() {
261262
shift
262263
;;
263264
--enable-vm-test)
264-
ENABLE_VM_TEST="true"
265-
export ENABLE_VM_TEST # export vm test results
265+
ENABLE_VM_TEST=true
266266
shift
267267
;;
268268
--image-base)

0 commit comments

Comments
 (0)