|
1 | 1 | package instances |
2 | 2 |
|
3 | 3 | import ( |
| 4 | +"context" |
| 5 | +"fmt" |
4 | 6 | "testing" |
5 | 7 |
|
| 8 | +"github.com/kernel/hypeman/lib/guestmemory" |
| 9 | +"github.com/kernel/hypeman/lib/hypervisor" |
| 10 | +"github.com/kernel/hypeman/lib/paths" |
6 | 11 | "github.com/stretchr/testify/assert" |
7 | 12 | "github.com/stretchr/testify/require" |
8 | 13 | ) |
@@ -32,3 +37,74 @@ func TestPlannedVMConfigWithoutOptionalDevices(t *testing.T) { |
32 | 37 | assert.Empty(t, config.Networks) |
33 | 38 | assert.Empty(t, config.PCIDevices) |
34 | 39 | } |
| 40 | + |
| 41 | +funcTestPrepareSnapshotTargetStandbyValidationIgnoresLiveBalloonPolicy(t*testing.T) { |
| 42 | +t.Parallel() |
| 43 | + |
| 44 | +hvType:=hypervisor.Type("snapshot-validation-test") |
| 45 | +starter:=&snapshotValidationStarter{} |
| 46 | +m:=&manager{ |
| 47 | +vmStarters: map[hypervisor.Type]hypervisor.VMStarter{ |
| 48 | +hvType: starter, |
| 49 | + }, |
| 50 | +guestMemoryPolicy: guestmemory.Policy{ |
| 51 | +Enabled: true, |
| 52 | +ReclaimEnabled: true, |
| 53 | + }, |
| 54 | + } |
| 55 | +source:=StoredMetadata{ |
| 56 | +HypervisorType: hvType, |
| 57 | +HypervisorVersion: "test", |
| 58 | +Volumes: []VolumeAttachment{ |
| 59 | + {VolumeID: "v1"}, |
| 60 | + {VolumeID: "v2"}, |
| 61 | + {VolumeID: "v3"}, |
| 62 | + {VolumeID: "v4"}, |
| 63 | + }, |
| 64 | + } |
| 65 | + |
| 66 | +_, _, err:=m.prepareSnapshotTarget(context.Background(), SnapshotKindStopped, source, hvType) |
| 67 | +require.ErrorIs(t, err, ErrInvalidRequest) |
| 68 | +assert.True(t, starter.lastConfig.GuestMemory.EnableBalloon, "stopped validation should use live balloon policy") |
| 69 | + |
| 70 | +_, _, err=m.prepareSnapshotTarget(context.Background(), SnapshotKindStandby, source, hvType) |
| 71 | +require.NoError(t, err) |
| 72 | +assert.False(t, starter.lastConfig.GuestMemory.EnableBalloon, "standby validation should not inject live balloon policy") |
| 73 | +} |
| 74 | + |
| 75 | +typesnapshotValidationStarterstruct { |
| 76 | +lastConfig hypervisor.VMConfig |
| 77 | +} |
| 78 | + |
| 79 | +func (s*snapshotValidationStarter) ValidateConfig(config hypervisor.VMConfig) error { |
| 80 | +s.lastConfig=config |
| 81 | +devices:=len(config.Disks) +len(config.Networks) |
| 82 | +ifconfig.VsockCID>0 { |
| 83 | +devices++ |
| 84 | + } |
| 85 | +ifconfig.GuestMemory.EnableBalloon { |
| 86 | +devices++ |
| 87 | + } |
| 88 | +ifdevices>8 { |
| 89 | +returnfmt.Errorf("too many virtio-mmio devices: %d", devices) |
| 90 | + } |
| 91 | +returnnil |
| 92 | +} |
| 93 | + |
| 94 | +func (*snapshotValidationStarter) SocketName() string { return"snapshot-validation.sock" } |
| 95 | +func (*snapshotValidationStarter) GetBinaryPath(*paths.Paths, string) (string, error) { |
| 96 | +return"", nil |
| 97 | +} |
| 98 | +func (*snapshotValidationStarter) GetVersion(*paths.Paths) (string, error) { return"test", nil } |
| 99 | +func (*snapshotValidationStarter) ResolveVersion(*paths.Paths, string) (string, error) { |
| 100 | +return"test", nil |
| 101 | +} |
| 102 | +func (*snapshotValidationStarter) StartVM(context.Context, *paths.Paths, string, string, hypervisor.VMConfig) (int, hypervisor.Hypervisor, error) { |
| 103 | +return0, nil, nil |
| 104 | +} |
| 105 | +func (*snapshotValidationStarter) RestoreVM(context.Context, *paths.Paths, string, string, string, hypervisor.RestoreOptions) (int, hypervisor.Hypervisor, error) { |
| 106 | +return0, nil, nil |
| 107 | +} |
| 108 | +func (*snapshotValidationStarter) PrepareFork(context.Context, hypervisor.ForkPrepareRequest) (hypervisor.ForkPrepareResult, error) { |
| 109 | +return hypervisor.ForkPrepareResult{}, nil |
| 110 | +} |
0 commit comments