diff --git a/test/e2e/shared/common.go b/test/e2e/shared/common.go index 8bef9e9964..68f266cb89 100644 --- a/test/e2e/shared/common.go +++ b/test/e2e/shared/common.go @@ -174,9 +174,13 @@ func getOpenStackClusterFromMachine(ctx context.Context, client client.Client, m return openStackCluster, err } -// getIDFromProviderID returns the server ID part of a provider ID string. -func getIDFromProviderID(providerID string) string { - return strings.TrimPrefix(providerID, "openstack:///") +// GetIDFromProviderID returns the server ID part of a provider ID string. +func GetIDFromProviderID(providerID string) string { + providerIDSplit := strings.SplitN(providerID, "://", 2) + Expect(providerIDSplit[0]).To(Equal("openstack")) + providerIDPathSplit := strings.SplitN(providerIDSplit[1], "/", 2) + // providerIDPathSplit[0] contain region name, could be empty + return providerIDPathSplit[1] } type OpenStackLogCollector struct { @@ -201,7 +205,7 @@ func (o OpenStackLogCollector) CollectMachineLog(ctx context.Context, management } ip := m.Status.Addresses[0].Address - srv, err := GetOpenStackServerWithIP(o.E2EContext, getIDFromProviderID(*m.Spec.ProviderID), openStackCluster) + srv, err := GetOpenStackServerWithIP(o.E2EContext, GetIDFromProviderID(*m.Spec.ProviderID), openStackCluster) if err != nil { return fmt.Errorf("error getting OpenStack server: %w", err) } diff --git a/test/e2e/suites/e2e/e2e_test.go b/test/e2e/suites/e2e/e2e_test.go index 7ae512c457..cb860044b4 100644 --- a/test/e2e/suites/e2e/e2e_test.go +++ b/test/e2e/suites/e2e/e2e_test.go @@ -1137,11 +1137,7 @@ func getInstanceIDForMachine(machine *clusterv1.Machine) string { providerID := machine.Spec.ProviderID Expect(providerID).NotTo(BeNil()) - providerIDSplit := strings.SplitN(*providerID, "://", 2) - Expect(providerIDSplit[0]).To(Equal("openstack")) - providerIDPathSplit := strings.SplitN(providerIDSplit[1], "/", 2) - // providerIDPathSplit[0] contain region name, could be empty - return providerIDPathSplit[1] + return shared.GetIDFromProviderID(*machine.Spec.ProviderID) } func isErrorEventExists(namespace, machineDeploymentName, eventReason, errorMsg string, eList *corev1.EventList) bool {