Skip to content

Commit

Permalink
Merge pull request #623 from test-network-function/remove_err_check
Browse files Browse the repository at this point in the history
Various ginkgo_removal fixes
  • Loading branch information
sebrandon1 authored Dec 13, 2023
2 parents e384710 + 86f2445 commit bb41d30
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ make install

* To debug

Use `DEBUG_TNF=true` and `TNF_LOG_LEVEL=trace` while running the above commands.
Use `DEBUG_TNF=true` and `TNF_LOG_LEVEL=debug` while running the above commands.
This would create a `Debug` folder containing suites folders with TNF logs for each of the tests.

```sh
Expand All @@ -153,7 +153,7 @@ This would create a `Debug` folder containing suites folders with TNF logs for e
FEATURES=platformalteration \
KUBECONFIG=$HOME/.kube/config \
NON_LINUX_ENV= \
TNF_LOG_LEVEL=trace \
TNF_LOG_LEVEL=debug \
TNF_REPO_PATH=$HOME/path/to/cnf-certification-test \
make test-features
```
Expand All @@ -163,7 +163,7 @@ This would create a `Debug` folder containing suites folders with TNF logs for e
DEBUG_TNF=true \
FEATURES=platformalteration \
KUBECONFIG=$HOME/.kube/config \
TNF_LOG_LEVEL=trace \
TNF_LOG_LEVEL=debug \
TNF_REPO_PATH=$HOME/path/to/cnf-certification-test \
make test-features
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var _ = Describe("Access-control bpf-capability-check,", func() {
dep, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -63,6 +64,7 @@ var _ = Describe("Access-control bpf-capability-check,", func() {

deployment.RedefineWithContainersSecurityContextBpf(dep)

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -84,12 +86,15 @@ var _ = Describe("Access-control bpf-capability-check,", func() {
dep, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment1", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment without BPF")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

By("Define deployment 2 without BPF")
dep2, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment2", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 2 without BPF")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep2, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -113,12 +118,15 @@ var _ = Describe("Access-control bpf-capability-check,", func() {

deployment.RedefineWithContainersSecurityContextBpf(dep)

By("Create deployment with BPF")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

By("Define deployment 2 without BPF")
dep2, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment2", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 2 without BPF")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep2, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var _ = Describe("Access-control container-host-port,", func() {
dep, err := tshelper.DefineDeployment(1, 1, "acdeployment", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -71,6 +72,7 @@ var _ = Describe("Access-control container-host-port,", func() {
dep, err := tshelper.DefineDeploymentWithContainerPorts("acdeployment", randomNamespace, 1, ports)
Expect(err).ToNot(HaveOccurred())

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -102,6 +104,7 @@ var _ = Describe("Access-control container-host-port,", func() {
dep, err := tshelper.DefineDeploymentWithContainerPorts("acdeployment", randomNamespace, 1, ports)
Expect(err).ToNot(HaveOccurred())

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -136,6 +139,7 @@ var _ = Describe("Access-control container-host-port,", func() {
dep, err := tshelper.DefineDeploymentWithContainerPorts("acdeployment", randomNamespace, 1, ports)
Expect(err).ToNot(HaveOccurred())

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var _ = Describe("Access-control non-root user,", func() {
dep, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -70,6 +71,7 @@ var _ = Describe("Access-control non-root user,", func() {

deployment.RedefineWithPodSecurityContextRunAsUser(dep, 0)

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -98,6 +100,7 @@ var _ = Describe("Access-control non-root user,", func() {
dep, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment1", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 1")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -110,6 +113,7 @@ var _ = Describe("Access-control non-root user,", func() {
dep2, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment2", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 2")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep2, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -139,6 +143,7 @@ var _ = Describe("Access-control non-root user,", func() {

deployment.RedefineWithPodSecurityContextRunAsUser(dep, 0)

By("Create deployment 1")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -148,9 +153,11 @@ var _ = Describe("Access-control non-root user,", func() {
Expect(runningDeployment.Spec.Template.Spec.SecurityContext.RunAsUser).ToNot(BeNil())
Expect(*runningDeployment.Spec.Template.Spec.SecurityContext.RunAsUser).To(Equal(int64(0)))

By("Define deployment 2")
dep2, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment2", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 2")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep2, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var _ = Describe("Access-control ipc-lock-capability-check,", func() {

deployment.RedefineWithContainersSecurityContextIpcLock(dep)

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -99,6 +100,7 @@ var _ = Describe("Access-control ipc-lock-capability-check,", func() {
dep, err := tshelper.DefineDeployment(1, 1, "acdeployment1", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 1")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -110,6 +112,7 @@ var _ = Describe("Access-control ipc-lock-capability-check,", func() {
dep2, err := tshelper.DefineDeployment(1, 1, "acdeployment2", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 2")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep2, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -139,6 +142,7 @@ var _ = Describe("Access-control ipc-lock-capability-check,", func() {

deployment.RedefineWithContainersSecurityContextIpcLock(dep)

By("Create deployment 1")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -148,9 +152,11 @@ var _ = Describe("Access-control ipc-lock-capability-check,", func() {
Expect(runningDeployment.Spec.Template.Spec.Containers[0].
SecurityContext.Capabilities.Add).To(ContainElement(corev1.Capability("IPC_LOCK")))

By("Define deployment 2")
dep2, err := tshelper.DefineDeployment(1, 1, "acdeployment2", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 2")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep2, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var _ = Describe("Access-control namespace-resource-quota,", func() {
dep, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -81,6 +82,7 @@ var _ = Describe("Access-control namespace-resource-quota,", func() {
dep, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -99,10 +101,11 @@ var _ = Describe("Access-control namespace-resource-quota,", func() {

// 56471
It("two deployments, one pod each, both in a namespace with resource quota", func() {
By("Define deployments")
By("Define deployment 1")
dep, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment1", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 1")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -114,10 +117,12 @@ var _ = Describe("Access-control namespace-resource-quota,", func() {
err = globalhelper.CreateResourceQuota(resourceQuota)
Expect(err).ToNot(HaveOccurred())

By("Define deployment 2")
dep2, err := tshelper.DefineDeploymentWithNamespace(1, 1, "accesscontroldeployment2",
randomNamespace2)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 2")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep2, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -144,17 +149,20 @@ var _ = Describe("Access-control namespace-resource-quota,", func() {

// 56472
It("two deployments, one pod each, one in a namespace without resource quota [negative]", func() {
By("Define deployments")
By("Define deployment 1")
dep, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment1", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 1")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

By("Define deployment 2")
dep2, err := tshelper.DefineDeploymentWithNamespace(1, 1, "accesscontroldeployment2",
randomNamespace2)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 2")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep2, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var _ = Describe("Access-control net-admin-capability-check,", func() {
dep, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -71,6 +72,7 @@ var _ = Describe("Access-control net-admin-capability-check,", func() {

deployment.RedefineWithContainersSecurityContextNetAdmin(dep)

By("Create deployment")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -99,6 +101,7 @@ var _ = Describe("Access-control net-admin-capability-check,", func() {
dep, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment1", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 1")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -107,9 +110,11 @@ var _ = Describe("Access-control net-admin-capability-check,", func() {
Expect(err).ToNot(HaveOccurred())
Expect(runningDeployment.Spec.Template.Spec.Containers[0].SecurityContext).To(BeNil())

By("Define deployment 2")
dep2, err := tshelper.DefineDeployment(1, 1, "accesscontroldeployment2", randomNamespace)
Expect(err).ToNot(HaveOccurred())

By("Create deployment 2")
err = globalhelper.CreateAndWaitUntilDeploymentIsReady(dep2, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred())

Expand Down
12 changes: 7 additions & 5 deletions tests/globalhelper/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ func CreateAndWaitUntilDaemonSetIsReady(daemonSet *appsv1.DaemonSet, timeout tim
}

// CreateAndWaitUntilDaemonSetIsReady creates daemonSet and waits until all pods are up and running.
func createAndWaitUntilDaemonSetIsReady(client appsv1Typed.AppsV1Interface, daemonSet *appsv1.DaemonSet, timeout time.Duration) error {
runningDaemonSet, err := client.DaemonSets(daemonSet.Namespace).Create(
func createAndWaitUntilDaemonSetIsReady(appsClient appsv1Typed.AppsV1Interface,
daemonSet *appsv1.DaemonSet, timeout time.Duration) error {
runningDaemonSet, err := appsClient.DaemonSets(daemonSet.Namespace).Create(
context.TODO(), daemonSet, metav1.CreateOptions{})
if k8serrors.IsAlreadyExists(err) {
glog.V(5).Info(fmt.Sprintf("daemonset %s already exists", daemonSet.Name))
Expand All @@ -32,7 +33,7 @@ func createAndWaitUntilDaemonSetIsReady(client appsv1Typed.AppsV1Interface, daem
}

Eventually(func() bool {
status, err := isDaemonSetReady(client, runningDaemonSet.Namespace, runningDaemonSet.Name)
status, err := isDaemonSetReady(appsClient, runningDaemonSet.Namespace, runningDaemonSet.Name)
if err != nil {
glog.Errorf(
"daemonset %s is not ready, retry in 5 seconds", runningDaemonSet.Name)
Expand All @@ -56,8 +57,9 @@ func isDaemonSetReady(client appsv1Typed.AppsV1Interface, namespace string, name
return false, err
}

if daemonSet.Status.NumberAvailable == daemonSet.Status.DesiredNumberScheduled &&
daemonSet.Status.NumberUnavailable == 0 &&
// Get number of nodes and compare with the number of scheduled pods
numNodes := GetNumberOfNodes()
if daemonSet.Status.DesiredNumberScheduled == int32(numNodes) &&
daemonSet.Status.NumberReady == daemonSet.Status.DesiredNumberScheduled {
return true, nil
}
Expand Down
2 changes: 1 addition & 1 deletion tests/globalhelper/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestCreateAndWaitUntilDaemonSetIsReady(t *testing.T) {
client := k8sfake.NewSimpleClientset(runtimeObjects...)

t.Run(testCase.name, func(t *testing.T) {
err := createAndWaitUntilDaemonSetIsReady(client.AppsV1(),
err := createAndWaitUntilDaemonSetIsReady(client.AppsV1(), client.CoreV1(),
generateDaemonset(testCase.numAvailable, testCase.numScheduled, testCase.numUnavailable, testCase.numReady), 5)
if (err != nil) != testCase.wantErr {
t.Errorf("CreateAndWaitUntilDaemonSetIsReady() error = %v, wantErr %v", err, testCase.wantErr)
Expand Down
7 changes: 7 additions & 0 deletions tests/globalhelper/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ func BeforeEachSetupWithRandomNamespace(incomingNamespace string) (randomNamespa
}

func AfterEachCleanupWithRandomNamespace(randomNamespace, origReportDir, origConfigDir string, waitingTime time.Duration) {
// logfile := "cnf-certsuite.log"
// By("Print logs")
// myFile, err := os.ReadFile(GetConfiguration().General.TnfReportDir + "/" + logfile)
// if err != nil {
// glog.Errorf("can not read file %s - %s", logfile, err)
// }
// fmt.Println(string(myFile))
By(fmt.Sprintf("Remove reports from report directory: %s", GetConfiguration().General.TnfReportDir))

err := RemoveContentsFromReportDir()
Expand Down
16 changes: 16 additions & 0 deletions tests/globalhelper/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,19 @@ func NodeHasHugePagesEnabled(node *corev1.Node, resourceName string) bool {

return hugepagesEnabled
}

func GetNumberOfNodes() int {
return getNumberOfNodes(GetAPIClient().K8sClient.CoreV1())
}

func getNumberOfNodes(client corev1Typed.CoreV1Interface) int {
nodes, err := client.Nodes().List(context.TODO(), metav1.ListOptions{
LabelSelector: "node-role.kubernetes.io/worker-cnf",
})

if err != nil {
return 0
}

return len(nodes.Items)
}
1 change: 1 addition & 0 deletions tests/lifecycle/tests/lifecycle_container_startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ var _ = Describe("lifecycle-container-poststart", func() {
globalhelper.GetConfiguration().General.TestImage,
tsparams.TestTargetLabels, tsparams.TestDaemonSetName)

By("Deploy daemonSet")
err := globalhelper.CreateAndWaitUntilDaemonSetIsReady(daemonSet, tsparams.WaitingTime)
Expect(err).ToNot(HaveOccurred())

Expand Down
Loading

0 comments on commit bb41d30

Please sign in to comment.