From db073339f28c256e79650a7e3f24829384ee25b9 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Thu, 29 Jun 2023 11:06:53 -0400 Subject: [PATCH] e2e: allow to run regualar vertical scale tests in OpenStack If `OPENSTACK_CONTROLPLANE_FLAVOR_ALTERNATE` is found in the environment variables, we'll use that flavor when running the control plane verticale scale tests. Otherwise, roll back on the tags. --- test/e2e/framework/framework.go | 23 +++++++++++++++++++++++ test/e2e/helpers/machine.go | 10 ++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index c1ed6bae3..189120097 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -21,6 +21,7 @@ import ( "encoding/json" "errors" "fmt" + "os" "regexp" "strconv" @@ -56,6 +57,9 @@ var ( // This means that even though the format is correct, we haven't implemented the logic to increase // this instance size. errInstanceTypeNotSupported = errors.New("instance type is not supported") + + // errMissingInstanceSize is returned when the instance size is missing. + errMissingInstanceSize = errors.New("instance size is missing") ) // Framework is an interface for getting clients and information @@ -236,6 +240,8 @@ func (f *framework) IncreaseProviderSpecInstanceSize(rawProviderSpec *runtime.Ra return increaseGCPInstanceSize(rawProviderSpec, providerConfig) case configv1.NutanixPlatformType: return increaseNutanixInstanceSize(rawProviderSpec, providerConfig) + case configv1.OpenStackPlatformType: + return increaseOpenStackInstanceSize(rawProviderSpec, providerConfig) default: return fmt.Errorf("%w: %s", errUnsupportedPlatform, f.platform) } @@ -683,6 +689,23 @@ func increaseNutanixInstanceSize(rawProviderSpec *runtime.RawExtension, provider return nil } +// increase OpenStackInstanceSize increases the instance size of the instance on the providerSpec for an OpenStack providerSpec. +func increaseOpenStackInstanceSize(rawProviderSpec *runtime.RawExtension, providerConfig providerconfig.ProviderConfig) error { + cfg := providerConfig.OpenStack().Config() + + if os.Getenv("OPENSTACK_CONTROLPLANE_FLAVOR_ALTERNATE") == "" { + return fmt.Errorf("OPENSTACK_CONTROLPLANE_FLAVOR_ALTERNATE environment variable not set: %w", errMissingInstanceSize) + } else { + cfg.Flavor = os.Getenv("OPENSTACK_CONTROLPLANE_FLAVOR_ALTERNATE") + } + + if err := setProviderSpecValue(rawProviderSpec, cfg); err != nil { + return fmt.Errorf("failed to set provider spec value: %w", err) + } + + return nil +} + // nextGCPVMSize returns the next GCP machine size in the series. // The Machine sizes being used are in format -standard-. func nextGCPMachineSize(current string) (string, error) { diff --git a/test/e2e/helpers/machine.go b/test/e2e/helpers/machine.go index 705ed7716..e878cc8b6 100644 --- a/test/e2e/helpers/machine.go +++ b/test/e2e/helpers/machine.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "os" "regexp" "sort" "strconv" @@ -409,8 +410,13 @@ func IncreaseControlPlaneMachineInstanceSize(testFramework framework.Framework, switch platformType { case configv1.OpenStackPlatformType: - // OpenStack flavors are not predictable, so we just tag the instance with a new tag, which will trigger the redeployment. - Expect(testFramework.TagInstanceInProviderSpec(updatedProviderSpec.Value)).To(Succeed(), "provider spec should be updated with a new tag") + // OpenStack flavors are not predictable. So if OPENSTACK_CONTROLPLANE_FLAVOR_ALTERNATE is set in the environment, we'll use it + // to increase the instance size, otherwise we just tag the instance with a new tag, which will trigger the redeployment. + if os.Getenv("OPENSTACK_CONTROLPLANE_FLAVOR_ALTERNATE") == "" { + Expect(testFramework.TagInstanceInProviderSpec(updatedProviderSpec.Value)).To(Succeed(), "provider spec should be updated with a new tag") + } else { + Expect(testFramework.IncreaseProviderSpecInstanceSize(updatedProviderSpec.Value)).To(Succeed(), "provider spec should be updated with bigger instance size") + } default: Expect(testFramework.IncreaseProviderSpecInstanceSize(updatedProviderSpec.Value)).To(Succeed(), "provider spec should be updated with bigger instance size") }