From 9e24500d13d6f3c0e10c519923b9d79bbdfd2031 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 19 Feb 2014 13:07:15 +0000 Subject: Make tests be short and clear, and fix shared user data test --- test_trove_upgrades.py | 80 +++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 49 deletions(-) diff --git a/test_trove_upgrades.py b/test_trove_upgrades.py index 9cb7017..898383f 100644 --- a/test_trove_upgrades.py +++ b/test_trove_upgrades.py @@ -456,6 +456,25 @@ class BaseTestSuite(object): class TestUpgrades(BaseTestSuite): + def upgrade_to_latest_trove(self, workspace_dir, instance): + branch = self.create_system_branch(workspace_dir, 'current') + upgrade = TroveUpgrade(branch) + upgrade.create_config(instance, upgrade_method='ssh-rsync', + version_label='trove-current') + upgrade.run_build() + upgrade.run_deploy(autostart=True) + self.wait_for_machine_to_boot(instance) + + def rollback_system_to_factory(self, instance, version_label): + try: + instance.runcmd(['snapshot-mgr', 'set-default', version_label]) + instance.runcmd(['reboot']) + except cliapp.AppException: + # Bit of a hack because we get disconnect before the command + # exits so SSH returns failure. + pass + self.wait_for_machine_to_boot(instance) + def get_lighttpd_version(self, instance, expected_start=None): text = instance.runcmd(['lighttpd', '-v']) version_string = text.split(' ')[0] @@ -537,28 +556,12 @@ class TestUpgrades(BaseTestSuite): with self.given_out_of_date_trove_instance( fixture_dir, reuse=reuse_fixture) as instance: - branch = self.create_system_branch(workspace_dir, 'current') - old_lighttpd_version = self.get_lighttpd_version(instance) - upgrade = TroveUpgrade(branch) - upgrade.create_config(instance, upgrade_method='ssh-rsync', - version_label='trove-current') - upgrade.run_build() - upgrade.run_deploy(autostart=True) - - self.wait_for_machine_to_boot(instance) + self.upgrade_to_latest_trove(workspace_dir, instance) new_lighttpd_version = self.get_lighttpd_version(instance) - try: - instance.runcmd(['snapshot-mgr', 'set-default', 'factory']) - instance.runcmd(['reboot']) - except cliapp.AppException: - # Bit of a hack because we get disconnect before the command - # exits so SSH returns failure. - pass - - self.wait_for_machine_to_boot(instance) + self.rollback_system_to_factory(instance) rollback_lighttpd_version = self.get_lighttpd_version(instance) if config.VERBOSE: @@ -566,8 +569,8 @@ class TestUpgrades(BaseTestSuite): print "Upgraded system lighttpd version: %s" % new_lighttpd_version print "Lighttpd version after rollback: %s" % rollback_lighttpd_version - assert old_lighttpd_version == rollback_lighttpd_version assert new_lighttpd_version > old_lighttpd_version + assert old_lighttpd_version == rollback_lighttpd_version def get_linux_version(self, instance, expected_start=None): text = instance.runcmd(['uname', '--kernel-release']) @@ -619,35 +622,19 @@ class TestUpgrades(BaseTestSuite): WHEN Bob builds and upgrades to the current version of Trove with AUTOSTART=1 THEN the Trove uses the standard version of Linux used Baserock master - WHEN Bob rolls back to the old version of Linux + WHEN Bob rolls back to the old version of the system THEN the Trove uses Linux 3.6 ''' with self.given_trove_instance_with_old_kernel( fixture_dir, reuse=reuse_fixture) as instance: - branch = self.create_system_branch(workspace_dir, 'current') - old_linux_version = self.get_linux_version(instance) - upgrade = TroveUpgrade(branch) - upgrade.create_config(instance, upgrade_method='ssh-rsync', - version_label='trove-current') - upgrade.run_build() - upgrade.run_deploy(autostart=True) - - self.wait_for_machine_to_boot(instance) + self.upgrade_to_latest_trove(workspace_dir, instance) new_linux_version = self.get_linux_version(instance) - try: - instance.runcmd(['snapshot-mgr', 'set-default', 'factory']) - instance.runcmd(['reboot']) - except cliapp.AppException: - # Bit of a hack because we get disconnect before the command - # exits so SSH returns failure. - pass - - self.wait_for_machine_to_boot(instance) + self.rollback_system_to_factory(instance) rollback_linux_version = self.get_linux_version( instance, expected_start=='3.6') @@ -686,22 +673,16 @@ class TestUpgrades(BaseTestSuite): with self.given_out_of_date_trove_instance( fixture_dir, reuse=reuse_fixture) as instance: - branch = self.create_system_branch(workspace_dir, 'current') - for statedir in statedirs: - cmd = 'echo "Test user data" > %s/TEST_FILE' % statedir - instance.runcmd(['sh', 'c', cmd]) + cmd = '\"echo \\"Test user data\\" > %s/TEST_FILE\"' % statedir + instance.runcmd(['sh', '-c', cmd]) - upgrade = TroveUpgrade(branch) - upgrade.create_config(instance, upgrade_method='ssh-rsync') - upgrade.run_build() - upgrade.run_deploy() + self.upgrade_to_latest_trove(workspace_dir, instance) for statedir in statedirs: test_file = '%s/TEST_FILE' % statedir content = instance.runcmd(['cat', test_file]) - assert content == "Test user data" - + assert content == "Test user data\n" class SimpleTestRunner(cliapp.Application): ''' @@ -766,8 +747,9 @@ class SimpleTestRunner(cliapp.Application): self.run_test() def run_test(self): - test = TestUpgrades().test_scenario_trove_upgrade + #test = TestUpgrades().test_scenario_trove_upgrade #test = TestUpgrades().test_scenario_trove_kernel_upgrade + test = TestUpgrades().test_scenario_trove_upgrade_shared_user_data if self.settings['reuse-fixture'] is not None: fixture_dir = self.settings['reuse-fixture'] -- cgit v1.2.1