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 27, 2025
1 parent 37f0ecc commit 5d37489
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 16 deletions.
28 changes: 25 additions & 3 deletions tests/e2e/policy_driven_vol_allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ var spareSpace int64 = 200
var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation tests", func() {
f := framework.NewDefaultFramework("e2e-spbm-policy")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
if supervisorCluster {
f.SkipNamespaceCreation = true
}
var (
client clientset.Interface
namespace string
Expand All @@ -71,13 +74,16 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
sshWcpConfig *ssh.ClientConfig
svcNamespace string
pandoraSyncWaitTime int
vcRestSessionId string
)

ginkgo.BeforeEach(func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client = f.ClientSet
namespace = getNamespaceToRunTests(f)
if vanillaCluster {
namespace = getNamespaceToRunTests(f)
}
bootstrap()
if guestCluster {
svcClient, svNamespace := getSvcClientAndNamespace()
Expand Down Expand Up @@ -126,6 +132,9 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
setVpxdTaskTimeout(ctx, 0) // reset vpxd timeout to default
if supervisorCluster {
dumpSvcNsEventsOnTestFailure(client, namespace)

delTestWcpNs(vcRestSessionId, namespace)
gomega.Expect(waitForNamespaceToGetDeleted(ctx, client, namespace, poll, pollTimeout)).To(gomega.Succeed())
}
if guestCluster {
svcClient, svNamespace := getSvcClientAndNamespace()
Expand Down Expand Up @@ -267,7 +276,20 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
}

if supervisorCluster {
assignPolicyToWcpNamespace(client, ctx, namespace, policyNames, resourceQuotaLimit)
//vcAddress := e2eVSphere.Config.Global.VCenterHostname + ":" + sshdPort
vcRestSessionId = createVcSession4RestApis(ctx)

//storageClassName = strings.ReplaceAll(storagePolicyName, "_", "-") // since this is a wcp setup

/*eztstoragePolicyId := e2eVSphere.GetSpbmPolicyID(policyNames[0])
lztstoragePolicyId := e2eVSphere.GetSpbmPolicyID(policyNames[1])
thinstoragePolicyId := e2eVSphere.GetSpbmPolicyID(policyNames[2])*/

framework.Logf("Create a WCP namespace for the test")

namespace = createTestWcpNsWithStoragePolicy(
vcRestSessionId, policyNames, resourceQuotaLimit, "e2e-spbm", getSvcId(vcRestSessionId))
//assignPolicyToWcpNamespace(client, ctx, namespace, policyNames, resourceQuotaLimit)
} else if guestCluster {
_, svNamespace := getSvcClientAndNamespace()
assignPolicyToWcpNamespace(client, ctx, svNamespace, policyNames, resourceQuotaLimit)
Expand All @@ -285,7 +307,7 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
} else if supervisorCluster {
ginkgo.By("CNS_TEST: Running for WCP setup")
// create resource quota
createResourceQuota(client, namespace, rqLimit, policyName)
//createResourceQuota(client, namespace, rqLimit, policyName)
if wcpVsanDirectCluster {
storageclass, err = client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand Down
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
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
60 changes: 50 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,43 @@ 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
}
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

0 comments on commit 5d37489

Please sign in to comment.