Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LXD: Fix start and stop for FROZEN instances #13452

Merged
merged 4 commits into from
May 22, 2024
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
9 changes: 8 additions & 1 deletion lxd/instance_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,19 @@ func doInstanceStatePut(inst instance.Instance, req api.InstanceStatePut) error

switch instancetype.InstanceAction(req.Action) {
case instancetype.Start:
return inst.Start(req.Stateful)
if inst.IsFrozen() {
return inst.Unfreeze()
} else {
return inst.Start(req.Stateful)
}

case instancetype.Stop:
if req.Stateful {
return inst.Stop(req.Stateful)
} else if req.Timeout == 0 {
return inst.Stop(false)
} else if inst.IsFrozen() {
return fmt.Errorf("Cannot shutdown frozen instance (try force to stop)")
} else {
return inst.Shutdown(timeout)
}
Expand Down
2 changes: 1 addition & 1 deletion lxd/instances_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func instancesPut(d *Daemon, r *http.Request) response.Response {
}

case instancetype.Start:
if inst.IsRunning() {
if !inst.IsFrozen() && inst.IsRunning() {
continue
}

Expand Down
15 changes: 15 additions & 0 deletions test/suites/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ test_basic_usage() {
false
fi

# Test freeze/pause
lxc freeze foo
! lxc stop foo || false
lxc stop -f foo
lxc start foo
lxc freeze foo
lxc start foo

# Test instance types
lxc launch testimage test-limits -t c0.5-m0.2
[ "$(lxc config get test-limits limits.cpu)" = "1" ]
Expand Down Expand Up @@ -548,6 +556,13 @@ test_basic_usage() {
lxc start --all
lxc list | grep c1 | grep RUNNING
lxc list | grep c2 | grep RUNNING

lxc freeze c2
lxc list | grep c2 | grep FROZEN
lxc start --all
lxc list | grep c1 | grep RUNNING
lxc list | grep c2 | grep RUNNING

! lxc stop --all c1 || false
lxc stop --all -f
lxc list | grep c1 | grep STOPPED
Expand Down
Loading