This repository was archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathe2e_debug_server_test.go
105 lines (85 loc) · 3.37 KB
/
e2e_debug_server_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
100
101
102
103
104
105
package e2e
import (
"fmt"
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openservicemesh/osm/tests/framework"
. "github.com/openservicemesh/osm/tests/framework"
)
var _ = OSMDescribe("Test Debug Server by toggling enableDebugServer",
OSMDescribeInfo{
Tier: 2,
Bucket: 1,
},
func() {
Context("DebugServer", func() {
var sourceNs = framework.RandomNameWithPrefix("client")
It("Starts debug server only when enableDebugServer flag is enabled", func() {
// Install OSM
installOpts := Td.GetOSMInstallOpts()
installOpts.EnableDebugServer = false
Expect(Td.InstallOSM(installOpts)).To(Succeed())
meshConfig, _ := Td.GetMeshConfig(Td.OsmNamespace)
// Create Test NS
Expect(Td.CreateNs(sourceNs, nil)).To(Succeed())
// Get simple Pod definitions for the client
svcAccDef, podDef, svcDef, err := Td.SimplePodApp(SimplePodAppDef{
PodName: "client",
Namespace: sourceNs,
Command: []string{"/bin/bash", "-c", "--"},
Args: []string{"while true; do sleep 30; done;"},
Image: "songrgg/alpine-debug",
Ports: []int{80},
OS: Td.ClusterOS,
})
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateServiceAccount(sourceNs, &svcAccDef)
Expect(err).NotTo(HaveOccurred())
srcPod, err := Td.CreatePod(sourceNs, podDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateService(sourceNs, svcDef)
Expect(err).NotTo(HaveOccurred())
Expect(Td.WaitForPodsRunningReady(sourceNs, 90*time.Second, 1, nil)).To(Succeed())
controllerDest := "osm-controller." + Td.OsmNamespace + ":9092/debug"
req := HTTPRequestDef{
SourceNs: srcPod.Namespace,
SourcePod: srcPod.Name,
SourceContainer: srcPod.Name,
Destination: controllerDest,
}
iterations := 2
for i := 1; i <= iterations; i++ {
By(fmt.Sprintf("(%d/%d) Ensuring debug server is available when enableDebugServer is enabled", i, iterations))
meshConfig.Spec.Observability.EnableDebugServer = true
meshConfig, err = Td.UpdateOSMConfig(meshConfig)
Expect(err).NotTo(HaveOccurred())
cond := Td.WaitForRepeatedSuccess(func() bool {
result := Td.HTTPRequest(req)
if result.Err != nil || result.StatusCode != 200 {
Td.T.Logf("> REST req failed (status: %d) %v", result.StatusCode, result.Err)
return false
}
Td.T.Logf("> REST req succeeded: %d", result.StatusCode)
return true
}, 5 /*consecutive success threshold*/, 90*time.Second /*timeout*/)
Expect(cond).To(BeTrue())
By(fmt.Sprintf("(%d/%d) Ensuring debug server is unavailable when enableDebugServer is disabled", i, iterations))
meshConfig.Spec.Observability.EnableDebugServer = false
meshConfig, err = Td.UpdateOSMConfig(meshConfig)
Expect(err).NotTo(HaveOccurred())
cond = Td.WaitForRepeatedSuccess(func() bool {
result := Td.HTTPRequest(req)
if result.Err == nil || !strings.Contains(result.Err.Error(), "command terminated with exit code 7 ") {
Td.T.Logf("> REST req received unexpected response (status: %d) %v", result.StatusCode, result.Err)
return false
}
Td.T.Logf("> REST req succeeded, got expected error: %v", result.Err)
return true
}, 5 /*consecutive success threshold*/, 90*time.Second /*timeout*/)
Expect(cond).To(BeTrue())
}
})
})
})