Skip to content

Commit 9e27169

Browse files
andre-j3susleokondrashov
authored andcommitted
Fix snapshot commit
Signed-off-by: André Jesus <andre.jesus.pilar@gmail.com>
1 parent 71228b0 commit 9e27169

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

.github/workflows/cri_tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ jobs:
4949
- name: Run vHive CRI tests
5050
run: source /etc/profile && go clean -testcache && go test ./cri -v -race -cover
5151

52+
- name: Run sandbox specific tests
53+
if: ${{ inputs.sandbox == 'firecracker' }}
54+
run: source /etc/profile && go clean -testcache && go test ./cri/${{ inputs.sandbox }} -v -race -cover
55+
5256
- name: Archive log artifacts
5357
if: ${{ always() }}
5458
uses: actions/upload-artifact@v4

cri/firecracker/coordinator.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,24 +211,26 @@ func (c *coordinator) orchCreateSnapshot(ctx context.Context, fi *funcInstance)
211211

212212
fi.Logger.Debug("creating instance snapshot before stopping")
213213

214-
err = c.orch.PauseVM(ctxTimeout, fi.VmID)
215-
if err != nil {
216-
fi.Logger.WithError(err).Error("failed to pause VM")
217-
return err
218-
}
214+
if !c.withoutOrchestrator {
215+
err = c.orch.PauseVM(ctxTimeout, fi.VmID)
216+
if err != nil {
217+
fi.Logger.WithError(err).Error("failed to pause VM")
218+
return err
219+
}
219220

220-
err = c.orch.CreateSnapshot(ctxTimeout, fi.VmID, snap)
221-
if err != nil {
222-
fi.Logger.WithError(err).Error("failed to create snapshot")
223-
return err
224-
}
221+
err = c.orch.CreateSnapshot(ctxTimeout, fi.VmID, snap)
222+
if err != nil {
223+
fi.Logger.WithError(err).Error("failed to create snapshot")
224+
return err
225+
}
225226

226-
if _, err := c.orch.ResumeVM(ctx, fi.VmID); err != nil {
227-
fi.Logger.WithError(err).Error("failed to resume VM")
228-
return err
227+
if _, err := c.orch.ResumeVM(ctx, fi.VmID); err != nil {
228+
fi.Logger.WithError(err).Error("failed to resume VM")
229+
return err
230+
}
229231
}
230232

231-
if err := c.snapshotManager.CommitSnapshot(fi.VmID); err != nil {
233+
if err := c.snapshotManager.CommitSnapshot(fi.Revision); err != nil {
232234
fi.Logger.WithError(err).Error("failed to commit snapshot")
233235
return err
234236
}

cri/firecracker/coordinator_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,28 @@ func TestParallelStartStop(t *testing.T) {
9898

9999
wg.Wait()
100100
}
101+
102+
func TestOrchCreateSnapshot(t *testing.T) {
103+
containerID := "1"
104+
revision := "myrev-1"
105+
106+
// Start VM
107+
fi, err := coord.startVM(context.Background(), testImageName, revision)
108+
require.NoError(t, err, "could not start VM")
109+
110+
err = coord.insertActive(containerID, fi)
111+
require.NoError(t, err, "could not insert mapping")
112+
113+
// Trigger snapshot creation
114+
err = coord.orchCreateSnapshot(context.Background(), fi)
115+
require.NoError(t, err, "snapshot creation failed")
116+
117+
// Verify that the snapshot is available and ready
118+
snap, err := coord.snapshotManager.AcquireSnapshot(revision)
119+
require.NoError(t, err, "snapshot was not marked ready or does not exist")
120+
require.NotNil(t, snap, "acquired snapshot is nil")
121+
122+
// Clean up
123+
err = coord.stopVM(context.Background(), containerID)
124+
require.NoError(t, err, "could not stop VM")
125+
}

0 commit comments

Comments
 (0)