github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/apiv2/35-networks.at (about)

     1  # -*- sh -*-
     2  #
     3  # network-related tests
     4  #
     5  
     6  t GET networks/non-existing-network 404 \
     7    .cause='network not found'
     8  
     9  t POST libpod/networks/create name='"network1"' 200 \
    10    .name=network1 \
    11    .created~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.*
    12  
    13  network1_id=$(jq -r '.id' <<<"$output")
    14  
    15  t POST /v3.4.0/libpod/networks/create name='"bad_version"' 400 \
    16      .cause='given version is not supported'
    17  
    18  # --data '{"name":"network2","subnets":[{"subnet":"10.10.254.0/24"}],"Labels":{"abc":"val"}}'
    19  t POST libpod/networks/create name='"network2"' \
    20    subnets='[{"subnet":"10.10.254.0/24"}]' \
    21    labels='{"abc":"val"}' \
    22    200 \
    23    .name=network2 \
    24    .subnets[0].subnet=10.10.254.0/24 \
    25    .subnets[0].gateway=10.10.254.1 \
    26    .labels.abc=val
    27  
    28  # --data '{"name":"network3","subnets":[{"subnet":"10.10.133.0/24"}],"Labels":{"xyz":"val"}}'
    29  t POST libpod/networks/create name="network3" \
    30    subnets='[{"subnet":"10.10.133.0/24"}]' \
    31    labels='{"xyz":"val"}' \
    32    200 \
    33    .name=network3 \
    34    .subnets[0].subnet=10.10.133.0/24 \
    35    .subnets[0].gateway=10.10.133.1 \
    36    .labels.xyz=val
    37  
    38  # --data '{"name":"network4","subnets":[{"subnet":"10.10.134.0/24"}],"Labels":{"zaq":"val"}}'
    39  t POST libpod/networks/create name="network4" \
    40    subnets='[{"subnet":"10.10.134.0/24"}]' \
    41    labels='{"zaq":"val"}' \
    42    200 \
    43    .name=network4 \
    44    .subnets[0].subnet=10.10.134.0/24 \
    45    .subnets[0].gateway=10.10.134.1 \
    46    .labels.zaq=val
    47  
    48  # test for empty mask
    49  t POST libpod/networks/create subnets='[{"subnet":"10.10.134.0"}]' 500 \
    50    .cause~'.*invalid CIDR address: 10.10.134.0'
    51  # test for invalid mask
    52  t POST libpod/networks/create subnets='[{"subnet":"10.10.134.0/65"}]' 500 \
    53    .cause~'.*invalid CIDR address: 10.10.134.0/65'
    54  
    55  # network list
    56  t GET libpod/networks/json 200
    57  t GET libpod/networks/json?filters='{"name":["network1"]}' 200 \
    58    length=1 \
    59    .[0].name=network1
    60  t GET networks 200
    61  
    62  #inspect network
    63  t GET libpod/networks/network1/json 200 \
    64    .name="network1"
    65  
    66  #network list docker endpoint
    67  t GET networks?filters='{"name":["network1","network2"]}' 200 \
    68    length=2
    69  t GET networks?filters='{"name":["network"]}' 200 \
    70    length=4
    71  t GET networks?filters='{"label":["abc"]}' 200 \
    72    length=1
    73  # old docker filter type see #9526
    74  t GET networks?filters='{"label":{"abc":true}}' 200 \
    75    length=1
    76  t GET networks?filters="{\"id\":[\"$network1_id\"]}" 200 \
    77    length=1 \
    78    .[0].Name=network1 \
    79    .[0].Id=$network1_id
    80  # invalid filter
    81  t GET networks?filters='{"dangling":["1"]}' 500 \
    82    .cause='invalid filter "dangling"'
    83  # (#9293 with no networks the endpoint should return empty array instead of null)
    84  t GET networks?filters='{"name":["doesnotexists"]}' 200 \
    85    "[]"
    86  
    87  # network inspect docker
    88  t GET networks/$network1_id 200 \
    89    .Name=network1 \
    90    .Id=$network1_id \
    91    .Scope=local
    92  
    93  # network create docker
    94  t POST networks/create Name=net3\ IPAM='{"Config":[]}' 201
    95  # network delete docker
    96  t DELETE networks/net3 204
    97  
    98  #compat api list networks sanity checks
    99  t GET networks?filters='garb1age}' 500 \
   100      .cause="invalid character 'g' looking for beginning of value"
   101  t GET networks?filters='{"label":["testl' 500 \
   102      .cause="unexpected end of JSON input"
   103  
   104  #libpod api list networks sanity checks
   105  t GET libpod/networks/json?filters='garb1age}' 500 \
   106      .cause="invalid character 'g' looking for beginning of value"
   107  t GET libpod/networks/json?filters='{"label":["testl' 500 \
   108      .cause="unexpected end of JSON input"
   109  
   110  # Prune networks compat api
   111  t POST networks/prune?filters='garb1age}' 500 \
   112      .cause="invalid character 'g' looking for beginning of value"
   113  t POST networks/prune?filters='{"label":["tes' 500 \
   114      .cause="unexpected end of JSON input"
   115  
   116  # Prune networks libpod api
   117  t POST libpod/networks/prune?filters='garb1age}' 500 \
   118      .cause="invalid character 'g' looking for beginning of value"
   119  t POST libpod/networks/prune?filters='{"label":["tes' 500 \
   120      .cause="unexpected end of JSON input"
   121  
   122  # prune networks using filter - compat api
   123  t POST networks/prune?filters='{"label":["xyz"]}' 200
   124  t GET networks?filters='{"label":["xyz"]}' 200 length=0
   125  
   126  # prune networks using filter - libpod api
   127  t POST libpod/networks/prune?filters='{"label":["zaq=val"]}' 200
   128  t GET libpod/networks/json?filters='{"label":["zaq=val"]}' 200 length=0
   129  
   130  # clean the network
   131  t DELETE libpod/networks/network1 200 \
   132    .[0].Name~network1 \
   133    .[0].Err=null
   134  t DELETE libpod/networks/network2 200 \
   135    .[0].Name~network2 \
   136    .[0].Err=null
   137  
   138  # test until filter - libpod api
   139  # create network via cli to test that the server can use it
   140  podman network create --label xyz network5
   141  
   142  # with date way back in the past, network should not be deleted
   143  t POST libpod/networks/prune?filters='{"until":["500000"]}' 200
   144  t GET libpod/networks/json?filters='{"label":["xyz"]}' 200 length=1
   145  
   146  # with date far in the future, network should be deleted
   147  t POST libpod/networks/prune?filters='{"until":["5000000000"]}' 200
   148  t GET libpod/networks/json?filters='{"label":["xyz"]}' 200 length=0
   149  
   150  # test until filter - compat api
   151  t POST networks/create Name='"network6"' Labels='{"zaq":""}' 201 \
   152    .Id~[0-9a-f]\\{64\\}
   153  
   154  # with date way back in the past, network should not be deleted
   155  t POST networks/prune?filters='{"until":["500000"]}' 200
   156  t GET networks?filters='{"label":["zaq"]}' 200 length=1
   157  
   158  # with date far in the future, network should be deleted
   159  t POST networks/prune?filters='{"until":["5000000000"]}' 200
   160  t GET networks?filters='{"label":["zaq"]}' 200 length=0
   161  
   162  # test macvlan network response
   163  # we have to use a static subnet because of netavark does not support dhcp yet
   164  t POST libpod/networks/create name='"macvlan1"' driver="macvlan" subnets='[{"subnet":"10.10.135.0/24"}]' 200 \
   165    .name=macvlan1 \
   166    .driver=macvlan
   167  
   168  # libpod api inspect the macvlan network
   169  t GET libpod/networks/macvlan1/json 200 .name="macvlan1"
   170  
   171  # compat api inspect the macvlan network
   172  t GET networks/macvlan1 200 .Name="macvlan1"
   173  
   174  # clean the macvlan network
   175  t DELETE libpod/networks/macvlan1 200 \
   176    .[0].Name~macvlan1 \
   177    .[0].Err=null
   178  
   179  #
   180  # test networks with containers
   181  #
   182  podman pull $IMAGE &>/dev/null
   183  
   184  # Ensure clean slate
   185  podman rm -a -f &>/dev/null
   186  
   187  # create a network
   188  podman network create --subnet 10.10.253.0/24 --gateway 10.10.253.1 network5
   189  t GET libpod/networks/json?filters='{"name":["network5"]}' 200 \
   190    .[0].id~[0-9a-f]\\{64\\}
   191  nid=$(jq -r '.[0].id' <<<"$output")
   192  # create a pod on a network
   193  CNAME=mynettest
   194  podman run --network network5 --name $CNAME --ip 10.10.253.2 --mac-address 0a:01:73:78:43:18 -td $IMAGE top
   195  t GET libpod/containers/json?all=true 200 \
   196    .[0].Id~[0-9a-f]\\{64\\}
   197  cid=$(jq -r '.[0].Id' <<<"$output")
   198  # compat api inspect network
   199  t GET networks/$nid 200 .Name="network5" \
   200    .Containers[\"$cid\"].Name=$CNAME \
   201    .Containers[\"$cid\"].MacAddress=0a:01:73:78:43:18 \
   202    .Containers[\"$cid\"].IPv4Address=10.10.253.2/24
   203  # clean the network
   204  podman network rm -f network5
   205  
   206  # vim: filetype=sh