installer_test.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. package integration
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. . "gopkg.in/check.v1"
  7. )
  8. func (s *QemuSuite) TestInstallMsDosMbr(c *C) {
  9. // test_17 cloud config is an invalid http proxy cfg, so the installer has no network
  10. runArgs := []string{
  11. "--iso",
  12. "--fresh",
  13. "--cloud-config",
  14. "./tests/assets/test_17/cloud-config.yml",
  15. }
  16. version := ""
  17. {
  18. s.RunQemuWith(c, runArgs...)
  19. version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v")
  20. fmt.Printf("installing %s", version)
  21. s.CheckCall(c, `
  22. echo "---------------------------------- generic"
  23. set -ex
  24. sudo parted /dev/vda print
  25. echo "ssh_authorized_keys:" > config.yml
  26. echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
  27. sudo ros install --force --no-reboot --device /dev/vda -c config.yml --append rancher.password=rancher
  28. sync
  29. `)
  30. time.Sleep(500 * time.Millisecond)
  31. s.Stop(c)
  32. }
  33. // ./scripts/run --no-format --append "rancher.debug=true"
  34. runArgs = []string{
  35. "--boothd",
  36. }
  37. s.RunQemuWith(c, runArgs...)
  38. s.CheckOutput(c, version, Equals, "sudo ros -v")
  39. s.Stop(c)
  40. }
  41. func (s *QemuSuite) TestInstallGptMbr(c *C) {
  42. // ./scripts/run --no-format --append "rancher.debug=true" --iso --fresh
  43. runArgs := []string{
  44. "--iso",
  45. "--fresh",
  46. }
  47. version := ""
  48. {
  49. s.RunQemuWith(c, runArgs...)
  50. version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v")
  51. fmt.Printf("installing %s", version)
  52. s.CheckCall(c, `
  53. echo "---------------------------------- gptsyslinux"
  54. set -ex
  55. sudo parted /dev/vda print
  56. echo "ssh_authorized_keys:" > config.yml
  57. echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
  58. sudo ros install --force --no-reboot --device /dev/vda -t gptsyslinux -c config.yml
  59. sync
  60. `)
  61. time.Sleep(500 * time.Millisecond)
  62. s.Stop(c)
  63. }
  64. // ./scripts/run --no-format --append "rancher.debug=true"
  65. runArgs = []string{
  66. "--boothd",
  67. }
  68. s.RunQemuWith(c, runArgs...)
  69. s.CheckOutput(c, version, Equals, "sudo ros -v")
  70. // TEST parted output? (gpt non-uefi == legacy_boot)
  71. s.Stop(c)
  72. }
  73. func (s *QemuSuite) TestInstallAlpine(c *C) {
  74. // ./scripts/run --no-format --append "rancher.debug=true" --iso --fresh
  75. runArgs := []string{
  76. "--iso",
  77. "--fresh",
  78. }
  79. version := ""
  80. {
  81. s.RunQemuWith(c, runArgs...)
  82. s.MakeCall("sudo ros console switch -f alpine")
  83. c.Assert(s.WaitForSSH(), IsNil)
  84. version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v")
  85. fmt.Printf("installing %s", version)
  86. s.CheckCall(c, `
  87. set -ex
  88. echo "ssh_authorized_keys:" > config.yml
  89. echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
  90. sudo ros install --force --no-reboot --device /dev/vda -c config.yml
  91. sync
  92. `)
  93. time.Sleep(500 * time.Millisecond)
  94. s.Stop(c)
  95. }
  96. // ./scripts/run --no-format --append "rancher.debug=true"
  97. runArgs = []string{
  98. "--boothd",
  99. }
  100. s.RunQemuWith(c, runArgs...)
  101. s.CheckOutput(c, version, Equals, "sudo ros -v")
  102. s.Stop(c)
  103. }
  104. func (s *QemuSuite) TestAutoResize(c *C) {
  105. runArgs := []string{
  106. "--iso",
  107. "--fresh",
  108. }
  109. version := ""
  110. disk := "/dev/vda1\n"
  111. size := ""
  112. {
  113. s.RunQemuWith(c, runArgs...)
  114. version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v")
  115. fmt.Printf("installing %s", version)
  116. s.CheckCall(c, `
  117. set -ex
  118. echo "ssh_authorized_keys:" > config.yml
  119. echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
  120. sudo ros install --force --no-reboot --device /dev/vda -c config.yml --append "rancher.resize_device=/dev/vda"
  121. sync
  122. `)
  123. time.Sleep(500 * time.Millisecond)
  124. s.CheckCall(c, "sudo mount "+strings.TrimSpace(disk)+" /mnt")
  125. size = s.CheckOutput(c, size, Not(Equals), "df -h | grep "+strings.TrimSpace(disk)+" | head -n1 | sed 's/ \\+/;/g' | cut -d ';' -f 2")
  126. s.Stop(c)
  127. }
  128. // ./scripts/run --no-format --append "rancher.debug=true"
  129. runArgs = []string{
  130. "--boothd",
  131. "--resizehd", "+20G",
  132. }
  133. s.RunQemuWith(c, runArgs...)
  134. s.CheckOutput(c, version, Equals, "sudo ros -v")
  135. s.CheckOutput(c, disk, Equals, "blkid | cut -f 1 -d ' ' | sed 's/://'")
  136. s.CheckOutput(c, size, Not(Equals), "df -h | grep "+strings.TrimSpace(disk)+" | head -n1 | sed 's/ \\+/;/g' | cut -d ';' -f 2")
  137. s.Stop(c)
  138. }
  139. func (s *QemuSuite) KillsMyServerTestInstalledDhcp(c *C) {
  140. // ./scripts/run --no-format --append "rancher.debug=true" --iso --fresh
  141. runArgs := []string{
  142. "--iso",
  143. "--fresh",
  144. // "-net", "nic,vlan=0,model=virtio",
  145. // "-net", "user,vlan=0",
  146. // "-net", "nic,vlan=0,model=virtio",
  147. // "-net", "user,vlan=0",
  148. }
  149. version := ""
  150. {
  151. s.RunQemuWith(c, runArgs...)
  152. s.MakeCall("ip a")
  153. version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v")
  154. fmt.Printf("installing %s", version)
  155. s.CheckCall(c, `
  156. echo "ssh_authorized_keys:" > config.yml
  157. echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
  158. echo "rancher:" >> config.yml
  159. echo " network:" >> config.yml
  160. echo " interfaces:" >> config.yml
  161. echo " eth2:" >> config.yml
  162. echo " dhcp: true" >> config.yml
  163. echo " eth1:" >> config.yml
  164. echo " address: 10.0.2.253/24" >> config.yml
  165. echo " dhcp: false" >> config.yml
  166. echo " gateway: 10.0.2.1" >> config.yml
  167. echo " mtu: 1500" >> config.yml
  168. ip a
  169. echo "==================="
  170. cat config.yml | sudo ros config merge
  171. sudo ros service stop network
  172. sleep 1
  173. sudo ros service start network
  174. sleep 1
  175. ip a
  176. echo "==================="
  177. sudo ros install --force --no-reboot --device /dev/vda -c config.yml -a "console=ttyS0 rancher.console=ttyS0 rancher.autologin=ttyS0 rancher.console=ttyS1 rancher.autologin=ttyS1 rancher.debug=true"
  178. sync
  179. `)
  180. time.Sleep(500 * time.Millisecond)
  181. s.Stop(c)
  182. }
  183. runArgs = []string{
  184. "--boothd",
  185. "-net", "nic,vlan=0,model=virtio",
  186. "-net", "user,vlan=0",
  187. "-net", "nic,vlan=0,model=virtio",
  188. "-net", "user,vlan=0",
  189. }
  190. s.RunQemuWithNetConsole(c, runArgs...)
  191. s.NetCheckOutput(c, version, Equals, "sudo ros -v")
  192. s.NetCheckOutput(c, "", Not(Equals), "sh", "-c", "ip a show eth1 | grep 10.0.2..253")
  193. s.Stop(c)
  194. }
  195. func (s *QemuSuite) TestConfigDhcp(c *C) {
  196. runArgs := []string{
  197. "--iso",
  198. "--fresh",
  199. "-net", "nic,vlan=0,model=virtio",
  200. "-net", "user,vlan=0",
  201. "-net", "nic,vlan=0,model=virtio",
  202. "-net", "user,vlan=0",
  203. }
  204. version := ""
  205. {
  206. s.RunQemuWithNetConsole(c, runArgs...)
  207. s.NetCall("ip a")
  208. version = s.NetCheckOutput(c, version, Not(Equals), "sudo ros -v")
  209. fmt.Printf("installing %s", version)
  210. s.NetCheckCall(c, `
  211. echo "ssh_authorized_keys:" > config.yml
  212. echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
  213. echo "rancher:" >> config.yml
  214. echo " network:" >> config.yml
  215. echo " interfaces:" >> config.yml
  216. echo " eth2:" >> config.yml
  217. echo " dhcp: true" >> config.yml
  218. echo " eth1:" >> config.yml
  219. echo " address: 10.0.2.253/24" >> config.yml
  220. echo " dhcp: false" >> config.yml
  221. echo " gateway: 10.0.2.1" >> config.yml
  222. echo " mtu: 1500" >> config.yml
  223. ip a
  224. echo "==================="
  225. cat config.yml | sudo ros config merge
  226. sudo ros service stop network
  227. sleep 1
  228. sudo ros service start network
  229. sleep 1
  230. echo "==================="
  231. sudo system-docker logs network
  232. echo "==================="
  233. ip a
  234. `)
  235. s.NetCheckOutput(c, version, Equals, "sudo ros -v")
  236. s.NetCheckOutput(c, "", Not(Equals), "sh", "-c", "\"ip a show eth1 | grep 10.0.2.253\"")
  237. s.Stop(c)
  238. }
  239. }