summaryrefslogtreecommitdiff
path: root/tests/cloud_tests/platforms/instances.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-12-05 17:05:29 -0500
committerScott Moser <smoser@brickies.net>2017-12-05 17:05:29 -0500
commit47016791ca5e97d80e45d3f100bc4e5d0b88627d (patch)
tree70f9e5bad3b136abeecd6399b077c82a81953220 /tests/cloud_tests/platforms/instances.py
parent7acc9e68fafbbd7c56587aebe752ba6ba8c8a3db (diff)
downloadvyos-cloud-init-47016791ca5e97d80e45d3f100bc4e5d0b88627d.tar.gz
vyos-cloud-init-47016791ca5e97d80e45d3f100bc4e5d0b88627d.zip
tests: consolidate platforms into specific dirs
This groups up each test platform into its own directory rather than having files spread between four different directories for one platform. Platforms tend to be worked on one at a time and so having the platforms together makes more sense than apart.
Diffstat (limited to 'tests/cloud_tests/platforms/instances.py')
-rw-r--r--tests/cloud_tests/platforms/instances.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/cloud_tests/platforms/instances.py b/tests/cloud_tests/platforms/instances.py
new file mode 100644
index 00000000..8c59d62c
--- /dev/null
+++ b/tests/cloud_tests/platforms/instances.py
@@ -0,0 +1,77 @@
+# This file is part of cloud-init. See LICENSE file for license information.
+
+"""Base instance."""
+
+from ..util import TargetBase
+
+
+class Instance(TargetBase):
+ """Base instance object."""
+
+ platform_name = None
+
+ def __init__(self, platform, name, properties, config, features):
+ """Set up instance.
+
+ @param platform: platform object
+ @param name: hostname of instance
+ @param properties: image properties
+ @param config: image config
+ @param features: supported feature flags
+ """
+ self.platform = platform
+ self.name = name
+ self.properties = properties
+ self.config = config
+ self.features = features
+ self._tmp_count = 0
+
+ def console_log(self):
+ """Instance console.
+
+ @return_value: bytes of this instance’s console
+ """
+ raise NotImplementedError
+
+ def reboot(self, wait=True):
+ """Reboot instance."""
+ raise NotImplementedError
+
+ def shutdown(self, wait=True):
+ """Shutdown instance."""
+ raise NotImplementedError
+
+ def start(self, wait=True, wait_for_cloud_init=False):
+ """Start instance."""
+ raise NotImplementedError
+
+ def destroy(self):
+ """Clean up instance."""
+ pass
+
+ def _wait_for_system(self, wait_for_cloud_init):
+ """Wait until system has fully booted and cloud-init has finished.
+
+ @param wait_time: maximum time to wait
+ @return_value: None, may raise OSError if wait_time exceeded
+ """
+ def clean_test(test):
+ """Clean formatting for system ready test testcase."""
+ return ' '.join(l for l in test.strip().splitlines()
+ if not l.lstrip().startswith('#'))
+
+ time = self.config['boot_timeout']
+ tests = [self.config['system_ready_script']]
+ if wait_for_cloud_init:
+ tests.append(self.config['cloud_init_ready_script'])
+
+ formatted_tests = ' && '.join(clean_test(t) for t in tests)
+ cmd = ('i=0; while [ $i -lt {time} ] && i=$(($i+1)); do {test} && '
+ 'exit 0; sleep 1; done; exit 1').format(time=time,
+ test=formatted_tests)
+
+ if self.execute(cmd, rcs=(0, 1))[-1] != 0:
+ raise OSError('timeout: after {}s system not started'.format(time))
+
+
+# vi: ts=4 expandtab