github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/libnetwork/test/integration/dnet/multi.bats (about)

     1  # -*- mode: sh -*-
     2  #!/usr/bin/env bats
     3  
     4  load helpers
     5  
     6  function is_network_exist() {
     7      line=$(dnet_cmd $(inst_id2port $1) network ls | grep ${2})
     8      name=$(echo ${line} | cut -d" " -f2)
     9      driver=$(echo ${line} | cut -d" " -f3)
    10      if [ "$name" == "$2"  -a  "$driver" == "$3" ]; then
    11  	echo "true"
    12      else
    13  	echo "false"
    14      fi
    15  }
    16  
    17  @test "Test multinode network create" {
    18      echo $(docker ps)
    19      for i in `seq 1 3`;
    20      do
    21  	oname="mh$i"
    22  	run dnet_cmd $(inst_id2port $i) network create -d test ${oname}
    23  	echo ${output}
    24  	[ "$status" -eq 0 ]
    25  
    26  	for j in `seq 1 3`;
    27  	do
    28  	    result=$(is_network_exist $j ${oname} test)
    29  	    [ "$result" = "true" ]
    30  	done
    31  
    32  	# Always try to remove the network from the second node
    33  	dnet_cmd $(inst_id2port 2) network rm ${oname}
    34  	echo "delete ${oname}"
    35  	nresult=$(is_network_exist 1 ${oname} test)
    36  	echo ${nresult}
    37  	dnet_cmd $(inst_id2port 1) network ls
    38  	[ "$nresult" = "false" ]
    39      done
    40  }
    41  
    42  @test "Test multinode service create" {
    43      echo $(docker ps)
    44      dnet_cmd $(inst_id2port 1) network create -d test multihost
    45      for i in `seq 1 3`;
    46      do
    47  	oname="svc$i"
    48  	run dnet_cmd $(inst_id2port $i) service publish ${oname}.multihost
    49  	echo ${output}
    50  	[ "$status" -eq 0 ]
    51  
    52  	for j in `seq 1 3`;
    53  	do
    54  	    run dnet_cmd $(inst_id2port $j) service ls
    55  	    [ "$status" -eq 0 ]
    56  	    echo ${output}
    57  	    echo ${lines[1]}
    58  	    svc=$(echo ${lines[1]} | cut -d" " -f2)
    59  	    network=$(echo ${lines[1]} | cut -d" " -f3)
    60  	    echo ${svc} ${network}
    61  	    [ "$network" = "multihost" ]
    62  	    [ "$svc" = "${oname}" ]
    63  	done
    64  	dnet_cmd $(inst_id2port 2) service unpublish ${oname}.multihost
    65      done
    66      dnet_cmd $(inst_id2port 3) network rm multihost
    67  }
    68  
    69  @test "Test multinode service attach" {
    70      echo $(docker ps)
    71      dnet_cmd $(inst_id2port 2) network create -d test multihost
    72      dnet_cmd $(inst_id2port 3) service publish svc.multihost
    73      for i in `seq 1 3`;
    74      do
    75  	dnet_cmd $(inst_id2port $i) container create container_${i}
    76  	dnet_cmd $(inst_id2port $i) service attach container_${i} svc.multihost
    77  	run dnet_cmd $(inst_id2port $i) service ls
    78  	[ "$status" -eq 0 ]
    79  	echo ${output}
    80  	echo ${lines[1]}
    81  	container=$(echo ${lines[1]} | cut -d" " -f4)
    82  	[ "$container" = "container_$i" ]
    83  	for j in `seq 1 3`;
    84  	do
    85  	    if [ "$j" = "$i" ]; then
    86  		continue
    87  	    fi
    88  	    dnet_cmd $(inst_id2port $j) container create container_${j}
    89  	    run dnet_cmd $(inst_id2port $j) service attach container_${j} svc.multihost
    90  	    echo ${output}
    91  	    [ "$status" -ne 0 ]
    92  	    dnet_cmd $(inst_id2port $j) container rm container_${j}
    93  	done
    94  	dnet_cmd $(inst_id2port $i) service detach container_${i} svc.multihost
    95  	dnet_cmd $(inst_id2port $i) container rm container_${i}
    96      done
    97      dnet_cmd $(inst_id2port 1) service unpublish svc.multihost
    98      dnet_cmd $(inst_id2port 3) network rm multihost
    99  }
   100  
   101  @test "Test multinode network and service delete" {
   102      echo $(docker ps)
   103      for i in `seq 1 3`;
   104      do
   105  	oname="mh$i"
   106  	osvc="svc$i"
   107  	dnet_cmd $(inst_id2port $i) network create -d test ${oname}
   108  	dnet_cmd $(inst_id2port $i) service publish ${osvc}.${oname}
   109  	dnet_cmd $(inst_id2port $i) container create container_${i}
   110  	dnet_cmd $(inst_id2port $i) network ls
   111  	dnet_cmd $(inst_id2port $i) service attach container_${i} ${osvc}.${oname}
   112  
   113  	for j in `seq 1 3`;
   114  	do
   115  	    run dnet_cmd $(inst_id2port $i) service unpublish ${osvc}.${oname}
   116  	    echo ${output}
   117  	    [ "$status" -ne 0 ]
   118  	    run dnet_cmd $(inst_id2port $j) network rm ${oname}
   119  	    echo ${output}
   120  	    [ "$status" -ne 0 ]
   121  	done
   122  
   123  	dnet_cmd $(inst_id2port $i) service detach container_${i} ${osvc}.${oname}
   124  	dnet_cmd $(inst_id2port $i) container rm container_${i}
   125  
   126  	# Always try to remove the service from different nodes
   127  	dnet_cmd $(inst_id2port 2) service unpublish ${osvc}.${oname}
   128  	dnet_cmd $(inst_id2port 3) network rm ${oname}
   129      done
   130  }