Permalink
Browse files

libmachine: Add usage of ss to check Docker Engine listening port whe…

…n netstat is not available

Signed-off-by: Guillaume Fieni <gfieni@users.noreply.github.com>
  • Loading branch information...
gfieni authored and shin- committed Nov 8, 2017
1 parent 6f12672 commit 796b36730911f008d6c3e9d30a81330dd54ae091
Showing with 21 additions and 1 deletion.
  1. +1 −1 libmachine/provision/utils.go
  2. +20 −0 libmachine/provision/utils_test.go
@@ -255,7 +255,7 @@ func checkDaemonUp(p Provisioner, dockerPort int) func() bool {
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 -tln")
netstatOut, err := p.SSHCommand("if ! type netstat 1>/dev/null; then ss -tln; else netstat -tln; fi")
if err != nil {
log.Warnf("Error running SSH command: %s", err)
return false
@@ -43,6 +43,26 @@ tcp6 0 0 :::22 :::* LISTEN`
}
}
func TestMatchSsOutMissing(t *testing.T) {
ssOut := `State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 :::23760 :::* `
if matchNetstatOut(reDaemonListening, ssOut) {
t.Fatal("Expected not to match the ss output as showing the daemon listening but got a match")
}
}
func TestMatchSsOutPresent(t *testing.T) {
ssOut := `State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 :::2376 :::* `
if !matchNetstatOut(reDaemonListening, ssOut) {
t.Fatal("Expected to match the ss output as showing the daemon listening but didn't")
}
}
func TestGenerateDockerOptionsBoot2Docker(t *testing.T) {
p := &Boot2DockerProvisioner{
Driver: &fakedriver.Driver{},

0 comments on commit 796b367

Please sign in to comment.