network_test.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. package integration
  2. import . "gopkg.in/check.v1"
  3. func (s *QemuSuite) TestNetwork(c *C) {
  4. netArgs := []string{"-net", "nic,vlan=0,model=virtio"}
  5. args := []string{"--cloud-config", "./tests/assets/test_09/cloud-config.yml"}
  6. for i := 0; i < 7; i++ {
  7. args = append(args, netArgs...)
  8. }
  9. s.RunQemu(c, args...)
  10. s.CheckCall(c, `
  11. cat > test-merge << "SCRIPT"
  12. set -x -e
  13. ip link show dev br0
  14. ip link show dev br0.100 | grep br0.100@br0
  15. ip link show dev eth1.100 | grep 'master br0'
  16. ip link show dev eth6 | grep 'master bond0'
  17. ip link show dev eth7 | grep 'master bond0'
  18. [ "$(</sys/class/net/bond0/bonding/mode)" = "active-backup 1" ]
  19. SCRIPT
  20. sudo bash test-merge`)
  21. s.CheckCall(c, `
  22. cat > test-merge << "SCRIPT"
  23. set -x -e
  24. cat /etc/resolv.conf | grep "search mydomain.com example.com"
  25. cat /etc/resolv.conf | grep "nameserver 208.67.222.123"
  26. cat /etc/resolv.conf | grep "nameserver 208.67.220.123"
  27. SCRIPT
  28. sudo bash test-merge`)
  29. }
  30. func (s *QemuSuite) TestNetworkBootCfg(c *C) {
  31. args := []string{"--append", "rancher.network.interfaces.eth1.address=10.1.0.41/24 rancher.network.interfaces.eth1.gateway=10.1.0.1 rancher.network.interfaces.eth0.dhcp=true"}
  32. args = append(args, []string{"-net", "nic,vlan=1,model=virtio"}...)
  33. args = append(args, []string{"-net", "nic,vlan=1,model=virtio"}...)
  34. args = append(args, []string{"-net", "nic,vlan=0,model=virtio"}...)
  35. s.RunQemu(c, args...)
  36. s.CheckOutput(c,
  37. "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1\n"+
  38. " link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n"+
  39. " inet 127.0.0.1/8 scope XXXX lo\n"+
  40. " valid_lft forever preferred_lft forever\n"+
  41. " inet6 ::1/128 scope host \n"+
  42. " valid_lft forever preferred_lft forever\n"+
  43. "2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"+
  44. " inet XX.XX.XX.XX/24 brd 10.0.2.255 scope global eth0\n"+
  45. " valid_lft forever preferred_lft forever\n"+
  46. " inet6 fe80::5054:ff:fe12:3456/64 scope link \n"+
  47. " valid_lft forever preferred_lft forever\n"+
  48. "3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"+
  49. " inet 10.1.0.41/24 scope global eth1\n"+
  50. " valid_lft forever preferred_lft forever\n"+
  51. "4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000\n"+
  52. "5: eth3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000\n"+
  53. "6: docker-sys: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000\n"+
  54. " inet 172.18.42.2/16 scope global docker-sys\n"+
  55. " valid_lft forever preferred_lft forever\n"+
  56. " inet6 XX::XX:XX:XX:XX/64 scope link \n"+
  57. " valid_lft forever preferred_lft forever\n"+
  58. "8: docker0: XXXXXXX......\n"+
  59. " inet 172.17.0.1/16 scope global docker0\n"+
  60. " valid_lft forever preferred_lft forever\n",
  61. Equals,
  62. "ip a | "+
  63. "grep -v ether | "+
  64. // TODO: figure out why sometimes loopback is scope global
  65. "sed 's/scope host lo/scope XXXX lo/g' | sed 's/scope global lo/scope XXXX lo/g' | "+
  66. "sed 's/inet 10\\.0\\.2\\..*\\/24 brd/inet XX.XX.XX.XX\\/24 brd/' | "+
  67. "sed 's/8: docker0: .*/8: docker0: XXXXXXX....../g' | "+
  68. "sed '/inet6 fe80::5054:ff:fe12:.*\\/64/!s/inet6 .*\\/64 scope/inet6 XX::XX:XX:XX:XX\\/64 scope/'",
  69. // fe80::18b6:9ff:fef5:be33
  70. )
  71. }
  72. func (s *QemuSuite) TestNetworkBootAndCloudCfg(c *C) {
  73. args := []string{
  74. "--append", "rancher.network.interfaces.eth1.address=10.1.0.52/24 rancher.network.interfaces.eth1.gateway=10.1.0.1 rancher.network.interfaces.eth0.dhcp=true rancher.network.interfaces.eth3.dhcp=true",
  75. "--cloud-config", "./tests/assets/multi_nic/cloud-config.yml",
  76. }
  77. args = append(args, []string{"-net", "nic,vlan=1,model=virtio"}...)
  78. args = append(args, []string{"-net", "nic,vlan=1,model=virtio"}...)
  79. args = append(args, []string{"-net", "nic,vlan=0,model=virtio"}...)
  80. s.RunQemu(c, args...)
  81. s.CheckOutput(c,
  82. "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1\n"+
  83. " link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n"+
  84. " inet 127.0.0.1/8 scope XXXX lo\n"+
  85. " valid_lft forever preferred_lft forever\n"+
  86. " inet6 ::1/128 scope host \n"+
  87. " valid_lft forever preferred_lft forever\n"+
  88. "2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"+
  89. " inet XX.XX.XX.XX/24 brd 10.0.2.255 scope global eth0\n"+
  90. " valid_lft forever preferred_lft forever\n"+
  91. " inet6 fe80::5054:ff:fe12:3456/64 scope link \n"+
  92. " valid_lft forever preferred_lft forever\n"+
  93. "3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"+
  94. // This shows that the boot cmdline wins over the cloud-config
  95. // But IIRC, the cloud-init metadata wins allowing you to use ip4ll to get the hoster's metadata
  96. // Need a test for that (presumably once we have libmachine based tests)
  97. " inet 10.1.0.52/24 scope global eth1\n"+
  98. " valid_lft forever preferred_lft forever\n"+
  99. "4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"+
  100. " inet 10.31.168.85/24 scope global eth2\n"+
  101. " valid_lft forever preferred_lft forever\n"+
  102. // TODO: I think it would be better if this was dhcp: false, but it could go either way
  103. "5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"+
  104. " inet XX.XX.XX.XX/24 brd 10.0.2.255 scope global eth3\n"+
  105. " valid_lft forever preferred_lft forever\n"+
  106. " inet6 fe80::5054:ff:fe12:3459/64 scope link \n"+
  107. " valid_lft forever preferred_lft forever\n"+
  108. "6: docker-sys: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000\n"+
  109. " inet 172.18.42.2/16 scope global docker-sys\n"+
  110. " valid_lft forever preferred_lft forever\n"+
  111. " inet6 XX::XX:XX:XX:XX/64 scope link \n"+
  112. " valid_lft forever preferred_lft forever\n"+
  113. "8: docker0: XXXXXXX......\n"+
  114. " inet 172.17.0.1/16 scope global docker0\n"+
  115. " valid_lft forever preferred_lft forever\n",
  116. Equals,
  117. "ip a | "+
  118. "grep -v ether | "+
  119. // TODO: figure out why sometimes loopback is scope global
  120. "sed 's/scope host lo/scope XXXX lo/g' | sed 's/scope global lo/scope XXXX lo/g' | "+
  121. "sed 's/inet 10\\.0\\.2\\..*\\/24 brd/inet XX.XX.XX.XX\\/24 brd/' | "+
  122. "sed 's/8: docker0: .*/8: docker0: XXXXXXX....../g' | "+
  123. "sed '/inet6 fe80::5054:ff:fe12:.*\\/64/!s/inet6 .*\\/64 scope/inet6 XX::XX:XX:XX:XX\\/64 scope/'",
  124. // fe80::18b6:9ff:fef5:be33
  125. )
  126. }
  127. func (s *QemuSuite) TestNetworkCfg(c *C) {
  128. args := []string{"--cloud-config", "./tests/assets/multi_nic/cloud-config.yml"}
  129. args = append(args, []string{"-net", "nic,vlan=1,model=virtio"}...)
  130. args = append(args, []string{"-net", "nic,vlan=1,model=virtio"}...)
  131. args = append(args, []string{"-net", "nic,vlan=0,model=virtio"}...)
  132. s.RunQemu(c, args...)
  133. // TODO: work out why the ipv6 loopback isn't present
  134. // inet6 ::1/128 scope host
  135. // valid_lft forever preferred_lft forever
  136. // show ip a output without mac addresses
  137. s.CheckOutput(c,
  138. "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1\n"+
  139. " link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n"+
  140. " inet 127.0.0.1/8 scope XXXX lo\n"+
  141. " valid_lft forever preferred_lft forever\n"+
  142. " inet6 ::1/128 scope host \n"+
  143. " valid_lft forever preferred_lft forever\n"+
  144. "2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"+
  145. " inet XX.XX.XX.XX/24 brd 10.0.2.255 scope global eth0\n"+
  146. " valid_lft forever preferred_lft forever\n"+
  147. " inet6 fe80::5054:ff:fe12:3456/64 scope link \n"+
  148. " valid_lft forever preferred_lft forever\n"+
  149. "3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"+
  150. " inet 10.1.0.41/24 scope global eth1\n"+
  151. " valid_lft forever preferred_lft forever\n"+
  152. "4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"+
  153. " inet 10.31.168.85/24 scope global eth2\n"+
  154. " valid_lft forever preferred_lft forever\n"+
  155. // TODO: I think it would be better if this was dhcp: false, but it could go either way
  156. "5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"+
  157. " inet XX.XX.XX.XX/24 brd 10.0.2.255 scope global eth3\n"+
  158. " valid_lft forever preferred_lft forever\n"+
  159. " inet6 fe80::5054:ff:fe12:3459/64 scope link \n"+
  160. " valid_lft forever preferred_lft forever\n"+
  161. "6: docker-sys: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000\n"+
  162. " inet 172.18.42.2/16 scope global docker-sys\n"+
  163. " valid_lft forever preferred_lft forever\n"+
  164. " inet6 XX::XX:XX:XX:XX/64 scope link \n"+
  165. " valid_lft forever preferred_lft forever\n"+
  166. "8: docker0: XXXXXXX......\n"+
  167. " inet 172.17.0.1/16 scope global docker0\n"+
  168. " valid_lft forever preferred_lft forever\n",
  169. Equals,
  170. "ip a | "+
  171. "grep -v ether | "+
  172. // TODO: figure out why sometimes loopback is scope global
  173. "sed 's/scope host lo/scope XXXX lo/g' | sed 's/scope global lo/scope XXXX lo/g' | "+
  174. "sed 's/inet 10\\.0\\.2\\..*\\/24 brd/inet XX.XX.XX.XX\\/24 brd/' | "+
  175. "sed 's/8: docker0: .*/8: docker0: XXXXXXX....../g' | "+
  176. "sed '/inet6 fe80::5054:ff:fe12:.*\\/64/!s/inet6 .*\\/64 scope/inet6 XX::XX:XX:XX:XX\\/64 scope/'",
  177. // fe80::18b6:9ff:fef5:be33
  178. )
  179. s.CheckOutput(c,
  180. "Kernel IP routing table\n"+
  181. "Destination Gateway Genmask Flags Metric Ref Use Iface\n"+
  182. "0.0.0.0 10.1.0.1 0.0.0.0 UG 0 0 0 eth1\n"+
  183. "0.0.0.0 10.0.2.2 0.0.0.0 UG 202 0 0 eth0\n"+
  184. "0.0.0.0 10.0.2.2 0.0.0.0 UG 205 0 0 eth3\n"+
  185. "10.0.2.0 0.0.0.0 255.255.255.0 U 202 0 0 eth0\n"+
  186. "10.0.2.0 0.0.0.0 255.255.255.0 U 205 0 0 eth3\n"+
  187. "10.1.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1\n"+
  188. "10.31.168.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2\n"+
  189. "172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0\n"+
  190. "172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker-sys\n",
  191. Equals, "route -n")
  192. s.CheckCall(c, "sudo ros config set rancher.network.interfaces.eth3.dhcp true")
  193. //s.CheckCall(c, "sudo netconf")
  194. s.Reboot(c)
  195. s.CheckOutput(c,
  196. "5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"+
  197. " inet XX.XX.XX.XX/24 brd 10.0.2.255 scope global eth3\n"+
  198. " valid_lft forever preferred_lft forever\n"+
  199. " inet6 fe80::5054:ff:fe12:3459/64 scope link \n"+
  200. " valid_lft forever preferred_lft forever\n",
  201. Equals,
  202. "ip a show eth3 | "+
  203. "grep -v ether | "+
  204. // TODO: figure out why sometimes loopback is scope global
  205. "sed 's/scope host lo/scope XXXX lo/g' | sed 's/scope global lo/scope XXXX lo/g' | "+
  206. "sed 's/inet 10\\.0\\.2\\..*\\/24 brd/inet XX.XX.XX.XX\\/24 brd/' | "+
  207. "sed '/inet6 fe80::5054:ff:fe12:.*\\/64/!s/inet6 .*\\/64 scope/inet6 XX::XX:XX:XX:XX\\/64 scope/'",
  208. )
  209. }