From 93fbcd2af615d33754affc7d193f474746f55e38 Mon Sep 17 00:00:00 2001 From: Georgiy Lebedev Date: Tue, 12 Sep 2023 17:20:37 +0300 Subject: [PATCH] Add basic remote snapshot create and load tests for firecracker Signed-off-by: Georgiy Lebedev --- ctriface/Makefile | 9 +++ ctriface/manual_cleanup_test.go | 102 ++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) diff --git a/ctriface/Makefile b/ctriface/Makefile index 8f92f6fba..bc8f6fcd3 100644 --- a/ctriface/Makefile +++ b/ctriface/Makefile @@ -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 & diff --git a/ctriface/manual_cleanup_test.go b/ctriface/manual_cleanup_test.go index 4476a453f..85ff312c1 100644 --- a/ctriface/manual_cleanup_test.go +++ b/ctriface/manual_cleanup_test.go @@ -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 @@ -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() +}