Skip to content

Commit 0165b0b

Browse files
authored
Merge pull request #292 from kzys/config-on-the-fly
Create firecracker-runtime.json on the fly
2 parents 7649f00 + 193b303 commit 0165b0b

File tree

7 files changed

+94
-46
lines changed

7 files changed

+94
-46
lines changed

examples/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ integ-test:
3636
--ipc=host \
3737
--volume /dev:/dev \
3838
--volume /run/udev/control:/run/udev/control \
39+
--volume $(CURDIR)/etc/containerd/firecracker-runtime.json:/etc/containerd/firecracker-runtime.json \
3940
--volume $(CURDIR)/logs:/var/log/firecracker-containerd-test \
4041
--env EXTRAGOARGS="${EXTRAGOARGS}" \
4142
--workdir="/firecracker-containerd/examples" \

tools/docker/firecracker-runtime.json renamed to examples/etc/containerd/firecracker-runtime.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@
55
"root_drive": "/var/lib/firecracker-containerd/runtime/default-rootfs.img",
66
"cpu_count": 1,
77
"cpu_template": "T2",
8-
"log_fifo": "/tmp/fc-logs.fifo",
9-
"log_level": "Debug",
10-
"metrics_fifo": "/tmp/fc-metrics.fifo"
8+
"log_level": "Debug"
119
}

runtime/cni_integ_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
)
4040

4141
func TestCNISupport_Isolated(t *testing.T) {
42-
internal.RequiresIsolation(t)
42+
prepareIntegTest(t)
4343

4444
testTimeout := 120 * time.Second
4545
ctx, cancel := context.WithTimeout(namespaces.WithNamespace(context.Background(), defaultNamespace), testTimeout)
@@ -133,8 +133,7 @@ func TestCNISupport_Isolated(t *testing.T) {
133133
}
134134

135135
func TestAutomaticCNISupport_Isolated(t *testing.T) {
136-
internal.RequiresIsolation(t)
137-
useDefaultNetworkInterfaceRuntimeConfig(t)
136+
prepareIntegTest(t, withDefaultNetwork())
138137

139138
testTimeout := 120 * time.Second
140139
ctx, cancel := context.WithTimeout(namespaces.WithNamespace(context.Background(), defaultNamespace), testTimeout)
@@ -200,7 +199,7 @@ func TestAutomaticCNISupport_Isolated(t *testing.T) {
200199
}
201200

202201
func TestCNIPlugin_Performance(t *testing.T) {
203-
internal.RequiresIsolation(t)
202+
prepareIntegTest(t)
204203

205204
numVMs := perfTestVMCount(t)
206205
runtimeDuration := perfTestRuntime(t)
@@ -354,14 +353,17 @@ func writeCNIConf(path, chainedPluginName, networkName, nameserver string) error
354353
}`, networkName, nameserver, chainedPluginName)), 0644)
355354
}
356355

357-
func useDefaultNetworkInterfaceRuntimeConfig(t *testing.T) {
358-
t.Helper()
359-
360-
err := os.RemoveAll(runtimeConfigPath)
361-
require.NoError(t, err, "failed to remove existing firecracker containerd runtime config file")
362-
363-
err = os.Symlink(defaultNetworkInterfaceRuntimeConfigPath, runtimeConfigPath)
364-
require.NoError(t, err, "failed to symlink default network interface runtime config")
356+
func withDefaultNetwork() func(c *Config) {
357+
return func(c *Config) {
358+
c.DefaultNetworkInterfaces = []proto.FirecrackerNetworkInterface{
359+
{
360+
CNIConfig: &proto.CNIConfiguration{
361+
NetworkName: "fcnet",
362+
InterfaceName: "veth0",
363+
},
364+
},
365+
}
366+
}
365367
}
366368

367369
func runCommand(ctx context.Context, t *testing.T, name string, args ...string) {

runtime/integ_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
package main
14+
15+
import (
16+
"encoding/json"
17+
"os"
18+
"testing"
19+
20+
"github.com/firecracker-microvm/firecracker-containerd/internal"
21+
)
22+
23+
const runtimeConfigPath = "/etc/containerd/firecracker-runtime.json"
24+
25+
var defaultRuntimeConfig = Config{
26+
FirecrackerBinaryPath: "/usr/local/bin/firecracker",
27+
KernelImagePath: "/var/lib/firecracker-containerd/runtime/default-vmlinux.bin",
28+
KernelArgs: "ro console=ttyS0 noapic reboot=k panic=1 pci=off nomodules systemd.journald.forward_to_console systemd.unit=firecracker.target init=/sbin/overlay-init",
29+
RootDrive: "/var/lib/firecracker-containerd/runtime/default-rootfs.img",
30+
CPUCount: 1,
31+
CPUTemplate: "T2",
32+
LogLevel: "Debug",
33+
}
34+
35+
func prepareIntegTest(t *testing.T, options ...func(*Config)) {
36+
t.Helper()
37+
38+
internal.RequiresIsolation(t)
39+
40+
err := writeRuntimeConfig(options...)
41+
if err != nil {
42+
t.Error(err)
43+
}
44+
}
45+
46+
func writeRuntimeConfig(options ...func(*Config)) error {
47+
config := defaultRuntimeConfig
48+
for _, option := range options {
49+
option(&config)
50+
}
51+
52+
file, err := os.Create(runtimeConfigPath)
53+
if err != nil {
54+
return err
55+
}
56+
defer file.Close()
57+
58+
bytes, err := json.Marshal(config)
59+
if err != nil {
60+
return err
61+
}
62+
63+
_, err = file.Write(bytes)
64+
if err != nil {
65+
return err
66+
}
67+
68+
return nil
69+
}

runtime/service_integ_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ const (
6363
defaultVMRootfsPath = "/var/lib/firecracker-containerd/runtime/default-rootfs.img"
6464
defaultVMNetDevName = "eth0"
6565
varRunDir = "/run/firecracker-containerd"
66-
67-
runtimeConfigPath = "/etc/containerd/firecracker-runtime.json"
68-
defaultNetworkInterfaceRuntimeConfigPath = "/etc/containerd/firecracker-runtime-defaultnetwork.json"
6966
)
7067

7168
// Images are presumed by the isolated tests to have already been pulled
@@ -94,7 +91,7 @@ func iperf3Image(ctx context.Context, client *containerd.Client, snapshotterName
9491
}
9592

9693
func TestShimExitsUponContainerDelete_Isolated(t *testing.T) {
97-
internal.RequiresIsolation(t)
94+
prepareIntegTest(t)
9895

9996
ctx := namespaces.WithNamespace(context.Background(), defaultNamespace)
10097

@@ -224,7 +221,7 @@ func createTapDevice(ctx context.Context, tapName string) error {
224221
}
225222

226223
func TestMultipleVMs_Isolated(t *testing.T) {
227-
internal.RequiresIsolation(t)
224+
prepareIntegTest(t)
228225

229226
const (
230227
numVMs = 3
@@ -457,13 +454,14 @@ func TestMultipleVMs_Isolated(t *testing.T) {
457454
}
458455

459456
func TestLongUnixSocketPath_Isolated(t *testing.T) {
457+
prepareIntegTest(t)
458+
460459
// Verify that if the absolute path of the Firecracker unix sockets are longer
461460
// than the max length enforced by the kernel (UNIX_PATH_MAX, usually 108), we
462461
// don't fail (due to the internal implementation using relative paths).
463462
// We do this by using the max VMID len (76 chars), which in combination with the
464463
// default location we store state results in a path like
465464
// "/run/firecracker-containerd/default/<vmID>" (with len 112).
466-
internal.RequiresIsolation(t)
467465
const maxUnixSockLen = 108
468466
vmID := strings.Repeat("x", 76)
469467

@@ -502,7 +500,8 @@ func TestLongUnixSocketPath_Isolated(t *testing.T) {
502500
}
503501

504502
func TestStubBlockDevices_Isolated(t *testing.T) {
505-
internal.RequiresIsolation(t)
503+
prepareIntegTest(t)
504+
506505
const vmID = 0
507506

508507
ctx := namespaces.WithNamespace(context.Background(), "default")
@@ -734,7 +733,7 @@ func testCreateContainerWithSameName(t *testing.T, vmID string) {
734733
}
735734

736735
func TestCreateContainerWithSameName_Isolated(t *testing.T) {
737-
internal.RequiresIsolation(t)
736+
prepareIntegTest(t)
738737

739738
testCreateContainerWithSameName(t, "")
740739

@@ -743,7 +742,8 @@ func TestCreateContainerWithSameName_Isolated(t *testing.T) {
743742
}
744743

745744
func TestCreateTooManyContainers_Isolated(t *testing.T) {
746-
internal.RequiresIsolation(t)
745+
prepareIntegTest(t)
746+
747747
assert := assert.New(t)
748748

749749
ctx := namespaces.WithNamespace(context.Background(), "default")

tools/docker/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ COPY _submodules/firecracker/target/$FIRECRACKER_TARGET/release/firecracker /usr
149149
COPY _submodules/firecracker/target/$FIRECRACKER_TARGET/release/jailer /usr/local/bin/
150150
COPY _submodules/runc/runc /usr/local/bin
151151
COPY tools/image-builder/rootfs.img /var/lib/firecracker-containerd/runtime/default-rootfs.img
152-
COPY tools/docker/firecracker-runtime.json /etc/containerd/firecracker-runtime.json
153152

154153
# pull the images the tests need into the content store so we don't need internet
155154
# access during the tests themselves
@@ -164,8 +163,6 @@ RUN make -C /firecracker-containerd/internal test-bridged-tap && \
164163
cp /firecracker-containerd/internal/test-bridged-tap /opt/cni/bin/ && \
165164
chmod a+x /firecracker-containerd/internal/test-bridged-tap
166165

167-
COPY tools/docker/firecracker-runtime.json /etc/containerd/firecracker-runtime.json
168-
COPY tools/docker/firecracker-runtime-defaultnetwork.json /etc/containerd/firecracker-runtime-defaultnetwork.json
169166
COPY tools/docker/naive-snapshotter/entrypoint.sh /entrypoint
170167

171168
ENTRYPOINT ["/entrypoint"]

tools/docker/firecracker-runtime-defaultnetwork.json

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

0 commit comments

Comments
 (0)