diff --git a/cli/deploy.go b/cli/deploy.go index a9c3254f..f0205d95 100644 --- a/cli/deploy.go +++ b/cli/deploy.go @@ -230,11 +230,11 @@ func (obj *DeployArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error Logf("world: etcd: "+format, v...) }, } - if err := world.Init(worldInit); err != nil { - return false, errwrap.Wrapf(err, "world Init failed") + if err := world.Connect(ctx, worldInit); err != nil { + return false, errwrap.Wrapf(err, "world Connect failed") } defer func() { - err := errwrap.Wrapf(world.Close(), "world Close failed") + err := errwrap.Wrapf(world.Cleanup(), "world Cleanup failed") if err != nil { // TODO: cause the final exit code to be non-zero? Logf("close error: %+v", err) diff --git a/engine/world.go b/engine/world.go index af02f8d6..527fbf97 100644 --- a/engine/world.go +++ b/engine/world.go @@ -54,11 +54,11 @@ type WorldInit struct { // GAPI to store state and exchange information throughout the cluster. It is // the interface each machine uses to communicate with the rest of the world. type World interface { // TODO: is there a better name for this interface? - // Init sets things up and is called once before any other methods. - Init(*WorldInit) error + // Connect sets things up and is called once before any other methods. + Connect(context.Context, *WorldInit) error - // Close does some cleanup and is the last method that is ever called. - Close() error + // Cleanup does some cleanup and is the last method that is ever called. + Cleanup() error FsWorld diff --git a/etcd/ssh/ssh.go b/etcd/ssh/ssh.go index 1c7777cb..78380c80 100644 --- a/etcd/ssh/ssh.go +++ b/etcd/ssh/ssh.go @@ -143,8 +143,8 @@ func (obj *World) hostKeyCallback() (ssh.HostKeyCallback, error) { return knownhosts.New(p) } -// Init runs first. -func (obj *World) Init(init *engine.WorldInit) error { +// Connect runs first. +func (obj *World) Connect(ctx context.Context, init *engine.WorldInit) error { obj.init = init obj.cleanups = []func() error{} @@ -310,11 +310,11 @@ func (obj *World) Init(init *engine.WorldInit) error { StandaloneFs: obj.StandaloneFs, GetURI: obj.GetURI, } - if err := obj.World.Init(init); err != nil { + if err := obj.World.Connect(ctx, init); err != nil { return errwrap.Append(obj.cleanup(), err) } obj.cleanups = append(obj.cleanups, func() error { - e := obj.World.Close() + e := obj.World.Cleanup() if obj.init.Debug && e != nil { obj.init.Logf("world close error: %+v", e) } @@ -337,7 +337,7 @@ func (obj *World) cleanup() error { return errs } -// Close runs last. -func (obj *World) Close() error { +// CLeanup runs last. +func (obj *World) Cleanup() error { return obj.cleanup() } diff --git a/etcd/world.go b/etcd/world.go index 944fb30e..f364c48c 100644 --- a/etcd/world.go +++ b/etcd/world.go @@ -78,8 +78,8 @@ type World struct { cleanups []func() error } -// Init runs first. -func (obj *World) Init(init *engine.WorldInit) error { +// Connect runs first. +func (obj *World) Connect(ctx context.Context, init *engine.WorldInit) error { obj.init = init obj.client = obj.Client // legacy default @@ -135,8 +135,8 @@ func (obj *World) cleanup() error { return errs } -// Close runs last. -func (obj *World) Close() error { +// Cleanup runs last. +func (obj *World) Cleanup() error { return obj.cleanup() } diff --git a/lang/interpret_test.go b/lang/interpret_test.go index fee80a38..55dd837b 100644 --- a/lang/interpret_test.go +++ b/lang/interpret_test.go @@ -905,12 +905,12 @@ func TestAstFunc2(t *testing.T) { logf("world: etcd: "+format, v...) }, } - if err := world.Init(worldInit); err != nil { - t.Errorf("world Init failed: %+v", err) + if err := world.Connect(context.TODO(), worldInit); err != nil { + t.Errorf("world Connect failed: %+v", err) return } defer func() { - err := errwrap.Wrapf(world.Close(), "world Close failed") + err := errwrap.Wrapf(world.Cleanup(), "world Cleanup failed") if err != nil { t.Errorf("close error: %+v", err) } @@ -1805,12 +1805,12 @@ func TestAstFunc3(t *testing.T) { logf("world: etcd: "+format, v...) }, } - if err := world.Init(worldInit); err != nil { - t.Errorf("world Init failed: %+v", err) + if err := world.Connect(context.TODO(), worldInit); err != nil { + t.Errorf("world Connect failed: %+v", err) return } defer func() { - err := errwrap.Wrapf(world.Close(), "world Close failed") + err := errwrap.Wrapf(world.Cleanup(), "world Cleanup failed") if err != nil { t.Errorf("close error: %+v", err) } diff --git a/lib/main.go b/lib/main.go index 72f84289..99a53582 100644 --- a/lib/main.go +++ b/lib/main.go @@ -640,11 +640,11 @@ func (obj *Main) Run() error { obj.Logf("world: etcd: "+format, v...) }, } - if err := world.Init(worldInit); err != nil { - return errwrap.Wrapf(err, "world Init failed") + if err := world.Connect(exitCtx, worldInit); err != nil { + return errwrap.Wrapf(err, "world Connect failed") } defer func() { - err := errwrap.Wrapf(world.Close(), "world Close failed") + err := errwrap.Wrapf(world.Cleanup(), "world Cleanup failed") if err != nil { // TODO: cause the final exit code to be non-zero? Logf("close error: %+v", err)