multi.bats 3.7 KB

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