From f61f6fb9fed460e0d129f618fc440b975f3bdfae Mon Sep 17 00:00:00 2001 From: ahreehong <46465244+ahreehong@users.noreply.github.com> Date: Mon, 16 Oct 2023 10:14:46 -0700 Subject: [PATCH] Add e2e for oob configuration --- internal/test/e2e/oob.go | 23 ++++++++++++++++ test/e2e/oob.go | 26 +++++++++++++++++++ test/e2e/tinkerbell_test.go | 30 +++++++++++++++++++++ test/framework/cluster.go | 12 +++++++++ test/framework/oob.go | 52 +++++++++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 internal/test/e2e/oob.go create mode 100644 test/e2e/oob.go create mode 100644 test/framework/oob.go diff --git a/internal/test/e2e/oob.go b/internal/test/e2e/oob.go new file mode 100644 index 0000000000000..90331e290e9b9 --- /dev/null +++ b/internal/test/e2e/oob.go @@ -0,0 +1,23 @@ +package e2e + +import ( + "os" + "regexp" + + e2etests "github.com/aws/eks-anywhere/test/framework" +) + +func (e *E2ESession) setupOOBEnv(testRegex string) error { + re := regexp.MustCompile(`^.*OOB.*$`) + if !re.MatchString(testRegex) { + return nil + } + + requiredEnvVars := e2etests.RequiredOOBEnvVars() + for _, eVar := range requiredEnvVars { + if val, ok := os.LookupEnv(eVar); ok { + e.testEnvVars[eVar] = val + } + } + return nil +} diff --git a/test/e2e/oob.go b/test/e2e/oob.go new file mode 100644 index 0000000000000..661e2bffef42d --- /dev/null +++ b/test/e2e/oob.go @@ -0,0 +1,26 @@ +package e2e + +import ( + "github.com/aws/eks-anywhere/pkg/api/v1alpha1" + "github.com/aws/eks-anywhere/test/framework" +) + +func runOOBConfigFlow(test *framework.ClusterE2ETest) { + test.GenerateClusterConfig() + test.GenerateHardwareConfig() + test.CreateCluster(framework.WithControlPlaneWaitTimeout("20m")) + test.DeleteCluster() + test.PowerOffHardware() + test.ValidateHardwareDecommissioned() +} + +func runOOBConfigUpgradeFlow(test *framework.ClusterE2ETest, updateVersion v1alpha1.KubernetesVersion, clusterOpts ...framework.ClusterE2ETestOpt) { + test.GenerateClusterConfig() + test.GenerateHardwareConfig() + test.CreateCluster(framework.WithControlPlaneWaitTimeout("20m")) + test.UpgradeClusterWithNewConfig(clusterOpts) + test.ValidateCluster(updateVersion) + test.StopIfFailed() + test.DeleteCluster() + test.ValidateHardwareDecommissioned() +} diff --git a/test/e2e/tinkerbell_test.go b/test/e2e/tinkerbell_test.go index c0e052d4c626c..ac50c02f315eb 100644 --- a/test/e2e/tinkerbell_test.go +++ b/test/e2e/tinkerbell_test.go @@ -2125,3 +2125,33 @@ func TestTinkerbellAirgappedKubernetes128UbuntuProxyConfigFlow(t *testing.T) { runTinkerbellAirgapConfigProxyFlow(test, "10.80.0.0/16") } + +// OOB test +func TestTinkerbellKubernetes127UbuntuOOB(t *testing.T) { + test := framework.NewClusterE2ETest( + t, + framework.NewTinkerbell(t, framework.WithUbuntu127Tinkerbell()), + framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube127)), + framework.WithOOBConfiguration(), + framework.WithControlPlaneHardware(1), + framework.WithWorkerHardware(1), + ) + runOOBConfigFlow(test) +} + +func TestTinkerbellK8sUpgrade127to128WithUbuntuOOB(t *testing.T) { + test := framework.NewClusterE2ETest( + t, + framework.NewTinkerbell(t, framework.WithUbuntu127Tinkerbell()), + framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube127)), + framework.WithOOBConfiguration(), + framework.WithControlPlaneHardware(1), + framework.WithWorkerHardware(1), + ) + runOOBConfigUpgradeFlow( + test, + v1alpha1.Kube128, + framework.WithClusterUpgrade(api.WithKubernetesVersion(v1alpha1.Kube128)), + provider.WithProviderUpgrade(framework.Ubuntu128Image()), + ) +} diff --git a/test/framework/cluster.go b/test/framework/cluster.go index 703e6387544ba..53e69b86211af 100644 --- a/test/framework/cluster.go +++ b/test/framework/cluster.go @@ -81,6 +81,7 @@ type ClusterE2ETest struct { TestHardware map[string]*api.Hardware HardwarePool map[string]*api.Hardware WithNoPowerActions bool + WithOOBConfiguration bool ClusterName string ClusterConfig *cluster.Config clusterStateValidationConfig *clusterf.StateValidationConfig @@ -495,6 +496,17 @@ func (e *ClusterE2ETest) generateHardwareConfig(opts ...CommandOpt) { } testHardware = hardwareWithNoBMC } + // create hardware CSV with no bmc username/password + if e.WithOOBConfiguration { + hardwareWithNoUsernamePassword := make(map[string]*api.Hardware) + for k, h := range testHardware { + lessBmc := *h + lessBmc.BMCUsername = "" + lessBmc.BMCPassword = "" + hardwareWithNoUsernamePassword[k] = &lessBmc + } + testHardware = hardwareWithNoUsernamePassword + } err := api.WriteHardwareMapToCSV(testHardware, e.HardwareCsvLocation) if err != nil { diff --git a/test/framework/oob.go b/test/framework/oob.go new file mode 100644 index 0000000000000..ed9708d06a71a --- /dev/null +++ b/test/framework/oob.go @@ -0,0 +1,52 @@ +package framework + +import ( + "os" +) + +const ( + // oob related stuff + tinkerbellBMCConsumerURL = "T_TINKERBELL_BMC_CONSUMER_URL" + tinkerbellBMCHMACSecret = "T_TINKERBELL_BMC_HMAC_SECRETS" + tinkerbellBMCTimestampHeader = "T_TINKERBELL_BMC_TIMESTAMP_HEADER" + tinkerbellBMCIncludedPayloadHeaders = "T_TINKERBELL_BMC_INCLUDED_PAYLOAD_HEADERS" +) + +var requiredOOBEnvVars = []string{ + tinkerbellBMCConsumerURL, + tinkerbellBMCHMACSecret, + tinkerbellBMCTimestampHeader, + tinkerbellBMCIncludedPayloadHeaders, +} + +func RequiredOOBEnvVars() []string { + return requiredOOBEnvVars +} + +func WithOOBConfiguration() ClusterE2ETestOpt { + return func(e *ClusterE2ETest) { + checkRequiredEnvVars(e.T, requiredOOBEnvVars) + consumerURL := os.Getenv(tinkerbellBMCConsumerURL) + HMACSecret := os.Getenv(tinkerbellBMCHMACSecret) + timestampHeader := os.Getenv(tinkerbellBMCTimestampHeader) + includedPayloadHeaders := os.Getenv(tinkerbellBMCIncludedPayloadHeaders) + err := os.Setenv("TINKERBELL_BMC_CONSUMER_URL", consumerURL) + if err != nil { + e.T.Fatalf("unable to set TINKERBELL_BMC_CONSUMER_URL: %v", err) + } + err = os.Setenv("TINKERBELL_BMC_HMAC_SECRETS", HMACSecret) + if err != nil { + e.T.Fatalf("unable to set TINKERBELL_BMC_HMAC_SECRETS: %v", err) + } + err = os.Setenv("TINKERBELL_BMC_TIMESTAMP_HEADER", timestampHeader) + if err != nil { + e.T.Fatalf("unable to set TINKERBELL_BMC_TIMESTAMP_HEADER: %v", err) + } + err = os.Setenv("TINKERBELL_BMC_INCLUDED_PAYLOAD_HEADERS", includedPayloadHeaders) + if err != nil { + e.T.Fatalf("unable to set TINKERBELL_BMC_INCLUDED_PAYLOAD_HEADERS: %v", err) + } + + e.WithOOBConfiguration = true + } +}