restart fix + slack commands
This commit is contained in:
1 parent
e90c9f324b
commit
25fcf85855
22 files changed
+1077
-119
No files matched your search
@@ -28,6 +28,7 @@ go_test(
|
||||
"cluster_test.go",
|
||||
"files_test.go",
|
||||
"migrate_test.go",
|
||||
"update_test.go",
|
||||
],
|
||||
embed = [":manager"],
|
||||
deps = [
|
||||
|
||||
@@ -248,6 +248,50 @@ func (m *Manager) EnsureProgress(ctx context.Context, id string, kind model.Owne
|
||||
return u, nil
|
||||
}
|
||||
|
||||
// Restart stops a running container and starts it again, so it boots the
|
||||
// node's current system.
|
||||
func (m *Manager) Restart(ctx context.Context, id string, kind model.OwnerKind, progress func(StartEvent)) (*model.Owner, error) {
|
||||
if m.IsMigrating(id) {
|
||||
return nil, ErrMigrating
|
||||
}
|
||||
unlock := m.ownerMu.Lock(id)
|
||||
u, err := m.ownerRecord(id, kind)
|
||||
if err == nil && u.Node != "" {
|
||||
var n node.Node
|
||||
if n, err = m.nodeByName(u.Node); err == nil && n.IsRunning(u.Machine) {
|
||||
log.Printf("container: restarting %s for %s %s on %s", u.Machine, u.Kind, u.ID, u.Node)
|
||||
if err = n.Poweroff(ctx, u.Machine); err == nil {
|
||||
err = n.WaitStopped(ctx, u.Machine)
|
||||
}
|
||||
}
|
||||
}
|
||||
unlock()
|
||||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
return m.EnsureProgress(ctx, id, kind, progress)
|
||||
}
|
||||
|
||||
func (m *Manager) Outdated(ctx context.Context, u *model.Owner) bool {
|
||||
if u == nil || u.Node == "" {
|
||||
return false
|
||||
}
|
||||
n, err := m.nodeByName(u.Node)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
running, err := n.Running(ctx)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, r := range running {
|
||||
if r.Name == u.Machine {
|
||||
return r.Outdated
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// The old home folder stays on its node, untouched.
|
||||
func (m *Manager) Recreate(id string) error {
|
||||
if m.IsMigrating(id) {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package manager_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"slackerbot/internal/model"
|
||||
"slackerbot/internal/testutil"
|
||||
"slackerbot/internal/testutil/clustertest"
|
||||
)
|
||||
|
||||
func TestRestartAppliesUpdate(t *testing.T) {
|
||||
c := clustertest.New(t)
|
||||
c.AddOwner(t, testutil.HomeData(), true)
|
||||
u := c.Store.Owner("C1")
|
||||
if c.Mgr.Outdated(c.Ctx, u) {
|
||||
t.Fatal("a container on the current system isn't outdated")
|
||||
}
|
||||
|
||||
c.Master.Mu.Lock()
|
||||
c.Master.Outdated["c-c1"] = true
|
||||
c.Master.Mu.Unlock()
|
||||
if !c.Mgr.Outdated(c.Ctx, u) {
|
||||
t.Fatal("the node said the container is outdated")
|
||||
}
|
||||
|
||||
if _, err := c.Mgr.Restart(c.Ctx, "C1", model.OwnerChannel, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !c.Master.IsRunning("c-c1") || c.Mgr.Outdated(c.Ctx, u) {
|
||||
t.Fatal("after a restart the container should run the current system")
|
||||
}
|
||||
if c.Master.Last.Machine != "c-c1" {
|
||||
t.Fatal("the container wasn't started again")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutdatedThroughSlave(t *testing.T) {
|
||||
c := clustertest.New(t)
|
||||
u := &model.Owner{ID: "C2", Kind: model.OwnerChannel, Machine: "c-c2", Node: "slave-1", Drive: "/d"}
|
||||
c.Slave.Mu.Lock()
|
||||
c.Slave.Runs["c-c2"], c.Slave.Outdated["c-c2"] = true, true
|
||||
c.Slave.Mu.Unlock()
|
||||
testutil.WaitFor(t, "slave to report the outdated container", func() bool { return c.Mgr.Outdated(c.Ctx, u) })
|
||||
}
|
||||
|
||||
func TestRestartStoppedContainerJustStarts(t *testing.T) {
|
||||
c := clustertest.New(t)
|
||||
c.AddOwner(t, testutil.HomeData(), false)
|
||||
if _, err := c.Mgr.Restart(c.Ctx, "C1", model.OwnerChannel, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !c.Master.IsRunning("c-c1") {
|
||||
t.Fatal("a stopped container should just start")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user