Merge pull request #17434 from NikkeiFTLearning/saltstack-race-problem

fix ssh problem with communicator.Retry
This commit is contained in:
James Bardin 2018-02-26 09:56:13 -05:00 committed by GitHub
commit 81dc23c65d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 2 deletions

View File

@ -131,6 +131,24 @@ func applyFn(ctx context.Context) error {
return err return err
} }
ctx, cancelFunc := context.WithTimeout(ctx, comm.Timeout())
defer cancelFunc()
// Wait for the context to end and then disconnect
go func() {
<-ctx.Done()
comm.Disconnect()
}()
// Wait and retry until we establish the connection
err = communicator.Retry(ctx, func() error {
return comm.Connect(o)
})
if err != nil {
return err
}
var src, dst string var src, dst string
o.Output("Provisioning with Salt...") o.Output("Provisioning with Salt...")
@ -147,7 +165,7 @@ func applyFn(ctx context.Context) error {
if err == nil { if err == nil {
cmd.Wait() cmd.Wait()
if cmd.ExitStatus != 0 { if cmd.ExitStatus != 0 {
err = fmt.Errorf("Script exited with non-zero exit status: %d", cmd.ExitStatus) err = fmt.Errorf("Curl exited with non-zero exit status: %d", cmd.ExitStatus)
} }
} }
@ -171,7 +189,7 @@ func applyFn(ctx context.Context) error {
if err == nil { if err == nil {
cmd.Wait() cmd.Wait()
if cmd.ExitStatus != 0 { if cmd.ExitStatus != 0 {
err = fmt.Errorf("Script exited with non-zero exit status: %d", cmd.ExitStatus) err = fmt.Errorf("install_salt.sh exited with non-zero exit status: %d", cmd.ExitStatus)
} }
} }
// Wait for output to clean up // Wait for output to clean up