Skip to content

Commit 410695d

Browse files
committed
Update tests to be compatible with AL2
This adds the necessary cleanup functions to TestMultipleVMs as well as adding a default runc config path to our tests. Signed-off-by: xibz <[email protected]>
1 parent 32db173 commit 410695d

File tree

8 files changed

+112
-88
lines changed

8 files changed

+112
-88
lines changed

.buildkite/al2_cleanup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
source .buildkite/al2env.sh
3+
4+
sudo rm -rf $dir
5+
./tools/thinpool.sh remove $unique_id

.buildkite/al2_pipeline.yml

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,67 +24,28 @@ steps:
2424
command:
2525
- ./.buildkite/setup_al2.sh
2626
- docker run --rm -v $PWD:/mnt debian:stretch-slim rm -rf /mnt/tools/image-builder/rootfs
27-
- sudo install -d -o root -g buildkite-agent -m 775 "/local/artifacts/$BUILDKITE_BUILD_NUMBER"
28-
- cp tools/image-builder/rootfs.img "/local/artifacts/$BUILDKITE_BUILD_NUMBER/"
2927

3028
- wait
3129

32-
# Global concurrency has been set to one in the website configuration.
33-
# With that we can now clean up loop devices before starting jobs to ensure
34-
# we don't hit the loop device limit
35-
- label: ":lint-roller: loop device cleanup"
36-
agents:
37-
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
38-
distro: "${BUILDKITE_AGENT_META_DATA_DISTRO}"
39-
hostname: "${BUILDKITE_AGENT_META_DATA_HOSTNAME}"
40-
command: 'sudo losetup -D'
41-
concurrency: 1
42-
concurrency_group: 'loop-device test'
43-
44-
- wait
45-
46-
# Git history validation happens after the 'wait' step so it happens
47-
# in parallel with the subsequent tests and does not prevent them
48-
# from running in the event of a validation failure.
49-
- label: 'git log validation'
50-
command: './.buildkite/logcheck.sh'
51-
# This should run in the same queue, but we don't care whether it runs on
52-
# the same host.
53-
agents:
54-
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
55-
56-
- label: ":protractor: verify proto"
30+
- label: ":onion: al2 tests"
5731
agents:
5832
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
5933
distro: "${BUILDKITE_AGENT_META_DATA_DISTRO}"
6034
hostname: "${BUILDKITE_AGENT_META_DATA_HOSTNAME}"
6135
env:
62-
DOCKER_IMAGE_TAG: "$BUILDKITE_BUILD_NUMBER"
36+
NUMBER_OF_VMS: "100"
6337
command:
64-
- make proto
65-
- test -z "$(git status --porcelain)" && exit 0 || git status && echo -e '\nGenerated protobuf code differs from committed, please run "make proto" and commit the updated files.\n' && exit 1
66-
timeout_in_minutes: 1
38+
- ./.buildkite/al2_test.sh
39+
timeout_in_minutes: 10
6740

68-
- label: ":golang: go mod tidy"
69-
agents:
70-
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
71-
distro: "${BUILDKITE_AGENT_META_DATA_DISTRO}"
72-
hostname: "${BUILDKITE_AGENT_META_DATA_HOSTNAME}"
73-
env:
74-
DOCKER_IMAGE_TAG: "$BUILDKITE_BUILD_NUMBER"
75-
command:
76-
- sudo make tidy-in-docker
77-
- test -z "$(git status --porcelain)" && exit 0 || git status && echo -e '\ngo.mod and/or go.sum differ from committed, please run "go mod tidy" and commit the updated files.\n' && exit 1
78-
timeout_in_minutes: 1
79-
80-
- label: ":onion: al2 tests"
41+
- wait: ~
42+
continue_on_failure: true
43+
44+
- label: ":onion: cleanup"
8145
agents:
8246
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
8347
distro: "${BUILDKITE_AGENT_META_DATA_DISTRO}"
8448
hostname: "${BUILDKITE_AGENT_META_DATA_HOSTNAME}"
85-
env:
86-
NUMBER_OF_VMS: "5"
8749
command:
88-
- ./.buildkite/al2_test.sh
50+
- ./.buildkite/al2_cleanup.sh
8951
timeout_in_minutes: 10
90-

.buildkite/al2_test.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#!/bin/bash
2+
set -eu
23

34
source ./.buildkite/al2env.sh
45

56
export PATH=$bin_path:$PATH
7+
export FIRECRACKER_CONTAINERD_RUNTIME_CONFIG_PATH=$runtime_config_path
8+
export ENABLE_ISOLATED_TESTS=true
9+
export CONTAINERD_SOCKET=$dir/containerd.sock
10+
export SHIM_BASE_DIR=$dir
611

7-
sudo -E "FIRECRACKER_CONTAINERD_RUNTIME_CONFIG_PATH=$runtime_config_path" $bin_path/firecracker-containerd --config $dir/config.toml &
12+
sudo -E PATH=$PATH $bin_path/firecracker-containerd --config $dir/config.toml &
813
containerd_pid=$!
914
sudo $bin_path/firecracker-ctr --address $dir/containerd.sock content fetch docker.io/library/alpine:3.10.1
10-
sudo -E env "PATH=$PATH" /usr/local/bin/go test -run TestMultipleVMs_Isolated ./...
15+
sudo -E PATH=$bin_path:$PATH /usr/local/bin/go test -count=1 -run TestMultipleVMs_Isolated ./... -v
1116

12-
# cleanup
13-
sudo kill -9 $containerd_pid
14-
sudo rm -rf $dir
15-
./tools/thinpool.sh remove $uuid
17+
sudo kill $containerd_pid

.buildkite/al2env.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

33
shim_base=/tmp/shim-base
4-
uuid=$BUILDKITE_BUILD_NUMBER
5-
dir=$shim_base/$uuid
4+
unique_id=$BUILDKITE_BUILD_NUMBER
5+
dir=$shim_base/$unique_id
66
bin_path=$dir/bin
77
devmapper_path=$dir/devmapper
88
state_path=$dir/state

.buildkite/hooks/pre-exit

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/bin/bash
2-
set -eu
3-
4-
sudo make -C "$BUILDKITE_BUILD_CHECKOUT_PATH" clean
2+
sudo -E PATH=$PATH make -C "$BUILDKITE_BUILD_CHECKOUT_PATH" clean
53

64
# clean up ephemeral files since this will cause an error to build kite due to
75
# these files being owned by root
8-
sudo make -C "$BUILDKITE_BUILD_CHECKOUT_PATH/tools/image-builder" distclean
6+
sudo -E PATH=$PATH make -C "$BUILDKITE_BUILD_CHECKOUT_PATH/tools/image-builder" distclean

.buildkite/setup_al2.sh

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
#!/bin/bash
22

3-
source ./.buildkite/al2env.sh
3+
set -eux
44

5-
echo "Creating necessary directories"
5+
source ./.buildkite/al2env.sh
66

77
mkdir -p $dir
8+
mkdir -p $dir/rootfs
89
mkdir -p $bin_path
910
mkdir -p $devmapper_path
1011
mkdir -p $state_path
1112

12-
echo "Resetting thinpool $uuid"
13-
./tools/thinpool.sh reset $uuid
13+
./tools/thinpool.sh reset $unique_id
1414

1515
export INSTALLROOT=$dir
1616
export FIRECRACKER_CONTAINERD_RUNTIME_DIR=$dir
17-
echo "Running make"
18-
sudo make
19-
echo "Running make install"
20-
sudo -E "INSTALLROOT=$INSTALLROOT" make install
21-
echo "Running make install-default-vmlinux"
22-
sudo make install-default-vmlinux
23-
echo "Running make image"
24-
sudo make image
25-
echo "Running make install-default-rootfs"
26-
sudo make install-default-rootfs
17+
make
18+
sudo -E INSTALLROOT=$INSTALLROOT PATH=$PATH make install
19+
cp /var/lib/fc-ci/vmlinux.bin $dir/default-vmlinux.bin
20+
make image
21+
sudo -E PATH=$PATH make install-default-rootfs
2722

28-
echo "Creating $dir/config.toml"
2923
cat << EOF > $dir/config.toml
3024
disabled_plugins = ["cri"]
3125
root = "$dir"
@@ -34,14 +28,13 @@ state = "$state_path"
3428
address = "$dir/containerd.sock"
3529
[plugins]
3630
[plugins.devmapper]
37-
pool_name = "fcci--vg-$uuid"
31+
pool_name = "fcci--vg-$unique_id"
3832
base_image_size = "10GB"
3933
root_path = "$devmapper_path"
4034
[debug]
4135
level = "debug"
4236
EOF
4337

44-
echo "Creating $runtime_config_path"
4538
cat << EOF > $runtime_config_path
4639
{
4740
"cpu_template": "T2",
@@ -59,7 +52,5 @@ cat << EOF > $runtime_config_path
5952
}
6053
EOF
6154

62-
echo "Copying firecracker-runc-config.json"
6355
cp ./runtime/firecracker-runc-config.json.example $dir/config.json
64-
echo "Copying runc"
6556
cp ./_submodules/runc/runc $bin_path/runc

runtime/integ_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import (
2929
)
3030

3131
const runtimeConfigPath = "/etc/containerd/firecracker-runtime.json"
32-
const shimBaseDir = "/srv/firecracker_containerd_tests"
32+
const shimBaseDirEnvVar = "SHIM_BASE_DIR"
33+
const defaultShimBaseDir = "/srv/firecracker_containerd_tests"
3334

3435
var defaultRuntimeConfig = config.Config{
3536
FirecrackerBinaryPath: "/usr/local/bin/firecracker",
@@ -39,12 +40,21 @@ var defaultRuntimeConfig = config.Config{
3940
CPUTemplate: "T2",
4041
LogLevel: "Debug",
4142
Debug: true,
42-
ShimBaseDir: shimBaseDir,
43+
ShimBaseDir: shimBaseDir(),
4344
JailerConfig: config.JailerConfig{
4445
RuncBinaryPath: "/usr/local/bin/runc",
46+
RuncConfigPath: "/etc/containerd/firecracker-runc-config.json",
4547
},
4648
}
4749

50+
func shimBaseDir() string {
51+
if v := os.Getenv(shimBaseDirEnvVar); v != "" {
52+
return v
53+
}
54+
55+
return defaultShimBaseDir
56+
}
57+
4858
func defaultSnapshotterName() string {
4959
if name := os.Getenv("FICD_SNAPSHOTTER"); name != "" {
5060
return name

runtime/service_integ_test.go

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"bytes"
1818
"context"
1919
"fmt"
20+
"io"
2021
"io/ioutil"
2122
"os"
2223
"os/exec"
@@ -60,23 +61,30 @@ import (
6061
const (
6162
defaultNamespace = namespaces.Default
6263

63-
containerdSockPath = "/run/containerd/containerd.sock"
64-
6564
firecrackerRuntime = "aws.firecracker"
6665
shimProcessName = "containerd-shim-aws-firecracker"
6766
firecrackerProcessName = "firecracker"
6867

69-
defaultVMRootfsPath = "/var/lib/firecracker-containerd/runtime/default-rootfs.img"
7068
defaultVMNetDevName = "eth0"
7169
numberOfVmsEnvName = "NUMBER_OF_VMS"
7270
defaultNumberOfVms = 5
71+
72+
containerdSockPathEnvVar = "CONTAINERD_SOCKET"
7373
)
7474

7575
var (
7676
findShim = findProcWithName(shimProcessName)
7777
findFirecracker = findProcWithName(firecrackerProcessName)
78+
79+
containerdSockPath = "/run/containerd/containerd.sock"
7880
)
7981

82+
func init() {
83+
if v := os.Getenv(containerdSockPathEnvVar); v != "" {
84+
containerdSockPath = v
85+
}
86+
}
87+
8088
// Images are presumed by the isolated tests to have already been pulled
8189
// into the content store. This will just unpack the layers into an
8290
// image with the provided snapshotter.
@@ -211,6 +219,18 @@ func vmIDtoMacAddr(vmID uint) string {
211219
return strings.Join(addrParts, ":")
212220
}
213221

222+
func deleteTapDevice(ctx context.Context, tapName string) error {
223+
if err := exec.CommandContext(ctx, "ip", "link", "delete", tapName).Run(); err != nil {
224+
return err
225+
}
226+
227+
if err := exec.CommandContext(ctx, "ip", "tuntap", "del", tapName, "mode", "tap").Run(); err != nil {
228+
return err
229+
}
230+
231+
return nil
232+
}
233+
214234
func createTapDevice(ctx context.Context, tapName string) error {
215235
err := exec.CommandContext(ctx, "ip", "tuntap", "add", tapName, "mode", "tap").Run()
216236
if err != nil {
@@ -225,7 +245,39 @@ func createTapDevice(ctx context.Context, tapName string) error {
225245
return nil
226246
}
227247

248+
type testMultipleVMsRunner struct {
249+
containers []containerd.Container
250+
}
251+
252+
func (runner *testMultipleVMsRunner) ImportPath() string { return "" }
253+
func (runner *testMultipleVMsRunner) MatchString(pat, str string) (bool, error) {
254+
return pat == str, nil
255+
}
256+
func (runner *testMultipleVMsRunner) StartCPUProfile(w io.Writer) error { return nil }
257+
func (runner *testMultipleVMsRunner) StopCPUProfile() {}
258+
func (runner *testMultipleVMsRunner) StartTestLog(w io.Writer) {}
259+
func (runner *testMultipleVMsRunner) StopTestLog() error { return nil }
260+
func (runner *testMultipleVMsRunner) WriteProfileTo(str string, w io.Writer, n int) error { return nil }
261+
228262
func TestMultipleVMs_Isolated(t *testing.T) {
263+
runner := &testMultipleVMsRunner{}
264+
tests := []testing.InternalTest{
265+
{
266+
Name: "TestMultipleVMs_Isolated",
267+
F: runner.TestMultipleVMs,
268+
},
269+
}
270+
m := testing.MainStart(runner, tests, nil, nil)
271+
code := m.Run()
272+
for _, container := range runner.containers {
273+
err := container.Delete(context.Background())
274+
t.Log(err)
275+
}
276+
277+
os.Exit(code)
278+
}
279+
280+
func (runner *testMultipleVMsRunner) TestMultipleVMs(t *testing.T) {
229281
prepareIntegTest(t)
230282

231283
netns, err := ns.GetCurrentNS()
@@ -270,6 +322,9 @@ func TestMultipleVMs_Isolated(t *testing.T) {
270322
pluginClient, err := ttrpcutil.NewClient(containerdSockPath + ".ttrpc")
271323
require.NoError(t, err, "failed to create ttrpc client")
272324

325+
cfg, err := config.LoadConfig("")
326+
require.NoError(t, err, "failed to load config")
327+
273328
// This test spawns separate VMs in parallel and ensures containers are spawned within each expected VM. It asserts each
274329
// container ends up in the right VM by assigning each VM a network device with a unique mac address and having each container
275330
// print the mac address it sees inside its VM.
@@ -283,10 +338,11 @@ func TestMultipleVMs_Isolated(t *testing.T) {
283338

284339
tapName := fmt.Sprintf("tap%d", vmID)
285340
err := createTapDevice(ctx, tapName)
341+
defer deleteTapDevice(ctx, tapName)
286342

287343
require.NoError(t, err, "failed to create tap device for vm %d", vmID)
288344

289-
rootfsPath := defaultVMRootfsPath
345+
rootfsPath := cfg.RootDrive
290346

291347
vmIDStr := strconv.Itoa(vmID)
292348
fcClient := fccontrol.NewFirecrackerClient(pluginClient.Client())
@@ -321,7 +377,7 @@ func TestMultipleVMs_Isolated(t *testing.T) {
321377
containerWg.Add(1)
322378
go func(containerID int) {
323379
defer containerWg.Done()
324-
testMultipleExecs(
380+
runner.testMultipleExecs(
325381
ctx,
326382
t,
327383
vmID,
@@ -366,7 +422,7 @@ func TestMultipleVMs_Isolated(t *testing.T) {
366422
vmWg.Wait()
367423
}
368424

369-
func testMultipleExecs(
425+
func (runner *testMultipleVMsRunner) testMultipleExecs(
370426
ctx context.Context,
371427
t *testing.T,
372428
vmID int,
@@ -399,6 +455,7 @@ func testMultipleExecs(
399455
),
400456
)
401457
require.NoError(t, err, "failed to create container %s", containerName)
458+
runner.containers = append(runner.containers, newContainer)
402459

403460
var taskStdout bytes.Buffer
404461
var taskStderr bytes.Buffer
@@ -438,7 +495,7 @@ func testMultipleExecs(
438495
if jailerConfig != nil {
439496
jailer := &runcJailer{
440497
Config: runcJailerConfig{
441-
OCIBundlePath: filepath.Join(shimBaseDir, vmIDStr),
498+
OCIBundlePath: filepath.Join(shimBaseDir(), vmIDStr),
442499
},
443500
vmID: vmIDStr,
444501
}

0 commit comments

Comments
 (0)