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

Commit 5bd77cc

Browse files
authored
fsdiff test fix (#326)
remove the need to discover fsdiff pod update the fsdiff handler remove unnecessary script and folder from code base
1 parent aaea790 commit 5bd77cc

File tree

8 files changed

+43
-48
lines changed

8 files changed

+43
-48
lines changed

pkg/config/autodiscover/autodiscover.go

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func buildContainersFromPodResource(pr *PodResource) (containers []configsection
113113
container.Namespace = pr.Metadata.Namespace
114114
container.PodName = pr.Metadata.Name
115115
container.ContainerName = containerResource.Name
116+
container.NodeName = pr.Spec.NodeName
116117
container.DefaultNetworkDevice, err = pr.getDefaultNetworkDeviceFromAnnotations()
117118
if err != nil {
118119
log.Warnf("error encountered getting default network device: %s", err)

pkg/config/autodiscover/autodiscover_partner.go

-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
const (
2525
genericLabelName = "generic"
2626
orchestratorValue = "orchestrator"
27-
fsDiffMasterValue = "fs_diff_master"
2827
)
2928

3029
// FindTestPartner completes a `configsections.TestPartner` from the current state of the cluster,
@@ -38,14 +37,4 @@ func FindTestPartner(tp *configsections.TestPartner) {
3837
tp.ContainerConfigList = append(tp.ContainerConfigList, orchestrator)
3938
tp.TestOrchestratorID = orchestrator.ContainerIdentifier
4039
}
41-
42-
if tp.FsDiffMasterContainerID.ContainerName == "" {
43-
fsDiffMasterContainer, err := getContainerByLabel(configsections.Label{Namespace: tnfNamespace, Name: genericLabelName, Value: fsDiffMasterValue})
44-
if err == nil {
45-
tp.ContainerConfigList = append(tp.ContainerConfigList, fsDiffMasterContainer)
46-
tp.FsDiffMasterContainerID = fsDiffMasterContainer.ContainerIdentifier
47-
} else {
48-
log.Warnf("an error (%s) occurred when getting the FS Diff Master Container. Attempting to continue", err)
49-
}
50-
}
5140
}

pkg/config/autodiscover/pod_info.go

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type PodResource struct {
5454
Containers []struct {
5555
Name string `json:"name"`
5656
} `json:"containers"`
57+
NodeName string `json:"nodeName"`
5758
} `json:"spec"`
5859
Status struct {
5960
PodIPs []map[string]string `json:"podIPs"`

pkg/config/config.go

-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ type TestEnvironment struct {
119119
// connectivity testing.
120120
ContainersToExcludeFromConnectivityTests map[configsections.ContainerIdentifier]interface{}
121121
TestOrchestrator *Container
122-
FsDiffMasterContainer *Container
123122
Config configsections.TestConfiguration
124123
// loaded tracks if the config has been loaded to prevent it being reloaded.
125124
loaded bool
@@ -179,7 +178,6 @@ func (env *TestEnvironment) doAutodiscover() {
179178
env.PodsUnderTest = env.Config.PodsUnderTest
180179
env.PartnerContainers = env.createContainers(env.Config.Partner.ContainerConfigList)
181180
env.TestOrchestrator = env.PartnerContainers[env.Config.Partner.TestOrchestratorID]
182-
env.FsDiffMasterContainer = env.PartnerContainers[env.Config.Partner.FsDiffMasterContainerID]
183181
log.Info(env.TestOrchestrator)
184182
log.Info(env.ContainersUnderTest)
185183
env.needsRefresh = false

pkg/config/configsections/common.go

-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ type TestPartner struct {
6060
ContainerConfigList []ContainerConfig `yaml:"partnerContainers" json:"partnerContainers"`
6161
// TestOrchestratorID is the id of the partner container for conducting connectivity tests
6262
TestOrchestratorID ContainerIdentifier `yaml:"testOrchestrator" json:"testOrchestrator"`
63-
// FsDiffMasterContainerID is the id of the partner container for conducting base image comparison
64-
FsDiffMasterContainerID ContainerIdentifier `yaml:"fsDiffMasterContainer" json:"fsDiffMasterContainer"`
6563
}
6664

6765
// TestTarget is a collection of resources under test

pkg/config/configsections/container.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type ContainerIdentifier struct {
2121
Namespace string `yaml:"namespace" json:"namespace"`
2222
PodName string `yaml:"podName" json:"podName"`
2323
ContainerName string `yaml:"containerName" json:"containerName"`
24+
NodeName string `yaml:"nodeName" json:"nodeName"`
2425
}
2526

2627
// ContainerConfig contains the payload of container facets.

pkg/tnf/handlers/cnffsdiff/cnffsdiff.go

+23-15
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ type CnfFsDiff struct {
2929
result int
3030
timeout time.Duration
3131
args []string
32-
diff string
3332
}
3433

3534
const (
36-
// SuccessfulOutputRegex matches a successfully run "fsdiff" command. That does not mean that no errors or drops
37-
// occurred during the test.
38-
SuccessfulOutputRegex = `(?m)empty\n`
39-
// AcceptAllRegex matches all strings
40-
AcceptAllRegex = `(?m)(.|\n)+`
35+
bin = `(?m)\/bin`
36+
sbin = `(?m)\/sbin`
37+
lib = `(?m)\/lib`
38+
err = `(?m)Error`
39+
successfulOutputRegex = `(?m){}`
40+
acceptAllRegex = `(?m)(.|\n)+`
4141
)
4242

4343
// Args returns the command line args for the test.
@@ -71,10 +71,18 @@ func (p *CnfFsDiff) ReelFirst() *reel.Step {
7171
// ReelMatch checks if the test passed the first regex which means there were no installation on the container
7272
// or the second regex which accepts everything and means that something in the container was installed.
7373
func (p *CnfFsDiff) ReelMatch(pattern, before, match string) *reel.Step {
74-
if pattern == SuccessfulOutputRegex {
75-
p.result = tnf.SUCCESS
76-
} else {
74+
p.result = tnf.SUCCESS
75+
switch pattern {
76+
case lib:
77+
p.result = tnf.FAILURE
78+
case bin:
7779
p.result = tnf.FAILURE
80+
case sbin:
81+
p.result = tnf.FAILURE
82+
case err:
83+
p.result = tnf.ERROR
84+
case successfulOutputRegex:
85+
p.result = tnf.SUCCESS
7886
}
7987
return nil
8088
}
@@ -89,20 +97,20 @@ func (p *CnfFsDiff) ReelEOF() {
8997
}
9098

9199
// Command returns command line args for checking the fs difference between a container and it's image
92-
func Command(containerID string) []string {
93-
return []string{"/diff-fs.sh", containerID}
100+
func Command(containerID, nodeName string) []string {
101+
return []string{"echo", "-e", "\"chroot /host\n\"", "podman", "diff", "--format", "json", containerID, "|", "oc", "debug", "node/" + nodeName}
94102
}
95103

96104
// NewFsDiff creates a new `FsDiff` test which checks the fs difference between a container and it's image
97-
func NewFsDiff(timeout time.Duration, containerID string) *CnfFsDiff {
105+
func NewFsDiff(timeout time.Duration, containerID, nodeName string) *CnfFsDiff {
98106
return &CnfFsDiff{
99-
result: tnf.ERROR,
107+
result: tnf.SUCCESS,
100108
timeout: timeout,
101-
args: Command(containerID),
109+
args: Command(containerID, nodeName),
102110
}
103111
}
104112

105113
// GetReelFirstRegularExpressions returns the regular expressions used for matching in ReelFirst.
106114
func (p *CnfFsDiff) GetReelFirstRegularExpressions() []string {
107-
return []string{SuccessfulOutputRegex, AcceptAllRegex}
115+
return []string{err, bin, sbin, lib, successfulOutputRegex, acceptAllRegex}
108116
}

test-network-function/platform/suite.go

+17-18
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/onsi/ginkgo"
3333
ginkgoconfig "github.com/onsi/ginkgo/config"
3434
"github.com/onsi/gomega"
35-
log "github.com/sirupsen/logrus"
3635
"github.com/test-network-function/test-network-function/pkg/tnf"
3736
"github.com/test-network-function/test-network-function/pkg/tnf/handlers/base/redhat"
3837
"github.com/test-network-function/test-network-function/pkg/tnf/handlers/cnffsdiff"
@@ -116,23 +115,25 @@ func testContainerIsRedHatRelease(cut *config.Container) {
116115
func testContainersFsDiff(env *config.TestEnvironment) {
117116
testID := identifiers.XformToGinkgoItIdentifier(identifiers.TestUnalteredBaseImageIdentifier)
118117
ginkgo.It(testID, func() {
119-
fsDiffContainer := env.FsDiffMasterContainer
120-
if fsDiffContainer != nil {
121-
for _, cut := range env.ContainersUnderTest {
122-
podName := cut.Oc.GetPodName()
123-
containerName := cut.Oc.GetPodContainerName()
124-
context := cut.Oc
125-
ginkgo.By(fmt.Sprintf("%s(%s) should not install new packages after starting", podName, containerName))
126-
testContainerFsDiff(fsDiffContainer.Oc, context)
118+
var badContainers []string
119+
for _, cut := range env.ContainersUnderTest {
120+
podName := cut.Oc.GetPodName()
121+
containerName := cut.Oc.GetPodContainerName()
122+
context := cut.Oc
123+
nodeName := cut.ContainerConfiguration.NodeName
124+
ginkgo.By(fmt.Sprintf("%s(%s) should not install new packages after starting", podName, containerName))
125+
testResult, err := testContainerFsDiff(nodeName, context)
126+
if testResult != tnf.SUCCESS || err != nil {
127+
badContainers = append(badContainers, containerName)
128+
ginkgo.By(fmt.Sprintf("pod %s container %s did update/install/modify additional packages", podName, containerName))
127129
}
128-
} else {
129-
log.Warn("no fs diff container is configured, cannot run fs diff test")
130130
}
131+
gomega.Expect(badContainers).To(gomega.BeNil())
131132
})
132133
}
133134

134135
// testContainerFsDiff test that the CUT didn't install new packages after starting, and report through Ginkgo.
135-
func testContainerFsDiff(masterPodOc, targetContainerOC *interactive.Oc) {
136+
func testContainerFsDiff(nodeName string, targetContainerOC *interactive.Oc) (int, error) {
136137
defer results.RecordResult(identifiers.TestUnalteredBaseImageIdentifier)
137138
targetContainerOC.GetExpecter()
138139
containerIDTester := containerid.NewContainerID(common.DefaultTimeout)
@@ -142,13 +143,11 @@ func testContainerFsDiff(masterPodOc, targetContainerOC *interactive.Oc) {
142143
gomega.Expect(testResult).To(gomega.Equal(tnf.SUCCESS))
143144
gomega.Expect(err).To(gomega.BeNil())
144145
containerID := containerIDTester.GetID()
145-
146-
fsDiffTester := cnffsdiff.NewFsDiff(common.DefaultTimeout, containerID)
147-
test, err = tnf.NewTest(masterPodOc.GetExpecter(), fsDiffTester, []reel.Handler{fsDiffTester}, masterPodOc.GetErrorChannel())
148-
gomega.Expect(err).To(gomega.BeNil())
149-
testResult, err = test.Run()
150-
gomega.Expect(testResult).To(gomega.Equal(tnf.SUCCESS))
146+
context := common.GetContext()
147+
fsDiffTester := cnffsdiff.NewFsDiff(common.DefaultTimeout, containerID, nodeName)
148+
test, err = tnf.NewTest(context.GetExpecter(), fsDiffTester, []reel.Handler{fsDiffTester}, context.GetErrorChannel())
151149
gomega.Expect(err).To(gomega.BeNil())
150+
return test.Run()
152151
}
153152

154153
func getMcKernelArguments(context *interactive.Context, mcName string) map[string]string {

0 commit comments

Comments
 (0)