Skip to content

Commit

Permalink
kola/tests: Replace nmap's ncat with openbsd ncat
Browse files Browse the repository at this point in the history
OpenBSD netcat has no long flags and has no idle timeout flag, so
these need to be replaced with short flags and using a timeout
utility, respectively.

The CRIO and podman are untested - they do not run on Flatcar.
  • Loading branch information
krnowak committed Aug 5, 2024
1 parent ac3b487 commit 612b009
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
12 changes: 6 additions & 6 deletions kola/tests/crio/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,16 @@ func crioNetwork(c cluster.TestCluster) {
machines := c.Machines()
src, dest := machines[0], machines[1]

c.Log("creating ncat containers")
c.Log("creating netcat containers")

// Since genContainer also generates crio pod/container configs,
// there will be a duplicate config file on each machine.
// Thus we only save one set for later use.
crioConfigPod, crioConfigContainer, err := genContainer(c, src, "ncat", "ncat", []string{"ncat", "echo"}, []string{"ncat"})
crioConfigPod, crioConfigContainer, err := genContainer(c, src, "netcat", "netcat", []string{"nc", "echo", "timeout"}, []string{"nc"})
if err != nil {
c.Fatal(err)
}
_, _, err = genContainer(c, dest, "ncat", "ncat", []string{"ncat", "echo"}, []string{"ncat"})
_, _, err = genContainer(c, dest, "netcat", "netcat", []string{"nc", "echo", "timeout"}, []string{"nc"})
if err != nil {
c.Fatal(err)
}
Expand All @@ -285,8 +285,8 @@ func crioNetwork(c cluster.TestCluster) {
return err
}

// This command will block until a message is recieved
output, err := c.SSH(dest, fmt.Sprintf("sudo timeout 30 crictl exec %s echo 'HELLO FROM SERVER' | timeout 20 ncat --listen 0.0.0.0 9988 || echo 'LISTENER TIMEOUT'", containerID))
// This command will block until a message is received
output, err := c.SSH(dest, fmt.Sprintf("sudo timeout 30 crictl exec %s echo 'HELLO FROM SERVER' | timeout 20 nc -l -N 0.0.0.0 9988 || echo 'LISTENER TIMEOUT'", containerID))
if err != nil {
return err
}
Expand Down Expand Up @@ -328,7 +328,7 @@ func crioNetwork(c cluster.TestCluster) {
return err
}

output, err := c.SSH(src, fmt.Sprintf("sudo crictl exec %s echo 'HELLO FROM CLIENT' | ncat %s 9988",
output, err := c.SSH(src, fmt.Sprintf("sudo crictl exec %s echo 'HELLO FROM CLIENT' | nc %s 9988",
containerID, dest.PrivateIP()))
if err != nil {
return err
Expand Down
14 changes: 8 additions & 6 deletions kola/tests/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,17 @@ func dockerNetwork(c cluster.TestCluster) {
machines := c.Machines()
src, dest := machines[0], machines[1]

c.Log("creating ncat containers")
c.Log("creating netcat containers")

GenDockerImage(c, src, "ncat", []string{"ncat"})
GenDockerImage(c, dest, "ncat", []string{"ncat"})
GenDockerImage(c, src, "netcat", []string{"timeout", "nc"})
GenDockerImage(c, dest, "netcat", []string{"timeout", "nc"})

listener := func(ctx context.Context) error {
// Will block until a message is recieved
// Will block until a message is received
out, err := c.SSH(dest,
`echo "HELLO FROM SERVER" | docker run -i -p 9988:9988 ncat ncat --idle-timeout 20 --listen 0.0.0.0 9988`,
// -N means "Shutdown the network socket after EOF on stdin"
// -l means "Listen mode, for inbound connects"
`echo "HELLO FROM SERVER" | docker run -i -p 9988:9988 netcat timeout 20 nc -N -l 0.0.0.0 9988`,
)
if err != nil {
return err
Expand Down Expand Up @@ -409,7 +411,7 @@ func dockerNetwork(c cluster.TestCluster) {
}
}

srcCmd := fmt.Sprintf(`echo "HELLO FROM CLIENT" | docker run -i ncat ncat %s 9988`, dest.PrivateIP())
srcCmd := fmt.Sprintf(`echo "HELLO FROM CLIENT" | docker run -i netcat nc %s 9988`, dest.PrivateIP())
out, err := c.SSH(src, srcCmd)
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions kola/tests/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ func podmanNetworkTest(c cluster.TestCluster) {
machines := c.Machines()
src, dest := machines[0], machines[1]

c.Log("creating ncat containers")
c.Log("creating netcat containers")

tutil.GenPodmanScratchContainer(c, src, "ncat", []string{"ncat"})
tutil.GenPodmanScratchContainer(c, dest, "ncat", []string{"ncat"})
tutil.GenPodmanScratchContainer(c, src, "netcat", []string{"timeout", "nc"})
tutil.GenPodmanScratchContainer(c, dest, "netcat", []string{"timeout", "nc"})

listener := func(ctx context.Context) error {
// Will block until a message is recieved
out, err := c.SSH(dest,
`echo "HELLO FROM SERVER" | sudo podman run -i -p 9988:9988 ncat ncat --idle-timeout 20 --listen 0.0.0.0 9988`,
`echo "HELLO FROM SERVER" | sudo podman run -i -p 9988:9988 netcat timeout 20 nc -l -N 0.0.0.0 9988`,
)
if err != nil {
return err
Expand Down Expand Up @@ -317,7 +317,7 @@ func podmanNetworkTest(c cluster.TestCluster) {
}
}

srcCmd := fmt.Sprintf(`echo "HELLO FROM CLIENT" | sudo podman run -i ncat ncat %s 9988`, dest.PrivateIP())
srcCmd := fmt.Sprintf(`echo "HELLO FROM CLIENT" | sudo podman run -i netcat nc %s 9988`, dest.PrivateIP())
out, err := c.SSH(src, srcCmd)
if err != nil {
return err
Expand Down

0 comments on commit 612b009

Please sign in to comment.