Skip to content

Commit 045a275

Browse files
committed
verify config state before proceeding
1 parent 83207ef commit 045a275

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

integration-tests/pkg/assert/assert.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/davecgh/go-spew/spew"
11+
"github.com/google/go-cmp/cmp"
1112
"github.com/stretchr/testify/assert"
1213

1314
"github.com/stackrox/collector/integration-tests/pkg/collector"
@@ -17,25 +18,35 @@ import (
1718

1819
var (
1920
runtimeConfigErrorMsg = "Runtime configuration was not updated"
21+
22+
tickTime = 1 * time.Second
23+
timeout = 3 * time.Minute
2024
)
2125

22-
func AssertExternalIps(t *testing.T, enabled string, collectorIP string) {
23-
tickTime := 1 * time.Second
24-
timeout := 3 * time.Minute
26+
func getCollectorRuntimeConfig(t *testing.T, collectorIP string) types.RuntimeConfig {
27+
body, err := collector.IntrospectionQuery(collectorIP, "/state/runtime-config")
28+
assert.NoError(t, err)
29+
var response types.RuntimeConfig
30+
err = json.Unmarshal(body, &response)
31+
assert.NoError(t, err)
32+
return response
33+
}
34+
35+
func AssertRuntimeConfig(t *testing.T, collectorIP string, config types.RuntimeConfig) {
2536
AssertRepeated(t, tickTime, timeout, runtimeConfigErrorMsg, func() bool {
26-
body, err := collector.IntrospectionQuery(collectorIP, "/state/runtime-config")
27-
assert.NoError(t, err)
28-
var response types.RuntimeConfig
29-
err = json.Unmarshal(body, &response)
30-
assert.NoError(t, err)
37+
collectorConfig := getCollectorRuntimeConfig(t, collectorIP)
38+
return cmp.Equal(config, collectorConfig)
39+
})
40+
}
3141

32-
return response.Networking.ExternalIps.Enabled == enabled
42+
func AssertExternalIps(t *testing.T, enabled string, collectorIP string) {
43+
AssertRepeated(t, tickTime, timeout, runtimeConfigErrorMsg, func() bool {
44+
collectorConfig := getCollectorRuntimeConfig(t, collectorIP)
45+
return collectorConfig.Networking.ExternalIps.Enabled == enabled
3346
})
3447
}
3548

3649
func AssertNoRuntimeConfig(t *testing.T, collectorIP string) {
37-
tickTime := 1 * time.Second
38-
timeout := 3 * time.Minute
3950
AssertRepeated(t, tickTime, timeout, runtimeConfigErrorMsg, func() bool {
4051
body, err := collector.IntrospectionQuery(collectorIP, "/state/runtime-config")
4152
assert.NoError(t, err)

integration-tests/suites/runtime_config_file.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ var (
6161

6262
type RuntimeConfigFileTestSuite struct {
6363
IntegrationTestSuiteBase
64-
EgressClientContainer string
65-
IngressClientContainer string
66-
IngressServerContainer string
64+
EgressClientContainer string
6765
}
6866

6967
func (s *RuntimeConfigFileTestSuite) writeRuntimeConfig(runtimeConfigFile string, configStr string) {
@@ -76,7 +74,6 @@ func (s *RuntimeConfigFileTestSuite) setRuntimeConfig(config types.RuntimeConfig
7674
}
7775

7876
func (s *RuntimeConfigFileTestSuite) runNetworkDirectionContainers() (client, server string) {
79-
8077
serverCmd := fmt.Sprintf("/scripts/prepare-tap.sh -a %s -o && nc -lk %s %d", ingressIP, ingressIP, ingressPort)
8178
containerID, err := s.Executor().StartContainer(
8279
config.ContainerStartConfig{
@@ -92,7 +89,7 @@ func (s *RuntimeConfigFileTestSuite) runNetworkDirectionContainers() (client, se
9289
s.Require().NoError(err)
9390
server = common.ContainerShortID(containerID)
9491

95-
clientCmd := fmt.Sprintf("sleep 10; while true; do nc -zv %s %d; sleep 60; done", ingressIP, ingressPort)
92+
clientCmd := fmt.Sprintf("sleep 20; while true; do nc -zv %s %d; sleep 60; done", ingressIP, ingressPort)
9693
containerID, err = s.Executor().StartContainer(
9794
config.ContainerStartConfig{
9895
Name: "external-connection-ingress-client",
@@ -255,14 +252,17 @@ func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigNetworkIngress() {
255252
client, server := s.runNetworkDirectionContainers()
256253
defer s.teardownNetworkDirectionContainers()
257254

258-
s.setRuntimeConfig(types.RuntimeConfig{
255+
config := types.RuntimeConfig{
259256
Networking: types.NetworkConfig{
260257
ExternalIps: types.ExternalIpsConfig{
261258
Enabled: "ENABLED",
262259
Direction: "INGRESS",
263260
},
264261
},
265-
})
262+
}
263+
264+
s.setRuntimeConfig(config)
265+
assert.AssertRuntimeConfig(s.T(), collectorIP, config)
266266

267267
// Expect both open and close events for the non-aggregated
268268
// ingress connection. If Collector is aggregating to 255.255.255.255
@@ -310,14 +310,17 @@ func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigNetworkEgress() {
310310
client, server := s.runNetworkDirectionContainers()
311311
defer s.teardownNetworkDirectionContainers()
312312

313-
s.setRuntimeConfig(types.RuntimeConfig{
313+
config := types.RuntimeConfig{
314314
Networking: types.NetworkConfig{
315315
ExternalIps: types.ExternalIpsConfig{
316316
Enabled: "ENABLED",
317317
Direction: "EGRESS",
318318
},
319319
},
320-
})
320+
}
321+
322+
s.setRuntimeConfig(config)
323+
assert.AssertRuntimeConfig(s.T(), collectorIP, config)
321324

322325
// Expect both open and close events for the non-aggregated
323326
// egress connection. If Collector is aggregating to 255.255.255.255
@@ -365,14 +368,17 @@ func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigNetworkBoth() {
365368
client, server := s.runNetworkDirectionContainers()
366369
defer s.teardownNetworkDirectionContainers()
367370

368-
s.setRuntimeConfig(types.RuntimeConfig{
371+
config := types.RuntimeConfig{
369372
Networking: types.NetworkConfig{
370373
ExternalIps: types.ExternalIpsConfig{
371374
Enabled: "ENABLED",
372375
Direction: "BOTH",
373376
},
374377
},
375-
})
378+
}
379+
380+
s.setRuntimeConfig(config)
381+
assert.AssertRuntimeConfig(s.T(), collectorIP, config)
376382

377383
// Expect both open and close events for the non-aggregated
378384
// egress and ingress connections. If Collector is aggregating to 255.255.255.255

0 commit comments

Comments
 (0)