Skip to content

Commit

Permalink
Add basic remote snapshot create and load tests for firecracker
Browse files Browse the repository at this point in the history
Signed-off-by: Georgiy Lebedev <lebedev.gk@phystech.edu>
  • Loading branch information
CuriousGeorgiy committed Sep 26, 2023
1 parent 7fbeebd commit 93fbcd2
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ctriface/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ test-man:
sudo mkdir -m777 -p $(CTRDLOGDIR) && sudo env "PATH=$(PATH)" /usr/local/bin/firecracker-containerd --config /etc/firecracker-containerd/config.toml 1>$(CTRDLOGDIR)/ctriface_log_lazy_man_travis.out 2>$(CTRDLOGDIR)/ctriface_log_lazy_man_travis.err &
sudo env "PATH=$(PATH)" go test $(EXTRAGOARGS) -run TestSnapLoad -args $(WITHUPF) $(WITHLAZY)
./../scripts/clean_fcctr.sh
sudo mkdir -m777 -p $(CTRDLOGDIR) && sudo env "PATH=$(PATH)" /usr/local/bin/firecracker-containerd --config /etc/firecracker-containerd/config.toml 1>$(CTRDLOGDIR)/ctriface_log_remote_snap_create_man_travis.out 2>$(CTRDLOGDIR)/ctriface_log_remote_snap_create_man_travis.err &
# Creates a remote snapshot.
sudo env "PATH=$(PATH)" go test $(EXTRAGOARGS) -run TestRemoteSnapCreate
# Cleans up the node.
./../scripts/clean_fcctr.sh
sudo mkdir -m777 -p $(CTRDLOGDIR) && sudo env "PATH=$(PATH)" /usr/local/bin/firecracker-containerd --config /etc/firecracker-containerd/config.toml 1>$(CTRDLOGDIR)/ctriface_log_remote_snap_load_man_travis.out 2>$(CTRDLOGDIR)/ctriface_log_remote_snap_load_man_travis.err &
# Loads the remote snapshot.
sudo env "PATH=$(PATH)" go test $(EXTRAGOARGS) -run TestRemoteSnapLoad
./../scripts/clean_fcctr.sh

test-skip:
sudo mkdir -m777 -p $(CTRDLOGDIR) && sudo env "PATH=$(PATH)" /usr/local/bin/firecracker-containerd --config /etc/firecracker-containerd/config.toml 1>$(CTRDLOGDIR)/ctriface_log_noupf_man_skip.out 2>$(CTRDLOGDIR)/ctriface_log_noupf_man_skip.err &
Expand Down
102 changes: 102 additions & 0 deletions ctriface/manual_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ import (
"github.com/vhive-serverless/vhive/snapshotting"
)

const (
remoteSnapshotsDir = "/tmp/vhive/remote-snapshots"
)

func TestSnapLoad(t *testing.T) {
// Need to clean up manually after this test because StopVM does not
// work for stopping machines which are loaded from snapshots yet
Expand Down Expand Up @@ -392,3 +396,101 @@ func TestParallelPhasedSnapLoad(t *testing.T) {

orch.Cleanup()
}

func TestRemoteSnapCreate(t *testing.T) {
// Needs to be cleaned up manually.
log.SetFormatter(&log.TextFormatter{
TimestampFormat: ctrdlog.RFC3339NanoFixed,
FullTimestamp: true,
})
//log.SetReportCaller(true) // FIXME: make sure it's false unless debugging

log.SetOutput(os.Stdout)

log.SetLevel(log.InfoLevel)

testTimeout := 120 * time.Second
ctx, cancel := context.WithTimeout(namespaces.WithNamespace(context.Background(), namespaceName), testTimeout)
defer cancel()

vmID := "37"
revision := "myrev-37"

err := os.MkdirAll(remoteSnapshotsDir, 0755)
require.NoError(t, err, "Failed to create remote snapshots directory")

orch := NewOrchestrator(
"devmapper",
"",
WithTestModeOn(true),
WithUPF(*isUPFEnabled),
WithLazyMode(*isLazyMode),
)

_, _, err = orch.StartVM(ctx, vmID, testImageName)
require.NoError(t, err, "Failed to start VM")

err = orch.PauseVM(ctx, vmID)
require.NoError(t, err, "Failed to pause VM")

snap := snapshotting.NewSnapshot(revision, remoteSnapshotsDir, testImageName)
_ = snap.Cleanup()
err = snap.CreateSnapDir()
require.NoError(t, err, "Failed to create remote snapshots directory")

err = orch.CreateSnapshot(ctx, vmID, snap)
require.NoError(t, err, "Failed to create snapshot of VM")

_, err = orch.ResumeVM(ctx, vmID)
require.NoError(t, err, "Failed to resume VM")

err = orch.StopSingleVM(ctx, vmID)
require.NoError(t, err, "Failed to offload VM")

orch.Cleanup()
}

func TestRemoteSnapLoad(t *testing.T) {
// Needs to be cleaned up manually.
log.SetFormatter(&log.TextFormatter{
TimestampFormat: ctrdlog.RFC3339NanoFixed,
FullTimestamp: true,
})
//log.SetReportCaller(true) // FIXME: make sure it's false unless debugging

log.SetOutput(os.Stdout)

log.SetLevel(log.InfoLevel)

testTimeout := 120 * time.Second
ctx, cancel := context.WithTimeout(namespaces.WithNamespace(context.Background(), namespaceName), testTimeout)
defer cancel()

vmID := "37"
revision := "myrev-37"

_, err := os.Stat(remoteSnapshotsDir)
require.NoError(t, err, "Failed to stat remote snapshots directory")

orch := NewOrchestrator(
"devmapper",
"",
WithTestModeOn(true),
WithUPF(*isUPFEnabled),
WithLazyMode(*isLazyMode),
)

snap := snapshotting.NewSnapshot(revision, remoteSnapshotsDir, testImageName)

_, _, err = orch.LoadSnapshot(ctx, vmID, snap)
require.NoError(t, err, "Failed to load remote snapshot of VM")

_, err = orch.ResumeVM(ctx, vmID)
require.NoError(t, err, "Failed to resume VM")

err = orch.StopSingleVM(ctx, vmID)
require.NoError(t, err, "Failed to offload VM")

_ = snap.Cleanup()
orch.Cleanup()
}

0 comments on commit 93fbcd2

Please sign in to comment.