Skip to content

Commit fdd1181

Browse files
committed
CSPL-3558 Refactoring
1 parent 0393139 commit fdd1181

File tree

3 files changed

+106
-104
lines changed

3 files changed

+106
-104
lines changed

test/index_and_ingestion_separation/index_and_ingestion_separation_suite_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
. "github.com/onsi/ginkgo/v2"
2121
. "github.com/onsi/gomega"
2222

23+
enterpriseApi "github.com/splunk/splunk-operator/api/v4"
2324
"github.com/splunk/splunk-operator/test/testenv"
2425
)
2526

@@ -35,6 +36,59 @@ const (
3536
var (
3637
testenvInstance *testenv.TestEnv
3738
testSuiteName = "indingsep-" + testenv.RandomDNSName(3)
39+
40+
bus = enterpriseApi.PushBusSpec{
41+
Type: "sqs_smartbus",
42+
SQS: enterpriseApi.SQSSpec{
43+
QueueName: "test-queue",
44+
AuthRegion: "us-west-2",
45+
Endpoint: "https://sqs.us-west-2.amazonaws.com",
46+
LargeMessageStoreEndpoint: "https://s3.us-west-2.amazonaws.com",
47+
LargeMessageStorePath: "s3://test-bucket/smartbus-test",
48+
DeadLetterQueueName: "test-dead-letter-queue",
49+
MaxRetriesPerPart: 4,
50+
RetryPolicy: "max_count",
51+
SendInterval: "5s",
52+
EncodingFormat: "s2s",
53+
},
54+
}
55+
pipelineConfig = enterpriseApi.PipelineConfigSpec{
56+
RemoteQueueRuleset: false,
57+
RuleSet: true,
58+
RemoteQueueTyping: false,
59+
RemoteQueueOutput: false,
60+
Typing: true,
61+
IndexerPipe: true,
62+
}
63+
serviceAccountName = "index-ingest-sa"
64+
65+
inputs = []string{
66+
"[remote_queue:test-queue]",
67+
"remote_queue.type = sqs_smartbus",
68+
"remote_queue.sqs_smartbus.auth_region = us-west-2",
69+
"remote_queue.sqs_smartbus.dead_letter_queue.name = test-dead-letter-queue",
70+
"remote_queue.sqs_smartbus.endpoint = https://sqs.us-west-2.amazonaws.com",
71+
"remote_queue.sqs_smartbus.large_message_store.endpoint = https://s3.us-west-2.amazonaws.com",
72+
"remote_queue.sqs_smartbus.large_message_store.path = s3://test-bucket/smartbus-test",
73+
"remote_queue.sqs_smartbus.retry_policy = max_count",
74+
"remote_queue.max_count.sqs_smartbus.max_retries_per_part = 4"}
75+
outputs = append(inputs, "remote_queue.sqs_smartbus.encoding_format = s2s", "remote_queue.sqs_smartbus.send_interval = 5s")
76+
defaultsAll = []string{
77+
"[pipeline:remotequeueruleset]\ndisabled = false",
78+
"[pipeline:ruleset]\ndisabled = true",
79+
"[pipeline:remotequeuetyping]\ndisabled = false",
80+
"[pipeline:remotequeueoutput]\ndisabled = false",
81+
"[pipeline:typing]\ndisabled = true",
82+
}
83+
defaultsIngest = append(defaultsAll, "[pipeline:indexerPipe]\ndisabled = true")
84+
85+
awsEnvVars = []string{
86+
"AWS_REGION=us-west-2",
87+
"AWS_DEFAULT_REGION=us-west-2",
88+
"AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token",
89+
"AWS_ROLE_ARN=arn:aws:iam::",
90+
"AWS_STS_REGIONAL_ENDPOINTS=regional",
91+
}
3892
)
3993

4094
// TestBasic is the main entry point

test/index_and_ingestion_separation/index_and_ingestion_separation_test.go

Lines changed: 42 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,22 @@ var _ = Describe("indingsep test", func() {
3232
var testcaseEnvInst *testenv.TestCaseEnv
3333
var deployment *testenv.Deployment
3434

35+
var cmSpec enterpriseApi.ClusterManagerSpec
36+
3537
ctx := context.TODO()
3638

3739
BeforeEach(func() {
3840
var err error
3941

42+
cmSpec = enterpriseApi.ClusterManagerSpec{
43+
CommonSplunkSpec: enterpriseApi.CommonSplunkSpec{
44+
Spec: enterpriseApi.Spec{
45+
ImagePullPolicy: "Always",
46+
Image: testcaseEnvInst.GetSplunkImage(),
47+
},
48+
},
49+
}
50+
4051
name := fmt.Sprintf("%s-%s", testenvInstance.GetName(), testenv.RandomDNSName(3))
4152
testcaseEnvInst, err = testenv.NewDefaultTestCaseEnv(testenvInstance.GetKubeClient(), name)
4253
Expect(err).To(Succeed(), "Unable to create testcaseenv")
@@ -59,33 +70,9 @@ var _ = Describe("indingsep test", func() {
5970
})
6071

6172
Context("Ingestor and Indexer deployment", func() {
62-
It("indingsep, smoke, indingsep: Splunk Operator can configure Ingestors and Indexers", func() {
63-
bus := enterpriseApi.PushBusSpec{
64-
Type: "sqs_smartbus",
65-
SQS: enterpriseApi.SQSSpec{
66-
QueueName: "test-queue",
67-
AuthRegion: "us-west-2",
68-
Endpoint: "https://sqs.us-west-2.amazonaws.com",
69-
LargeMessageStoreEndpoint: "https://s3.us-west-2.amazonaws.com",
70-
LargeMessageStorePath: "s3://test-bucket/smartbus-test",
71-
DeadLetterQueueName: "test-dead-letter-queue",
72-
MaxRetriesPerPart: 4,
73-
RetryPolicy: "max_count",
74-
SendInterval: "5s",
75-
EncodingFormat: "s2s",
76-
},
77-
}
78-
pipelineConfig := enterpriseApi.PipelineConfigSpec{
79-
RemoteQueueRuleset: false,
80-
RuleSet: true,
81-
RemoteQueueTyping: false,
82-
RemoteQueueOutput: false,
83-
Typing: true,
84-
IndexerPipe: true,
85-
}
86-
serviceAccountName := "index-ingest-sa"
87-
73+
It("indingsep, smoke, indingsep: Splunk Operator can deploy Ingestors and Indexers", func() {
8874
// Create Service Account
75+
testcaseEnvInst.Log.Info("Create Service Account")
8976
testcaseEnvInst.CreateServiceAccount(serviceAccountName)
9077

9178
// Deploy Ingestor Cluster
@@ -95,14 +82,6 @@ var _ = Describe("indingsep test", func() {
9582

9683
// Deploy Cluster Manager
9784
testcaseEnvInst.Log.Info("Deploy Cluster Manager")
98-
cmSpec := enterpriseApi.ClusterManagerSpec{
99-
CommonSplunkSpec: enterpriseApi.CommonSplunkSpec{
100-
Spec: enterpriseApi.Spec{
101-
ImagePullPolicy: "Always",
102-
Image: testcaseEnvInst.GetSplunkImage(),
103-
},
104-
},
105-
}
10685
_, err = deployment.DeployClusterManagerWithGivenSpec(ctx, deployment.GetName(), cmSpec)
10786
Expect(err).To(Succeed(), "Unable to deploy Cluster Manager")
10887

@@ -112,44 +91,23 @@ var _ = Describe("indingsep test", func() {
11291
Expect(err).To(Succeed(), "Unable to deploy Indexer Cluster")
11392

11493
// Ensure that Ingestor Cluster is in Ready phase
94+
testcaseEnvInst.Log.Info("Ensure that Ingestor Cluster is in Ready phase")
11595
testenv.IngestorReady(ctx, deployment, testcaseEnvInst)
11696

11797
// Ensure that Cluster Manager is in Ready phase
98+
testcaseEnvInst.Log.Info("Ensure that Cluster Manager is in Ready phase")
11899
testenv.ClusterManagerReady(ctx, deployment, testcaseEnvInst)
119100

120101
// Ensure that Indexer Cluster is in Ready phase
102+
testcaseEnvInst.Log.Info("Ensure that Indexer Cluster is in Ready phase")
121103
testenv.SingleSiteIndexersReady(ctx, deployment, testcaseEnvInst)
122104
})
123105
})
124106

125107
Context("Ingestor and Indexer deployment", func() {
126-
It("indingsep, integration, indingsep: Splunk Operator can configure Ingestors and Indexers", func() {
127-
bus := enterpriseApi.PushBusSpec{
128-
Type: "sqs_smartbus",
129-
SQS: enterpriseApi.SQSSpec{
130-
QueueName: "test-queue",
131-
AuthRegion: "us-west-2",
132-
Endpoint: "https://sqs.us-west-2.amazonaws.com",
133-
LargeMessageStoreEndpoint: "https://s3.us-west-2.amazonaws.com",
134-
LargeMessageStorePath: "s3://test-bucket/smartbus-test",
135-
DeadLetterQueueName: "test-dead-letter-queue",
136-
MaxRetriesPerPart: 4,
137-
RetryPolicy: "max_count",
138-
SendInterval: "5s",
139-
EncodingFormat: "s2s",
140-
},
141-
}
142-
pipelineConfig := enterpriseApi.PipelineConfigSpec{
143-
RemoteQueueRuleset: false,
144-
RuleSet: true,
145-
RemoteQueueTyping: false,
146-
RemoteQueueOutput: false,
147-
Typing: true,
148-
IndexerPipe: true,
149-
}
150-
serviceAccountName := "index-ingest-sa"
151-
108+
It("indingsep, integration, indingsep: Splunk Operator can deploy Ingestors and Indexers with correct setup", func() {
152109
// Create Service Account
110+
testcaseEnvInst.Log.Info("Create Service Account")
153111
testcaseEnvInst.CreateServiceAccount(serviceAccountName)
154112

155113
// Deploy Ingestor Cluster
@@ -159,14 +117,6 @@ var _ = Describe("indingsep test", func() {
159117

160118
// Deploy Cluster Manager
161119
testcaseEnvInst.Log.Info("Deploy Cluster Manager")
162-
cmSpec := enterpriseApi.ClusterManagerSpec{
163-
CommonSplunkSpec: enterpriseApi.CommonSplunkSpec{
164-
Spec: enterpriseApi.Spec{
165-
ImagePullPolicy: "Always",
166-
Image: testcaseEnvInst.GetSplunkImage(),
167-
},
168-
},
169-
}
170120
_, err = deployment.DeployClusterManagerWithGivenSpec(ctx, deployment.GetName(), cmSpec)
171121
Expect(err).To(Succeed(), "Unable to deploy Cluster Manager")
172122

@@ -176,90 +126,78 @@ var _ = Describe("indingsep test", func() {
176126
Expect(err).To(Succeed(), "Unable to deploy Indexer Cluster")
177127

178128
// Ensure that Ingestor Cluster is in Ready phase
129+
testcaseEnvInst.Log.Info("Ensure that Ingestor Cluster is in Ready phase")
179130
testenv.IngestorReady(ctx, deployment, testcaseEnvInst)
180131

181132
// Ensure that Cluster Manager is in Ready phase
133+
testcaseEnvInst.Log.Info("Ensure that Cluster Manager is in Ready phase")
182134
testenv.ClusterManagerReady(ctx, deployment, testcaseEnvInst)
183135

184136
// Ensure that Indexer Cluster is in Ready phase
137+
testcaseEnvInst.Log.Info("Ensure that Indexer Cluster is in Ready phase")
185138
testenv.SingleSiteIndexersReady(ctx, deployment, testcaseEnvInst)
186139

187140
// Get instance of current Ingestor Cluster CR with latest config
141+
testcaseEnvInst.Log.Info("Get instance of current Ingestor Cluster CR with latest config")
188142
ingest := &enterpriseApi.IngestorCluster{}
189143
err = deployment.GetInstance(ctx, deployment.GetName()+"-ingest", ingest)
190144
Expect(err).To(Succeed(), "Failed to get instance of Ingestor Cluster")
191145

192146
// Verify Ingestor Cluster Status
147+
testcaseEnvInst.Log.Info("Verify Ingestor Cluster Status")
193148
Expect(ingest.Status.PushBus).To(Equal(bus), "Ingestor PushBus status is not the same as provided as input")
194149
Expect(ingest.Status.PipelineConfig).To(Equal(pipelineConfig), "Ingestor PipelineConfig status is not the same as provided as input")
195150

196151
// Get instance of current Indexer Cluster CR with latest config
152+
testcaseEnvInst.Log.Info("Get instance of current Indexer Cluster CR with latest config")
197153
index := &enterpriseApi.IndexerCluster{}
198154
err = deployment.GetInstance(ctx, deployment.GetName()+"-idxc", index)
199155
Expect(err).To(Succeed(), "Failed to get instance of Indexer Cluster")
200156

201157
// Verify Indexer Cluster Status
158+
testcaseEnvInst.Log.Info("Verify Indexer Cluster Status")
202159
Expect(index.Status.PullBus).To(Equal(bus), "Indexer PullBus status is not the same as provided as input")
203160
Expect(index.Status.PipelineConfig).To(Equal(pipelineConfig), "Indexer PipelineConfig status is not the same as provided as input")
204161

205162
// Verify conf files
163+
testcaseEnvInst.Log.Info("Verify conf files")
206164
pods := testenv.DumpGetPods(deployment.GetName())
207165
for _, pod := range pods {
208166
defaultsConf := ""
209167

210168
if strings.Contains(pod, "ingest") || strings.Contains(pod, "idxc") {
211-
// Get outputs.conf
169+
// Verify outputs.conf
170+
testcaseEnvInst.Log.Info("Verify outputs.conf")
212171
outputsPath := "opt/splunk/etc/system/local/outputs.conf"
213172
outputsConf, err := testenv.GetConfFile(pod, outputsPath, deployment.GetName())
214173
Expect(err).To(Succeed(), "Failed to get outputs.conf from Ingestor Cluster pod")
215-
Expect(outputsConf).To(ContainSubstring("[remote_queue:test-queue]"), "outputs.conf does not contain smartbus queue name configuration")
216-
Expect(outputsConf).To(ContainSubstring("remote_queue.type = sqs_smartbus"), "outputs.conf does not contain smartbus type configuration")
217-
Expect(outputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.auth_region = us-west-2"), "outputs.conf does not contain smartbus region configuration")
218-
Expect(outputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.dead_letter_queue.name = test-dead-letter-queue"), "outputs.conf does not contain smartbus dead letter queue configuration")
219-
Expect(outputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.encoding_format = s2s"), "outputs.conf does not contain smartbus encoding format configuration")
220-
Expect(outputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.endpoint = https://sqs.us-west-2.amazonaws.com"), "outputs.conf does not contain smartbus endpoint configuration")
221-
Expect(outputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.large_message_store.endpoint = https://s3.us-west-2.amazonaws.com"), "outputs.conf does not contain smartbus large message store endpoint configuration")
222-
Expect(outputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.large_message_store.path = s3://test-bucket/smartbus-test"), "outputs.conf does not contain smartbus large message store path configuration")
223-
Expect(outputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.retry_policy = max_count"), "outputs.conf does not contain smartbus retry policy configuration")
224-
Expect(outputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.send_interval = 5s"), "outputs.conf does not contain smartbus send interval configuration")
225-
Expect(outputsConf).To(ContainSubstring("remote_queue.max_count.sqs_smartbus.max_retries_per_part = 4"), "outputs.conf does not contain smartbus max retries per part configuration")
226-
227-
// Get default-mode.conf
174+
testenv.ValidateConfFileContent(outputsConf, outputs)
175+
176+
// Verify default-mode.conf
177+
testcaseEnvInst.Log.Info("Verify default-mode.conf")
228178
defaultsPath := "opt/splunk/etc/system/local/default-mode.conf"
229179
defaultsConf, err := testenv.GetConfFile(pod, defaultsPath, deployment.GetName())
230180
Expect(err).To(Succeed(), "Failed to get default-mode.conf from Ingestor Cluster pod")
231-
Expect(defaultsConf).To(ContainSubstring("[pipeline:remotequeueruleset]\ndisabled = false"), "default-mode.conf does not contain remote queue ruleset stanza")
232-
Expect(defaultsConf).To(ContainSubstring("[pipeline:ruleset]\ndisabled = true"), "default-mode.conf does not contain ruleset stanza")
233-
Expect(defaultsConf).To(ContainSubstring("[pipeline:remotequeuetyping]\ndisabled = false"), "default-mode.conf does not contain remote queue typing stanza")
234-
Expect(defaultsConf).To(ContainSubstring("[pipeline:remotequeueoutput]\ndisabled = false"), "default-mode.conf does not contain remote queue output stanza")
235-
Expect(defaultsConf).To(ContainSubstring("[pipeline:typing]\ndisabled = true"), "default-mode.conf does not contain typing stanza")
181+
testenv.ValidateConfFileContent(defaultsConf, defaultsAll)
236182

237-
// Get AWS env variables
183+
// Verify AWS env variables
184+
testcaseEnvInst.Log.Info("Verify AWS env variables")
238185
envVars, err := testenv.GetAWSEnv(pod, deployment.GetName())
239186
Expect(err).To(Succeed(), "Failed to get AWS env variables from Ingestor Cluster pod")
240-
Expect(envVars).To(ContainSubstring("AWS_REGION=us-west-2"), "AWS env variables do not contain region")
241-
Expect(envVars).To(ContainSubstring("AWS_DEFAULT_REGION=us-west-2"), "AWS env variables do not contain default region")
242-
Expect(envVars).To(ContainSubstring("AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token"), "AWS env variables do not contain web identity token file")
243-
Expect(envVars).To(ContainSubstring("AWS_ROLE_ARN=arn:aws:iam::"), "AWS env variables do not contain role arn")
244-
Expect(envVars).To(ContainSubstring("AWS_STS_REGIONAL_ENDPOINTS=regional"), "AWS env variables do not contain STS regional endpoints")
187+
testenv.ValidateConfFileContent(envVars, awsEnvVars)
245188
}
246189

247190
if strings.Contains(pod, "ingest") {
248-
Expect(defaultsConf).To(ContainSubstring("[pipeline:indexerPipe]\ndisabled = true"), "default-mode.conf does not contain indexer pipe stanza")
191+
// Verify default-mode.conf
192+
testcaseEnvInst.Log.Info("Verify default-mode.conf")
193+
testenv.ValidateConfFileContent(defaultsConf, defaultsIngest)
249194
} else if strings.Contains(pod, "idxc") {
250-
// Get inputs.conf
195+
// Verify inputs.conf
196+
testcaseEnvInst.Log.Info("Verify inputs.conf")
251197
inputsPath := "opt/splunk/etc/system/local/inputs.conf"
252198
inputsConf, err := testenv.GetConfFile(pod, inputsPath, deployment.GetName())
253199
Expect(err).To(Succeed(), "Failed to get inputs.conf from Indexer Cluster pod")
254-
Expect(inputsConf).To(ContainSubstring("[remote_queue:test-queue]"), "inputs.conf does not contain smartbus queue name configuration")
255-
Expect(inputsConf).To(ContainSubstring("remote_queue.type = sqs_smartbus"), "inputs.conf does not contain smartbus type configuration")
256-
Expect(inputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.auth_region = us-west-2"), "inputs.conf does not contain smartbus region configuration")
257-
Expect(inputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.dead_letter_queue.name = test-dead-letter-queue"), "inputs.conf does not contain smartbus dead letter queue configuration")
258-
Expect(inputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.endpoint = https://sqs.us-west-2.amazonaws.com"), "inputs.conf does not contain smartbus endpoint configuration")
259-
Expect(inputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.large_message_store.endpoint = https://s3.us-west-2.amazonaws.com"), "inputs.conf does not contain smartbus large message store endpoint configuration")
260-
Expect(inputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.large_message_store.path = s3://test-bucket/smartbus-test"), "inputs.conf does not contain smartbus large message store path configuration")
261-
Expect(inputsConf).To(ContainSubstring("remote_queue.sqs_smartbus.retry_policy = max_count"), "inputs.conf does not contain smartbus retry policy configuration")
262-
Expect(inputsConf).To(ContainSubstring("remote_queue.max_count.sqs_smartbus.max_retries_per_part = 4"), "inputs.conf does not contain smartbus max retries per part configuration")
200+
testenv.ValidateConfFileContent(inputsConf, inputs)
263201
}
264202
}
265203
})

test/testenv/util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030

3131
enterpriseApi "github.com/splunk/splunk-operator/api/v4"
3232

33+
. "github.com/onsi/gomega"
34+
3335
"github.com/onsi/ginkgo/v2"
3436
enterpriseApiV3 "github.com/splunk/splunk-operator/api/v3"
3537
splcommon "github.com/splunk/splunk-operator/pkg/splunk/common"
@@ -1249,3 +1251,11 @@ func GetAWSEnv(podName, ns string) (string, error) {
12491251

12501252
return string(output), err
12511253
}
1254+
1255+
func ValidateConfFileContent(confFileContent string, listOfStringsForValidation []string) {
1256+
for _, str := range listOfStringsForValidation {
1257+
if !strings.Contains(confFileContent, str) {
1258+
Expect(confFileContent).To(ContainSubstring(str), "Failed to find string "+str+" in conf file")
1259+
}
1260+
}
1261+
}

0 commit comments

Comments
 (0)