Merge pull request #17412 from karalabe/puppeth-fix-dial-panic

cmd/puppeth: fix nil panic on disconnected stats gathering
This commit is contained in:
Péter Szilágyi 2018-08-16 13:19:01 +03:00 committed by GitHub
commit 5952d962dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,7 +82,6 @@ func (w *wizard) gatherStats(server string, pubkey []byte, client *sshClient) *s
logger.Info("Starting remote server health-check") logger.Info("Starting remote server health-check")
stat := &serverStat{ stat := &serverStat{
address: client.address,
services: make(map[string]map[string]string), services: make(map[string]map[string]string),
} }
if client == nil { if client == nil {
@ -94,6 +93,8 @@ func (w *wizard) gatherStats(server string, pubkey []byte, client *sshClient) *s
} }
client = conn client = conn
} }
stat.address = client.address
// Client connected one way or another, run health-checks // Client connected one way or another, run health-checks
logger.Debug("Checking for nginx availability") logger.Debug("Checking for nginx availability")
if infos, err := checkNginx(client, w.network); err != nil { if infos, err := checkNginx(client, w.network); err != nil {
@ -214,6 +215,9 @@ func (stats serverStats) render() {
if len(stat.address) > len(separator[1]) { if len(stat.address) > len(separator[1]) {
separator[1] = strings.Repeat("-", len(stat.address)) separator[1] = strings.Repeat("-", len(stat.address))
} }
if len(stat.failure) > len(separator[1]) {
separator[1] = strings.Repeat("-", len(stat.failure))
}
for service, configs := range stat.services { for service, configs := range stat.services {
if len(service) > len(separator[2]) { if len(service) > len(separator[2]) {
separator[2] = strings.Repeat("-", len(service)) separator[2] = strings.Repeat("-", len(service))
@ -250,8 +254,12 @@ func (stats serverStats) render() {
sort.Strings(services) sort.Strings(services)
if len(services) == 0 { if len(services) == 0 {
if stats[server].failure != "" {
table.Append([]string{server, stats[server].failure, "", "", ""})
} else {
table.Append([]string{server, stats[server].address, "", "", ""}) table.Append([]string{server, stats[server].address, "", "", ""})
} }
}
for j, service := range services { for j, service := range services {
// Add an empty line between all services // Add an empty line between all services
if j > 0 { if j > 0 {