summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2022-02-03 09:21:11 -0600
committerBrent Baude <bbaude@redhat.com>2022-02-04 08:08:49 -0600
commitf80042631ffeda311e07d09de66cda69f829d136 (patch)
tree58e60dc7222ee6e89345d2231cec341a06d844ce /test
parent7d660d17bc3f7ac1b2b5a2cc39f17a242be35d11 (diff)
Add "IBM" use case 1/2
Verify that one of the IBM use cases where we have three networks (A, B, C). And the a container is created on A and one on C, referred to as A1 and B1. Then A1 and C1 do a network connect and join network B and they each add and alias. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'test')
-rw-r--r--test/100-basic-name-resolution.bats25
-rw-r--r--test/200-two-networks.bats36
-rw-r--r--test/300-three-networks.bats179
-rw-r--r--test/400-aliases.bats2
-rw-r--r--test/500-reverse-lookups.bats32
-rw-r--r--test/helpers.bash12
6 files changed, 244 insertions, 42 deletions
diff --git a/test/100-basic-name-resolution.bats b/test/100-basic-name-resolution.bats
index c69832d..b7ed420 100644
--- a/test/100-basic-name-resolution.bats
+++ b/test/100-basic-name-resolution.bats
@@ -6,7 +6,6 @@
load helpers
@test "basic container - dns itself" {
- basic_host_setup
subnet_a=$(random_subnet 5)
create_config "podman1" $(random_string 64) "aone" "$subnet_a" "a1" "1a"
config_a1=$config
@@ -17,3 +16,27 @@ load helpers
run_in_container_netns "$a1_pid" "dig" "+short" "aone" "@$gw"
assert "$ip_a1"
}
+
+@test "two containers on the same network" {
+ # container a1
+ subnet_a=$(random_subnet 5)
+ create_config "podman1" $(random_string 64) "aone" "$subnet_a" "a1" "1a"
+ config_a1="$config"
+ a1_ip=$(echo "$config_a1" | jq -r .networks.podman1.static_ips[0])
+ gw=$(echo "$config_a1" | jq -r .network_info.podman1.subnets[0].gateway)
+ create_container "$config_a1"
+ a1_pid=$CONTAINER_NS_PID
+
+ # container a2
+ create_config "podman1" $(random_string 64) "atwo" "$subnet_a" "a2" "2a"
+ config_a2="$config"
+ a2_ip=$(echo "$config_a2" | jq -r .networks.podman1.static_ips[0])
+ create_container "$config_a2"
+ a2_pid="$CONTAINER_NS_PID"
+
+ # Resolve container names to IPs
+ dig "$a1_pid" "atwo" "$gw"
+ assert "$a2_ip"
+ dig "$a2_pid" "aone" "$gw"
+ assert "$a1_ip"
+}
diff --git a/test/200-two-networks.bats b/test/200-two-networks.bats
index 0bd17a3..979da72 100644
--- a/test/200-two-networks.bats
+++ b/test/200-two-networks.bats
@@ -5,42 +5,9 @@
load helpers
-@test "two containers on the same network" {
-
- basic_host_setup
- # container a1
- subnet_a=$(random_subnet 5)
- create_config "podman1" $(random_string 64) "aone" "$subnet_a" "a1" "1a"
- config_a1="$config"
- a1_ip=$(echo "$config_a1" | jq -r .networks.podman1.static_ips[0])
- gw=$(echo "$config_a1" | jq -r .network_info.podman1.subnets[0].gateway)
- create_container "$config_a1"
- a1_pid=$CONTAINER_NS_PID
-
- # container a2
- create_config "podman1" $(random_string 64) "atwo" "$subnet_a" "a2" "2a"
- config_a2="$config"
- a2_ip=$(echo "$config_a2" | jq -r .networks.podman1.static_ips[0])
- create_container "$config_a2"
- a2_pid="$CONTAINER_NS_PID"
-
- # Resolve container names to IPs
- dig "$a1_pid" "atwo" "$gw"
- assert "$a2_ip"
- dig "$a2_pid" "aone" "$gw"
- assert "$a1_ip"
-
- # Resolve IPs to container names
- # Reverse lookups are not supported
- #dig_reverse "$a1_pid" "$a2_ip" "$gw"
- #assert $output "atwo"
- #dig_reverse "$a2_pid" "$a1_ip" "$gw"
- #assert $output "atwo"
-}
@test "two containers on different networks" {
# container a1 on subnet a
- basic_host_setup
subnet_a=$(random_subnet 5)
create_config "podman1" $(random_string 64) "aone" "$subnet_a"
a1_config="$config"
@@ -75,7 +42,6 @@ load helpers
@test "two subnets with isolated container and one shared" {
# container a1 on subnet a
- basic_host_setup
subnet_a=$(random_subnet 5)
subnet_b=$(random_subnet 5)
@@ -143,4 +109,4 @@ load helpers
assert "${#lines[@]}" = 2
assert "$output" =~ "$a2_ip"
assert "$output" =~ "$b2_ip"
-} \ No newline at end of file
+}
diff --git a/test/300-three-networks.bats b/test/300-three-networks.bats
index 5ccd04d..d6d2555 100644
--- a/test/300-three-networks.bats
+++ b/test/300-three-networks.bats
@@ -4,3 +4,182 @@
#
load helpers
+
+@test "three networks with a connect" {
+ subnet_a=$(random_subnet 5)
+ subnet_b=$(random_subnet 5)
+
+ # A1
+ create_config "podman1" $(random_string 64) "aone" "$subnet_a"
+ a1_config=$config
+ a1_container_id=$(echo "$a1_config" | jq -r .container_id)
+ a1_ip=$(echo "$a1_config" | jq -r .networks.podman1.static_ips[0])
+ a_gw=$(echo "$a1_config" | jq -r .network_info.podman1.subnets[0].gateway)
+ a1_hash=$(echo "$a1_config" | jq -r .network_info.podman1.id)
+ create_container "$a1_config"
+ a1_pid=$CONTAINER_NS_PID
+
+ # container b1 on subnet b
+ create_config "podman2" $(random_string 64) "bone" "$subnet_b"
+ b1_config=$config
+ b1_ip=$(echo "$b1_config" | jq -r .networks.podman2.static_ips[0])
+ b_gw=$(echo "$b1_config" | jq -r .network_info.podman2.subnets[0].gateway)
+ b1_hash=$(echo "$b1_config" | jq -r .network_info.podman1.id)
+ create_container "$b1_config"
+ b1_pid=$CONTAINER_NS_PID
+ b_subnets=$(echo $b1_config | jq -r .network_info.podman2.subnets[0])
+
+ # AB2
+ create_config "podman1" $(random_string 64) "abtwo" "$subnet_a"
+ a2_config=$config
+ a2_ip=$(echo "$a2_config" | jq -r .networks.podman1.static_ips[0])
+
+ b2_ip=$(random_ip_in_subnet "$subnet_b")
+ create_network "podman2" "$b2_ip" "eth1"
+ b2_network="{$new_network}"
+ create_network_infos "podman2" "$b1_hash" "$b_subnets"
+ b2_network_info="{$new_network_info}"
+ ab2_config=$(jq -r ".networks += $b2_network" <<<"$a2_config")
+ ab2_config=$(jq -r ".network_info += $b2_network_info" <<<"$ab2_config")
+
+ create_container "$ab2_config"
+ ab2_pid=$CONTAINER_NS_PID
+
+ # aone should be able to resolve AB2 and NOT B1
+ dig "$a1_pid" "abtwo" "$a_gw"
+ assert "$a2_ip"
+ dig "$a1_pid" "bone" "$a_gw"
+ assert ""
+
+ # bone should be able to resolve AB2 and NOT A1
+ dig "$b1_pid" "abtwo" "$b_gw"
+ assert "$b2_ip"
+ dig "$b1_pid" "aone" "$b_gw"
+ assert ""
+
+ # abtwo should be able to resolve A1, B1, and AB2 on both gws
+ dig "$ab2_pid" "aone" "$a_gw"
+ assert "$a1_ip"
+ dig "$ab2_pid" "bone" "$b_gw"
+ assert "$b1_ip"
+
+ # check ab2 from itself, first from the a side
+ dig "$ab2_pid" "abtwo" "$a_gw"
+ assert "${#lines[@]}" = 2
+ assert "$output" =~ "$a2_ip"
+ assert "$output" =~ "$b2_ip"
+
+ # and now from the bside
+ dig "$ab2_pid" "abtwo" "$b_gw"
+ assert "${#lines[@]}" = 2
+ assert "$output" =~ "$a2_ip"
+ assert "$output" =~ "$b2_ip"
+}
+
+@test "three subnets, one container or two of the subnets, network connect" {
+ # Create all three subnets
+ subnet_a=$(random_subnet 5)
+ subnet_b=$(random_subnet 5)
+ subnet_c=$(random_subnet 5)
+
+ # A1 on subnet A
+ create_config "podman1" $(random_string 64) "aone" "$subnet_a"
+ a1_config=$config
+ a1_container_id=$(echo "$a1_config" | jq -r .container_id)
+ a1_ip=$(echo "$a1_config" | jq -r .networks.podman1.static_ips[0])
+ a_gw=$(echo "$a1_config" | jq -r .network_info.podman1.subnets[0].gateway)
+ a1_hash=$(echo "$a1_config" | jq -r .network_info.podman1.id)
+ create_container "$a1_config"
+ a1_pid=$CONTAINER_NS_PID
+
+ # C1 on subnet C
+ create_config "podman3" $(random_string 64) "cone" "$subnet_c"
+ c1_config=$config
+ c1_container_id=$(echo "$c1_config" | jq -r .container_id)
+ c1_ip=$(echo "$c1_config" | jq -r .networks.podman3.static_ips[0])
+ c_gw=$(echo "$c1_config" | jq -r .network_info.podman3.subnets[0].gateway)
+ c1_hash=$(echo "$c1_config" | jq -r .network_info.podman3.id)
+ create_container "$c1_config"
+ c1_pid=$CONTAINER_NS_PID
+ c_subnets=$(echo $c1_config | jq -r .network_info.podman3.subnets[0])
+
+ # We now have one container on A and one on C. We now similate
+ # a network connect on both to B.
+ #
+ # This is also where things get tricky and we are trying to mimic
+ # a connect. First, we need to trim off the last two container
+ # configs for teardown. We will leave the NS_PIDS alone because
+ # the order should be OK.
+ #
+
+ # Create B1 config for network connect
+ #
+ create_config "podman2" $(random_string 64) "aone" "$subnet_b" "aone_nw"
+ b1_config=$config
+ # The container ID should be the same
+ b1_config=$(jq ".container_id |= \"$a1_container_id\"" <<<"$b1_config")
+ b1_config=$(jq ".networks.podman2.interface_name |= \"eth1\"" <<<"$b1_config")
+ b1_network=$(echo "$b1_config" | jq -r .networks)
+ b1_network_info=$(echo "$b1_config" | jq -r .network_info)
+ b1_ip=$(echo "$b1_network" | jq -r .podman2.static_ips[0])
+ b_gw=$(echo "$b1_network_info" | jq -r .podman2.subnets[0].gateway)
+
+ # Now we must merge a1 and b1 for eventual teardown
+ a1b1_config=$(jq -r ".networks += $b1_network" <<<"$a1_config")
+ a1b1_config=$(jq -r ".network_info += $b1_network_info" <<<"$a1b1_config")
+
+ # Create B2 config for network connect
+ #
+ create_config "podman2" $(random_string 64) "cone" "$subnet_b" "cone_nw"
+ b2_config=$config
+ # The container ID should be the same
+ b2_config=$(jq ".container_id |= \"$c1_container_id\"" <<<"$b2_config")
+ b2_config=$(jq ".networks.podman2.interface_name |= \"eth1\"" <<<"$b2_config")
+ b2_network=$(echo "$b2_config" | jq -r .networks)
+ b2_network_info=$(echo "$b2_config" | jq -r .network_info)
+ b2_ip=$(echo "$b2_network" | jq -r .podman2.static_ips[0])
+
+ # Now we must merge c1 and b2 for eventual teardown
+ c1b2_config=$(jq -r ".networks += $b2_network" <<<"$c1_config")
+ c1b2_config=$(jq -r ".network_info += $b2_network_info" <<<"$c1b2_config")
+
+ echo "$c1_id"
+ echo "$b2_config" | jq
+ echo "--------------"
+ echo "$a1b1_config" | jq
+ echo "$c1b2_config" | jq
+ echo "--------------"
+ # Create the containers but do not add to NS_PIDS or CONTAINER_CONFIGS
+ connect "$a1_pid" "$b1_config"
+ connect "$c1_pid" "$b2_config"
+
+ # Reset CONTAINER_CONFIGS and add the two news ones
+ #
+ CONTAINER_CONFIGS=("$a1b1_config" "$c1b2_config")
+
+ # Verify
+ #
+ # b1 should be able to resolve cone through b subnet
+ dig "$a1_pid" "cone" "$b_gw"
+ assert "$b2_ip"
+
+ # a1 should be able to resolve cone
+ dig "$a1_pid" "cone" "$a_gw"
+ assert "$b2_ip"
+
+ # a1b1 should be able to resolve cone_nw alias
+ dig "$a1_pid" "cone_nw" "$a_gw"
+ assert "$b2_ip"
+
+ # b2 should be able to resolve cone through b subnet
+ dig "$c1_pid" "aone" "$b_gw"
+ assert "$b1_ip"
+
+ # c1 should be able to resolve aone
+ dig "$c1_pid" "aone" "$c_gw"
+ assert "$b1_ip"
+
+ # b2c1 should be able to resolve aone_nw alias
+ dig "$c1_pid" "aone_nw" "$c_gw"
+ assert "$b1_ip"
+}
diff --git a/test/400-aliases.bats b/test/400-aliases.bats
index bfcb080..3f5a404 100644
--- a/test/400-aliases.bats
+++ b/test/400-aliases.bats
@@ -7,7 +7,6 @@ load helpers
@test "two containers on the same network with aliases" {
# container a1
- basic_host_setup
subnet_a=$(random_subnet 5)
create_config "podman1" $(random_string 64) "aone" "$subnet_a" "a1" "1a"
config_a1="$config"
@@ -23,7 +22,6 @@ load helpers
create_container "$config_a2"
a2_pid="$CONTAINER_NS_PID"
-
dig "$a1_pid" "a2" "$gw"
assert "$a2_ip"
dig "$a1_pid" "2a" "$gw"
diff --git a/test/500-reverse-lookups.bats b/test/500-reverse-lookups.bats
index 5ccd04d..7900f35 100644
--- a/test/500-reverse-lookups.bats
+++ b/test/500-reverse-lookups.bats
@@ -4,3 +4,35 @@
#
load helpers
+
+@test "check reverse lookups" {
+ skip
+ # container a1
+ subnet_a=$(random_subnet 5)
+ create_config "podman1" $(random_string 64) "aone" "$subnet_a" "a1" "1a"
+ config_a1="$config"
+ a1_ip=$(echo "$config_a1" | jq -r .networks.podman1.static_ips[0])
+ gw=$(echo "$config_a1" | jq -r .network_info.podman1.subnets[0].gateway)
+ create_container "$config_a1"
+ a1_pid=$CONTAINER_NS_PID
+
+ # container a2
+ create_config "podman1" $(random_string 64) "atwo" "$subnet_a" "a2" "2a"
+ config_a2="$config"
+ a2_ip=$(echo "$config_a2" | jq -r .networks.podman1.static_ips[0])
+ create_container "$config_a2"
+ a2_pid="$CONTAINER_NS_PID"
+
+ # Resolve container names to IPs
+ dig "$a1_pid" "atwo" "$gw"
+ assert "$a2_ip"
+ dig "$a2_pid" "aone" "$gw"
+ assert "$a1_ip"
+
+ # Resolve IPs to container names
+ # Reverse lookups are not supported
+ #dig_reverse "$a1_pid" "$a2_ip" "$gw"
+ #assert $output "atwo"
+ #dig_reverse "$a2_pid" "$a1_ip" "$gw"
+ #assert $output "atwo"
+}
diff --git a/test/helpers.bash b/test/helpers.bash
index 84c4e8a..132eca0 100644
--- a/test/helpers.bash
+++ b/test/helpers.bash
@@ -439,15 +439,15 @@ function create_container() {
CONTAINER_NS_PID=$(create_netns)
CONTAINER_NS_PIDS+=("$CONTAINER_NS_PID")
create_container_backend "$CONTAINER_NS_PID" "$1"
+ CONTAINER_CONFIGS+=("$1")
}
# arg1 is pid
# arg2 is config
function create_container_backend() {
- run_netavark setup $(get_container_netns_path $1) <<<"$2"
- CONTAINER_CONFIGS+=("$2")
-
+ run_netavark setup $(get_container_netns_path $1) <<<"$2"
}
+
################
# connect# Connects netns to another network
################
@@ -512,4 +512,8 @@ function dig_reverse() {
# third arg is server addr
#run_in_container_netns "$1" "dig" "-x" "$2" "+short" "@$3"
run_in_container_netns "$1" "nslookup" "$2" "$3"
-} \ No newline at end of file
+}
+
+function setup() {
+ basic_host_setup
+}