Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions cmd/unikraft/integration/instance_checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,76 @@ func TestInstanceCheckpoints(t *testing.T) {
r.Run(t, []string{"unikraft", "instance", "delete", "test-" + instName})
})

// volumes proves a checkpoint gets its own cloned copy of the source
// instance's volumes, that the clone is a volume template rather than a
// plain volume, and that the source volume is left untouched.
t.Run("volumes", func(t *testing.T) {
r := runner(t, true, []string{staging, stable})
instName := uniq()
volName := uniq()

r.Run(t, []string{
"unikraft", "volume", "create",
"--output", "quiet",
"--set", "name=test-" + volName,
"--set", "metro=" + r.Config.MetroName,
"--set", "size=10",
})

out := r.Run(t, []string{
"unikraft", "volume", "inspect", "test-" + volName,
"--output", "template={{ .uuid }}",
})
srcVolUUID := strings.TrimSpace(out)
assert.NotEmpty(t, srcVolUUID)

r.Run(t, []string{
"unikraft", "instance", "create",
"--output", "quiet",
"--set", "name=test-" + instName,
"--set", "metro=" + r.Config.MetroName,
"--set", "image=nginx:latest",
"--set", "autostart=false",
"--set", "resources.memory=128",
"--set", "resources.vcpus=1",
"--set", "volumes=test-" + volName + ":/data",
})

out = r.Run(t, []string{
"unikraft", "instance", "checkpoint", "create", "test-" + instName,
"--set", "wait-timeout=30s",
"--output", "template={{ .name }}",
})
checkpointName := strings.TrimSpace(out)
assert.NotEmpty(t, checkpointName)

out = r.Run(t, []string{"unikraft", "instance", "checkpoint", "inspect", checkpointName, "-f", "all"})
assert.Regexp(t, `at:\s+/data`, out)

// The checkpoint's volume is a clone, created without a name, so it is
// only addressable by UUID.
out = r.Run(t, []string{
"unikraft", "instance", "checkpoint", "inspect", checkpointName,
"--output", "template=" + `{{ (index .volumes 0).uuid }}`,
})
ckptVolUUID := strings.TrimSpace(out)
assert.NotEmpty(t, ckptVolUUID)
assert.NotEqual(t, srcVolUUID, ckptVolUUID)

out = r.Run(t, []string{"unikraft", "volume", "template", "inspect", ckptVolUUID})
assert.Regexp(t, `state:\s+template`, out)
r.Run(t, []string{"unikraft", "volume", "inspect", ckptVolUUID}, integ.ExpectFail())

// The source volume is unaffected: still a plain volume.
out = r.Run(t, []string{"unikraft", "volume", "inspect", "test-" + volName})
assert.NotRegexp(t, `state:\s+template`, out)

r.Run(t, []string{"unikraft", "instance", "checkpoint", "delete", checkpointName})
r.Run(t, []string{"unikraft", "instance", "delete", "test-" + instName})
r.Run(t, []string{"unikraft", "--timeout", "30s", "volume", "wait", "--until", "state==available", "test-" + volName})
r.Run(t, []string{"unikraft", "volume", "delete", "test-" + volName})
})

t.Run("create-from-checkpoint", func(t *testing.T) {
r := runner(t, true, []string{staging, stable})
baseName := uniq()
Expand Down
56 changes: 56 additions & 0 deletions cmd/unikraft/integration/instance_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"

"github.com/stretchr/testify/assert"

integ "unikraft.com/cli/internal/integration"
)

func TestInstanceTemplates(t *testing.T) {
Expand Down Expand Up @@ -85,6 +87,60 @@ func TestInstanceTemplates(t *testing.T) {
r.Run(t, []string{"unikraft", "instance", "template", "delete", templateName})
})

// volumes proves the mountpoints survive the in-place conversion, and that
// the attached volume becomes a volume template - so it is reachable via
// `volume template` and no longer via `volume`.
t.Run("volumes", func(t *testing.T) {
r := runner(t, true, []string{staging, stable})
instName := uniq()
volName := uniq()

r.Run(t, []string{
"unikraft", "volume", "create",
"--output", "quiet",
"--set", "name=test-" + volName,
"--set", "metro=" + r.Config.MetroName,
"--set", "size=10",
})

r.Run(t, []string{
"unikraft", "instance", "create",
"--output", "quiet",
"--set", "name=test-" + instName,
"--set", "metro=" + r.Config.MetroName,
"--set", "image=nginx:latest",
"--set", "autostart=false",
"--set", "resources.memory=128",
"--set", "resources.vcpus=1",
"--set", "volumes=test-" + volName + ":/data",
})

out := r.Run(t, []string{
"unikraft", "instance", "template", "create", "test-" + instName,
"--output", "template={{ .name }}",
})
templateName := strings.TrimSpace(out)

out = r.Run(t, []string{"unikraft", "instance", "template", "inspect", templateName, "-f", "all"})
assert.Contains(t, out, "test-"+volName)
assert.Regexp(t, `at:\s+/data`, out)

out = r.Run(t, []string{"unikraft", "volume", "template", "list", "--output", "quiet"})
assert.Contains(t, out, "test-"+volName)

out = r.Run(t, []string{"unikraft", "volume", "list", "--output", "quiet"})
assert.NotContains(t, out, "test-"+volName)

out = r.Run(t, []string{"unikraft", "volume", "template", "inspect", "test-" + volName})
assert.Regexp(t, `state:\s+template`, out)
r.Run(t, []string{"unikraft", "volume", "inspect", "test-" + volName}, integ.ExpectFail())

// Deleting the template takes its volume template with it: the
// conversion re-parented the volume to the template.
r.Run(t, []string{"unikraft", "instance", "template", "delete", templateName})
r.Run(t, []string{"unikraft", "volume", "template", "delete", "test-" + volName}, integ.AllowFail())
})

t.Run("tags", func(t *testing.T) {
r := runner(t, true, []string{staging, stable})
instName := uniq()
Expand Down
58 changes: 45 additions & 13 deletions cmd/unikraft/testdata/TestHelp/instances

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions internal/cmd/instance_checkpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ type InstanceCheckpoint struct {
UUID string `mirror:"instance.uuid" field:",long"`

Tags []string `mirror:"instance.tags" field:",long" edit:"set,add,del"`
DeleteLock bool `mirror:"instance.delete_lock" field:"delete-lock,hidden" edit:"set"`
DeleteLock bool `mirror:"instance.delete_lock" field:"delete-lock,long" edit:"set"`

State types.InstanceState `mirror:"instance.state" field:",short"`
Image types.ImageRef[reference.Named] `mirror:"instance.image" field:",short"`
Type_ *platform.InstanceType `mirror:"instance.type" field:"type,long"`

Runtime struct {
Args InstanceArgs `mirror:"instance.args" field:",short"`
Expand All @@ -96,7 +97,11 @@ type InstanceCheckpoint struct {
VCPUs int `mirror:"instance.vcpus" field:"vcpus,short"`
}

Volumes []*InstanceVolume `mirror:"instance.volumes" field:",embed"`
Volumes []InstanceTemplateVolume `mirror:"instance.volumes" field:",embed"`

Snapshot struct {
UUID string `mirror:"instance.snapshot.uuid" field:",long"`
}

Timestamps struct {
Created types.RelativeTime `mirror:"instance.created_at" field:",short"`
Expand Down
12 changes: 11 additions & 1 deletion internal/cmd/instance_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type InstanceTemplate struct {

State types.InstanceState `mirror:"instance.state" field:",short"`
Image types.ImageRef[reference.Named] `mirror:"instance.image" field:",short"`
Type_ *platform.InstanceType `mirror:"instance.type" field:"type,long"`

Runtime struct {
Args InstanceArgs `mirror:"instance.args" field:",short"`
Expand All @@ -93,12 +94,21 @@ type InstanceTemplate struct {
VCPUs int `mirror:"instance.vcpus" field:"vcpus,short"`
}

Volumes []*InstanceVolume `mirror:"instance.volumes" field:",embed"`
Volumes []InstanceTemplateVolume `mirror:"instance.volumes" field:",embed"`

Snapshot struct {
UUID string `mirror:"instance.snapshot.uuid" field:",long"`
}

Timestamps struct {
Created types.RelativeTime `mirror:"instance.created_at" field:",short"`
}

Timing struct {
BootTime types.DurationUS `mirror:"instance.boot_time_us" field:",long"`
NetTime types.DurationUS `mirror:"instance.net_time_us"`
}

ScaleToZero InstanceScaleToZero `field:",embed" mirror:"instance.scale_to_zero"`

Restart struct {
Expand Down
Loading
Loading