forked from cloudfoundry/cf-networking-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_connectivity_test.go
99 lines (80 loc) · 2.63 KB
/
task_connectivity_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package acceptance_test
import (
"encoding/json"
"os/exec"
"strconv"
"strings"
"time"
"github.com/cloudfoundry/cf-test-helpers/v2/cf"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
)
const Timeout_Task_Curl = 1 * time.Minute
type ProxyResponse struct {
ListenAddresses []string ""
Port int
}
var _ = Describe("task connectivity on the overlay network", func() {
Describe("networking policy", func() {
var (
prefix string
domain string
orgName string
proxy1 string
proxy2 string
)
BeforeEach(func() {
prefix = testConfig.Prefix
domain = config.AppsDomain
orgName = prefix + "task-org"
Expect(cf.Cf("create-org", orgName).Wait(Timeout_Push)).To(gexec.Exit(0))
Expect(cf.Cf("target", "-o", orgName).Wait(Timeout_Push)).To(gexec.Exit(0))
spaceName := prefix + "space"
Expect(cf.Cf("create-space", spaceName, "-o", orgName).Wait(Timeout_Push)).To(gexec.Exit(0))
Expect(cf.Cf("target", "-o", orgName, "-s", spaceName).Wait(Timeout_Push)).To(gexec.Exit(0))
proxy1 = "proxy-task-connectivity-1"
proxy2 = "proxy-task-connectivity-2"
pushProxy(proxy1)
pushProxy(proxy2)
cfCLI.AddNetworkPolicy(proxy1, proxy2, 8080, "tcp")
})
AfterEach(func() {
Expect(cf.Cf("delete-org", orgName, "-f").Wait(Timeout_Push)).To(gexec.Exit(0))
_, err := cfCLI.CleanupStaleNetworkPolicies()
Expect(err).NotTo(HaveOccurred())
})
It("allows tasks to talk to app instances", func(ctx SpecContext) {
By("getting the overlay ip of proxy2")
cmd := exec.Command("curl", "--fail", proxy2+"."+domain)
sess, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(sess, 5*time.Second).Should(gexec.Exit(0))
var proxy2Response ProxyResponse
Expect(json.Unmarshal(sess.Out.Contents(), &proxy2Response)).To(Succeed())
containerIP := getContainerIP(proxy2Response.ListenAddresses)
By("Checking that the task associated with proxy1 can connect to proxy2")
commandToRun := `
while true; do
if curl --fail "` + containerIP + `:` + strconv.Itoa(proxy2Response.Port) + `" ; then
exit 0
fi
done;
exit 1
`
Expect(cfCLI.RunTask(proxy1, commandToRun)).To(Succeed())
Eventually(func() *gbytes.Buffer {
return cf.Cf("tasks", proxy1).Wait(10 * time.Second).Out
}, Timeout_Task_Curl).Should(gbytes.Say("SUCCEEDED"))
}, SpecTimeout(30*time.Minute))
})
})
func getContainerIP(listenAddresses []string) string {
for _, listenAddr := range listenAddresses {
if !strings.HasPrefix(listenAddr, "127.0.0.1") {
return listenAddr
}
}
return ""
}