Skip to content

Commit

Permalink
Do not consider the exec probes in performance-rt-apps-no-exec-probes (
Browse files Browse the repository at this point in the history
…#1590)

* Do not consider the exec probes in the performance-rt-apps-no-exec-probes test.
Reverts commit d7dc6cd and adds logic to whitelist processes belonging to the exec probes.

* addressing comments from David R.
  • Loading branch information
edcdavid authored Nov 7, 2023
1 parent ac209bc commit 551d84b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
53 changes: 52 additions & 1 deletion cnf-certification-test/performance/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,30 @@ func testSchedulingPolicyInCPUPool(env *provider.TestEnvironment,
testhelper.AddTestResultReason(compliantContainersPids, nonCompliantContainersPids, tnf.ClaimFilePrintf, ginkgo.Fail)
}

func getExecProbesCmds(c *provider.Container) map[string]bool {
cmds := map[string]bool{}

if c.LivenessProbe != nil && c.LivenessProbe.Exec != nil {
cmd := strings.Join(c.LivenessProbe.Exec.Command, "")
cmd = strings.Join(strings.Fields(cmd), "")
cmds[cmd] = true
}

if c.ReadinessProbe != nil && c.ReadinessProbe.Exec != nil {
cmd := strings.Join(c.ReadinessProbe.Exec.Command, "")
cmd = strings.Join(strings.Fields(cmd), "")
cmds[cmd] = true
}

if c.StartupProbe != nil && c.StartupProbe.Exec != nil {
cmd := strings.Join(c.StartupProbe.Exec.Command, "")
cmd = strings.Join(strings.Fields(cmd), "")
cmds[cmd] = true
}

return cmds
}

const noProcessFoundErrMsg = "No such process"

func testRtAppsNoExecProbes(env *provider.TestEnvironment, cuts []*provider.Container) {
Expand All @@ -251,8 +275,10 @@ func testRtAppsNoExecProbes(env *provider.TestEnvironment, cuts []*provider.Cont
break
}

notExecProbeProcesses, compliantObjectsProbes := filterProbeProcesses(processes, cut)
compliantObjects = append(compliantObjects, compliantObjectsProbes...)
allProcessesCompliant := true
for _, p := range processes {
for _, p := range notExecProbeProcesses {
schedPolicy, _, err := scheduling.GetProcessCPUScheduling(p.Pid, cut)
if err != nil {
// If the process does not exist anymore it means that it has finished since the time the process list
Expand Down Expand Up @@ -284,3 +310,28 @@ func testRtAppsNoExecProbes(env *provider.TestEnvironment, cuts []*provider.Cont
}
testhelper.AddTestResultReason(compliantObjects, nonCompliantObjects, tnf.ClaimFilePrintf, ginkgo.Fail)
}

func filterProbeProcesses(allProcesses []*crclient.Process, cut *provider.Container) (notExecProbeProcesses []*crclient.Process, compliantObjects []*testhelper.ReportObject) {
execProbeProcesses := []int{}
execProbesCmds := getExecProbesCmds(cut)
// find all exec probes by matching command line
for _, p := range allProcesses {
if execProbesCmds[strings.Join(strings.Fields(p.Args), "")] {
compliantObjects = append(compliantObjects, testhelper.NewContainerReportObject(cut.Namespace, cut.Podname, cut.Name, "Container process belongs to an exec probe (skipping verification)", true).
AddField(testhelper.ProcessID, strconv.Itoa(p.Pid)).
AddField(testhelper.ProcessCommandLine, p.Args))
execProbeProcesses = append(execProbeProcesses, p.Pid)
}
}
// remove all exec probes and their children from the process list
for _, p := range allProcesses {
for _, parentProbePid := range execProbeProcesses {
if p.Pid == parentProbePid || p.PPid == parentProbePid {
// skip exec probe processes (child or parent)
continue
}
notExecProbeProcesses = append(notExecProbeProcesses, p)
}
}
return notExecProbeProcesses, compliantObjects
}
15 changes: 10 additions & 5 deletions internal/crclient/crclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"github.com/test-network-function/cnf-certification-test/pkg/provider"
)

const PsRegex = `(?m)^(\d+?)\s+?(\d+?)\s+?(.*?)$`
const PsRegex = `(?m)^(\d+?)\s+?(\d+?)\s+?(\d+?)\s+?(.*?)$`

type Process struct {
PidNs, Pid int
Args string
PidNs, Pid, PPid int
Args string
}

const (
Expand Down Expand Up @@ -140,7 +140,7 @@ func ExecCommandContainerNSEnter(command string,
}

func GetPidsFromPidNamespace(pidNamespace string, container *provider.Container) (p []*Process, err error) {
const command = "trap \"\" SIGURG ; ps -e -o pidns,pid,args"
const command = "trap \"\" SIGURG ; ps -e -o pidns,pid,ppid,args"
env := provider.GetTestEnvironment()
ctx, err := GetNodeDebugPodContext(container.NodeName, &env)
if err != nil {
Expand Down Expand Up @@ -170,7 +170,12 @@ func GetPidsFromPidNamespace(pidNamespace string, container *provider.Container)
logrus.Errorf("could not convert string %s to integer, err=%s", v[2], err)
continue
}
p = append(p, &Process{PidNs: aPidNs, Pid: aPid, Args: v[3]})
aPPid, err := strconv.Atoi(v[3])
if err != nil {
logrus.Errorf("could not convert string %s to integer, err=%s", v[3], err)
continue
}
p = append(p, &Process{PidNs: aPidNs, Pid: aPid, Args: v[4], PPid: aPPid})
}
return p, nil
}

0 comments on commit 551d84b

Please sign in to comment.