Skip to content

Commit 9141a82

Browse files
committed
Uses netcat instead of berserker for simplicity, adds ingress/egress/both tests
1 parent 1f03b30 commit 9141a82

File tree

6 files changed

+156
-102
lines changed

6 files changed

+156
-102
lines changed

integration-tests/container/berserker/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
FROM quay.io/rhacs-eng/qa:berserker-1.0-79-g617ec32386
22

3-
RUN sudo dnf install -y which iproute bpftool procps iptables
3+
RUN sudo dnf install -y which netcat iproute bpftool procps iptables
44

55
COPY workloads/ /etc/berserker/
6-
COPY init.sh /scripts/
76
COPY prepare-tap.sh /scripts/
87

98
ENV PATH="${PATH}:/usr/local/bin"

integration-tests/container/berserker/init.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

integration-tests/container/berserker/workloads/network/client.toml

Lines changed: 0 additions & 15 deletions
This file was deleted.

integration-tests/container/berserker/workloads/network/server.toml

Lines changed: 0 additions & 13 deletions
This file was deleted.

integration-tests/pkg/types/network.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import (
66

77
const (
88
NilTimestamp = "<nil>"
9+
10+
// This sentinel value can be used for expected network infos
11+
// where the timestamp is not known ahead of time, but is expected
12+
// to be non-nil for the purposes of assertions (e.g. compared to
13+
// NilTimestamp as seen in IsActive() below)
14+
NotNilTimestamp = "Not Nil"
915
)
1016

1117
type NetworkInfo struct {

integration-tests/suites/runtime_config_file.go

Lines changed: 149 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,23 @@ var (
4040
RemoteAddress: fmt.Sprintf("%s:%d", normalizedIp, serverPort),
4141
Role: "ROLE_CLIENT",
4242
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
43-
CloseTimestamp: "Not nill time",
43+
CloseTimestamp: types.NotNilTimestamp,
4444
}
4545

4646
inactiveUnnormalizedConnectionEgress = types.NetworkInfo{
4747
LocalAddress: "",
4848
RemoteAddress: fmt.Sprintf("%s:%d", externalIp, serverPort),
4949
Role: "ROLE_CLIENT",
5050
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
51-
CloseTimestamp: "Not nill time",
51+
CloseTimestamp: types.NotNilTimestamp,
5252
}
5353

5454
runtimeConfigDir = "/tmp/collector-test"
5555
runtimeConfigFile = filepath.Join(runtimeConfigDir, "/runtime_config.yaml")
5656
collectorIP = "localhost"
57+
58+
ingressIP = "223.42.0.1"
59+
ingressPort = 1337
5760
)
5861

5962
type RuntimeConfigFileTestSuite struct {
@@ -72,47 +75,42 @@ func (s *RuntimeConfigFileTestSuite) setRuntimeConfig(config types.RuntimeConfig
7275
s.writeRuntimeConfig(runtimeConfigFile, config.String())
7376
}
7477

75-
func (s *RuntimeConfigFileTestSuite) runBerserkerContainers() (client, server string) {
78+
func (s *RuntimeConfigFileTestSuite) runNetworkDirectionContainers() (client, server string) {
79+
80+
serverCmd := fmt.Sprintf("/scripts/prepare-tap.sh -a %s -o && nc -lk %s %d", ingressIP, ingressIP, ingressPort)
7681
containerID, err := s.Executor().StartContainer(
7782
config.ContainerStartConfig{
78-
Name: "external-connection-ingress-client",
83+
Name: "external-connection-ingress-server",
7984
Image: config.Images().QaImageByKey("performance-berserker"),
8085
Privileged: true,
8186
NetworkMode: "host",
8287
Entrypoint: []string{
83-
"/scripts/init.sh",
84-
},
85-
Env: map[string]string{
86-
"RUST_LOG": "DEBUG",
87-
"IS_CLIENT": "true",
88+
"sh", "-c", serverCmd,
8889
},
8990
},
9091
)
9192
s.Require().NoError(err)
92-
client = common.ContainerShortID(containerID)
93+
server = common.ContainerShortID(containerID)
9394

95+
clientCmd := fmt.Sprintf("sleep 10; while true; do nc -zv %s %d; sleep 60; done", ingressIP, ingressPort)
9496
containerID, err = s.Executor().StartContainer(
9597
config.ContainerStartConfig{
96-
Name: "external-connection-ingress-server",
98+
Name: "external-connection-ingress-client",
9799
Image: config.Images().QaImageByKey("performance-berserker"),
98100
Privileged: true,
99101
NetworkMode: "host",
100102
Entrypoint: []string{
101-
"/scripts/init.sh",
102-
},
103-
Env: map[string]string{
104-
"RUST_LOG": "DEBUG",
105-
"IS_CLIENT": "false",
103+
"sh", "-c", clientCmd,
106104
},
107105
},
108106
)
109107
s.Require().NoError(err)
110-
server = common.ContainerShortID(containerID)
108+
client = common.ContainerShortID(containerID)
111109

112110
return client, server
113111
}
114112

115-
func (s *RuntimeConfigFileTestSuite) teardownBerserkerContainers() {
113+
func (s *RuntimeConfigFileTestSuite) teardownNetworkDirectionContainers() {
116114
s.cleanupContainers("external-connection-ingress-server", "external-connection-ingress-client")
117115
}
118116

@@ -254,12 +252,8 @@ func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigFileInvalid() {
254252
}
255253

256254
func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigNetworkIngress() {
257-
client, server := s.runBerserkerContainers()
258-
defer s.teardownBerserkerContainers()
259-
260-
// assert.AssertNoRuntimeConfig(s.T(), collectorIP)
261-
// expectedConnections := []types.NetworkInfo{activeNormalizedConnectionEgress}
262-
// s.Require().True(s.Sensor().ExpectSameElementsConnections(s.T(), server, 10*time.Second, expectedConnections...))
255+
client, server := s.runNetworkDirectionContainers()
256+
defer s.teardownNetworkDirectionContainers()
263257

264258
s.setRuntimeConfig(types.RuntimeConfig{
265259
Networking: types.NetworkConfig{
@@ -270,22 +264,51 @@ func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigNetworkIngress() {
270264
},
271265
})
272266

273-
common.Sleep(45 * time.Second)
267+
// Expect both open and close events for the non-aggregated
268+
// ingress connection. If Collector is aggregating to 255.255.255.255
269+
// this will fail.
270+
// We are not concerned with event ordering in this test.
271+
expectedIngressConnections := []types.NetworkInfo{
272+
{
273+
LocalAddress: fmt.Sprintf(":%d", ingressPort),
274+
RemoteAddress: ingressIP,
275+
Role: "ROLE_SERVER",
276+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
277+
CloseTimestamp: types.NotNilTimestamp,
278+
},
279+
{
280+
LocalAddress: fmt.Sprintf(":%d", ingressPort),
281+
RemoteAddress: ingressIP,
282+
Role: "ROLE_SERVER",
283+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
284+
CloseTimestamp: types.NilTimestamp,
285+
},
286+
}
274287

275-
fmt.Println(s.Sensor().Connections(client))
276-
fmt.Println("===========")
277-
fmt.Println(s.Sensor().Connections(server))
288+
expectedEgressConnections := []types.NetworkInfo{
289+
{
290+
LocalAddress: "",
291+
RemoteAddress: fmt.Sprintf("%s:%d", normalizedIp, ingressPort),
292+
Role: "ROLE_CLIENT",
293+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
294+
CloseTimestamp: types.NotNilTimestamp,
295+
},
296+
{
297+
LocalAddress: "",
298+
RemoteAddress: fmt.Sprintf("%s:%d", normalizedIp, ingressPort),
299+
Role: "ROLE_CLIENT",
300+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
301+
CloseTimestamp: types.NilTimestamp,
302+
},
303+
}
278304

279-
// assert.AssertExternalIps(s.T(), "ENABLED", collectorIP)
280-
// expectedConnections = append(expectedConnections, activeUnnormalizedConnectionEgress, inactiveNormalizedConnectionEgress)
281-
// common.Sleep(3 * time.Second) // Sleep so that collector has a chance to report connections
282-
// s.Require().True(s.Sensor().ExpectSameElementsConnections(s.T(), client, 10*time.Second, expectedConnections...))
305+
s.Sensor().ExpectConnections(s.T(), client, 30*time.Second, expectedEgressConnections...)
306+
s.Sensor().ExpectConnections(s.T(), server, 30*time.Second, expectedIngressConnections...)
283307
}
284308

285309
func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigNetworkEgress() {
286-
assert.AssertNoRuntimeConfig(s.T(), collectorIP)
287-
expectedConnections := []types.NetworkInfo{activeNormalizedConnectionEgress}
288-
s.Require().True(s.Sensor().ExpectSameElementsConnections(s.T(), s.EgressClientContainer, 10*time.Second, expectedConnections...))
310+
client, server := s.runNetworkDirectionContainers()
311+
defer s.teardownNetworkDirectionContainers()
289312

290313
s.setRuntimeConfig(types.RuntimeConfig{
291314
Networking: types.NetworkConfig{
@@ -296,12 +319,99 @@ func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigNetworkEgress() {
296319
},
297320
})
298321

299-
assert.AssertExternalIps(s.T(), "ENABLED", collectorIP)
300-
expectedConnections = append(expectedConnections, activeUnnormalizedConnectionEgress, inactiveNormalizedConnectionEgress)
301-
common.Sleep(3 * time.Second) // Sleep so that collector has a chance to report connections
302-
s.Require().True(s.Sensor().ExpectSameElementsConnections(s.T(), s.EgressClientContainer, 10*time.Second, expectedConnections...))
322+
// Expect both open and close events for the non-aggregated
323+
// egress connection. If Collector is aggregating to 255.255.255.255
324+
// this will fail.
325+
// We are not concerned with event ordering in this test.
326+
expectedEgressConnections := []types.NetworkInfo{
327+
{
328+
LocalAddress: "",
329+
RemoteAddress: fmt.Sprintf("%s:%d", ingressIP, ingressPort),
330+
Role: "ROLE_CLIENT",
331+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
332+
CloseTimestamp: types.NotNilTimestamp,
333+
},
334+
{
335+
LocalAddress: "",
336+
RemoteAddress: fmt.Sprintf("%s:%d", ingressIP, ingressPort),
337+
Role: "ROLE_CLIENT",
338+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
339+
CloseTimestamp: types.NilTimestamp,
340+
},
341+
}
342+
343+
expectedIngressConnections := []types.NetworkInfo{
344+
{
345+
LocalAddress: fmt.Sprintf(":%d", ingressPort),
346+
RemoteAddress: normalizedIp,
347+
Role: "ROLE_SERVER",
348+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
349+
CloseTimestamp: types.NotNilTimestamp,
350+
},
351+
{
352+
LocalAddress: fmt.Sprintf(":%d", ingressPort),
353+
RemoteAddress: normalizedIp,
354+
Role: "ROLE_SERVER",
355+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
356+
CloseTimestamp: types.NilTimestamp,
357+
},
358+
}
359+
360+
s.Require().True(s.Sensor().ExpectConnections(s.T(), client, 30*time.Second, expectedEgressConnections...))
361+
s.Require().True(s.Sensor().ExpectConnections(s.T(), server, 30*time.Second, expectedIngressConnections...))
303362
}
304363

305364
func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigNetworkBoth() {
365+
client, server := s.runNetworkDirectionContainers()
366+
defer s.teardownNetworkDirectionContainers()
367+
368+
s.setRuntimeConfig(types.RuntimeConfig{
369+
Networking: types.NetworkConfig{
370+
ExternalIps: types.ExternalIpsConfig{
371+
Enabled: "ENABLED",
372+
Direction: "BOTH",
373+
},
374+
},
375+
})
376+
377+
// Expect both open and close events for the non-aggregated
378+
// egress and ingress connections. If Collector is aggregating to 255.255.255.255
379+
// this will fail.
380+
// We are not concerned with event ordering in this test.
381+
expectedEgressConnections := []types.NetworkInfo{
382+
{
383+
LocalAddress: "",
384+
RemoteAddress: fmt.Sprintf("%s:%d", ingressIP, ingressPort),
385+
Role: "ROLE_CLIENT",
386+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
387+
CloseTimestamp: types.NotNilTimestamp,
388+
},
389+
{
390+
LocalAddress: "",
391+
RemoteAddress: fmt.Sprintf("%s:%d", ingressIP, ingressPort),
392+
Role: "ROLE_CLIENT",
393+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
394+
CloseTimestamp: types.NilTimestamp,
395+
},
396+
}
397+
398+
expectedIngressConnections := []types.NetworkInfo{
399+
{
400+
LocalAddress: fmt.Sprintf(":%d", ingressPort),
401+
RemoteAddress: ingressIP,
402+
Role: "ROLE_SERVER",
403+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
404+
CloseTimestamp: types.NotNilTimestamp,
405+
},
406+
{
407+
LocalAddress: fmt.Sprintf(":%d", ingressPort),
408+
RemoteAddress: ingressIP,
409+
Role: "ROLE_SERVER",
410+
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
411+
CloseTimestamp: types.NilTimestamp,
412+
},
413+
}
306414

415+
s.Require().True(s.Sensor().ExpectConnections(s.T(), client, 30*time.Second, expectedEgressConnections...))
416+
s.Require().True(s.Sensor().ExpectConnections(s.T(), server, 30*time.Second, expectedIngressConnections...))
307417
}

0 commit comments

Comments
 (0)