/
platform_alteration_service_mesh.go
196 lines (160 loc) · 7.55 KB
/
platform_alteration_service_mesh.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package tests
import (
"context"
"os"
"os/exec"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/test-network-function/cnfcert-tests-verification/tests/globalparameters"
tshelper "github.com/test-network-function/cnfcert-tests-verification/tests/platformalteration/helper"
tsparams "github.com/test-network-function/cnfcert-tests-verification/tests/platformalteration/parameters"
"github.com/test-network-function/cnfcert-tests-verification/tests/utils/pod"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/test-network-function/cnfcert-tests-verification/tests/globalhelper"
)
const (
WaitingTime = 5 * time.Minute
istioNamespace = "istio-system"
)
var _ = Describe("platform-alteration-service-mesh-usage-installed", Ordered, func() {
var randomNamespace string
var randomReportDir string
var randomTnfConfigDir string
BeforeAll(func() {
if _, exists := os.LookupEnv("NON_LINUX_ENV"); !exists {
By("Install istio")
//nolint:goconst
cmd := exec.Command("/bin/bash", "-c", "curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.20.3 sh - "+
"&& istio-1.20.3/bin/istioctl install --set profile=demo -y")
err := cmd.Run()
Expect(err).ToNot(HaveOccurred(), "Error installing istio")
}
})
AfterAll(func() {
if _, exists := os.LookupEnv("NON_LINUX_ENV"); !exists {
By("Uninstall istio")
cmd := exec.Command("/bin/bash", "-c", "curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.20.3 sh - "+
"&& istio-1.20.3/bin/istioctl uninstall -y --purge")
err := cmd.Run()
Expect(err).ToNot(HaveOccurred(), "Error uninstalling istio")
}
})
BeforeEach(func() {
// Create random namespace and keep original report and TNF config directories
randomNamespace, randomReportDir, randomTnfConfigDir = globalhelper.BeforeEachSetupWithRandomNamespace(
tsparams.PlatformAlterationNamespace)
By("Define TNF config file")
err := globalhelper.DefineTnfConfig(
[]string{randomNamespace},
[]string{tsparams.TestPodLabel},
[]string{},
[]string{},
[]string{}, randomTnfConfigDir)
Expect(err).ToNot(HaveOccurred())
if globalhelper.IsKindCluster() {
Skip("Service mesh test is not applicable for Kind cluster")
}
})
AfterEach(func() {
globalhelper.AfterEachCleanupWithRandomNamespace(randomNamespace, randomReportDir, randomTnfConfigDir, tsparams.WaitingTime)
})
// 56594
It("istio is installed", func() {
By("Define a test pod with istio container")
put := pod.DefinePod(tsparams.TestPodName, randomNamespace, globalhelper.GetConfiguration().General.TestImage,
tsparams.TnfTargetPodLabels)
tshelper.AppendIstioContainerToPod(put, globalhelper.GetConfiguration().General.TestImage)
err := globalhelper.CreateAndWaitUntilPodIsReady(put, WaitingTime)
Expect(err).ToNot(HaveOccurred())
By("Start platform-alteration-service-mesh-usage test")
err = globalhelper.LaunchTests(tsparams.TnfServiceMeshUsageName,
globalhelper.ConvertSpecNameToFileName(CurrentSpecReport().FullText()), randomReportDir, randomTnfConfigDir)
Expect(err).ToNot(HaveOccurred())
err = globalhelper.ValidateIfReportsAreValid(tsparams.TnfServiceMeshUsageName, globalparameters.TestCasePassed, randomReportDir)
Expect(err).ToNot(HaveOccurred())
})
// 56596
It("istio is installed but proxy containers does not exist [negative]", func() {
By("Define a test pod without istio container")
put := pod.DefinePod(tsparams.TestPodName, randomNamespace, globalhelper.GetConfiguration().General.TestImage,
tsparams.TnfTargetPodLabels)
err := globalhelper.CreateAndWaitUntilPodIsReady(put, WaitingTime)
Expect(err).ToNot(HaveOccurred())
By("Start platform-alteration-service-mesh-usage test")
err = globalhelper.LaunchTests(tsparams.TnfServiceMeshUsageName,
globalhelper.ConvertSpecNameToFileName(CurrentSpecReport().FullText()), randomReportDir, randomTnfConfigDir)
Expect(err).ToNot(HaveOccurred())
err = globalhelper.ValidateIfReportsAreValid(tsparams.TnfServiceMeshUsageName, globalparameters.TestCaseFailed, randomReportDir)
Expect(err).ToNot(HaveOccurred())
})
// 56597
It("istio is installed but proxy container exist on one pod only [negative]", func() {
By("Define first pod with istio container")
put := pod.DefinePod(tsparams.TestPodName, randomNamespace, globalhelper.GetConfiguration().General.TestImage,
tsparams.TnfTargetPodLabels)
tshelper.AppendIstioContainerToPod(put, globalhelper.GetConfiguration().General.TestImage)
err := globalhelper.CreateAndWaitUntilPodIsReady(put, WaitingTime)
Expect(err).ToNot(HaveOccurred())
putb := pod.DefinePod("lifecycle-putb", randomNamespace, globalhelper.GetConfiguration().General.TestImage,
tsparams.TnfTargetPodLabels)
err = globalhelper.CreateAndWaitUntilPodIsReady(putb, WaitingTime)
Expect(err).ToNot(HaveOccurred())
By("Start platform-alteration-service-mesh-usage test")
err = globalhelper.LaunchTests(tsparams.TnfServiceMeshUsageName,
globalhelper.ConvertSpecNameToFileName(CurrentSpecReport().FullText()), randomReportDir, randomTnfConfigDir)
Expect(err).ToNot(HaveOccurred())
err = globalhelper.ValidateIfReportsAreValid(tsparams.TnfServiceMeshUsageName, globalparameters.TestCaseFailed, randomReportDir)
Expect(err).ToNot(HaveOccurred())
})
})
var _ = Describe("platform-alteration-service-mesh-usage-uninstalled", Serial, func() {
var randomNamespace string
var randomReportDir string
var randomTnfConfigDir string
BeforeEach(func() {
// Create random namespace and keep original report and TNF config directories
randomNamespace, randomReportDir, randomTnfConfigDir = globalhelper.BeforeEachSetupWithRandomNamespace(
tsparams.PlatformAlterationNamespace)
By("Define TNF config file")
err := globalhelper.DefineTnfConfig(
[]string{randomNamespace},
[]string{tsparams.TestPodLabel},
[]string{},
[]string{},
[]string{}, randomTnfConfigDir)
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
globalhelper.AfterEachCleanupWithRandomNamespace(randomNamespace, randomReportDir, randomTnfConfigDir, tsparams.WaitingTime)
})
// 56595
It("istio is not installed", func() {
By("Check if Istio resource exists")
gvr := schema.GroupVersionResource{Group: "install.istio.io", Version: "v1alpha1", Resource: "istiooperators"}
_, err := globalhelper.GetAPIClient().DynamicClient.Resource(gvr).Namespace(istioNamespace).Get(context.TODO(),
"installed-state", metav1.GetOptions{})
if err == nil {
By("Uninstall istio")
if _, exists := os.LookupEnv("NON_LINUX_ENV"); !exists {
cmd := exec.Command("/bin/bash", "-c", "curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.20.3 sh - "+
"&& istio-1.20.3/bin/istioctl uninstall -y --purge")
err := cmd.Run()
Expect(err).ToNot(HaveOccurred(), "Error uninstalling istio")
}
}
By("Define a test pod with istio container")
put := pod.DefinePod(tsparams.TestPodName, randomNamespace, globalhelper.GetConfiguration().General.TestImage,
tsparams.TnfTargetPodLabels)
tshelper.AppendIstioContainerToPod(put, globalhelper.GetConfiguration().General.TestImage)
err = globalhelper.CreateAndWaitUntilPodIsReady(put, WaitingTime)
Expect(err).ToNot(HaveOccurred())
By("Start platform-alteration-service-mesh-usage test")
err = globalhelper.LaunchTests(tsparams.TnfServiceMeshUsageName,
globalhelper.ConvertSpecNameToFileName(CurrentSpecReport().FullText()), randomReportDir, randomTnfConfigDir)
Expect(err).ToNot(HaveOccurred())
err = globalhelper.ValidateIfReportsAreValid(tsparams.TnfServiceMeshUsageName, globalparameters.TestCaseSkipped, randomReportDir)
Expect(err).ToNot(HaveOccurred())
})
})