From 9408f311fd3926408f0f7f84ac3978b7937f73e8 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 6 Dec 2018 09:25:59 -0200 Subject: [PATCH] feat: added retry timeout options --- README.md | 4 +++- packer-provisioner-goss.go | 33 ++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 37264af..4a9fd84 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,9 @@ There is an example packer build with goss tests in the `example/` directory. "vars_file": "", "username": "", "password": "", - "debug": false + "debug": false, + "retry_timeout": "0s", + "sleep": "1s" } ] ``` diff --git a/packer-provisioner-goss.go b/packer-provisioner-goss.go index e92e044..102a03f 100644 --- a/packer-provisioner-goss.go +++ b/packer-provisioner-goss.go @@ -29,11 +29,15 @@ type GossConfig struct { // An array of tests to run. Tests []string + // Goss options for retry and timeouts + RetryTimeout string `mapstructure:"retry_timeout"` + Sleep string `mapstructure:"sleep"` + // Use Sudo UseSudo bool `mapstructure:"use_sudo"` // skip ssl check flag - SkipSSLChk bool `mapstructure:"skip_ssl"` + SkipSSLChk bool `mapstructure:"skip_ssl"` // The --gossfile flag GossFile string `mapstructure:"goss_file"` @@ -252,11 +256,12 @@ func (p *Provisioner) installGoss(ui packer.Ui, comm packer.Communicator) error // runGoss runs the Goss tests func (p *Provisioner) runGoss(ui packer.Ui, comm packer.Communicator) error { - goss := fmt.Sprintf("%s", p.config.DownloadPath) cmd := &packer.RemoteCmd{ Command: fmt.Sprintf( - "cd %s && %s %s %s %s %s validate %s", - p.config.RemotePath, p.enableSudo(), goss, p.config.GossFile, p.vars(), p.debug(), p.format()), + "cd %s && %s %s %s %s %s validate --retry-timeout %s --sleep %s %s", + p.config.RemotePath, p.enableSudo(), p.config.DownloadPath, p.config.GossFile, + p.vars(), p.debug(), p.retryTimeout(), p.sleep(), p.format(), + ), } if err := cmd.StartWithUi(comm, ui); err != nil { return err @@ -268,6 +273,20 @@ func (p *Provisioner) runGoss(ui packer.Ui, comm packer.Communicator) error { return nil } +func (p *Provisioner) retryTimeout() string { + if p.config.RetryTimeout == "" { + return "0s" // goss default + } + return p.config.RetryTimeout +} + +func (p *Provisioner) sleep() string { + if p.config.Sleep == "" { + return "1s" // goss default + } + return p.config.Sleep +} + // debug returns the debug flag if debug is configured func (p *Provisioner) debug() string { if p.config.Debug { @@ -292,7 +311,7 @@ func (p *Provisioner) vars() string { func (p *Provisioner) sslFlag(cmdType string) string { if p.config.SkipSSLChk { - switch(cmdType) { + switch cmdType { case "curl": return "-k" case "wget": @@ -315,7 +334,7 @@ func (p *Provisioner) enableSudo() string { // Deal with curl & wget username and password func (p *Provisioner) userPass(cmdType string) string { if p.config.Username != "" { - switch(cmdType) { + switch cmdType { case "curl": if p.config.Password == "" { return fmt.Sprintf("-u %s", p.config.Username) @@ -327,7 +346,7 @@ func (p *Provisioner) userPass(cmdType string) string { } return fmt.Sprintf("--user=%s --password=%s", p.config.Username, p.config.Password) default: - return "" + return "" } } return ""