summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-02-19 12:54:03 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-02-19 13:05:56 +0000
commit99a73f040cef4d1d09054a1f03d690fd4f1333e3 (patch)
tree6e0def023700d54ed8d8fc50c8614de42cada9d3
parent6038dcf085f3631fab3ff93afd91ed88bb1914e1 (diff)
downloadsystem-tests-99a73f040cef4d1d09054a1f03d690fd4f1333e3.tar.gz
Add Deployment.runcmd() method
-rw-r--r--test_trove_upgrades.py87
1 files changed, 41 insertions, 46 deletions
diff --git a/test_trove_upgrades.py b/test_trove_upgrades.py
index aed3a08..9cb7017 100644
--- a/test_trove_upgrades.py
+++ b/test_trove_upgrades.py
@@ -138,6 +138,27 @@ class Deployment(object):
f.write('0040700 0 0 /root/.ssh/\n')
f.write('0100644 0 0 /root/.ssh/authorized_keys\n')
+ def wait_for_ssh(self, timeout=config.BOOT_TIMEOUT, **kwargs):
+ print "Waiting for machine to respond over SSH ..."
+ start_time = time.time()
+ while True:
+ try:
+ print self.runcmd(['whoami'], **kwargs)
+ break
+ except cliapp.AppException as e:
+ if time.time() < start_time + timeout:
+ # Assume that this is because sshd hasn't started yet.
+ pass
+ else:
+ print("Waited > %s seconds for host %s to respond over "
+ "SSH" % (timeout, self.name))
+ raise
+ time.sleep(0.5)
+
+ def runcmd(self, command, **kwargs):
+ url = 'ssh://root@%s/' % self.name
+ return remote_runcmd(url, command, **kwargs)
+
class TroveInitialDeployment(Deployment):
'''
@@ -414,23 +435,6 @@ class BaseTestSuite(object):
(hostname, timeout))
time.sleep(0.5)
- def wait_for_ssh(self, host_url, timeout=config.BOOT_TIMEOUT, **kwargs):
- print "Waiting for machine to respond over SSH ..."
- start_time = time.time()
- while True:
- try:
- print remote_runcmd(host_url, ['whoami'], **kwargs)
- break
- except cliapp.AppException as e:
- if time.time() < start_time + timeout:
- # Assume that this is because sshd hasn't started yet.
- pass
- else:
- print("Waited > %s seconds for host %s to respond over "
- "SSH" % (timeout, host_url))
- raise
- time.sleep(0.5)
-
def wait_for_machine_to_boot(self, instance):
wait_time = self.wait_for_hostname_to_appear(
instance.name, timeout=config.BOOT_TIMEOUT)
@@ -442,9 +446,7 @@ class BaseTestSuite(object):
# changed.
cliapp.runcmd(['ssh-keygen', '-R', instance.name])
- test_url = 'ssh://root@%s/' % instance.name
- self.wait_for_ssh(
- test_url, timeout=config.BOOT_TIMEOUT-wait_time)
+ instance.wait_for_ssh(timeout=config.BOOT_TIMEOUT-wait_time)
def create_system_branch(self, workspace_dir, name, parent=config.BRANCH):
run_morph(
@@ -454,8 +456,8 @@ class BaseTestSuite(object):
class TestUpgrades(BaseTestSuite):
- def get_lighttpd_version(self, test_url, expected_start=None):
- text = remote_runcmd(test_url, ['lighttpd', '-v'])
+ def get_lighttpd_version(self, instance, expected_start=None):
+ text = instance.runcmd(['lighttpd', '-v'])
version_string = text.split(' ')[0]
version = distutils.version.LooseVersion(
version_string[len('lighttpd-'):])
@@ -489,9 +491,8 @@ class TestUpgrades(BaseTestSuite):
try:
self.wait_for_machine_to_boot(instance)
- test_url = 'ssh://root@%s/' % instance.name
- self.get_lighttpd_version(
- test_url, expected_start='lighttpd-1.3.14')
+ self.get_lighttpd_version(instance,
+ expected_start='lighttpd-1.3.14')
yield instance
finally:
# Should pass the .pub file really ...
@@ -538,8 +539,7 @@ class TestUpgrades(BaseTestSuite):
fixture_dir, reuse=reuse_fixture) as instance:
branch = self.create_system_branch(workspace_dir, 'current')
- test_url = 'ssh://root@%s/' % instance.name
- old_lighttpd_version = self.get_lighttpd_version(test_url)
+ old_lighttpd_version = self.get_lighttpd_version(instance)
upgrade = TroveUpgrade(branch)
upgrade.create_config(instance, upgrade_method='ssh-rsync',
@@ -548,19 +548,18 @@ class TestUpgrades(BaseTestSuite):
upgrade.run_deploy(autostart=True)
self.wait_for_machine_to_boot(instance)
- new_lighttpd_version = self.get_lighttpd_version(test_url)
+ new_lighttpd_version = self.get_lighttpd_version(instance)
try:
- remote_runcmd(test_url,
- ['snapshot-mgr', 'set-default', 'factory'])
- remote_runcmd(test_url, ['reboot'])
+ 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)
- rollback_lighttpd_version = self.get_lighttpd_version(test_url)
+ rollback_lighttpd_version = self.get_lighttpd_version(instance)
if config.VERBOSE:
print "Base system lighttpd version: %s" % old_lighttpd_version
@@ -570,8 +569,8 @@ class TestUpgrades(BaseTestSuite):
assert old_lighttpd_version == rollback_lighttpd_version
assert new_lighttpd_version > old_lighttpd_version
- def get_linux_version(self, test_url, expected_start=None):
- text = remote_runcmd(test_url, ['uname', '--kernel-release'])
+ def get_linux_version(self, instance, expected_start=None):
+ text = instance.runcmd(['uname', '--kernel-release'])
version = distutils.version.LooseVersion(text)
if config.VERBOSE:
print "uname output: %s (%s)" % (text, version.version)
@@ -603,7 +602,7 @@ class TestUpgrades(BaseTestSuite):
try:
self.wait_for_machine_to_boot(instance)
- self.get_linux_version(test_url, expected_start='3.6')
+ self.get_linux_version(instance, expected_start='3.6')
yield instance
finally:
# Should pass the .pub file really ...
@@ -629,8 +628,7 @@ class TestUpgrades(BaseTestSuite):
fixture_dir, reuse=reuse_fixture) as instance:
branch = self.create_system_branch(workspace_dir, 'current')
- test_url = 'ssh://root@%s/' % instance.name
- old_linux_version = self.get_linux_version(test_url)
+ old_linux_version = self.get_linux_version(instance)
upgrade = TroveUpgrade(branch)
upgrade.create_config(instance, upgrade_method='ssh-rsync',
@@ -639,12 +637,11 @@ class TestUpgrades(BaseTestSuite):
upgrade.run_deploy(autostart=True)
self.wait_for_machine_to_boot(instance)
- new_linux_version = self.get_linux_version(test_url)
+ new_linux_version = self.get_linux_version(instance)
try:
- remote_runcmd(test_url,
- ['snapshot-mgr', 'set-default', 'factory'])
- remote_runcmd(test_url, ['reboot'])
+ 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.
@@ -652,7 +649,7 @@ class TestUpgrades(BaseTestSuite):
self.wait_for_machine_to_boot(instance)
rollback_linux_version = self.get_linux_version(
- test_url, expected_start=='3.6')
+ instance, expected_start=='3.6')
if config.VERBOSE:
print "Base system linux version: %s" % old_linux_version
@@ -691,11 +688,9 @@ class TestUpgrades(BaseTestSuite):
fixture_dir, reuse=reuse_fixture) as instance:
branch = self.create_system_branch(workspace_dir, 'current')
- test_url = 'ssh://root@%s/' % instance.name
-
for statedir in statedirs:
cmd = 'echo "Test user data" > %s/TEST_FILE' % statedir
- remote_runcmd(test_url, ['sh', 'c', cmd])
+ instance.runcmd(['sh', 'c', cmd])
upgrade = TroveUpgrade(branch)
upgrade.create_config(instance, upgrade_method='ssh-rsync')
@@ -704,7 +699,7 @@ class TestUpgrades(BaseTestSuite):
for statedir in statedirs:
test_file = '%s/TEST_FILE' % statedir
- content = remote_runcmd(test_url, ['cat', test_file])
+ content = instance.runcmd(['cat', test_file])
assert content == "Test user data"