Skip to content

Commit 2d48810

Browse files
committed
Add BuildKite log file artifacts
Signed-off-by: xibz <[email protected]>
1 parent 7a3c22b commit 2d48810

File tree

7 files changed

+41
-6
lines changed

7 files changed

+41
-6
lines changed

.buildkite/hooks/pre-exit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
sudo rm -rf testdata/logs

.buildkite/master.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
FC_TEST_TAP=fc-mst-tap${BUILDKITE_BUILD_NUMBER} make test EXTRAGOARGS='-v -count=1 -race' DISABLE_ROOT_TESTS=
4+
exitCode=$?
5+
sudo -E buildkite-agent artifact upload $BUILDKITE_BUILD_CHECKOUT_PATH/testdata/logs/
6+
7+
exit $exitCode

.buildkite/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ steps:
115115
- 'chmod +x testdata/firecracker-master'
116116
- 'buildkite-agent artifact download testdata/jailer-master .'
117117
- 'chmod +x testdata/jailer-master'
118-
- "sudo -E FC_TEST_TAP=fc-mst-tap${BUILDKITE_BUILD_NUMBER} make test EXTRAGOARGS='-v -count=1 -race' DISABLE_ROOT_TESTS="
118+
- "sudo -E .buildkite/master.sh"
119119
agents:
120120
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
121121
distro: "${BUILDKITE_AGENT_META_DATA_DISTRO}"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ jailer-*
55
vmlinux
66
root-drive.img
77
TestPID.img
8+
testdata/logs/

jailer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ func (b JailerCommandBuilder) Args() []string {
136136
args = append(args, "--daemonize")
137137
}
138138

139-
args = append(args, b.firecrackerArgs...)
139+
if len(b.firecrackerArgs) > 0 {
140+
args = append(args, "--")
141+
args = append(args, b.firecrackerArgs...)
142+
}
140143

141144
return args
142145
}

jailer_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func TestJail(t *testing.T) {
162162
"/path/to/firecracker",
163163
"--node",
164164
"0",
165+
"--",
165166
"--seccomp-level",
166167
"0",
167168
},
@@ -190,6 +191,7 @@ func TestJail(t *testing.T) {
190191
"/path/to/firecracker",
191192
"--node",
192193
"0",
194+
"--",
193195
"--seccomp-level",
194196
"0",
195197
},
@@ -224,6 +226,7 @@ func TestJail(t *testing.T) {
224226
"/tmp",
225227
"--netns",
226228
"/path/to/netns",
229+
"--",
227230
"--seccomp-level",
228231
"0",
229232
},

machine_test.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ const (
5959
)
6060

6161
var (
62-
skipTuntap bool
63-
testDataPath = "./testdata"
64-
testDataBin = filepath.Join(testDataPath, "bin")
62+
skipTuntap bool
63+
testDataPath = "./testdata"
64+
testDataLogPath = filepath.Join(testDataPath, "logs")
65+
testDataBin = filepath.Join(testDataPath, "bin")
6566

6667
testRootfs = filepath.Join(testDataPath, "root-drive.img")
6768
)
@@ -72,6 +73,10 @@ func init() {
7273
if val := os.Getenv(testDataPathEnv); val != "" {
7374
testDataPath = val
7475
}
76+
77+
if err := os.MkdirAll(testDataLogPath, 0777); err != nil {
78+
panic(err)
79+
}
7580
}
7681

7782
// Ensure that we can create a new machine
@@ -106,9 +111,12 @@ func TestJailerMicroVMExecution(t *testing.T) {
106111
}
107112
fctesting.RequiresRoot(t)
108113

114+
logPath := filepath.Join(testDataLogPath, "TestJailerMicroVMExecution")
115+
err := os.MkdirAll(logPath, 0777)
116+
require.NoError(t, err, "unable to create %s path", logPath)
117+
109118
jailerUID := 123
110119
jailerGID := 100
111-
var err error
112120
if v := os.Getenv(sudoUID); v != "" {
113121
if jailerUID, err = strconv.Atoi(v); err != nil {
114122
t.Fatalf("Failed to parse %q", sudoUID)
@@ -156,13 +164,21 @@ func TestJailerMicroVMExecution(t *testing.T) {
156164
require.NoError(t, err, "failed to open fifo writer file")
157165
defer func() {
158166
fw.Close()
167+
exec.Command("cp", capturedLog, logPath).Run()
159168
os.Remove(capturedLog)
160169
os.Remove(socketPath)
161170
os.Remove(logFifo)
162171
os.Remove(metricsFifo)
163172
os.RemoveAll(tmpDir)
164173
}()
165174

175+
logFd, err := os.OpenFile(
176+
filepath.Join(logPath, "TestJailerMicroVMExecution.log"),
177+
os.O_CREATE|os.O_RDWR,
178+
0666)
179+
require.NoError(t, err, "failed to create log file")
180+
defer logFd.Close()
181+
166182
cfg := Config{
167183
Debug: true,
168184
SocketPath: socketPath,
@@ -193,6 +209,8 @@ func TestJailerMicroVMExecution(t *testing.T) {
193209
ChrootBaseDir: jailerTestPath,
194210
ExecFile: getFirecrackerBinaryPath(),
195211
ChrootStrategy: NewNaiveChrootStrategy(jailerFullRootPath, vmlinuxPath),
212+
Stdout: logFd,
213+
Stderr: logFd,
196214
},
197215
FifoLogWriter: fw,
198216
}

0 commit comments

Comments
 (0)