summaryrefslogtreecommitdiff
path: root/tests/cloud_tests/collect.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cloud_tests/collect.py')
-rw-r--r--tests/cloud_tests/collect.py114
1 files changed, 64 insertions, 50 deletions
diff --git a/tests/cloud_tests/collect.py b/tests/cloud_tests/collect.py
index 02fc0e52..b44e8bdd 100644
--- a/tests/cloud_tests/collect.py
+++ b/tests/cloud_tests/collect.py
@@ -1,34 +1,39 @@
# This file is part of cloud-init. See LICENSE file for license information.
-from tests.cloud_tests import (config, LOG, setup_image, util)
-from tests.cloud_tests.stage import (PlatformComponent, run_stage, run_single)
-from tests.cloud_tests import (platforms, images, snapshots, instances)
+"""Used to collect data from platforms during tests."""
from functools import partial
import os
+from cloudinit import util as c_util
+from tests.cloud_tests import (config, LOG, setup_image, util)
+from tests.cloud_tests.stage import (PlatformComponent, run_stage, run_single)
+from tests.cloud_tests import (platforms, images, snapshots, instances)
+
def collect_script(instance, base_dir, script, script_name):
- """
- collect script data
- instance: instance to run script on
- base_dir: base directory for output data
- script: script contents
- script_name: name of script to run
- return_value: None, may raise errors
+ """Collect script data.
+
+ @param instance: instance to run script on
+ @param base_dir: base directory for output data
+ @param script: script contents
+ @param script_name: name of script to run
+ @return_value: None, may raise errors
"""
LOG.debug('running collect script: %s', script_name)
- util.write_file(os.path.join(base_dir, script_name),
- instance.run_script(script))
+ (out, err, exit) = instance.run_script(
+ script, rcs=range(0, 256),
+ description='collect: {}'.format(script_name))
+ c_util.write_file(os.path.join(base_dir, script_name), out)
def collect_test_data(args, snapshot, os_name, test_name):
- """
- collect data for test case
- args: cmdline arguments
- snapshot: instantiated snapshot
- test_name: name or path of test to run
- return_value: tuple of results and fail count
+ """Collect data for test case.
+
+ @param args: cmdline arguments
+ @param snapshot: instantiated snapshot
+ @param test_name: name or path of test to run
+ @return_value: tuple of results and fail count
"""
res = ({}, 1)
@@ -39,15 +44,27 @@ def collect_test_data(args, snapshot, os_name, test_name):
test_scripts = test_config['collect_scripts']
test_output_dir = os.sep.join(
(args.data_dir, snapshot.platform_name, os_name, test_name))
- boot_timeout = (test_config.get('boot_timeout')
- if isinstance(test_config.get('boot_timeout'), int) else
- snapshot.config.get('timeout'))
# if test is not enabled, skip and return 0 failures
if not test_config.get('enabled', False):
LOG.warning('test config %s is not enabled, skipping', test_name)
return ({}, 0)
+ # if testcase requires a feature flag that the image does not support,
+ # skip the testcase with a warning
+ req_features = test_config.get('required_features', [])
+ if any(feature not in snapshot.features for feature in req_features):
+ LOG.warn('test config %s requires features not supported by image, '
+ 'skipping.\nrequired features: %s\nsupported features: %s',
+ test_name, req_features, snapshot.features)
+ return ({}, 0)
+
+ # if there are user data overrides required for this test case, apply them
+ overrides = snapshot.config.get('user_data_overrides', {})
+ if overrides:
+ LOG.debug('updating user data for collect with: %s', overrides)
+ user_data = util.update_user_data(user_data, overrides)
+
# create test instance
component = PlatformComponent(
partial(instances.get_instance, snapshot, user_data,
@@ -56,7 +73,7 @@ def collect_test_data(args, snapshot, os_name, test_name):
LOG.info('collecting test data for test: %s', test_name)
with component as instance:
start_call = partial(run_single, 'boot instance', partial(
- instance.start, wait=True, wait_time=boot_timeout))
+ instance.start, wait=True, wait_for_cloud_init=True))
collect_calls = [partial(run_single, 'script {}'.format(script_name),
partial(collect_script, instance,
test_output_dir, script, script_name))
@@ -69,11 +86,11 @@ def collect_test_data(args, snapshot, os_name, test_name):
def collect_snapshot(args, image, os_name):
- """
- collect data for snapshot of image
- args: cmdline arguments
- image: instantiated image with set up complete
- return_value tuple of results and fail count
+ """Collect data for snapshot of image.
+
+ @param args: cmdline arguments
+ @param image: instantiated image with set up complete
+ @return_value tuple of results and fail count
"""
res = ({}, 1)
@@ -91,19 +108,18 @@ def collect_snapshot(args, image, os_name):
def collect_image(args, platform, os_name):
- """
- collect data for image
- args: cmdline arguments
- platform: instantiated platform
- os_name: name of distro to collect for
- return_value: tuple of results and fail count
+ """Collect data for image.
+
+ @param args: cmdline arguments
+ @param platform: instantiated platform
+ @param os_name: name of distro to collect for
+ @return_value: tuple of results and fail count
"""
res = ({}, 1)
- os_config = config.load_os_config(os_name)
- if not os_config.get('enabled'):
- raise ValueError('OS {} not enabled'.format(os_name))
-
+ os_config = config.load_os_config(
+ platform.platform_name, os_name, require_enabled=True,
+ feature_overrides=args.feature_override)
component = PlatformComponent(
partial(images.get_image, platform, os_config))
@@ -118,18 +134,16 @@ def collect_image(args, platform, os_name):
def collect_platform(args, platform_name):
- """
- collect data for platform
- args: cmdline arguments
- platform_name: platform to collect for
- return_value: tuple of results and fail count
+ """Collect data for platform.
+
+ @param args: cmdline arguments
+ @param platform_name: platform to collect for
+ @return_value: tuple of results and fail count
"""
res = ({}, 1)
- platform_config = config.load_platform_config(platform_name)
- if not platform_config.get('enabled'):
- raise ValueError('Platform {} not enabled'.format(platform_name))
-
+ platform_config = config.load_platform_config(
+ platform_name, require_enabled=True)
component = PlatformComponent(
partial(platforms.get_platform, platform_name, platform_config))
@@ -143,10 +157,10 @@ def collect_platform(args, platform_name):
def collect(args):
- """
- entry point for collection
- args: cmdline arguments
- return_value: fail count
+ """Entry point for collection.
+
+ @param args: cmdline arguments
+ @return_value: fail count
"""
(res, failed) = run_stage(
'collect data', [partial(collect_platform, args, platform_name)