-
Notifications
You must be signed in to change notification settings - Fork 286
/
vsphere.go
53 lines (45 loc) · 1.42 KB
/
vsphere.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package e2e
import (
"fmt"
"os"
"regexp"
"strings"
e2etests "github.com/aws/eks-anywhere/test/framework"
)
const (
vsphereCidrVar = "T_VSPHERE_CIDR"
vspherePrivateNetworkCidrVar = "T_VSPHERE_PRIVATE_NETWORK_CIDR"
vsphereRegex = `^.*VSphere.*$`
)
func (e *E2ESession) setupVSphereEnv(testRegex string) error {
re := regexp.MustCompile(vsphereRegex)
if !re.MatchString(testRegex) {
return nil
}
requiredEnvVars := e2etests.RequiredVsphereEnvVars()
for _, eVar := range requiredEnvVars {
if val, ok := os.LookupEnv(eVar); ok {
e.testEnvVars[eVar] = val
}
}
// This algorithm is not very efficient with two nested loops
// Making the assumption that VSphereExtraEnvVarPrefixes() returns a very small number of prefixes
// this should be ok and probably not worth the complexity of building a more complex data structure.
// If in the future we see the need to have a bigger number of prefixes, we will need
// to change this to avoid the n*m complexity
envVars := os.Environ()
for _, envVarPrefix := range e2etests.VSphereExtraEnvVarPrefixes() {
for _, envVar := range envVars {
if strings.HasPrefix(envVar, envVarPrefix) {
split := strings.Split(envVar, "=")
if len(split) != 2 {
return fmt.Errorf("invalid vsphere env var format, expected key=value: %s", envVar)
}
key := split[0]
value := split[1]
e.testEnvVars[key] = value
}
}
}
return nil
}