Skip to content

Commit 109be5b

Browse files
authored
Merge pull request #791 from flatcar/chewi/ig
kola: Replace broken execsnoop and old local-gadget tests with ig test
2 parents 188106b + e74575b commit 109be5b

File tree

3 files changed

+100
-284
lines changed

3 files changed

+100
-284
lines changed

kola/tests/bpf/bpf.go

Lines changed: 0 additions & 123 deletions
This file was deleted.

kola/tests/bpf/ig.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright The Mantle Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
package bpf
4+
5+
import (
6+
"fmt"
7+
"strings"
8+
9+
"github.com/coreos/go-semver/semver"
10+
"github.com/flatcar/mantle/kola"
11+
"github.com/flatcar/mantle/kola/cluster"
12+
"github.com/flatcar/mantle/kola/register"
13+
"github.com/flatcar/mantle/platform/conf"
14+
)
15+
16+
var igVer = "v0.50.0"
17+
18+
func init() {
19+
register.Register(&register.Test{
20+
Run: igTest,
21+
Name: `bpf.ig`,
22+
Distros: []string{"cl"},
23+
MinVersion: semver.Version{Major: 4081},
24+
// This test is normally not related to the cloud environment
25+
Platforms: []string{"qemu", "qemu-unpriv", "azure"},
26+
// Required while SELinux policy is not correctly updated to support
27+
// `bpf` and `perfmon` permissions.
28+
Flags: []register.Flag{register.NoEnableSelinux},
29+
})
30+
}
31+
32+
func igTest(c cluster.TestCluster) {
33+
arch := strings.SplitN(kola.QEMUOptions.Board, "-", 2)[0]
34+
if arch == "amd64" {
35+
arch = "x86-64"
36+
}
37+
38+
c.Run("ig", func(c cluster.TestCluster) {
39+
node, err := c.NewMachine(conf.Butane(fmt.Sprintf(`
40+
variant: flatcar
41+
version: 1.0.0
42+
storage:
43+
files:
44+
- path: /etc/extensions/ig.raw
45+
mode: 0644
46+
contents:
47+
source: https://extensions.flatcar.org/extensions/ig-%s-%s.raw
48+
`, igVer, arch)))
49+
if err != nil {
50+
c.Fatalf("creating node: %v", err)
51+
}
52+
53+
// The following test that ig tracing and filtering works when applied
54+
// to the host. ig runs in the foreground, but it can take a few seconds
55+
// to be ready, even after prefetching the gadget. To avoid flakiness,
56+
// ig is put in the background and grep is used to wait for the
57+
// "running" debug message. coproc doesn't handle stderr, so stderr is
58+
// redirected to stdout and the real stdout is redirected to a file for
59+
// later analysis. The timeout against grep ensures that we don't wait
60+
// for "running" forever. The gadget is prefetched with --help so that
61+
// the download does not count against the timeout. The trap prevents ig
62+
// from keeping the script alive when an unexpected error occurs.
63+
64+
if _, err := c.SSH(node, fmt.Sprintf(`
65+
set -ex
66+
sudo ig run trace_exec:%[1]s --help
67+
coproc IG { sudo ig run trace_exec:%[1]s --host --filter 'proc.comm=docker,args~ps' --output json --verbose 2>&1 > ig.json; }
68+
trap 'kill %%%%' ERR
69+
timeout 30 grep -F -m1 'running...' <&${IG[0]}
70+
docker info
71+
docker ps
72+
docker images
73+
kill %%%%
74+
wait
75+
jq -s -e '.[] | select(.args == "/usr/bin/docker\u00a0ps")' ig.json
76+
jq -s -e 'isempty(.[] | select(.args == "/usr/bin/docker\u00a0info"))' ig.json
77+
jq -s -e 'isempty(.[] | select(.args == "/usr/bin/docker\u00a0images"))' ig.json
78+
`, igVer)); err != nil {
79+
c.Fatalf("ig run trace_exec did not behave as expected: %v", err)
80+
}
81+
82+
if _, err := c.SSH(node, fmt.Sprintf(`
83+
set -ex
84+
sudo ig run trace_dns:%[1]s --help
85+
coproc IG { sudo ig run trace_dns:%[1]s --host --filter 'name=flatcar.org.' --output json --verbose 2>&1 > ig.json; }
86+
trap 'kill %%%%' ERR
87+
timeout 30 grep -F -m1 'running...' <&${IG[0]}
88+
dig kinvolk.io
89+
dig flatcar.org
90+
dig stable.release.flatcar-linux.net
91+
kill %%%%
92+
wait
93+
jq -s -e '.[] | select(.name == "flatcar.org.")' ig.json
94+
jq -s -e 'isempty(.[] | select(.name == "kinvolk.io."))' ig.json
95+
jq -s -e 'isempty(.[] | select(.name == "stable.release.flatcar-linux.net."))' ig.json
96+
`, igVer)); err != nil {
97+
c.Fatalf("ig run trace_dns did not behave as expected: %v", err)
98+
}
99+
})
100+
}

kola/tests/bpf/local-gadget.go

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)