platform9 / ssh-provider

SSH Machine Controller for the Cluster API
11 stars 4 forks source link

Log output of stdout in addition to stderr in case of failure #19

Open vannrt opened 6 years ago

vannrt commented 6 years ago

While running cctl and the machine actuator hits an error:

# /opt/bin/cctl create machine --ip 10.105.16.42 --role master
2018/07/13 05:45:58 Using the existing state file
2018/07/13 05:45:58 Not able to verify machine SSH identity: No public keys given. Continuing...
2018/07/13 05:45:58 Running "/opt/bin/etcdadm init" on machine 10.105.16.42. This may take a few   minutes.
2018/07/13 05:46:00 error creating machine "10.105.16.42": error invoking ssh command Process exited with status 1

The tool only prints the stderr output. We don't see the output ofstdout. It's really hard to debug when the output of an error only says Process exited with status 1.

vannrt commented 6 years ago

Here's an example:

log.Printf("Running %q on machine %s. This may take a few minutes.", cmd, machine.Name)
out, err = session.CombinedOutput(cmd)
if err != nil {
        return fmt.Errorf("error invoking ssh command %s", err)
}
log.Println(string(out))

When there is an error, we return an error string that includes the stderr output only. We should also include stdout since it may contain helpful traces.