Skip to content

Commit

Permalink
Fix assigning of policies to WCP namespace in case of policy driven v…
Browse files Browse the repository at this point in the history
…olume provisioing testcases
  • Loading branch information
Aishwarya-Hebbar committed Jan 30, 2025
1 parent 37f0ecc commit c2069ee
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 38 deletions.
224 changes: 202 additions & 22 deletions tests/e2e/policy_driven_vol_allocation.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/e2e/snapshot_vmservice_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ var _ bool = ginkgo.Describe("[snapshot-vmsvc] Snapshot VM Service VM", func() {
framework.Logf("Create a WCP namespace for the test")
// creating wcp test namespace and setting vmclass, contlib, storage class fields in test ns
namespace = createTestWcpNs(
vcRestSessionId, storageProfileId, vmClass, contentLibId, getSvcId(vcRestSessionId))
vcRestSessionId, storageProfileId, "", "", vmClass, contentLibId, getSvcId(vcRestSessionId))

// creating vm schema
vmopScheme := runtime.NewScheme()
Expand Down
4 changes: 1 addition & 3 deletions tests/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6302,9 +6302,7 @@ func assignPolicyToWcpNamespace(client clientset.Interface, ctx context.Context,
curlCmd := fmt.Sprintf(`curl -s -o /dev/null -w "%s" -k -X PATCH`+
` 'https://%s/api/vcenter/namespaces/instances/%s' -H `+
`'vmware-api-session-id: %s' -H 'Content-type: application/json' -d `+
`'{ "access_list": [ { "domain": "", "role": "OWNER", "subject": "", "subject_type": "USER" } ], `+
`"description": "", "resource_spec": { }, "storage_specs": [ %s ], `+
`"vm_service_spec": { } }'`, httpCodeStr, vcIp, namespace, sessionId, curlStr)
`'{"storage_specs": [ %s ]}'`, httpCodeStr, vcIp, namespace, sessionId, curlStr)

framework.Logf("Running command: %s", curlCmd)
result, err := fssh.SSH(ctx, curlCmd, vcAddress, framework.TestContext.Provider)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/vm_service_vsan_stretch_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var _ bool = ginkgo.Describe("[vsan-stretch-vmsvc] vm service with csi vol tests
vmClass = vmClassBestEffortSmall
}
namespace = createTestWcpNs(
vcRestSessionId, storageProfileId, vmClass, contentLibId, getSvcId(vcRestSessionId))
vcRestSessionId, storageProfileId, "", "", vmClass, contentLibId, getSvcId(vcRestSessionId))

time.Sleep(5 * time.Minute)

Expand Down
80 changes: 70 additions & 10 deletions tests/e2e/vmservice_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type subscribedContentLibBasic struct {

// createTestWcpNs create a wcp namespace with given storage policy, vm class and content lib via REST API
func createTestWcpNs(
vcRestSessionId string, storagePolicyId string, vmClass string, contentLibId string,
vcRestSessionId string, eztstoragePolicyId string, lztstoragePolicyId string, thinstoragePolicyId string, vmClass string, contentLibId string,
supervisorId string) string {

vcIp := e2eVSphere.Config.Global.VCenterHostname
Expand All @@ -74,17 +74,17 @@ func createTestWcpNs(
"namespace": "%s",
"storage_specs": [ {
"policy": "%s"
} ],
"vm_service_spec": {
"vm_classes": [
"%s"
],
"content_libraries": [
"%s"
]
},
{
"policy": "%s"
},
{
"policy": "%s"
} ],
"supervisor": "%s"
}`, namespace, storagePolicyId, vmClass, contentLibId, supervisorId)
}`, namespace, eztstoragePolicyId, lztstoragePolicyId, thinstoragePolicyId, supervisorId)

framework.Logf("reqBody: %v", reqBody)

_, statusCode := invokeVCRestAPIPostRequest(vcRestSessionId, nsCreationUrl, reqBody)
gomega.Expect(statusCode).Should(gomega.BeNumerically("==", 204))
Expand Down Expand Up @@ -1193,3 +1193,63 @@ func createVMServiceandWaitForVMtoGetIP(ctx context.Context, vmopC ctlrclient.Cl
}
}
}

// createTestWcpNs create a wcp namespace with given storage policy, vm class and content lib via REST API
func createTestWcpNsWithStoragePolicy(
vcRestSessionId string, policyNames []string,
resourceQuotaLimit string, prefixNs string, supervisorId string) string {

curlStr := ""
policyNamesArrLength := len(policyNames)
defRqLimit := strings.Split(resourceQuotaLimit, "Gi")[0]
limit, err := strconv.Atoi(defRqLimit)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
limit *= 953 // to convert gb to mebibytes
if policyNamesArrLength >= 1 {
curlStr += fmt.Sprintf(`{ "limit": %d,"policy": "%s"}`, limit, e2eVSphere.GetSpbmPolicyID(policyNames[0]))
}
if policyNamesArrLength >= 2 {
for i := 1; i < policyNamesArrLength; i++ {
profileID := e2eVSphere.GetSpbmPolicyID(policyNames[i])
curlStr += "," + fmt.Sprintf(`{ "limit": %d,"policy": "%s"}`, limit, profileID)
}
}
vcIp := e2eVSphere.Config.Global.VCenterHostname
r := rand.New(rand.NewSource(time.Now().Unix()))

namespace := fmt.Sprintf("%s-%v", prefixNs, r.Intn(10000))
nsCreationUrl := "https://" + vcIp + "/api/vcenter/namespaces/instances/v2"
reqBody := fmt.Sprintf(`{
"namespace": "%s",
"storage_specs": [ %s ],
"supervisor": "%s"
}`, namespace, curlStr, supervisorId)

framework.Logf("reqBody: %v", reqBody)

_, statusCode := invokeVCRestAPIPostRequest(vcRestSessionId, nsCreationUrl, reqBody)
gomega.Expect(statusCode).Should(gomega.BeNumerically("==", 204))
framework.Logf("Successfully created namepsace %v in SVC.", namespace)
time.Sleep(5 * time.Minute)
return namespace
}

// waitForNamespaceToGetCreated waits for a namespace to get created or until
// timeout occurs, whichever comes first.
func waitForNamespaceToGetCreated(ctx context.Context, c clientset.Interface,
namespaceToCreate string, Poll, timeout time.Duration) error {
framework.Logf("Waiting up to %v for namespace %s to get created", timeout, namespaceToCreate)
for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) {
namespace, err := c.CoreV1().Namespaces().Get(ctx, namespaceToCreate, metav1.GetOptions{})
if err == nil {
framework.Logf("Namespace %s found and status=%s (%v)", namespaceToCreate, namespace.Status, time.Since(start))
break
}
if apierrors.IsNotFound(err) {
framework.Logf("namespace %s still not created", namespaceToCreate)
continue
}
framework.Logf("Get namespace %s is failed, ignoring for %v: %v", namespaceToCreate, Poll, err)
}
return fmt.Errorf("namespace %s still didn't get created within %v", namespaceToCreate, timeout)
}
2 changes: 1 addition & 1 deletion tests/e2e/vmservice_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var _ bool = ginkgo.Describe("[vmsvc] vm service with csi vol tests", func() {
vmClass = vmClassBestEffortSmall
}
namespace = createTestWcpNs(
vcRestSessionId, storageProfileId, vmClass, contentLibId, getSvcId(vcRestSessionId))
vcRestSessionId, storageProfileId, "", "", vmClass, contentLibId, getSvcId(vcRestSessionId))

vmopScheme := runtime.NewScheme()
gomega.Expect(vmopv1.AddToScheme(vmopScheme)).Should(gomega.Succeed())
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/vsphere_volume_expansion.go
Original file line number Diff line number Diff line change
Expand Up @@ -4173,6 +4173,10 @@ func getFSSizeMb(f *framework.Framework, pod *v1.Pod) (int64, error) {

if supervisorCluster {
namespace := getNamespaceToRunTests(f)
if f.SkipNamespaceCreation == true {
namespace = f.Namespace.Name
}
framework.Logf("namespace: %s", namespace)
var cmd []string
if wcpVsanDirectCluster {
cmd = []string{"exec", pod.Name, "--namespace=" + namespace, "--", "/bin/sh", "-c", "df -Tkm | grep /data0"}
Expand Down

0 comments on commit c2069ee

Please sign in to comment.