Skip to content

Commit

Permalink
Update VM controller unit test BackupRestore FSS enablement
Browse files Browse the repository at this point in the history
  • Loading branch information
dilyar85 committed Sep 13, 2023
1 parent ac55ce9 commit 7088eaa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package v1alpha1_test
import (
"context"
"errors"
"os"
"strings"
"sync/atomic"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -158,25 +158,13 @@ func unitTestsReconcile() {
})

When("The VM Service Backup and Restore FSS is enabled", func() {
var (
// This is manipulated atomically to avoid races where the controller
// is trying to read this _while_ the tests are updating it.
vmServiceBackupRestoreFSS uint32
origVMServiceBackupRestoreFSS uint32
)

// Modify the helper function to return the custom value of the FSS.
lib.IsVMServiceBackupRestoreFSSEnabled = func() bool {
return atomic.LoadUint32(&vmServiceBackupRestoreFSS) != 0
}

BeforeEach(func() {
origVMServiceBackupRestoreFSS = vmServiceBackupRestoreFSS
atomic.StoreUint32(&vmServiceBackupRestoreFSS, 1)
Expect(os.Setenv(lib.VMServiceBackupRestoreFSS, lib.TrueString)).To(Succeed())
})

AfterEach(func() {
atomic.StoreUint32(&vmServiceBackupRestoreFSS, origVMServiceBackupRestoreFSS)
Expect(os.Unsetenv(lib.VMServiceBackupRestoreFSS)).To(Succeed())
})

It("Should call backup Virtual Machine if ReconcileNormal succeeds", func() {
Expand Down
21 changes: 10 additions & 11 deletions pkg/lib/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

const (
trueString = "true"
TrueString = "true"
VmopNamespaceEnv = "POD_NAMESPACE"
WcpFaultDomainsFSS = "FSS_WCP_FAULTDOMAINS"
Expand Down Expand Up @@ -89,43 +88,43 @@ var IsNamedNetworkProviderEnabled = func() bool {
}

var IsWcpFaultDomainsFSSEnabled = func() bool {
return os.Getenv(WcpFaultDomainsFSS) == trueString
return os.Getenv(WcpFaultDomainsFSS) == TrueString
}

func IsVMServiceV1Alpha2FSSEnabled() bool {
return os.Getenv(VMServiceV1Alpha2FSS) == trueString
return os.Getenv(VMServiceV1Alpha2FSS) == TrueString
}

var IsInstanceStorageFSSEnabled = func() bool {
return os.Getenv(InstanceStorageFSS) == trueString
return os.Getenv(InstanceStorageFSS) == TrueString
}

var IsUnifiedTKGFSSEnabled = func() bool {
return os.Getenv(UnifiedTKGFSS) == trueString
return os.Getenv(UnifiedTKGFSS) == TrueString
}

var IsVMClassAsConfigFSSEnabled = func() bool {
return os.Getenv(VMClassAsConfigFSS) == trueString
return os.Getenv(VMClassAsConfigFSS) == TrueString
}

var IsVMClassAsConfigFSSDaynDateEnabled = func() bool {
return os.Getenv(VMClassAsConfigDaynDateFSS) == trueString
return os.Getenv(VMClassAsConfigDaynDateFSS) == TrueString
}

var IsWCPVMImageRegistryEnabled = func() bool {
return os.Getenv(VMImageRegistryFSS) == trueString
return os.Getenv(VMImageRegistryFSS) == TrueString
}

var IsNamespacedVMClassFSSEnabled = func() bool {
return os.Getenv(NamespacedVMClassFSS) == trueString
return os.Getenv(NamespacedVMClassFSS) == TrueString
}

var IsWindowsSysprepFSSEnabled = func() bool {
return os.Getenv(WindowsSysprepFSS) == trueString
return os.Getenv(WindowsSysprepFSS) == TrueString
}

var IsVMServiceBackupRestoreFSSEnabled = func() bool {
return os.Getenv(VMServiceBackupRestoreFSS) == trueString
return os.Getenv(VMServiceBackupRestoreFSS) == TrueString
}

// MaxConcurrentCreateVMsOnProvider returns the percentage of reconciler
Expand Down

0 comments on commit 7088eaa

Please sign in to comment.