2016-08-28 15:58:17 +00:00
package integration
import (
"fmt"
2017-01-30 03:07:05 +00:00
"time"
"strings"
2016-08-28 15:58:17 +00:00
. "gopkg.in/check.v1"
)
2017-01-30 03:07:05 +00:00
func ( s * QemuSuite ) TestUpgrade050 ( c * C ) {
2017-04-21 15:16:51 +00:00
// install 0.5.0, and then upgrade to `this` version
2017-05-16 03:35:19 +00:00
s . commonTestCode ( c , "v0.5.0" , "default" , "" )
}
func ( s * QemuSuite ) TestUpgrade061Docker1112 ( c * C ) {
// Test that by setting the Docker version to 1.11.2 (not the default in 0.6.1), that upgrading leaves it as 1.11.2
s . commonTestCode ( c , "v0.6.1" , "default" , "1.11.2" )
2017-02-03 03:47:08 +00:00
}
func ( s * QemuSuite ) TestUpgrade061 ( c * C ) {
2017-05-16 03:35:19 +00:00
s . commonTestCode ( c , "v0.6.1" , "debian" , "" )
2017-01-30 03:07:05 +00:00
}
func ( s * QemuSuite ) TestUpgrade070 ( c * C ) {
2017-05-16 03:35:19 +00:00
s . commonTestCode ( c , "v0.7.0" , "debian" , "" )
2017-01-30 03:07:05 +00:00
}
func ( s * QemuSuite ) TestUpgrade071 ( c * C ) {
2017-05-16 03:35:19 +00:00
s . commonTestCode ( c , "v0.7.1" , "default" , "" )
2017-02-03 03:47:08 +00:00
}
2017-04-21 15:16:51 +00:00
func ( s * QemuSuite ) TestUpgrade090 ( c * C ) {
2017-05-16 03:35:19 +00:00
s . commonTestCode ( c , "v0.9.0" , "default" , "" )
2017-04-21 15:16:51 +00:00
}
func ( s * QemuSuite ) TestUpgrade100 ( c * C ) {
2017-05-16 03:35:19 +00:00
s . commonTestCode ( c , "v1.0.0" , "default" , "" )
2017-04-21 15:16:51 +00:00
}
2017-02-03 03:47:08 +00:00
func ( s * QemuSuite ) TestUpgrade071Persistent ( c * C ) {
2017-05-16 03:35:19 +00:00
s . commonTestCode ( c , "v0.7.1" , "ubuntu" , "" )
2017-01-30 03:07:05 +00:00
}
func ( s * QemuSuite ) TestUpgrade080rc1 ( c * C ) {
2017-05-16 03:35:19 +00:00
s . commonTestCode ( c , "v0.8.0-rc1" , "debian" , "" )
2017-01-30 03:07:05 +00:00
}
func ( s * QemuSuite ) TestUpgrade080rc7 ( c * C ) {
2017-02-03 03:47:08 +00:00
// alpine console is unlikely to work before 0.8.0-rc5
2017-05-16 03:35:19 +00:00
s . commonTestCode ( c , "v0.8.0-rc7" , "alpine" , "" )
2017-01-30 03:07:05 +00:00
}
2017-03-23 04:17:21 +00:00
func ( s * QemuSuite ) TestUpgrade081Persistent ( c * C ) {
2017-05-16 03:35:19 +00:00
s . commonTestCode ( c , "v0.8.1" , "alpine" , "" )
2017-03-23 04:17:21 +00:00
}
func ( s * QemuSuite ) TestUpgrade081RollBack ( c * C ) {
2017-05-16 03:35:19 +00:00
s . commonTestCode ( c , "v0.7.1" , "default" , "" )
2017-03-23 04:17:21 +00:00
runArgs := [ ] string {
"--boothd" ,
}
{
// and now rollback to 0.8.1
thisVersion := "v0.8.1"
s . RunQemuWith ( c , runArgs ... )
s . CheckCall ( c , fmt . Sprintf ( "sudo ros os upgrade --no-reboot -i rancher/os:%s%s --force" , thisVersion , Suffix ) )
s . Reboot ( c )
s . CheckOutput ( c , "ros version " + thisVersion + "\n" , Equals , "sudo ros -v" )
s . Stop ( c )
}
{
// and now re-upgrade to latest
thisVersion := Version
s . RunQemuWith ( c , runArgs ... )
s . CheckCall ( c , fmt . Sprintf ( "sudo ros os upgrade --no-reboot -i rancher/os:%s%s --force" , thisVersion , Suffix ) )
s . Reboot ( c )
s . CheckOutput ( c , "ros version " + thisVersion + "\n" , Equals , "sudo ros -v" )
s . Stop ( c )
}
}
2017-01-30 03:07:05 +00:00
2017-02-03 03:47:08 +00:00
// DisabledTestUpgradeInner is used to debug the above tests if they fail - the current imple of the check code limits itself to depths _one_ stacktrace
func ( s * QemuSuite ) DisableTestUpgradeInner ( c * C ) {
startWithVersion := "v0.5.0"
// CENTOS fails due to "sudo: sorry, you must have a tty to run sudo" :) so we won't test with it atm
console := "debian"
2017-01-30 03:07:05 +00:00
runArgs := [ ] string {
"--iso" ,
"--fresh" ,
"--cloud-config" ,
"./tests/assets/test_12/cloud-config.yml" ,
}
version := ""
{
s . RunQemuWith ( c , runArgs ... )
version = s . CheckOutput ( c , version , Not ( Equals ) , "sudo ros -v" )
version = strings . TrimSpace ( strings . TrimPrefix ( version , "ros version" ) )
c . Assert ( Version , Equals , version )
fmt . Printf ( "installing %s" , startWithVersion )
2017-03-02 04:30:13 +00:00
s . PullAndLoadImage ( c , fmt . Sprintf ( "rancher/os:%s" , startWithVersion ) )
2017-01-30 06:11:46 +00:00
//ADD a custom append line and make sure its kept in the upgraded version too
2016-08-28 15:58:17 +00:00
2017-01-30 03:07:05 +00:00
s . CheckCall ( c , fmt . Sprintf ( `
echo "---------------------------------- generic"
2016-08-28 15:58:17 +00:00
set - ex
2017-05-16 03:35:19 +00:00
sudo cp / var / lib / rancher / conf / cloud - config . d / boot . yml config . yml
sudo chown rancher config . yml
2017-01-30 03:07:05 +00:00
sudo ros install -- force -- no - reboot -- device / dev / vda - c config . yml -- append rancher . password = rancher - i rancher / os : % s
sync
2017-01-30 06:11:46 +00:00
` , startWithVersion ) )
2017-01-30 03:07:05 +00:00
time . Sleep ( 500 * time . Millisecond )
s . Stop ( c )
}
2016-08-28 15:58:17 +00:00
2017-01-30 03:07:05 +00:00
// ./scripts/run --no-format --append "rancher.debug=true"
runArgs = [ ] string {
"--boothd" ,
}
s . RunQemuWith ( c , runArgs ... )
s . CheckOutput ( c , "ros version " + startWithVersion + "\n" , Equals , "sudo ros -v" )
2016-08-28 15:58:17 +00:00
2017-01-30 06:11:46 +00:00
if console != "default" {
// Can't preload the startWithVersion console image, as some don't exist by that name - not sure how to approach that
2017-03-02 04:30:13 +00:00
//s.PullAndLoadImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, startWithVersion))
2017-01-30 06:11:46 +00:00
// TODO: ouch. probably need to tag the dev / master version as latest cos this won't work
// Need to pull the image here - if we do it at boot, then the test will fail.
2017-03-02 04:30:13 +00:00
s . PullAndLoadImage ( c , fmt . Sprintf ( "rancher/os-%sconsole:%s" , console , "v0.8.0-rc3" ) )
2017-02-03 03:47:08 +00:00
s . MakeCall ( fmt . Sprintf ( "sudo ros console switch -f %s" , console ) )
c . Assert ( s . WaitForSSH ( ) , IsNil )
2017-01-30 06:11:46 +00:00
}
2017-02-03 03:47:08 +00:00
consoleVer := s . CheckOutput ( c , "" , Not ( Equals ) , "sudo system-docker ps --filter name=^/console$ --format {{.Image}}" )
2016-08-28 15:58:17 +00:00
s . LoadInstallerImage ( c )
2017-01-30 03:07:05 +00:00
s . CheckCall ( c , fmt . Sprintf ( "sudo ros os upgrade --no-reboot -i rancher/os:%s%s --force" , Version , Suffix ) )
2016-08-28 15:58:17 +00:00
s . Reboot ( c )
2017-01-30 03:07:05 +00:00
s . CheckOutput ( c , "ros version " + Version + "\n" , Equals , "sudo ros -v" )
2017-02-03 03:47:08 +00:00
s . CheckOutput ( c , consoleVer , Equals , "sudo system-docker ps --filter name=^/console$ --format {{.Image}}" )
2017-04-21 15:16:51 +00:00
// Make sure the original installed boot cmdline append value
s . CheckOutput ( c , ".*rancher.password=rancher.*" , Matches , "cat /proc/cmdline" )
2017-02-03 03:47:08 +00:00
s . Stop ( c )
}
2017-03-23 04:17:21 +00:00
2017-05-16 03:35:19 +00:00
func ( s * QemuSuite ) commonTestCode ( c * C , startWithVersion , console , dockerVersion string ) {
2017-02-03 03:47:08 +00:00
runArgs := [ ] string {
"--iso" ,
"--fresh" ,
"--cloud-config" ,
2017-05-16 03:35:19 +00:00
fmt . Sprintf ( "./tests/assets/test_12/cloud-config%s.yml" , dockerVersion ) ,
2017-02-03 03:47:08 +00:00
}
version := ""
{
s . RunQemuWith ( c , runArgs ... )
version = s . CheckOutput ( c , version , Not ( Equals ) , "sudo ros -v" )
version = strings . TrimSpace ( strings . TrimPrefix ( version , "ros version" ) )
c . Assert ( Version , Equals , version )
2017-05-16 03:35:19 +00:00
s . CheckOutputContains ( c , dockerVersion , "docker -v" )
2017-02-03 03:47:08 +00:00
fmt . Printf ( "installing %s" , startWithVersion )
2017-03-02 04:30:13 +00:00
s . PullAndLoadImage ( c , fmt . Sprintf ( "rancher/os:%s" , startWithVersion ) )
2017-02-03 03:47:08 +00:00
//ADD a custom append line and make sure its kept in the upgraded version too
s . CheckCall ( c , fmt . Sprintf ( `
echo "---------------------------------- generic"
set - ex
2017-05-16 03:35:19 +00:00
sudo cp / var / lib / rancher / conf / cloud - config . d / boot . yml config . yml
sudo chown rancher config . yml
2017-04-21 15:16:51 +00:00
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
2017-02-03 03:47:08 +00:00
sync
` , startWithVersion ) )
time . Sleep ( 500 * time . Millisecond )
s . Stop ( c )
}
// ./scripts/run --no-format --append "rancher.debug=true"
runArgs = [ ] string {
"--boothd" ,
}
s . RunQemuWith ( c , runArgs ... )
s . CheckOutput ( c , "ros version " + startWithVersion + "\n" , Equals , "sudo ros -v" )
2017-05-16 03:35:19 +00:00
s . CheckOutputContains ( c , dockerVersion , "docker -v" )
2017-02-03 03:47:08 +00:00
2017-04-21 15:16:51 +00:00
if startWithVersion != "v0.5.0" && startWithVersion != "v0.6.1" {
//s.CheckOutput(c, ".*password=ranc.*", Matches, "cat /proc/cmdline")
cmdline := s . CheckOutput ( c , "" , Not ( Equals ) , "cat /proc/cmdline" )
if ! strings . Contains ( cmdline , "rancher.password=rancher" ) {
c . Errorf ( "output(%s) does not contain(%s)" , cmdline , "rancher.password=rancher" )
}
if ! strings . Contains ( cmdline , "rancher.cloud_init.datasources=[invalid]" ) {
c . Errorf ( "output(%s) does not contain(%s)" , cmdline , "rancher.cloud_init.datasources=[invalid]" )
}
}
2017-02-03 03:47:08 +00:00
if console != "default" {
// Can't preload the startWithVersion console image, as some don't exist by that name - not sure how to approach that
2017-03-02 04:30:13 +00:00
//s.PullAndLoadImage(c, fmt.Sprintf("rancher/os-%sconsole:%s", console, startWithVersion))
2017-02-03 03:47:08 +00:00
// TODO: ouch. probably need to tag the dev / master version as latest cos this won't work
// Need to pull the image here - if we do it at boot, then the test will fail.
if console == "alpine" {
2017-03-02 04:30:13 +00:00
s . PullAndLoadImage ( c , fmt . Sprintf ( "rancher/os-%sconsole:%s" , console , "v0.8.0-rc5" ) )
2017-02-03 03:47:08 +00:00
} else {
2017-03-02 04:30:13 +00:00
s . PullAndLoadImage ( c , fmt . Sprintf ( "rancher/os-%sconsole:%s" , console , "v0.8.0-rc3" ) )
2017-02-03 03:47:08 +00:00
}
s . MakeCall ( fmt . Sprintf ( "sudo ros console switch -f %s" , console ) )
c . Assert ( s . WaitForSSH ( ) , IsNil )
}
consoleVer := s . CheckOutput ( c , "" , Not ( Equals ) , "sudo system-docker ps --filter name=^/console$ --format {{.Image}}" )
s . LoadInstallerImage ( c )
s . CheckCall ( c , fmt . Sprintf ( "sudo ros os upgrade --no-reboot -i rancher/os:%s%s --force" , Version , Suffix ) )
s . Reboot ( c )
s . CheckOutput ( c , "ros version " + Version + "\n" , Equals , "sudo ros -v" )
if console != "default" {
s . CheckOutput ( c , consoleVer , Equals , "sudo system-docker ps --filter name=^/console$ --format {{.Image}}" )
} else {
s . CheckOutput ( c , consoleVer , Not ( Equals ) , "sudo system-docker ps --filter name=^/console$ --format {{.Image}}" )
}
2016-08-28 15:58:17 +00:00
2017-05-16 03:35:19 +00:00
s . CheckOutputContains ( c , dockerVersion , "docker -v" )
2017-04-21 15:16:51 +00:00
if startWithVersion != "v0.5.0" && startWithVersion != "v0.6.1" {
// Make sure the original installed boot cmdline append value
// s.CheckOutput(c, ".*rancher.password=rancher.*", Matches, "cat /proc/cmdline")
cmdline := s . CheckOutput ( c , "" , Not ( Equals ) , "cat /proc/cmdline" )
if ! strings . Contains ( cmdline , "rancher.password=rancher" ) {
c . Errorf ( "output(%s) does not contain(%s)" , cmdline , "rancher.password=rancher" )
}
if ! strings . Contains ( cmdline , "rancher.cloud_init.datasources=[invalid]" ) {
c . Errorf ( "output(%s) does not contain(%s)" , cmdline , "rancher.cloud_init.datasources=[invalid]" )
}
}
2017-01-30 03:07:05 +00:00
s . Stop ( c )
2016-08-28 15:58:17 +00:00
}