-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): Reserve and unreserve CP endpoint IP per test cluster
- Loading branch information
1 parent
11e642c
commit 051d397
Showing
13 changed files
with
451 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//go:build e2e | ||
|
||
// Copyright 2024 Nutanix. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package nutanix | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
prismcommonapi "github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4/models/common/v1/config" | ||
prismapi "github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4/models/prism/v4/config" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/utils/ptr" | ||
"sigs.k8s.io/cluster-api/test/framework/clusterctl" | ||
|
||
prismgoclient "github.com/nutanix-cloud-native/prism-go-client" | ||
prismclientv4 "github.com/nutanix-cloud-native/prism-go-client/v4" | ||
) | ||
|
||
const ( | ||
prismEndpointVariableName = "NUTANIX_ENDPOINT" | ||
prismPortVariableName = "NUTANIX_PORT" | ||
prismUsernameVariableName = "NUTANIX_USER" | ||
prismPasswordVariableName = "NUTANIX_PASSWORD" | ||
) | ||
|
||
func CredentialsFromCAPIE2EConfig(e2eConfig *clusterctl.E2EConfig) *prismgoclient.Credentials { | ||
return &prismgoclient.Credentials{ | ||
Endpoint: e2eConfig.GetVariable(prismEndpointVariableName), | ||
Port: e2eConfig.GetVariable(prismPortVariableName), | ||
Username: e2eConfig.GetVariable(prismUsernameVariableName), | ||
Password: e2eConfig.GetVariable(prismPasswordVariableName), | ||
Insecure: false, | ||
} | ||
} | ||
|
||
func NewV4Client(credentials *prismgoclient.Credentials) (*prismclientv4.Client, error) { | ||
v4Client, err := prismclientv4.NewV4Client(*credentials) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create Nutanix V4 API client: %w", err) | ||
} | ||
|
||
return v4Client, nil | ||
} | ||
|
||
func WaitForTaskCompletion( | ||
ctx context.Context, | ||
taskID string, | ||
v4Client *prismclientv4.Client, | ||
) ([]prismcommonapi.KVPair, error) { | ||
var data []prismcommonapi.KVPair | ||
|
||
if err := wait.PollUntilContextCancel( | ||
ctx, | ||
100*time.Millisecond, | ||
true, | ||
func(ctx context.Context) (done bool, err error) { | ||
task, err := v4Client.TasksApiInstance.GetTaskById(ptr.To(taskID)) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to get task %s: %w", taskID, err) | ||
} | ||
|
||
taskData, ok := task.GetData().(prismapi.Task) | ||
if !ok { | ||
return false, fmt.Errorf("unexpected task data type %[1]T: %+[1]v", task.GetData()) | ||
} | ||
|
||
if ptr.Deref(taskData.Status, prismapi.TASKSTATUS_UNKNOWN) != prismapi.TASKSTATUS_SUCCEEDED { | ||
return false, nil | ||
} | ||
|
||
data = taskData.CompletionDetails | ||
|
||
return true, nil | ||
}, | ||
); err != nil { | ||
return nil, fmt.Errorf("failed to wait for task %s to complete: %w", taskID, err) | ||
} | ||
|
||
return data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//go:build e2e | ||
|
||
// Copyright 2024 Nutanix. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package nutanix | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/google/uuid" | ||
clustersapi "github.com/nutanix/ntnx-api-golang-clients/clustermgmt-go-client/v4/models/clustermgmt/v4/config" | ||
"k8s.io/utils/ptr" | ||
|
||
prismclientv4 "github.com/nutanix-cloud-native/prism-go-client/v4" | ||
) | ||
|
||
func GetClusterUUIDFromName(cluster string, v4Client *prismclientv4.Client) (uuid.UUID, error) { | ||
clusterUUID, err := uuid.Parse(cluster) | ||
if err == nil { | ||
return clusterUUID, nil | ||
} | ||
|
||
response, err := v4Client.ClustersApiInstance.ListClusters( | ||
nil, | ||
nil, | ||
ptr.To(`name eq '`+cluster+`'`), | ||
nil, | ||
nil, | ||
nil, | ||
) | ||
if err != nil { | ||
return uuid.UUID{}, fmt.Errorf( | ||
"failed to find cluster uuid for cluster %s: %w", | ||
cluster, | ||
err, | ||
) | ||
} | ||
clusters := response.GetData() | ||
if clusters == nil { | ||
return uuid.UUID{}, fmt.Errorf("no cluster found with name %s", cluster) | ||
} | ||
|
||
switch apiClusters := clusters.(type) { | ||
case []clustersapi.Cluster: | ||
if len(apiClusters) == 0 { | ||
return uuid.UUID{}, fmt.Errorf("no subnet found with name %s", cluster) | ||
} | ||
|
||
clusterUUID, err := uuid.Parse(*apiClusters[0].ExtId) | ||
if err != nil { | ||
return uuid.UUID{}, fmt.Errorf("failed to parse cluster uuid for cluster %s: %w", cluster, err) | ||
} | ||
|
||
return clusterUUID, nil | ||
default: | ||
return uuid.UUID{}, fmt.Errorf("unknown response: %+v", clusters) | ||
} | ||
} |
Oops, something went wrong.