Skip to content

Commit

Permalink
fix log collection with region name in providerID
Browse files Browse the repository at this point in the history
Signed-off-by: MatthieuFin <[email protected]>
  • Loading branch information
MatthieuFin committed Oct 29, 2024
1 parent 6e8653b commit 0bf46aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 8 additions & 4 deletions test/e2e/shared/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
6 changes: 1 addition & 5 deletions test/e2e/suites/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0bf46aa

Please sign in to comment.