Skip to content

Commit

Permalink
add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Sep 16, 2024
1 parent 9172ca6 commit 7c863b0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
11 changes: 11 additions & 0 deletions provisioner/testinfra.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ func (provisioner *Provisioner) Prepare(raws ...interface{}) error {
}
}

log.Print("packer plugin testinfra validation complete")

return nil
}

Expand All @@ -210,6 +212,13 @@ func (provisioner *Provisioner) Provision(ctx context.Context, ui packer.Ui, com

// prepare testinfra test command
cmd, localCmd, err := provisioner.determineExecCmd(ui)
if cmd != nil {
log.Printf("complete Testinfra remote command is: %s", cmd.String())
} else {
if localCmd != nil {
log.Printf("complete Testinfra local command is: %s", localCmd.Command)
}
}
if err != nil {
ui.Error("the execution command could not be accurately determined")
return err
Expand All @@ -231,5 +240,7 @@ func (provisioner *Provisioner) Provision(ctx context.Context, ui packer.Ui, com
return err
}

ui.Say("packer plugin testinfra provisioning complete")

return nil
}
2 changes: 0 additions & 2 deletions provisioner/testinfra_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
func execCmd(cmd *exec.Cmd, ui packer.Ui) error {
// merge in env settings
cmd.Env = os.Environ()
log.Printf("complete Testinfra remote command is: %s", cmd.String())

// prepare stdout and stderr pipes
stdout, err := cmd.StdoutPipe()
Expand Down Expand Up @@ -81,7 +80,6 @@ func execCmd(cmd *exec.Cmd, ui packer.Ui) error {
func packerRemoteCmd(localCmd *packer.RemoteCmd, installCmd []string, comm packer.Communicator, ui packer.Ui) error {
// initialize context and log command
ctx := context.Background()
log.Printf("complete Testinfra local command is: %s", localCmd.Command)

// install testinfra on temp packer instance
if len(installCmd) > 0 {
Expand Down
7 changes: 6 additions & 1 deletion provisioner/testinfra_communication.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (provisioner *Provisioner) determineCommunication(ui packer.Ui) ([]string,
if err != nil {
return nil, err
}
log.Print("determined ssh authentication information")

// determine additional args for ssh based on authentication information
switch sshAuthType {
Expand Down Expand Up @@ -98,10 +99,12 @@ func (provisioner *Provisioner) determineCommunication(ui packer.Ui) ([]string,
// append args with container connection backend information (instanceid)
args = append(args, fmt.Sprintf("--hosts=%s://%s", connectionType, instanceID))
default:
ui.Sayf("communication backend with machine image is not supported, and was resolved to '%s'", connectionType)
ui.Errorf("communication backend with machine image is not supported, and was resolved to '%s'", connectionType)
return nil, errors.New("unsupported communication type")
}

log.Printf("determined communicator argument as: %+q", args)

return args, nil
}

Expand Down Expand Up @@ -148,6 +151,8 @@ func (provisioner *Provisioner) determineUserAddr() (string, string, error) {
httpAddr = fmt.Sprintf("%s:%d", ipaddress, port)
}

log.Print("determined communication user and connection endpoint")

return user, httpAddr, nil
}

Expand Down

0 comments on commit 7c863b0

Please sign in to comment.