upgrade_test.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package integration
  2. import (
  3. "fmt"
  4. "time"
  5. "strings"
  6. . "gopkg.in/check.v1"
  7. )
  8. func (s *QemuSuite) TestUpgrade050(c *C) {
  9. // install 0.5.0, and then upgrade to `this` version
  10. s.commonTestCode(c, "v0.5.0", "default", "")
  11. }
  12. func (s *QemuSuite) DISABLEDTestUpgrade061Docker1131(c *C) {
  13. // Test that by setting the Docker version to 1.13.1 (not the default in 0.6.1), that upgrading leaves it as 1.13.1
  14. s.commonTestCode(c, "v0.6.1", "default", "1.13.1")
  15. }
  16. func (s *QemuSuite) TestUpgrade061(c *C) {
  17. s.commonTestCode(c, "v0.6.1", "debian", "")
  18. }
  19. func (s *QemuSuite) TestUpgrade070(c *C) {
  20. s.commonTestCode(c, "v0.7.0", "debian", "")
  21. }
  22. func (s *QemuSuite) TestUpgrade071(c *C) {
  23. s.commonTestCode(c, "v0.7.1", "default", "")
  24. }
  25. func (s *QemuSuite) TestUpgrade090(c *C) {
  26. s.commonTestCode(c, "v0.9.0", "default", "")
  27. }
  28. func (s *QemuSuite) TestUpgrade100(c *C) {
  29. s.commonTestCode(c, "v1.0.0", "default", "")
  30. }
  31. func (s *QemuSuite) TestUpgrade071Persistent(c *C) {
  32. s.commonTestCode(c, "v0.7.1", "ubuntu", "")
  33. }
  34. func (s *QemuSuite) TestUpgrade080rc1(c *C) {
  35. s.commonTestCode(c, "v0.8.0-rc1", "debian", "")
  36. }
  37. func (s *QemuSuite) TestUpgrade080rc7(c *C) {
  38. // alpine console is unlikely to work before 0.8.0-rc5
  39. s.commonTestCode(c, "v0.8.0-rc7", "alpine", "")
  40. }
  41. func (s *QemuSuite) TestUpgrade081Persistent(c *C) {
  42. s.commonTestCode(c, "v0.8.1", "alpine", "")
  43. }
  44. func (s *QemuSuite) TestUpgrade081RollBack(c *C) {
  45. s.commonTestCode(c, "v0.7.1", "default", "")
  46. runArgs := []string{
  47. "--boothd",
  48. }
  49. {
  50. // and now rollback to 0.8.1
  51. thisVersion := "v0.8.1"
  52. s.RunQemuWith(c, runArgs...)
  53. s.CheckCall(c, fmt.Sprintf("sudo ros os upgrade --no-reboot -i rancher/os:%s%s --force", thisVersion, Suffix))
  54. s.Reboot(c)
  55. s.CheckOutput(c, "ros version "+thisVersion+"\n", Equals, "sudo ros -v")
  56. s.Stop(c)
  57. }
  58. {
  59. // and now re-upgrade to latest
  60. thisVersion := Version
  61. s.RunQemuWith(c, runArgs...)
  62. s.CheckCall(c, fmt.Sprintf("sudo ros os upgrade --no-reboot -i rancher/os:%s%s --force", thisVersion, Suffix))
  63. s.Reboot(c)
  64. s.CheckOutput(c, "ros version "+thisVersion+"\n", Equals, "sudo ros -v")
  65. s.Stop(c)
  66. }
  67. }
  68. // DisabledTestUpgradeInner is used to debug the above tests if they fail - the current imple of the check code limits itself to depths _one_ stacktrace
  69. func (s *QemuSuite) DisableTestUpgradeInner(c *C) {
  70. startWithVersion := "v0.5.0"
  71. // CENTOS fails due to "sudo: sorry, you must have a tty to run sudo" :) so we won't test with it atm
  72. console := "debian"
  73. runArgs := []string{
  74. "--iso",
  75. "--fresh",
  76. "--cloud-config",
  77. "./tests/assets/test_12/cloud-config.yml",
  78. }
  79. version := ""
  80. {
  81. s.RunQemuWith(c, runArgs...)
  82. version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v")
  83. version = strings.TrimSpace(strings.TrimPrefix(version, "ros version"))
  84. c.Assert(Version, Equals, version)
  85. fmt.Printf("installing %s", startWithVersion)
  86. s.PullAndLoadImage(c, fmt.Sprintf("rancher/os:%s", startWithVersion))
  87. //ADD a custom append line and make sure its kept in the upgraded version too
  88. s.CheckCall(c, fmt.Sprintf(`
  89. echo "---------------------------------- generic"
  90. set -ex
  91. sudo cp /var/lib/rancher/conf/cloud-config.d/boot.yml config.yml
  92. sudo chown rancher config.yml
  93. sudo ros install --force --no-reboot --device /dev/vda -c config.yml --append rancher.password=rancher -i rancher/os:%s
  94. sync
  95. `, startWithVersion))
  96. time.Sleep(500 * time.Millisecond)
  97. s.Stop(c)
  98. }
  99. // ./scripts/run --no-format --append "rancher.debug=true"
  100. runArgs = []string{
  101. "--boothd",
  102. }
  103. s.RunQemuWith(c, runArgs...)
  104. s.CheckOutput(c, "ros version "+startWithVersion+"\n", Equals, "sudo ros -v")
  105. if console != "default" {
  106. // Can't preload the startWithVersion console image, as some don't exist by that name - not sure how to approach that
  107. //s.PullAndLoadImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, startWithVersion))
  108. // TODO: ouch. probably need to tag the dev / master version as latest cos this won't work
  109. // Need to pull the image here - if we do it at boot, then the test will fail.
  110. s.PullAndLoadImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, "v0.8.0-rc3"))
  111. s.MakeCall(fmt.Sprintf("sudo ros console switch -f %s", console))
  112. c.Assert(s.WaitForSSH(), IsNil)
  113. }
  114. consoleVer := s.CheckOutput(c, "", Not(Equals), "sudo system-docker ps --filter name=^/console$ --format {{.Image}}")
  115. s.LoadInstallerImage(c)
  116. s.CheckCall(c, fmt.Sprintf("sudo ros os upgrade --no-reboot -i rancher/os:%s%s --force", Version, Suffix))
  117. s.Reboot(c)
  118. s.CheckOutput(c, "ros version "+Version+"\n", Equals, "sudo ros -v")
  119. s.CheckOutput(c, consoleVer, Equals, "sudo system-docker ps --filter name=^/console$ --format {{.Image}}")
  120. // Make sure the original installed boot cmdline append value
  121. s.CheckOutput(c, ".*rancher.password=rancher.*", Matches, "cat /proc/cmdline")
  122. s.Stop(c)
  123. }
  124. func (s *QemuSuite) commonTestCode(c *C, startWithVersion, console, dockerVersion string) {
  125. runArgs := []string{
  126. "--iso",
  127. "--fresh",
  128. "--cloud-config",
  129. fmt.Sprintf("./tests/assets/test_12/cloud-config%s.yml", dockerVersion),
  130. }
  131. version := ""
  132. {
  133. s.RunQemuWith(c, runArgs...)
  134. version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v")
  135. version = strings.TrimSpace(strings.TrimPrefix(version, "ros version"))
  136. c.Assert(Version, Equals, version)
  137. s.CheckOutputContains(c, dockerVersion, "docker -v")
  138. fmt.Printf("installing %s", startWithVersion)
  139. s.PullAndLoadImage(c, fmt.Sprintf("rancher/os:%s", startWithVersion))
  140. //ADD a custom append line and make sure its kept in the upgraded version too
  141. s.CheckCall(c, fmt.Sprintf(`
  142. echo "---------------------------------- generic"
  143. set -ex
  144. sudo cp /var/lib/rancher/conf/cloud-config.d/boot.yml config.yml
  145. sudo chown rancher config.yml
  146. sudo ros install --force --no-reboot --device /dev/vda -c config.yml --append "rancher.password=rancher rancher.cloud_init.datasources=[invalid]" -i rancher/os:%s
  147. sync
  148. `, startWithVersion))
  149. time.Sleep(500 * time.Millisecond)
  150. s.Stop(c)
  151. }
  152. // ./scripts/run --no-format --append "rancher.debug=true"
  153. runArgs = []string{
  154. "--boothd",
  155. }
  156. s.RunQemuWith(c, runArgs...)
  157. s.CheckOutput(c, "ros version "+startWithVersion+"\n", Equals, "sudo ros -v")
  158. s.CheckOutputContains(c, dockerVersion, "docker -v")
  159. if startWithVersion != "v0.5.0" && startWithVersion != "v0.6.1" {
  160. //s.CheckOutput(c, ".*password=ranc.*", Matches, "cat /proc/cmdline")
  161. cmdline := s.CheckOutput(c, "", Not(Equals), "cat /proc/cmdline")
  162. if !strings.Contains(cmdline, "rancher.password=rancher") {
  163. c.Errorf("output(%s) does not contain(%s)", cmdline, "rancher.password=rancher")
  164. }
  165. if !strings.Contains(cmdline, "rancher.cloud_init.datasources=[invalid]") {
  166. c.Errorf("output(%s) does not contain(%s)", cmdline, "rancher.cloud_init.datasources=[invalid]")
  167. }
  168. }
  169. if console != "default" {
  170. // Can't preload the startWithVersion console image, as some don't exist by that name - not sure how to approach that
  171. //s.PullAndLoadImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, startWithVersion))
  172. // TODO: ouch. probably need to tag the dev / master version as latest cos this won't work
  173. // Need to pull the image here - if we do it at boot, then the test will fail.
  174. if console == "alpine" {
  175. s.PullAndLoadImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, "v0.8.0-rc5"))
  176. } else {
  177. s.PullAndLoadImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, "v0.8.0-rc3"))
  178. }
  179. s.MakeCall(fmt.Sprintf("sudo ros console switch -f %s", console))
  180. c.Assert(s.WaitForSSH(), IsNil)
  181. }
  182. consoleVer := s.CheckOutput(c, "", Not(Equals), "sudo system-docker ps --filter name=^/console$ --format {{.Image}}")
  183. s.LoadInstallerImage(c)
  184. s.CheckCall(c, fmt.Sprintf("sudo ros os upgrade --no-reboot -i rancher/os:%s%s --force", Version, Suffix))
  185. s.Reboot(c)
  186. s.CheckOutput(c, "ros version "+Version+"\n", Equals, "sudo ros -v")
  187. if console != "default" {
  188. s.CheckOutput(c, consoleVer, Equals, "sudo system-docker ps --filter name=^/console$ --format {{.Image}}")
  189. } else {
  190. s.CheckOutput(c, consoleVer, Not(Equals), "sudo system-docker ps --filter name=^/console$ --format {{.Image}}")
  191. }
  192. s.CheckOutputContains(c, dockerVersion, "docker -v")
  193. if startWithVersion != "v0.5.0" && startWithVersion != "v0.6.1" {
  194. // Make sure the original installed boot cmdline append value
  195. // s.CheckOutput(c, ".*rancher.password=rancher.*", Matches, "cat /proc/cmdline")
  196. cmdline := s.CheckOutput(c, "", Not(Equals), "cat /proc/cmdline")
  197. if !strings.Contains(cmdline, "rancher.password=rancher") {
  198. c.Errorf("output(%s) does not contain(%s)", cmdline, "rancher.password=rancher")
  199. }
  200. if !strings.Contains(cmdline, "rancher.cloud_init.datasources=[invalid]") {
  201. c.Errorf("output(%s) does not contain(%s)", cmdline, "rancher.cloud_init.datasources=[invalid]")
  202. }
  203. }
  204. s.Stop(c)
  205. }