Skip to content

Commit 7d2dccb

Browse files
authored
Adding test clients for vpxd and vsan (#3359)
#Adding test clients
1 parent 0ac3f21 commit 7d2dccb

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

tests/e2e/clients/vc/vcclient.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package vc
17+
18+
import (
19+
"context"
20+
"fmt"
21+
neturl "net/url"
22+
23+
"github.com/onsi/gomega"
24+
"github.com/vmware/govmomi"
25+
"github.com/vmware/govmomi/vim25"
26+
"sigs.k8s.io/vsphere-csi-driver/v3/tests/e2e/constants"
27+
"sigs.k8s.io/vsphere-csi-driver/v3/tests/e2e/env"
28+
)
29+
30+
const (
31+
RoundTripperDefaultCount = 3
32+
)
33+
34+
// This function creates a new client for vpxd connection.
35+
func NewClient(ctx context.Context, vCenterIp string,
36+
vCenterIpPort string, user string, password string) *govmomi.Client {
37+
isPrivateNetwork := env.GetBoolEnvVarOrDefault("IS_PRIVATE_NETWORK", false)
38+
if isPrivateNetwork {
39+
vCenterIp = env.GetStringEnvVarOrDefault("LOCAL_HOST_IP", constants.DefaultlocalhostIP)
40+
}
41+
url, err := neturl.Parse(fmt.Sprintf("https://%s:%s/sdk",
42+
vCenterIp, vCenterIpPort))
43+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
44+
url.User = neturl.UserPassword(user, password)
45+
client, err := govmomi.NewClient(ctx, url, true)
46+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
47+
err = client.UseServiceVersion(constants.VsanNamespace)
48+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
49+
client.RoundTripper = vim25.Retry(client.RoundTripper, vim25.TemporaryNetworkError(RoundTripperDefaultCount))
50+
return client
51+
}

tests/e2e/clients/vsan/vsanclient.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package vsan
17+
18+
import (
19+
"context"
20+
21+
"github.com/vmware/govmomi/vim25"
22+
"github.com/vmware/govmomi/vim25/soap"
23+
"sigs.k8s.io/vsphere-csi-driver/v3/tests/e2e/constants"
24+
)
25+
26+
// VsanClient struct holds vim and soap client
27+
type VsanClient struct {
28+
Vim25Client *vim25.Client
29+
ServiceClient *soap.Client
30+
}
31+
32+
// newVsanHealthSvcClient returns vSANhealth client.
33+
func NewVsanHealthSvcClient(ctx context.Context, client *vim25.Client) (*VsanClient, error) {
34+
sc := client.Client.NewServiceClient(constants.VsanHealthPath, constants.VsanNamespace)
35+
return &VsanClient{client, sc}, nil
36+
}

0 commit comments

Comments
 (0)