Skip to content

Commit 1f03b30

Browse files
committed
Initial attempt at ingress/egress/both tests for external IPs
1 parent 41109ea commit 1f03b30

File tree

8 files changed

+324
-39
lines changed

8 files changed

+324
-39
lines changed

integration-tests/container/QA_TAG

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.2
1+
2.0.3

integration-tests/container/berserker/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
FROM quay.io/rhacs-eng/qa:berserker-1.0-59-g87ad0d870e
1+
FROM quay.io/rhacs-eng/qa:berserker-1.0-79-g617ec32386
2+
3+
RUN sudo dnf install -y which iproute bpftool procps iptables
24

35
COPY workloads/ /etc/berserker/
6+
COPY init.sh /scripts/
7+
COPY prepare-tap.sh /scripts/
48

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
set -x
6+
7+
IP_BASE="${IP_BASE:-223.42.0.1/16}"
8+
9+
/scripts/prepare-tap.sh -a "$IP_BASE" -o
10+
11+
if [[ "$IS_CLIENT" == "true" ]]; then
12+
berserker /etc/berserker/network/client.toml &
13+
else
14+
berserker /etc/berserker/network/server.toml &
15+
fi
16+
17+
PID=$!
18+
19+
cleanup() {
20+
echo "Killing $PID"
21+
22+
kill -9 "$PID"
23+
24+
ip link delete berserker0
25+
26+
exit
27+
}
28+
29+
trap cleanup SIGINT SIGABRT
30+
31+
wait -n "$PID"
32+
33+
ip link delete berserker0
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env bash
2+
set -eou pipefail
3+
4+
# This script helps to prepare an environment for developing berserker network
5+
# workload. It has the following preparatory steps:
6+
# * Create and start up a new tun device for berserker to use
7+
# * Optionally prepare iptables for the device to be visible
8+
#
9+
# The last step is optional, because iptables configuration could be different
10+
# between development environments. Meaning it's not guaranteed that this part of
11+
# the script is suitable for every case.
12+
13+
stop() {
14+
echo "$*" 1>&2
15+
exit 1
16+
}
17+
18+
which ip &> /dev/null || stop "Don't have the ip tool"
19+
which whoami &> /dev/null || stop "Don't have the whoami tool"
20+
which sysctl &> /dev/null || stop "Don't have the sysctl tool"
21+
22+
ADDRESS="10.0.0.1/16"
23+
NAME="berserker0"
24+
USER="$(whoami)"
25+
CONFIGURE_IPTABLE="false"
26+
CONFIGURE_FIREWALLD="false"
27+
CONFIGURE_TUNTAP_IF_EXISTS="false"
28+
29+
while getopts ":a:t:u:i:fo" opt; do
30+
case $opt in
31+
a)
32+
ADDRESS="${OPTARG}"
33+
;;
34+
t)
35+
NAME="${OPTARG}"
36+
;;
37+
u)
38+
USER="${OPTARG}"
39+
;;
40+
i)
41+
CONFIGURE_IPTABLE="true"
42+
;;
43+
f)
44+
CONFIGURE_FIREWALLD="true"
45+
;;
46+
o)
47+
CONFIGURE_TUNTAP_IF_EXISTS="true"
48+
;;
49+
\?)
50+
echo "Invalid option -$OPTARG" >&2
51+
exit 1
52+
;;
53+
esac
54+
done
55+
56+
echo "Verifying if device ${NAME} is already created..."
57+
if ip tuntap | grep "${NAME}" &> /dev/null; then
58+
echo "The devince ${NAME} already exists!"
59+
if [[ "${CONFIGURE_TUNTAP_IF_EXISTS}" != "true" ]]; then
60+
exit 1
61+
fi
62+
63+
ip link delete "${NAME}"
64+
fi
65+
66+
echo "Creating tun device ${NAME} for user ${USER}..."
67+
ip tuntap add name "${NAME}" mode tun user "${USER}"
68+
ip link set "${NAME}" up
69+
70+
echo "Assigning address ${ADDRESS} to device ${NAME}..."
71+
ip addr add "${ADDRESS}" dev "${NAME}"
72+
73+
if [[ "${CONFIGURE_FIREWALLD}" == "true" ]]; then
74+
which firewall-cmd &> /dev/null || stop "Don't have the firewal-cmd tool"
75+
76+
echo "Adding to the trusted zone..."
77+
firewall-cmd --zone=trusted --add-interface="${NAME}"
78+
fi
79+
80+
if [[ "${CONFIGURE_IPTABLE}" == "true" ]]; then
81+
which iptables &> /dev/null || stop "Don't have the iptables tool"
82+
83+
echo "Enabling ip forward..."
84+
sysctl net.ipv4.ip_forward=1
85+
86+
echo "Preparing iptable..."
87+
iptables -t nat -A POSTROUTING -s "${ADDRESS}" -j MASQUERADE
88+
iptables -A FORWARD -i "${NAME}" -s "${ADDRESS}" -j ACCEPT
89+
iptables -A FORWARD -o "${NAME}" -d "${ADDRESS}" -j ACCEPT
90+
91+
RULE_NR=$(iptables -t filter -L INPUT --line-numbers \
92+
| grep "REJECT all" \
93+
| awk '{print $1}')
94+
95+
# Excempt tun device from potentiall reject all rule
96+
if [[ $RULE_NR == "" ]]; then
97+
iptables -I INPUT -i "${NAME}" -s "${ADDRESS}" -j ACCEPT
98+
else
99+
iptables -I INPUT $((RULE_NR - 1)) -i "${NAME}" -s "${ADDRESS}" -j ACCEPT
100+
fi
101+
fi
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
restart_interval = 10
2+
workers = 1
3+
per_core = false
4+
5+
[workload]
6+
type = "network"
7+
server = false
8+
address = "223.42.0.1"
9+
target_port = 1337
10+
arrival_rate = 10
11+
departure_rate = 10
12+
connections_static = 0
13+
connections_dyn_max = 20
14+
preempt = true
15+
conns_per_addr = 1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
restart_interval = 10
2+
workers = 1
3+
per_core = false
4+
5+
[workload]
6+
type = "network"
7+
server = true
8+
address = "223.42.0.1"
9+
target_port = 1337
10+
connections_static = 0
11+
connections_dyn_max = 20
12+
preempt = false
13+
conns_per_addr = 1

integration-tests/pkg/types/runtime_config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
)
66

77
type ExternalIpsConfig struct {
8-
Enabled string `yaml:"enabled"`
8+
Enabled string `yaml:"enabled"`
9+
Direction string `yaml:"direction,omitempty"`
910
}
1011

1112
type NetworkConfig struct {
@@ -29,12 +30,12 @@ func (n *RuntimeConfig) Equal(other RuntimeConfig) bool {
2930
return n.Networking.ExternalIps.Enabled == other.Networking.ExternalIps.Enabled
3031
}
3132

32-
func (n *RuntimeConfig) GetRuntimeConfigStr() (string, error) {
33+
func (n *RuntimeConfig) String() string {
3334
yamlBytes, err := yaml.Marshal(n)
3435

3536
if err != nil {
36-
return "", err
37+
panic(err)
3738
}
3839

39-
return string(yamlBytes), err
40+
return string(yamlBytes)
4041
}

0 commit comments

Comments
 (0)