diff --git a/internal/test/e2e/run.go b/internal/test/e2e/run.go index fa4c61b4899b..197401caa56e 100644 --- a/internal/test/e2e/run.go +++ b/internal/test/e2e/run.go @@ -125,7 +125,7 @@ func RunTestsInParallel(conf ParallelRunConf) error { for c := range work { r := instanceTestsResults{conf: c} - r.conf.instanceId, r.testCommandResult, err = RunTests(c, invCatalogue) + r.conf.InstanceID, r.testCommandResult, err = RunTests(c, invCatalogue) if err != nil { r.err = err } @@ -150,22 +150,22 @@ func RunTestsInParallel(conf ParallelRunConf) error { // Once the tool is updated to support the unified message, remove them if r.err != nil { result = testResultError - conf.Logger.Error(r.err, "Failed running e2e tests for instance", "jobId", r.conf.jobId, "instanceId", r.conf.instanceId, "tests", r.conf.regex, "status", testResultFail) + conf.Logger.Error(r.err, "Failed running e2e tests for instance", "jobId", r.conf.JobID, "instanceId", r.conf.InstanceID, "tests", r.conf.Regex, "status", testResultFail) failedInstances++ } else if !r.testCommandResult.Successful() { result = testResultFail - conf.Logger.Info("An e2e instance run has failed", "jobId", r.conf.jobId, "instanceId", r.conf.instanceId, "commandId", r.testCommandResult.CommandId, "tests", r.conf.regex, "status", testResultFail) + conf.Logger.Info("An e2e instance run has failed", "jobId", r.conf.JobID, "instanceId", r.conf.InstanceID, "commandId", r.testCommandResult.CommandId, "tests", r.conf.Regex, "status", testResultFail) failedInstances++ } else { result = testResultPass - conf.Logger.Info("Instance tests completed successfully", "jobId", r.conf.jobId, "instanceId", r.conf.instanceId, "commandId", r.testCommandResult.CommandId, "tests", r.conf.regex, "status", testResultPass) + conf.Logger.Info("Instance tests completed successfully", "jobId", r.conf.JobID, "instanceId", r.conf.InstanceID, "commandId", r.testCommandResult.CommandId, "tests", r.conf.Regex, "status", testResultPass) } completedInstances++ conf.Logger.Info("Instance tests run finished", "result", result, - "tests", r.conf.regex, - "jobId", r.conf.jobId, - "instanceId", r.conf.instanceId, + "tests", r.conf.Regex, + "jobId", r.conf.JobID, + "instanceId", r.conf.InstanceID, "completedInstances", completedInstances, "totalInstances", totalInstances, ) @@ -179,29 +179,35 @@ func RunTestsInParallel(conf ParallelRunConf) error { } type instanceRunConf struct { - session *session.Session - instanceProfileName, storageBucket, jobId, parentJobId, regex, instanceId string - testReportFolder, branchName string - ipPool networkutils.IPPool - hardware []*api.Hardware - hardwareCount int - tinkerbellAirgappedTest bool - bundlesOverride bool - testRunnerType TestRunnerType - testRunnerConfig TestInfraConfig - cleanupVms bool - logger logr.Logger + InstanceProfileName string + StorageBucket string + JobID string + ParentJobID string + Regex string + InstanceID string + TestReportFolder string + BranchName string + IPPool networkutils.IPPool + Hardware []*api.Hardware + HardwareCount int + TinkerbellAirgappedTest bool + BundlesOverride bool + TestRunnerType TestRunnerType + TestRunnerConfig TestInfraConfig + CleanupVMs bool + Logger logr.Logger + Session *session.Session } //nolint:gocyclo, revive // RunTests responsible launching test runner to run tests is complex. func RunTests(conf instanceRunConf, inventoryCatalogue map[string]*hardwareCatalogue) (testInstanceID string, testCommandResult *testCommandResult, err error) { - testRunner, err := newTestRunner(conf.testRunnerType, conf.testRunnerConfig) + testRunner, err := newTestRunner(conf.TestRunnerType, conf.TestRunnerConfig) if err != nil { return "", nil, err } - if conf.hardwareCount > 0 { + if conf.HardwareCount > 0 { var hardwareCatalogue *hardwareCatalogue - if conf.tinkerbellAirgappedTest { + if conf.TinkerbellAirgappedTest { hardwareCatalogue = inventoryCatalogue[airgappedHardware] } else { hardwareCatalogue = inventoryCatalogue[nonAirgappedHardware] @@ -214,16 +220,18 @@ func RunTests(conf instanceRunConf, inventoryCatalogue map[string]*hardwareCatal defer releaseTinkerbellHardware(&conf, hardwareCatalogue) } + conf.Logger.Info("Creating runner instance", "cfg", conf) instanceId, err := testRunner.createInstance(conf) if err != nil { return "", nil, err } - conf.logger.V(1).Info("TestRunner instance has been created", "instanceId", instanceId) + conf.Logger = conf.Logger.WithValues("instance_id", instanceId) + conf.Logger.Info("TestRunner instance has been created") defer func() { err := testRunner.decommInstance(conf) if err != nil { - conf.logger.V(1).Info("WARN: Failed to decomm e2e test runner instance", "error", err) + conf.Logger.V(1).Info("WARN: Failed to decomm e2e test runner instance", "error", err) } }() @@ -232,12 +240,12 @@ func RunTests(conf instanceRunConf, inventoryCatalogue map[string]*hardwareCatal return "", nil, err } - err = session.setup(conf.regex) + err = session.setup(conf.Regex) if err != nil { return session.instanceId, nil, err } - testCommandResult, err = session.runTests(conf.regex) + testCommandResult, err = session.runTests(conf.Regex) if err != nil { return session.instanceId, nil, err } @@ -288,13 +296,13 @@ func (e *E2ESession) runTests(regex string) (testCommandResult *testCommandResul } func (c instanceRunConf) runPostTestsProcessing(e *E2ESession, testCommandResult *testCommandResult) error { - regex := strings.Trim(c.regex, "\"") + regex := strings.Trim(c.Regex, "\"") tests := strings.Split(regex, "|") for _, testName := range tests { e.uploadJUnitReportFromInstance(testName) - if c.testReportFolder != "" { - e.downloadJUnitReportToLocalDisk(testName, c.testReportFolder) + if c.TestReportFolder != "" { + e.downloadJUnitReportToLocalDisk(testName, c.TestReportFolder) } if !testCommandResult.Successful() { @@ -486,30 +494,30 @@ func getTinkerbellTestsWithCount(tinkerbellTests []string, conf ParallelRunConf) func newInstanceRunConf(awsSession *session.Session, conf ParallelRunConf, jobNumber int, testRegex string, ipPool networkutils.IPPool, hardware []*api.Hardware, hardwareCount int, tinkerbellAirgappedTest bool, testRunnerType TestRunnerType, testRunnerConfig *TestInfraConfig) instanceRunConf { jobID := fmt.Sprintf("%s-%d", conf.JobId, jobNumber) return instanceRunConf{ - session: awsSession, - instanceProfileName: conf.InstanceProfileName, - storageBucket: conf.StorageBucket, - jobId: jobID, - parentJobId: conf.JobId, - regex: testRegex, - ipPool: ipPool, - hardware: hardware, - hardwareCount: hardwareCount, - tinkerbellAirgappedTest: tinkerbellAirgappedTest, - bundlesOverride: conf.BundlesOverride, - testReportFolder: conf.TestReportFolder, - branchName: conf.BranchName, - cleanupVms: conf.CleanupVms, - testRunnerType: testRunnerType, - testRunnerConfig: *testRunnerConfig, - logger: conf.Logger.WithValues("jobID", jobID, "test", testRegex), + Session: awsSession, + InstanceProfileName: conf.InstanceProfileName, + StorageBucket: conf.StorageBucket, + JobID: jobID, + ParentJobID: conf.JobId, + Regex: testRegex, + IPPool: ipPool, + Hardware: hardware, + HardwareCount: hardwareCount, + TinkerbellAirgappedTest: tinkerbellAirgappedTest, + BundlesOverride: conf.BundlesOverride, + TestReportFolder: conf.TestReportFolder, + BranchName: conf.BranchName, + CleanupVMs: conf.CleanupVms, + TestRunnerType: testRunnerType, + TestRunnerConfig: *testRunnerConfig, + Logger: conf.Logger.WithValues("jobID", jobID, "test", testRegex), } } func logTestGroups(logger logr.Logger, instancesConf []instanceRunConf) { testGroups := make([]string, 0, len(instancesConf)) for _, i := range instancesConf { - testGroups = append(testGroups, i.regex) + testGroups = append(testGroups, i.Regex) } logger.V(1).Info("Running tests in parallel", "testsGroups", testGroups) } @@ -551,24 +559,24 @@ func getAirgappedHardwarePool(storageBucket string) ([]*api.Hardware, error) { } func reserveTinkerbellHardware(conf *instanceRunConf, invCatalogue *hardwareCatalogue) error { - reservedTinkerbellHardware, err := invCatalogue.reserveHardware(conf.hardwareCount) + reservedTinkerbellHardware, err := invCatalogue.reserveHardware(conf.HardwareCount) if err != nil { return fmt.Errorf("timed out waiting for hardware") } - conf.hardware = reservedTinkerbellHardware + conf.Hardware = reservedTinkerbellHardware logTinkerbellTestHardwareInfo(conf, "Reserved") return nil } func releaseTinkerbellHardware(conf *instanceRunConf, invCatalogue *hardwareCatalogue) { logTinkerbellTestHardwareInfo(conf, "Releasing") - invCatalogue.releaseHardware(conf.hardware) + invCatalogue.releaseHardware(conf.Hardware) } func logTinkerbellTestHardwareInfo(conf *instanceRunConf, action string) { var hardwareInfo []string - for _, hardware := range conf.hardware { + for _, hardware := range conf.Hardware { hardwareInfo = append(hardwareInfo, hardware.Hostname) } - conf.logger.V(1).Info(action+" hardware for TestRunner", "hardwarePool", strings.Join(hardwareInfo, ", ")) + conf.Logger.V(1).Info(action+" hardware for TestRunner", "hardwarePool", strings.Join(hardwareInfo, ", ")) } diff --git a/internal/test/e2e/setup.go b/internal/test/e2e/setup.go index 554d4c98f995..e6ea140a88ca 100644 --- a/internal/test/e2e/setup.go +++ b/internal/test/e2e/setup.go @@ -49,19 +49,19 @@ type E2ESession struct { func newE2ESession(instanceId string, conf instanceRunConf) (*E2ESession, error) { e := &E2ESession{ - session: conf.session, + session: conf.Session, instanceId: instanceId, - instanceProfileName: conf.instanceProfileName, - storageBucket: conf.storageBucket, - jobId: conf.jobId, - ipPool: conf.ipPool, + instanceProfileName: conf.InstanceProfileName, + storageBucket: conf.StorageBucket, + jobId: conf.JobID, + ipPool: conf.IPPool, testEnvVars: make(map[string]string), - bundlesOverride: conf.bundlesOverride, - cleanupVms: conf.cleanupVms, + bundlesOverride: conf.BundlesOverride, + cleanupVms: conf.CleanupVMs, requiredFiles: requiredFiles, - branchName: conf.branchName, - hardware: conf.hardware, - logger: conf.logger, + branchName: conf.BranchName, + hardware: conf.Hardware, + logger: conf.Logger, } return e, nil @@ -179,6 +179,7 @@ func (e *E2ESession) setup(regex string) error { } ipPool := e.ipPool.ToString() + if ipPool != "" { e.testEnvVars[e2etests.ClusterIPPoolEnvVar] = ipPool } diff --git a/internal/test/e2e/testRunner.go b/internal/test/e2e/testRunner.go index 0ce0e08b957e..7f6e9490e83a 100644 --- a/internal/test/e2e/testRunner.go +++ b/internal/test/e2e/testRunner.go @@ -132,10 +132,10 @@ func (v *VSphereTestRunner) setEnvironment() (map[string]string, error) { } func (v *VSphereTestRunner) createInstance(c instanceRunConf) (string, error) { - name := getTestRunnerName(v.logger, c.jobId) + name := getTestRunnerName(v.logger, c.JobID) v.logger.V(1).Info("Creating vSphere Test Runner instance", "name", name) - ssmActivationInfo, err := ssm.CreateActivation(c.session, name, c.instanceProfileName) + ssmActivationInfo, err := ssm.CreateActivation(c.Session, name, c.InstanceProfileName) if err != nil { return "", fmt.Errorf("unable to create ssm activation: %v", err) } @@ -152,7 +152,7 @@ func (v *VSphereTestRunner) createInstance(c instanceRunConf) (string, error) { PropertyMapping: []vsphere.OVFProperty{ {Key: ssmActivationCodeKey, Value: ssmActivationInfo.ActivationCode}, {Key: ssmActivationIdKey, Value: ssmActivationInfo.ActivationID}, - {Key: ssmActivationRegionKey, Value: *c.session.Config.Region}, + {Key: ssmActivationRegionKey, Value: *c.Session.Config.Region}, }, } @@ -163,7 +163,7 @@ func (v *VSphereTestRunner) createInstance(c instanceRunConf) (string, error) { var ssmInstance *aws_ssm.InstanceInformation err = retrier.Retry(10, 5*time.Second, func() error { - ssmInstance, err = ssm.GetInstanceByActivationId(c.session, ssmActivationInfo.ActivationID) + ssmInstance, err = ssm.GetInstanceByActivationId(c.Session, ssmActivationInfo.ActivationID) if err != nil { return fmt.Errorf("failed to get ssm instance info post ovf deployment: %v", err) } @@ -180,19 +180,19 @@ func (v *VSphereTestRunner) createInstance(c instanceRunConf) (string, error) { } func (e *Ec2TestRunner) createInstance(c instanceRunConf) (string, error) { - name := getTestRunnerName(e.logger, c.jobId) + name := getTestRunnerName(e.logger, c.JobID) e.logger.V(1).Info("Creating ec2 Test Runner instance", "name", name) - instanceId, err := ec2.CreateInstance(c.session, e.AmiID, key, tag, c.instanceProfileName, e.SubnetID, name) + instanceID, err := ec2.CreateInstance(c.Session, e.AmiID, key, tag, c.InstanceProfileName, e.SubnetID, name) if err != nil { return "", fmt.Errorf("creating instance for e2e tests: %v", err) } - e.logger.V(1).Info("Instance created", "instance-id", instanceId) - e.InstanceID = instanceId - return instanceId, nil + e.logger.V(1).Info("Instance created", "instance-id", instanceID) + e.InstanceID = instanceID + return instanceID, nil } func (v *VSphereTestRunner) tagInstance(c instanceRunConf, key, value string) error { - vmName := getTestRunnerName(v.logger, c.jobId) + vmName := getTestRunnerName(v.logger, c.JobID) vmPath := fmt.Sprintf("/%s/vm/%s/%s", v.Datacenter, v.Folder, vmName) tag := fmt.Sprintf("%s:%s", key, value) @@ -203,7 +203,7 @@ func (v *VSphereTestRunner) tagInstance(c instanceRunConf, key, value string) er } func (e *Ec2TestRunner) tagInstance(c instanceRunConf, key, value string) error { - err := ec2.TagInstance(c.session, e.InstanceID, key, value) + err := ec2.TagInstance(c.Session, e.InstanceID, key, value) if err != nil { return fmt.Errorf("failed to tag Ec2 test runner: %v", err) } @@ -211,9 +211,9 @@ func (e *Ec2TestRunner) tagInstance(c instanceRunConf, key, value string) error } func (v *VSphereTestRunner) decommInstance(c instanceRunConf) error { - _, deregisterError := ssm.DeregisterInstance(c.session, v.InstanceID) - _, deactivateError := ssm.DeleteActivation(c.session, v.ActivationId) - deleteError := cleanup.VsphereRmVms(context.Background(), getTestRunnerName(v.logger, c.jobId), executables.WithGovcEnvMap(v.envMap)) + _, deregisterError := ssm.DeregisterInstance(c.Session, v.InstanceID) + _, deactivateError := ssm.DeleteActivation(c.Session, v.ActivationId) + deleteError := cleanup.VsphereRmVms(context.Background(), getTestRunnerName(v.logger, c.JobID), executables.WithGovcEnvMap(v.envMap)) if deregisterError != nil { return fmt.Errorf("failed to decommission vsphere test runner ssm instance: %v", deregisterError) @@ -231,9 +231,9 @@ func (v *VSphereTestRunner) decommInstance(c instanceRunConf) error { } func (e *Ec2TestRunner) decommInstance(c instanceRunConf) error { - runnerName := getTestRunnerName(e.logger, c.jobId) + runnerName := getTestRunnerName(e.logger, c.JobID) e.logger.V(1).Info("Terminating ec2 Test Runner instance", "instanceID", e.InstanceID, "runner", runnerName) - if err := ec2.TerminateEc2Instances(c.session, aws.StringSlice([]string{e.InstanceID})); err != nil { + if err := ec2.TerminateEc2Instances(c.Session, aws.StringSlice([]string{e.InstanceID})); err != nil { return fmt.Errorf("terminating instance %s for runner %s: %w", e.InstanceID, runnerName, err) } diff --git a/test/framework/cluster.go b/test/framework/cluster.go index 2b5c2a6b2a26..631740a65f35 100644 --- a/test/framework/cluster.go +++ b/test/framework/cluster.go @@ -59,6 +59,7 @@ const ( JobIdVar = "T_JOB_ID" BundlesOverrideVar = "T_BUNDLES_OVERRIDE" ClusterIPPoolEnvVar = "T_CLUSTER_IP_POOL" + ClusterIPEnvVar = "T_CLUSTER_IP" CleanupVmsVar = "T_CLEANUP_VMS" hardwareYamlPath = "hardware.yaml" hardwareCsvPath = "hardware.csv"