import (
"fmt"
+ "math/rand"
"net"
"os"
"path/filepath"
"github.com/vishvananda/netlink"
)
-const TIMEOUT = 20
+const TIMEOUT = 90
var _ = Describe("portmap integration tests", func() {
+ rand.Seed(time.Now().UTC().UnixNano())
var configList *libcni.NetworkConfigList
var cniConf *libcni.CNIConfig
"ipMasq": true,
"ipam": {
"type": "host-local",
- "subnet": "172.16.31.0/24"
+ "subnet": "172.16.31.0/24",
+ "routes": [
+ {"dst": "0.0.0.0/0"}
+ ]
}
},
{
// This needs to be done using Ginkgo's asynchronous testing mode.
It("forwards a TCP port on ipv4", func(done Done) {
var err error
- hostPort := 9999
+ hostPort := rand.Intn(10000) + 1025
runtimeConfig := libcni.RuntimeConf{
- ContainerID: "unit-test",
+ ContainerID: fmt.Sprintf("unit-test-%d", hostPort),
NetNS: targetNS.Path(),
IfName: "eth0",
CapabilityArgs: map[string]interface{}{
// we'll also manually check the iptables chains
ipt, err := iptables.NewWithProtocol(iptables.ProtocolIPv4)
Expect(err).NotTo(HaveOccurred())
- dnatChainName := genDnatChain("cni-portmap-unit-test", "unit-test", nil).name
+ dnatChainName := genDnatChain("cni-portmap-unit-test", runtimeConfig.ContainerID, nil).name
// Create the network
resI, err := cniConf.AddNetworkList(configList, &runtimeConfig)
Fail("could not determine container IP")
}
+ hostIP := getLocalIP()
+ fmt.Fprintf(GinkgoWriter, "hostIP: %s:%d, contIP: %s:%d\n",
+ hostIP, hostPort, contIP, containerPort)
+
// Sanity check: verify that the container is reachable directly
contOK := testEchoServer(fmt.Sprintf("%s:%d", contIP.String(), containerPort))
// Verify that a connection to the forwarded port works
- hostIP := getLocalIP()
dnatOK := testEchoServer(fmt.Sprintf("%s:%d", hostIP, hostPort))
// Verify that a connection to localhost works
close(done)
- }, TIMEOUT*3)
+ }, TIMEOUT*9)
})
// testEchoServer returns true if we found an echo server on the port
Expect(err).NotTo(HaveOccurred())
for _, addr := range addrs {
+ if !addr.IP.IsGlobalUnicast() {
+ continue
+ }
return addr.IP.String()
}
Fail("no live addresses")