Merge pull request #3243 from tpires/3141_fix_check_docker_running

FIX #3141 Refactor netstat command and tests
This commit is contained in:
Nathan LeClaire
2016-03-29 14:40:58 -07:00
2 changed files with 10 additions and 27 deletions
+2 -2
View File
@@ -250,10 +250,10 @@ func getFilesystemType(p Provisioner, directory string) (string, error) {
}
func checkDaemonUp(p Provisioner, dockerPort int) func() bool {
reDaemonListening := fmt.Sprintf(":%d.*LISTEN", dockerPort)
reDaemonListening := fmt.Sprintf(":%d\\s+.*:.*", dockerPort)
return func() bool {
// HACK: Check netstat's output to see if anyone's listening on the Docker API port.
netstatOut, err := p.SSHCommand("netstat -an")
netstatOut, err := p.SSHCommand("netstat -tln")
if err != nil {
log.Warnf("Error running SSH command: %s", err)
return false
+8 -25
View File
@@ -17,23 +17,16 @@ import (
)
var (
reDaemonListening = ":2376.*LISTEN"
reDaemonListening = ":2376\\s+.*:.*"
)
func TestMatchNetstatOutMissing(t *testing.T) {
nsOut := `Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 72 192.168.25.141:ssh 192.168.25.1:63213 ESTABLISHED
tcp 0 0 :::ssh :::* LISTEN
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 17990 /var/run/acpid.socket
unix 2 [ ACC ] SEQPACKET LISTENING 14233 /run/udev/control
unix 3 [ ] STREAM CONNECTED 18688
unix 3 [ ] DGRAM 14243
unix 3 [ ] STREAM CONNECTED 18689
unix 3 [ ] DGRAM 14242`
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:237 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 :::23760 :::* LISTEN`
if matchNetstatOut(reDaemonListening, nsOut) {
t.Fatal("Expected not to match the netstat output as showing the daemon listening but got a match")
}
@@ -42,19 +35,9 @@ unix 3 [ ] DGRAM 14242`
func TestMatchNetstatOutPresent(t *testing.T) {
nsOut := `Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 72 192.168.25.141:ssh 192.168.25.1:63235 ESTABLISHED
tcp 0 0 :::2376 :::* LISTEN
tcp 0 0 :::ssh :::* LISTEN
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 17990 /var/run/acpid.socket
unix 2 [ ACC ] SEQPACKET LISTENING 14233 /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 19365 /var/run/docker.sock
unix 3 [ ] STREAM CONNECTED 19774
unix 3 [ ] STREAM CONNECTED 19775
unix 3 [ ] DGRAM 14243
unix 3 [ ] DGRAM 14242`
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp6 0 0 :::2376 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN`
if !matchNetstatOut(reDaemonListening, nsOut) {
t.Fatal("Expected to match the netstat output as showing the daemon listening but didn't")
}