예제 #1
0
def collect_test_data(args, snapshot, os_name, test_name):
    """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)

    # load test config
    test_name = config.path_to_name(test_name)
    test_config = config.load_test_config(test_name)
    user_data = test_config['cloud_config']
    test_scripts = test_config['collect_scripts']
    test_output_dir = os.sep.join(
        (args.data_dir, snapshot.platform_name, os_name, test_name))

    # 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.warning('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(platforms.get_instance, snapshot, user_data,
                block=True, start=False, use_desc=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_for_cloud_init=True))
        collect_calls = [partial(run_single, 'script {}'.format(script_name),
                                 partial(collect_script, instance,
                                         test_output_dir, script, script_name))
                         for script_name, script in test_scripts.items()]

        console_log = partial(
            run_single, 'collect console',
            partial(collect_console, instance, test_output_dir))

        res = run_stage('collect for test: {}'.format(test_name),
                        [start_call] + collect_calls + [console_log])

    return res
예제 #2
0
 def snapshot(self):
     """Create snapshot of image, block until done."""
     # get empty user data to pass in to instance
     # if overrides for user data provided, use them
     empty_userdata = util.update_user_data({},
                                            self.config.get(
                                                'user_data_overrides', {}))
     conf = {'user.user-data': empty_userdata}
     # clone current instance
     instance = self.platform.launch_container(
         self.properties,
         self.config,
         self.features,
         container=self._instance.name,
         image_desc=str(self),
         use_desc='snapshot',
         container_config=conf)
     # wait for cloud-init before boot_clean_script is run to ensure
     # /var/lib/cloud is removed cleanly
     instance.start(wait=True, wait_for_cloud_init=True)
     if self.config.get('boot_clean_script'):
         instance.run_script(self.config.get('boot_clean_script'))
     # freeze current instance and return snapshot
     instance.freeze()
     return LXDSnapshot(self.platform, self.properties, self.config,
                        self.features, instance)
예제 #3
0
 def snapshot(self):
     """Create snapshot of image, block until done."""
     # get empty user data to pass in to instance
     # if overrides for user data provided, use them
     empty_userdata = util.update_user_data(
         {}, self.config.get('user_data_overrides', {}))
     conf = {'user.user-data': empty_userdata}
     # clone current instance
     instance = self.platform.launch_container(
         self.properties, self.config, self.features,
         container=self._instance.name, image_desc=str(self),
         use_desc='snapshot', container_config=conf)
     # wait for cloud-init before boot_clean_script is run to ensure
     # /var/lib/cloud is removed cleanly
     instance.start(wait=True, wait_for_cloud_init=True)
     if self.config.get('boot_clean_script'):
         instance.run_script(self.config.get('boot_clean_script'))
     # freeze current instance and return snapshot
     instance.freeze()
     return LXDSnapshot(self.platform, self.properties, self.config,
                        self.features, instance)
예제 #4
0
def collect_test_data(args, snapshot, os_name, test_name):
    """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)

    # load test config
    test_name_in = test_name
    test_name = config.path_to_name(test_name)
    test_config = config.load_test_config(test_name)
    user_data = test_config['cloud_config']
    test_scripts = test_config['collect_scripts']
    test_output_dir = os.sep.join(
        (args.data_dir, snapshot.platform_name, os_name, test_name))

    # 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)

    test_class = get_test_class(
        config.name_to_module(test_name_in),
        test_data={'platform': snapshot.platform_name, 'os_name': os_name},
        test_conf=test_config['cloud_config'])
    try:
        test_class.maybeSkipTest()
    except base.SkipTest as s:
        LOG.warning('skipping test config %s: %s', test_name, s)
        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.warning('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(platforms.get_instance, snapshot, user_data,
                block=True, start=False, use_desc=test_name),
        preserve_instance=args.preserve_instance)

    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_for_cloud_init=True))
        collect_calls = [partial(run_single, 'script {}'.format(script_name),
                                 partial(collect_script, instance,
                                         test_output_dir, script, script_name))
                         for script_name, script in test_scripts.items()]

        res = run_stage('collect for test: {}'.format(test_name),
                        [start_call] + collect_calls)

        instance.shutdown()
        collect_console(instance, test_output_dir)

    return res