Skip to content

Commit

Permalink
E2E test: enhance logging via ginkgo/gomega
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
  • Loading branch information
ArangoGutierrez committed Apr 24, 2024
1 parent d5f92aa commit 125279e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
9 changes: 5 additions & 4 deletions tests/e2e/common/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,19 @@ func CleanupNode(ctx context.Context, cs clientset.Interface) {
}

if updateStatus {
By("Deleting NFD extended resources from node " + nodeName)
By("[Cleanup]\tDeleting NFD extended resources from node " + nodeName)
if _, err := cs.CoreV1().Nodes().UpdateStatus(ctx, node, metav1.UpdateOptions{}); err != nil {
return err
}
}

if update {
By("Deleting NFD labels, annotations and taints from node " + node.Name)
By("[Cleanup]\tDeleting NFD labels, annotations and taints from node " + node.Name)
if _, err := cs.CoreV1().Nodes().Update(ctx, node, metav1.UpdateOptions{}); err != nil {
return err
}
}

return nil
}

Expand Down Expand Up @@ -180,7 +181,7 @@ func cleanupNodeFeatures(ctx context.Context, cli *nfdclient.Clientset, namespac
Expect(err).NotTo(HaveOccurred())

if len(nfs.Items) != 0 {
By("Deleting NodeFeature objects from namespace " + namespace)
By("[Cleanup]\tDeleting NodeFeature objects from namespace " + namespace)
for _, nf := range nfs.Items {
err = cli.NfdV1alpha1().NodeFeatures(namespace).Delete(ctx, nf.Name, metav1.DeleteOptions{})
if errors.IsNotFound(err) {
Expand All @@ -202,7 +203,7 @@ func cleanupNodeFeatureRules(ctx context.Context, cli *nfdclient.Clientset) {
Expect(err).NotTo(HaveOccurred())

if len(nfrs.Items) != 0 {
By("Deleting NodeFeatureRule objects from the cluster")
By("[Cleanup]\tDeleting NodeFeatureRule objects from the cluster")
for _, nfr := range nfrs.Items {
err = cli.NfdV1alpha1().NodeFeatureRules().Delete(ctx, nfr.Name, metav1.DeleteOptions{})
if errors.IsNotFound(err) {
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/device-plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ var _ = NVDescribe("GPU Device Plugin", func() {
ValuesOptions: values,
CleanupOnFail: true,
}

By("Installing k8s-device-plugin Helm chart")
_, err := f.HelmClient.InstallChart(ctx, &chartSpec, nil)
Expect(err).NotTo(HaveOccurred())
})

// Cleanup before next test run
AfterEach(func(ctx context.Context) {
// Run diagnostic collector if test failed
if CurrentSpecReport().Failed() {
Expand All @@ -123,6 +124,7 @@ var _ = NVDescribe("GPU Device Plugin", func() {
err = diagnosticsCollector.Collect(ctx)
Expect(err).NotTo(HaveOccurred())
}
// Cleanup before next test run
// Delete Helm release
err := f.HelmClient.UninstallReleaseByName(helmReleaseName)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -137,7 +139,6 @@ var _ = NVDescribe("GPU Device Plugin", func() {

Context("and NV Driver is installed", func() {
It("it should create nvidia.com/gpu resource", func(ctx context.Context) {
By("Getting node objects")
nodeList, err := f.ClientSet.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(len(nodeList.Items)).ToNot(BeZero())
Expand All @@ -147,24 +148,23 @@ var _ = NVDescribe("GPU Device Plugin", func() {
Expect(err).NotTo(HaveOccurred())

targetNodeName := nodes[0].Name
Expect(targetNodeName).ToNot(BeEmpty(), "No suitable worker node found")
Expect(targetNodeName).ToNot(BeEmpty())

By("Check node capacity")
By("Checking the node capacity")
capacityChecker := map[string]k8sLabels{
targetNodeName: {
"nvidia.com/gpu": "^[1-9]$",
}}
eventuallyNonControlPlaneNodes(ctx, f.ClientSet).Should(MatchCapacity(capacityChecker, nodes))
eventuallyNonControlPlaneNodes(ctx, f.ClientSet).Should(MatchCapacity(capacityChecker, nodes), "Node capacity does not match")
})
It("it should run GPU jobs", func(ctx context.Context) {
By("Creating GPU job")
By("Creating a GPU job")
job := common.GPUJob.DeepCopy()
job.Namespace = f.Namespace.Name
_, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).Create(ctx, job, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())

By("Waiting for job to complete")

Eventually(func() error {
job, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).Get(ctx, job.Name, metav1.GetOptions{})
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,15 @@ func (f *Framework) AfterEach(ctx context.Context) {
// if delete-namespace is true and delete-namespace-on-failure is false, namespace will be preserved if test failed.
if TestContext.DeleteNamespace && (TestContext.DeleteNamespaceOnFailure || !ginkgo.CurrentSpecReport().Failed()) {
for _, ns := range f.namespacesToDelete {
ginkgo.By(fmt.Sprintf("Destroying namespace %q for this suite.", ns.Name))
ginkgo.By(fmt.Sprintf("[Cleanup]\tDeleting testing namespace %q.", ns.Name))
if err := f.ClientSet.CoreV1().Namespaces().Delete(ctx, ns.Name, metav1.DeleteOptions{}); err != nil {
if !apierrors.IsNotFound(err) {
nsDeletionErrors = append(nsDeletionErrors, ns.Name)
}
}
// remove the namespace from the list of namespaces to delete
// so that it is not deleted again in the defer block
f.namespacesToDelete = f.namespacesToDelete[1:]
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func CreateTestingNS(ctx context.Context, baseName string, c clientset.Interface
// regenerate on conflict
namespaceObj.Name = fmt.Sprintf("%v-%v", baseName, RandomSuffix())
} else {
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to create namespace %s", namespaceObj.Name)
}
return false, nil
}
Expand Down
30 changes: 15 additions & 15 deletions tests/e2e/gpu-feature-discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ var _ = NVDescribe("GPU Feature Discovery", func() {
CleanupOnFail: true,
}

By("Installing GFD Helm chart")
_, err := f.HelmClient.InstallChart(ctx, &chartSpec, nil)
Expect(err).NotTo(HaveOccurred())
})
Expand All @@ -156,7 +157,8 @@ var _ = NVDescribe("GPU Feature Discovery", func() {
// Delete Helm release
err := f.HelmClient.UninstallReleaseByName(helmReleaseName)
Expect(err).NotTo(HaveOccurred())
// Cleanup node
// Cleanup environment
By("[Cleanup]\tCleaning up environment")
common.CleanupNode(ctx, f.ClientSet)
common.CleanupNFDObjects(ctx, nfdClient, f.Namespace.Name)
})
Expand All @@ -170,7 +172,6 @@ var _ = NVDescribe("GPU Feature Discovery", func() {

Context("and NV Driver is not installed", func() {
It("it should create nvidia.com timestamp label", func(ctx context.Context) {
By("Getting node objects")
nodeList, err := f.ClientSet.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(len(nodeList.Items)).ToNot(BeZero())
Expand All @@ -180,9 +181,9 @@ var _ = NVDescribe("GPU Feature Discovery", func() {
Expect(err).NotTo(HaveOccurred())

targetNodeName := nodes[0].Name
Expect(targetNodeName).ToNot(BeEmpty(), "No suitable worker node found")
Expect(targetNodeName).ToNot(BeEmpty())

By("Check node labels")
By("Checking the node labels")
labelChecker := map[string]k8sLabels{
targetNodeName: {
"nvidia.com/gfd.timestamp": "[0-9]{10}",
Expand All @@ -199,17 +200,17 @@ var _ = NVDescribe("GPU Feature Discovery", func() {
_, err := f.HelmClient.UpgradeChart(ctx, &chartSpec, nil)
Expect(err).NotTo(HaveOccurred())

By("Checking if node feature object is created")
By("Checking if NodeFeature CR object is created")
nodes, err := common.GetNonControlPlaneNodes(ctx, f.ClientSet)
Expect(err).NotTo(HaveOccurred())

targetNodeName := nodes[0].Name
Expect(targetNodeName).ToNot(BeEmpty(), "No suitable worker node found")
Expect(targetNodeName).ToNot(BeEmpty())
Eventually(func() bool {
return checkNodeFeatureObject(ctx, targetNodeName)
}, 2*time.Minute, 5*time.Second).Should(BeTrue(), "Node feature object is not created")
}, 2*time.Minute, 5*time.Second).Should(BeTrue())

By("Check node labels are created from NodeFeature object")
By("Checking that node labels are created from NodeFeature object")
labelChecker := map[string]k8sLabels{
targetNodeName: {
"nvidia.com/gfd.timestamp": "[0-9]{10}",
Expand All @@ -227,7 +228,6 @@ var _ = NVDescribe("GPU Feature Discovery", func() {
}
})
It("it should create nvidia.com labels", func(ctx context.Context) {
By("Getting node objects")
nodeList, err := f.ClientSet.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(len(nodeList.Items)).ToNot(BeZero())
Expand All @@ -237,9 +237,9 @@ var _ = NVDescribe("GPU Feature Discovery", func() {
Expect(err).NotTo(HaveOccurred())

targetNodeName := nodes[0].Name
Expect(targetNodeName).ToNot(BeEmpty(), "No suitable worker node found")
Expect(targetNodeName).ToNot(BeEmpty())

By("Check node labels")
By("Checking the node labels")
labelChecker := map[string]k8sLabels{
targetNodeName: expectedLabelPatterns}
eventuallyNonControlPlaneNodes(ctx, f.ClientSet).Should(MatchLabels(labelChecker, nodes))
Expand All @@ -254,17 +254,17 @@ var _ = NVDescribe("GPU Feature Discovery", func() {
_, err := f.HelmClient.UpgradeChart(ctx, &chartSpec, nil)
Expect(err).NotTo(HaveOccurred())

By("Checking if node feature object is created")
By("Checking if NodeFeature CR object is created")
nodes, err := common.GetNonControlPlaneNodes(ctx, f.ClientSet)
Expect(err).NotTo(HaveOccurred())

targetNodeName := nodes[0].Name
Expect(targetNodeName).ToNot(BeEmpty(), "No suitable worker node found")
Expect(targetNodeName).ToNot(BeEmpty())
Eventually(func() bool {
return checkNodeFeatureObject(ctx, targetNodeName)
}, 2*time.Minute, 5*time.Second).Should(BeTrue(), "Node feature object is not created")
}, 2*time.Minute, 5*time.Second).Should(BeTrue())

By("Check node labels are created from NodeFeature object")
By("Checking that node labels are created from NodeFeature CR object")
checkForLabels := map[string]k8sLabels{
targetNodeName: expectedLabelPatterns}
eventuallyNonControlPlaneNodes(ctx, f.ClientSet).Should(MatchLabels(checkForLabels, nodes))
Expand Down

0 comments on commit 125279e

Please sign in to comment.