Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
fsdiff test fix (#326)
Browse files Browse the repository at this point in the history
remove the need to discover fsdiff pod
   update the fsdiff handler
   remove unnecessary script and folder from code base
  • Loading branch information
hamadise authored Aug 27, 2021
1 parent aaea790 commit 5bd77cc
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 48 deletions.
1 change: 1 addition & 0 deletions pkg/config/autodiscover/autodiscover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions pkg/config/autodiscover/autodiscover_partner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
}
}
1 change: 1 addition & 0 deletions pkg/config/autodiscover/pod_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 0 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pkg/config/configsections/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/config/configsections/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 23 additions & 15 deletions pkg/tnf/handlers/cnffsdiff/cnffsdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand All @@ -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}
}
35 changes: 17 additions & 18 deletions test-network-function/platform/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 5bd77cc

Please sign in to comment.