upgrade_test.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. s.commonTestCode(c, "v0.5.0", "default")
  10. }
  11. func (s *QemuSuite) TestUpgrade061(c *C) {
  12. s.commonTestCode(c, "v0.6.1", "debian")
  13. }
  14. func (s *QemuSuite) TestUpgrade070(c *C) {
  15. s.commonTestCode(c, "v0.7.0", "debian")
  16. }
  17. func (s *QemuSuite) TestUpgrade071(c *C) {
  18. s.commonTestCode(c, "v0.7.1", "default")
  19. }
  20. func (s *QemuSuite) TestUpgrade071Persistent(c *C) {
  21. s.commonTestCode(c, "v0.7.1", "ubuntu")
  22. }
  23. func (s *QemuSuite) TestUpgrade080rc1(c *C) {
  24. s.commonTestCode(c, "v0.8.0-rc1", "debian")
  25. }
  26. func (s *QemuSuite) TestUpgrade080rc7(c *C) {
  27. // alpine console is unlikely to work before 0.8.0-rc5
  28. s.commonTestCode(c, "v0.8.0-rc7", "alpine")
  29. }
  30. // DisabledTestUpgradeInner is used to debug the above tests if they fail - the current imple of the check code limits itself to depths _one_ stacktrace
  31. func (s *QemuSuite) DisableTestUpgradeInner(c *C) {
  32. startWithVersion := "v0.5.0"
  33. // CENTOS fails due to "sudo: sorry, you must have a tty to run sudo" :) so we won't test with it atm
  34. console := "debian"
  35. runArgs := []string{
  36. "--iso",
  37. "--fresh",
  38. "--cloud-config",
  39. "./tests/assets/test_12/cloud-config.yml",
  40. }
  41. version := ""
  42. {
  43. s.RunQemuWith(c, runArgs...)
  44. version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v")
  45. version = strings.TrimSpace(strings.TrimPrefix(version, "ros version"))
  46. c.Assert(Version, Equals, version)
  47. fmt.Printf("installing %s", startWithVersion)
  48. s.PullAndLoadInstallerImage(c, fmt.Sprintf("rancher/os:%s", startWithVersion))
  49. //ADD a custom append line and make sure its kept in the upgraded version too
  50. s.CheckCall(c, fmt.Sprintf(`
  51. echo "---------------------------------- generic"
  52. set -ex
  53. echo "ssh_authorized_keys:" > config.yml
  54. echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
  55. sudo ros install --force --no-reboot --device /dev/vda -c config.yml --append rancher.password=rancher -i rancher/os:%s
  56. sync
  57. `, startWithVersion))
  58. time.Sleep(500 * time.Millisecond)
  59. s.Stop(c)
  60. }
  61. // ./scripts/run --no-format --append "rancher.debug=true"
  62. runArgs = []string{
  63. "--boothd",
  64. }
  65. s.RunQemuWith(c, runArgs...)
  66. s.CheckOutput(c, "ros version "+startWithVersion+"\n", Equals, "sudo ros -v")
  67. if console != "default" {
  68. // Can't preload the startWithVersion console image, as some don't exist by that name - not sure how to approach that
  69. //s.PullAndLoadInstallerImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, startWithVersion))
  70. // TODO: ouch. probably need to tag the dev / master version as latest cos this won't work
  71. // Need to pull the image here - if we do it at boot, then the test will fail.
  72. s.PullAndLoadInstallerImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, "v0.8.0-rc3"))
  73. s.MakeCall(fmt.Sprintf("sudo ros console switch -f %s", console))
  74. c.Assert(s.WaitForSSH(), IsNil)
  75. }
  76. consoleVer := s.CheckOutput(c, "", Not(Equals), "sudo system-docker ps --filter name=^/console$ --format {{.Image}}")
  77. s.LoadInstallerImage(c)
  78. s.CheckCall(c, fmt.Sprintf("sudo ros os upgrade --no-reboot -i rancher/os:%s%s --force", Version, Suffix))
  79. s.Reboot(c)
  80. s.CheckOutput(c, "ros version "+Version+"\n", Equals, "sudo ros -v")
  81. s.CheckOutput(c, consoleVer, Equals, "sudo system-docker ps --filter name=^/console$ --format {{.Image}}")
  82. s.Stop(c)
  83. }
  84. func (s *QemuSuite) commonTestCode(c *C, startWithVersion, console string) {
  85. runArgs := []string{
  86. "--iso",
  87. "--fresh",
  88. "--cloud-config",
  89. "./tests/assets/test_12/cloud-config.yml",
  90. }
  91. version := ""
  92. {
  93. s.RunQemuWith(c, runArgs...)
  94. version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v")
  95. version = strings.TrimSpace(strings.TrimPrefix(version, "ros version"))
  96. c.Assert(Version, Equals, version)
  97. fmt.Printf("installing %s", startWithVersion)
  98. s.PullAndLoadInstallerImage(c, fmt.Sprintf("rancher/os:%s", startWithVersion))
  99. //ADD a custom append line and make sure its kept in the upgraded version too
  100. s.CheckCall(c, fmt.Sprintf(`
  101. echo "---------------------------------- generic"
  102. set -ex
  103. echo "ssh_authorized_keys:" > config.yml
  104. echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
  105. sudo ros install --force --no-reboot --device /dev/vda -c config.yml --append rancher.password=rancher -i rancher/os:%s
  106. sync
  107. `, startWithVersion))
  108. time.Sleep(500 * time.Millisecond)
  109. s.Stop(c)
  110. }
  111. // ./scripts/run --no-format --append "rancher.debug=true"
  112. runArgs = []string{
  113. "--boothd",
  114. }
  115. s.RunQemuWith(c, runArgs...)
  116. s.CheckOutput(c, "ros version "+startWithVersion+"\n", Equals, "sudo ros -v")
  117. if console != "default" {
  118. // Can't preload the startWithVersion console image, as some don't exist by that name - not sure how to approach that
  119. //s.PullAndLoadInstallerImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, startWithVersion))
  120. // TODO: ouch. probably need to tag the dev / master version as latest cos this won't work
  121. // Need to pull the image here - if we do it at boot, then the test will fail.
  122. if console == "alpine" {
  123. s.PullAndLoadInstallerImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, "v0.8.0-rc5"))
  124. } else {
  125. s.PullAndLoadInstallerImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, "v0.8.0-rc3"))
  126. }
  127. s.MakeCall(fmt.Sprintf("sudo ros console switch -f %s", console))
  128. c.Assert(s.WaitForSSH(), IsNil)
  129. }
  130. consoleVer := s.CheckOutput(c, "", Not(Equals), "sudo system-docker ps --filter name=^/console$ --format {{.Image}}")
  131. s.LoadInstallerImage(c)
  132. s.CheckCall(c, fmt.Sprintf("sudo ros os upgrade --no-reboot -i rancher/os:%s%s --force", Version, Suffix))
  133. s.Reboot(c)
  134. s.CheckOutput(c, "ros version "+Version+"\n", Equals, "sudo ros -v")
  135. if console != "default" {
  136. s.CheckOutput(c, consoleVer, Equals, "sudo system-docker ps --filter name=^/console$ --format {{.Image}}")
  137. } else {
  138. s.CheckOutput(c, consoleVer, Not(Equals), "sudo system-docker ps --filter name=^/console$ --format {{.Image}}")
  139. }
  140. s.Stop(c)
  141. }