From 5bd77cc7b321b74c16e8e8df7359ee8807f7b00c Mon Sep 17 00:00:00 2001 From: Salaheddine Hamadi Date: Fri, 27 Aug 2021 17:40:13 -0400 Subject: [PATCH] fsdiff test fix (#326) remove the need to discover fsdiff pod update the fsdiff handler remove unnecessary script and folder from code base --- pkg/config/autodiscover/autodiscover.go | 1 + .../autodiscover/autodiscover_partner.go | 11 ------ pkg/config/autodiscover/pod_info.go | 1 + pkg/config/config.go | 2 - pkg/config/configsections/common.go | 2 - pkg/config/configsections/container.go | 1 + pkg/tnf/handlers/cnffsdiff/cnffsdiff.go | 38 +++++++++++-------- test-network-function/platform/suite.go | 35 +++++++++-------- 8 files changed, 43 insertions(+), 48 deletions(-) diff --git a/pkg/config/autodiscover/autodiscover.go b/pkg/config/autodiscover/autodiscover.go index e4fb25ab6..ce35dddff 100644 --- a/pkg/config/autodiscover/autodiscover.go +++ b/pkg/config/autodiscover/autodiscover.go @@ -113,6 +113,7 @@ func buildContainersFromPodResource(pr *PodResource) (containers []configsection container.Namespace = pr.Metadata.Namespace container.PodName = pr.Metadata.Name container.ContainerName = containerResource.Name + container.NodeName = pr.Spec.NodeName container.DefaultNetworkDevice, err = pr.getDefaultNetworkDeviceFromAnnotations() if err != nil { log.Warnf("error encountered getting default network device: %s", err) diff --git a/pkg/config/autodiscover/autodiscover_partner.go b/pkg/config/autodiscover/autodiscover_partner.go index b8ac75297..f35da8d23 100644 --- a/pkg/config/autodiscover/autodiscover_partner.go +++ b/pkg/config/autodiscover/autodiscover_partner.go @@ -24,7 +24,6 @@ import ( const ( genericLabelName = "generic" orchestratorValue = "orchestrator" - fsDiffMasterValue = "fs_diff_master" ) // FindTestPartner completes a `configsections.TestPartner` from the current state of the cluster, @@ -38,14 +37,4 @@ func FindTestPartner(tp *configsections.TestPartner) { tp.ContainerConfigList = append(tp.ContainerConfigList, orchestrator) tp.TestOrchestratorID = orchestrator.ContainerIdentifier } - - if tp.FsDiffMasterContainerID.ContainerName == "" { - fsDiffMasterContainer, err := getContainerByLabel(configsections.Label{Namespace: tnfNamespace, Name: genericLabelName, Value: fsDiffMasterValue}) - if err == nil { - tp.ContainerConfigList = append(tp.ContainerConfigList, fsDiffMasterContainer) - tp.FsDiffMasterContainerID = fsDiffMasterContainer.ContainerIdentifier - } else { - log.Warnf("an error (%s) occurred when getting the FS Diff Master Container. Attempting to continue", err) - } - } } diff --git a/pkg/config/autodiscover/pod_info.go b/pkg/config/autodiscover/pod_info.go index c2645d873..fe0cc49c2 100644 --- a/pkg/config/autodiscover/pod_info.go +++ b/pkg/config/autodiscover/pod_info.go @@ -54,6 +54,7 @@ type PodResource struct { Containers []struct { Name string `json:"name"` } `json:"containers"` + NodeName string `json:"nodeName"` } `json:"spec"` Status struct { PodIPs []map[string]string `json:"podIPs"` diff --git a/pkg/config/config.go b/pkg/config/config.go index b6e770afc..c15011619 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -119,7 +119,6 @@ type TestEnvironment struct { // connectivity testing. ContainersToExcludeFromConnectivityTests map[configsections.ContainerIdentifier]interface{} TestOrchestrator *Container - FsDiffMasterContainer *Container Config configsections.TestConfiguration // loaded tracks if the config has been loaded to prevent it being reloaded. loaded bool @@ -179,7 +178,6 @@ func (env *TestEnvironment) doAutodiscover() { env.PodsUnderTest = env.Config.PodsUnderTest env.PartnerContainers = env.createContainers(env.Config.Partner.ContainerConfigList) env.TestOrchestrator = env.PartnerContainers[env.Config.Partner.TestOrchestratorID] - env.FsDiffMasterContainer = env.PartnerContainers[env.Config.Partner.FsDiffMasterContainerID] log.Info(env.TestOrchestrator) log.Info(env.ContainersUnderTest) env.needsRefresh = false diff --git a/pkg/config/configsections/common.go b/pkg/config/configsections/common.go index 62f420e80..c88c50bd2 100644 --- a/pkg/config/configsections/common.go +++ b/pkg/config/configsections/common.go @@ -60,8 +60,6 @@ type TestPartner struct { ContainerConfigList []ContainerConfig `yaml:"partnerContainers" json:"partnerContainers"` // TestOrchestratorID is the id of the partner container for conducting connectivity tests TestOrchestratorID ContainerIdentifier `yaml:"testOrchestrator" json:"testOrchestrator"` - // FsDiffMasterContainerID is the id of the partner container for conducting base image comparison - FsDiffMasterContainerID ContainerIdentifier `yaml:"fsDiffMasterContainer" json:"fsDiffMasterContainer"` } // TestTarget is a collection of resources under test diff --git a/pkg/config/configsections/container.go b/pkg/config/configsections/container.go index 97d03c829..7c7356e23 100644 --- a/pkg/config/configsections/container.go +++ b/pkg/config/configsections/container.go @@ -21,6 +21,7 @@ type ContainerIdentifier struct { Namespace string `yaml:"namespace" json:"namespace"` PodName string `yaml:"podName" json:"podName"` ContainerName string `yaml:"containerName" json:"containerName"` + NodeName string `yaml:"nodeName" json:"nodeName"` } // ContainerConfig contains the payload of container facets. diff --git a/pkg/tnf/handlers/cnffsdiff/cnffsdiff.go b/pkg/tnf/handlers/cnffsdiff/cnffsdiff.go index 8fad03662..6cd2041ba 100644 --- a/pkg/tnf/handlers/cnffsdiff/cnffsdiff.go +++ b/pkg/tnf/handlers/cnffsdiff/cnffsdiff.go @@ -29,15 +29,15 @@ type CnfFsDiff struct { result int timeout time.Duration args []string - diff string } const ( - // SuccessfulOutputRegex matches a successfully run "fsdiff" command. That does not mean that no errors or drops - // occurred during the test. - SuccessfulOutputRegex = `(?m)empty\n` - // AcceptAllRegex matches all strings - AcceptAllRegex = `(?m)(.|\n)+` + bin = `(?m)\/bin` + sbin = `(?m)\/sbin` + lib = `(?m)\/lib` + err = `(?m)Error` + successfulOutputRegex = `(?m){}` + acceptAllRegex = `(?m)(.|\n)+` ) // Args returns the command line args for the test. @@ -71,10 +71,18 @@ func (p *CnfFsDiff) ReelFirst() *reel.Step { // ReelMatch checks if the test passed the first regex which means there were no installation on the container // or the second regex which accepts everything and means that something in the container was installed. func (p *CnfFsDiff) ReelMatch(pattern, before, match string) *reel.Step { - if pattern == SuccessfulOutputRegex { - p.result = tnf.SUCCESS - } else { + p.result = tnf.SUCCESS + switch pattern { + case lib: + p.result = tnf.FAILURE + case bin: p.result = tnf.FAILURE + case sbin: + p.result = tnf.FAILURE + case err: + p.result = tnf.ERROR + case successfulOutputRegex: + p.result = tnf.SUCCESS } return nil } @@ -89,20 +97,20 @@ func (p *CnfFsDiff) ReelEOF() { } // Command returns command line args for checking the fs difference between a container and it's image -func Command(containerID string) []string { - return []string{"/diff-fs.sh", containerID} +func Command(containerID, nodeName string) []string { + return []string{"echo", "-e", "\"chroot /host\n\"", "podman", "diff", "--format", "json", containerID, "|", "oc", "debug", "node/" + nodeName} } // NewFsDiff creates a new `FsDiff` test which checks the fs difference between a container and it's image -func NewFsDiff(timeout time.Duration, containerID string) *CnfFsDiff { +func NewFsDiff(timeout time.Duration, containerID, nodeName string) *CnfFsDiff { return &CnfFsDiff{ - result: tnf.ERROR, + result: tnf.SUCCESS, timeout: timeout, - args: Command(containerID), + args: Command(containerID, nodeName), } } // GetReelFirstRegularExpressions returns the regular expressions used for matching in ReelFirst. func (p *CnfFsDiff) GetReelFirstRegularExpressions() []string { - return []string{SuccessfulOutputRegex, AcceptAllRegex} + return []string{err, bin, sbin, lib, successfulOutputRegex, acceptAllRegex} } diff --git a/test-network-function/platform/suite.go b/test-network-function/platform/suite.go index 3cf96d3b1..db49a3c54 100644 --- a/test-network-function/platform/suite.go +++ b/test-network-function/platform/suite.go @@ -32,7 +32,6 @@ import ( "github.com/onsi/ginkgo" ginkgoconfig "github.com/onsi/ginkgo/config" "github.com/onsi/gomega" - log "github.com/sirupsen/logrus" "github.com/test-network-function/test-network-function/pkg/tnf" "github.com/test-network-function/test-network-function/pkg/tnf/handlers/base/redhat" "github.com/test-network-function/test-network-function/pkg/tnf/handlers/cnffsdiff" @@ -116,23 +115,25 @@ func testContainerIsRedHatRelease(cut *config.Container) { func testContainersFsDiff(env *config.TestEnvironment) { testID := identifiers.XformToGinkgoItIdentifier(identifiers.TestUnalteredBaseImageIdentifier) ginkgo.It(testID, func() { - fsDiffContainer := env.FsDiffMasterContainer - if fsDiffContainer != nil { - for _, cut := range env.ContainersUnderTest { - podName := cut.Oc.GetPodName() - containerName := cut.Oc.GetPodContainerName() - context := cut.Oc - ginkgo.By(fmt.Sprintf("%s(%s) should not install new packages after starting", podName, containerName)) - testContainerFsDiff(fsDiffContainer.Oc, context) + var badContainers []string + for _, cut := range env.ContainersUnderTest { + podName := cut.Oc.GetPodName() + containerName := cut.Oc.GetPodContainerName() + context := cut.Oc + nodeName := cut.ContainerConfiguration.NodeName + ginkgo.By(fmt.Sprintf("%s(%s) should not install new packages after starting", podName, containerName)) + testResult, err := testContainerFsDiff(nodeName, context) + if testResult != tnf.SUCCESS || err != nil { + badContainers = append(badContainers, containerName) + ginkgo.By(fmt.Sprintf("pod %s container %s did update/install/modify additional packages", podName, containerName)) } - } else { - log.Warn("no fs diff container is configured, cannot run fs diff test") } + gomega.Expect(badContainers).To(gomega.BeNil()) }) } // testContainerFsDiff test that the CUT didn't install new packages after starting, and report through Ginkgo. -func testContainerFsDiff(masterPodOc, targetContainerOC *interactive.Oc) { +func testContainerFsDiff(nodeName string, targetContainerOC *interactive.Oc) (int, error) { defer results.RecordResult(identifiers.TestUnalteredBaseImageIdentifier) targetContainerOC.GetExpecter() containerIDTester := containerid.NewContainerID(common.DefaultTimeout) @@ -142,13 +143,11 @@ func testContainerFsDiff(masterPodOc, targetContainerOC *interactive.Oc) { gomega.Expect(testResult).To(gomega.Equal(tnf.SUCCESS)) gomega.Expect(err).To(gomega.BeNil()) containerID := containerIDTester.GetID() - - fsDiffTester := cnffsdiff.NewFsDiff(common.DefaultTimeout, containerID) - test, err = tnf.NewTest(masterPodOc.GetExpecter(), fsDiffTester, []reel.Handler{fsDiffTester}, masterPodOc.GetErrorChannel()) - gomega.Expect(err).To(gomega.BeNil()) - testResult, err = test.Run() - gomega.Expect(testResult).To(gomega.Equal(tnf.SUCCESS)) + context := common.GetContext() + fsDiffTester := cnffsdiff.NewFsDiff(common.DefaultTimeout, containerID, nodeName) + test, err = tnf.NewTest(context.GetExpecter(), fsDiffTester, []reel.Handler{fsDiffTester}, context.GetErrorChannel()) gomega.Expect(err).To(gomega.BeNil()) + return test.Run() } func getMcKernelArguments(context *interactive.Context, mcName string) map[string]string {