diff --git a/test/100-basic-name-resolution.bats b/test/100-basic-name-resolution.bats index 05dbefec..83fbf69e 100644 --- a/test/100-basic-name-resolution.bats +++ b/test/100-basic-name-resolution.bats @@ -12,7 +12,7 @@ load helpers setup_slirp4netns subnet_a=$(random_subnet 5) - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "10.10.10.10" "a1" "1a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a" custom_dns_server='"10.10.10.10"' aliases='"a1", "1a"' config_a1=$config ip_a1=$(echo "$config_a1" | jq -r .networks.podman1.static_ips[0]) gw=$(echo "$config_a1" | jq -r .network_info.podman1.subnets[0].gateway) @@ -34,7 +34,8 @@ load helpers setup_slirp4netns subnet_a=$(random_subnet 5) - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "8.8.8.8" "a1" "1a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a" custom_dns_server='"8.8.8.8","1.1.1.1"' aliases='"a1", "1a"' + config_a1=$config ip_a1=$(echo "$config_a1" | jq -r .networks.podman1.static_ips[0]) gw=$(echo "$config_a1" | jq -r .network_info.podman1.subnets[0].gateway) @@ -58,7 +59,7 @@ load helpers setup_slirp4netns subnet_a=$(random_subnet 5) - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "" "a1" "1a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a" aliases='"a1", "1a"' config_a1=$config ip_a1=$(echo "$config_a1" | jq -r .networks.podman1.static_ips[0]) gw=$(echo "$config_a1" | jq -r .network_info.podman1.subnets[0].gateway) @@ -82,7 +83,7 @@ load helpers setup_slirp4netns subnet_a=$(random_subnet 5) - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "" "a1" "1a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a" aliases='"a1", "1a"' config_a1=$config ip_a1=$(echo "$config_a1" | jq -r .networks.podman1.static_ips[0]) gw=$(echo "$config_a1" | jq -r .network_info.podman1.subnets[0].gateway) @@ -96,7 +97,7 @@ load helpers setup_slirp4netns subnet_a=$(random_subnet 6) - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "" "a1" "1a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a" aliases='"a1", "1a"' config_a1=$config ip_a1=$(echo "$config_a1" | jq -r .networks.podman1.static_ips[0]) gw=$(echo "$config_a1" | jq -r .network_info.podman1.subnets[0].gateway) @@ -123,7 +124,7 @@ load helpers @test "basic container - dns itself with long network name" { subnet_a=$(random_subnet 5) long_name="podman11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" - create_config "$long_name" $(random_string 64) "aone" "$subnet_a" "" "a1" "1a" + create_config network_name="$long_name" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a" aliases='"a1", "1a"' config_a1=$config ip_a1=$(echo "$config_a1" | jq -r .networks.$long_name.static_ips[0]) gw=$(echo "$config_a1" | jq -r .network_info.$long_name.subnets[0].gateway) @@ -139,7 +140,7 @@ load helpers @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" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a" aliases='"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) @@ -147,7 +148,7 @@ load helpers a1_pid=$CONTAINER_NS_PID # container a2 - create_config "podman1" $(random_string 64) "atwo" "$subnet_a" "" "a2" "2a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="atwo" subnet="$subnet_a" aliases='"a2", "2a"' config_a2="$config" a2_ip=$(echo "$config_a2" | jq -r .networks.podman1.static_ips[0]) create_container "$config_a2" diff --git a/test/200-two-networks.bats b/test/200-two-networks.bats index 59ad2759..fd50489e 100644 --- a/test/200-two-networks.bats +++ b/test/200-two-networks.bats @@ -10,7 +10,7 @@ load helpers # container a1 on subnet a subnet_a=$(random_subnet 5) - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a" a1_config="$config" 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) @@ -19,7 +19,7 @@ load helpers # container b1 on subnet b subnet_b=$(random_subnet 5) - create_config "podman2" $(random_string 64) "bone" "$subnet_b" "" + create_config network_name="podman2" container_id=$(random_string 64) container_name="bone" subnet="$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) @@ -56,7 +56,7 @@ load helpers subnet_b=$(random_subnet 5) # A1 - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$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]) @@ -66,7 +66,7 @@ load helpers a1_pid=$CONTAINER_NS_PID # container b1 on subnet b - create_config "podman2" $(random_string 64) "bone" "$subnet_b" "" + create_config network_name="podman2" container_id=$(random_string 64) container_name="bone" subnet="$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) @@ -76,7 +76,7 @@ load helpers b_subnets=$(echo $b1_config | jq -r .network_info.podman2.subnets[0]) # AB2 - create_config "podman1" $(random_string 64) "abtwo" "$subnet_a" "" + create_config network_name="podman1" container_id=$(random_string 64) container_name="abtwo" subnet="$subnet_a" a2_config=$config a2_ip=$(echo "$a2_config" | jq -r .networks.podman1.static_ips[0]) diff --git a/test/300-three-networks.bats b/test/300-three-networks.bats index 45052961..90391227 100644 --- a/test/300-three-networks.bats +++ b/test/300-three-networks.bats @@ -10,7 +10,7 @@ load helpers subnet_b=$(random_subnet 5) # A1 - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$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]) @@ -20,7 +20,7 @@ load helpers a1_pid=$CONTAINER_NS_PID # container b1 on subnet b - create_config "podman2" $(random_string 64) "bone" "$subnet_b" "" + create_config network_name="podman2" container_id=$(random_string 64) container_name="bone" subnet="$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) @@ -30,7 +30,7 @@ load helpers b_subnets=$(echo $b1_config | jq -r .network_info.podman2.subnets[0]) # AB2 - create_config "podman1" $(random_string 64) "abtwo" "$subnet_a" "" + create_config network_name="podman1" container_id=$(random_string 64) container_name="abtwo" subnet="$subnet_a" a2_config=$config a2_ip=$(echo "$a2_config" | jq -r .networks.podman1.static_ips[0]) @@ -83,7 +83,7 @@ load helpers subnet_c=$(random_subnet 5) # A1 on subnet A - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$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]) @@ -93,7 +93,7 @@ load helpers a1_pid=$CONTAINER_NS_PID # C1 on subnet C - create_config "podman3" $(random_string 64) "cone" "$subnet_c" "" + create_config network_name="podman3" container_id=$(random_string 64) container_name="cone" subnet="$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]) @@ -112,7 +112,7 @@ load helpers # the order should be OK. # Create B1 config for network connect - create_config "podman2" $(random_string 64) "aone" "$subnet_b" "" "aone_nw" + create_config network_name="podman2" container_id=$(random_string 64) container_name="aone" subnet="$subnet_b" aliases='"aone_nw"' b1_config=$config # The container ID should be the same b1_config=$(jq ".container_id |= \"$a1_container_id\"" <<<"$b1_config") @@ -128,7 +128,7 @@ load helpers # Create B2 config for network connect # - create_config "podman2" $(random_string 64) "cone" "$subnet_b" "" "cone_nw" + create_config network_name="podman2" container_id=$(random_string 64) container_name="cone" subnet="$subnet_b" aliases='"cone_nw"' b2_config=$config # The container ID should be the same b2_config=$(jq ".container_id |= \"$c1_container_id\"" <<<"$b2_config") @@ -183,7 +183,7 @@ load helpers subnet_c=$(random_subnet 6) # A1 on subnet A - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$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]) @@ -193,7 +193,7 @@ load helpers a1_pid=$CONTAINER_NS_PID # C1 on subnet C - create_config "podman3" $(random_string 64) "cone" "$subnet_c" "" + create_config network_name="podman3" container_id=$(random_string 64) container_name="cone" subnet="$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]) @@ -207,7 +207,7 @@ load helpers # a network connect on both to B. # Create B1 config for network connect - create_config "podman2" $(random_string 64) "aone" "$subnet_b" "" "aone_nw" + create_config network_name="podman2" container_id=$(random_string 64) container_name="aone" subnet="$subnet_b" aliases='"aone_nw"' b1_config=$config # The container ID should be the same b1_config=$(jq ".container_id |= \"$a1_container_id\"" <<<"$b1_config") @@ -223,7 +223,7 @@ load helpers # Create B2 config for network connect # - create_config "podman2" $(random_string 64) "cone" "$subnet_b" "" "cone_nw" + create_config network_name="podman2" container_id=$(random_string 64) container_name="cone" subnet="$subnet_b" aliases='"cone_nw"' b2_config=$config # The container ID should be the same b2_config=$(jq ".container_id |= \"$c1_container_id\"" <<<"$b2_config") diff --git a/test/400-aliases.bats b/test/400-aliases.bats index 04354af8..7d0dadfa 100644 --- a/test/400-aliases.bats +++ b/test/400-aliases.bats @@ -8,7 +8,7 @@ load helpers @test "two containers on the same network with aliases" { # container a1 subnet_a=$(random_subnet 5) - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "" "a1" "1a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a" aliases='"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) @@ -16,7 +16,7 @@ load helpers a1_pid=$CONTAINER_NS_PID # container a2 - create_config "podman1" $(random_string 64) "atwo" "$subnet_a" "" "a2" "2a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="atwo" subnet="$subnet_a" aliases='"a2", "2a"' config_a2="$config" a2_ip=$(echo "$config_a2" | jq -r .networks.podman1.static_ips[0]) create_container "$config_a2" diff --git a/test/500-reverse-lookups.bats b/test/500-reverse-lookups.bats index 2b3be767..b513a9c5 100644 --- a/test/500-reverse-lookups.bats +++ b/test/500-reverse-lookups.bats @@ -8,7 +8,7 @@ load helpers @test "check reverse lookups" { # container a1 subnet_a=$(random_subnet 5) - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "" "a1" "1a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a" aliases='"a1", "1a"' a1_config="$config" a1_ip=$(echo "$a1_config" | jq -r .networks.podman1.static_ips[0]) gw=$(echo "$a1_config" | jq -r .network_info.podman1.subnets[0].gateway) @@ -16,7 +16,7 @@ load helpers a1_pid=$CONTAINER_NS_PID # container a2 - create_config "podman1" $(random_string 64) "atwo" "$subnet_a" "" "a2" "2a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="atwo" subnet="$subnet_a" aliases='"a2", "2a"' a2_config="$config" a2_ip=$(echo "$a2_config" | jq -r .networks.podman1.static_ips[0]) create_container "$a2_config" @@ -39,7 +39,7 @@ load helpers @test "check reverse lookups on ipaddress v6" { # container a1 subnet_a=$(random_subnet 6) - create_config "podman1" $(random_string 64) "aone" "$subnet_a" "" "a1" "1a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a" aliases='"a1", "1a"' a1_config="$config" a1_ip=$(echo "$a1_config" | jq -r .networks.podman1.static_ips[0]) gw=$(echo "$a1_config" | jq -r .network_info.podman1.subnets[0].gateway) @@ -47,7 +47,7 @@ load helpers a1_pid=$CONTAINER_NS_PID # container a2 - create_config "podman1" $(random_string 64) "atwo" "$subnet_a" "" "a2" "2a" + create_config network_name="podman1" container_id=$(random_string 64) container_name="atwo" subnet="$subnet_a" aliases='"a2", "2a"' a2_config="$config" a2_ip=$(echo "$a2_config" | jq -r .networks.podman1.static_ips[0]) create_container "$a2_config" diff --git a/test/helpers.bash b/test/helpers.bash index 9b28673b..b5a2d613 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -351,38 +351,51 @@ function run_in_host_netns() { # create_config# Creates a config netavark can use ################ # -# first arg is the network name -# second arg is container_id -# third is container name -# fourth is subnet -# fifth is custom dns server for container (empty will not be used) -# sixth and greater are aliases +# The following arguments are supported, the order does not matter: +# network_name=$network_name +# container_id=$container_id +# container_name=$container_name +# subnet=$subnet specifies the network subnet +# custom_dns_serve=$custom_dns_server +# aliases=$aliases comma seperated container aliases for dns resolution. function create_config() { - local network_name=$1 - shift - local container_id=$1 - shift - local container_name=$1 - shift - - local subnets="" - local subnet=$1 - shift + local network_name="" + local container_id="" + local container_name="" + local subnet="" local custom_dns_server - #local dns_server=$1 - if [ -n "$1" ]; then - custom_dns_server=\"$1\" - fi - shift + local aliases="" + + # parse arguments + while [[ "$#" -gt 0 ]]; do + IFS='=' read -r arg value <<<"$1" + case "$arg" in + network_name) + network_name="$value" + ;; + container_id) + container_id="$value" + ;; + container_name) + container_name="$value" + ;; + subnet) + subnet="$value" + ;; + custom_dns_server) + custom_dns_server="$value" + ;; + aliases) + aliases="$value" + ;; + *) die "unknown argument for '$arg' create_config" ;; + esac + shift + done + container_ip=$(random_ip_in_subnet $subnet) container_gw=$(gateway_from_subnet $subnet) subnets="{\"subnet\":\"$subnet\",\"gateway\":\"$container_gw\"}" - aliases="" - comma= - for i; do - aliases+="$comma \"$i\"" - comma=, - done create_network "$network_name" "$container_ip" "eth0" "$aliases" create_network_infos "$network_name" $(random_string 64) "$subnets"