Exemplo n.º 1
0
    def reset(self):
        '''Revert apt configuration for testbeds without reset'''

        if self.need_apt_reset and 'revert' not in self.testbed.caps:
            adtlog.info('Binaries: resetting testbed apt configuration')
            self.testbed.check_exec(
                ['sh', '-ec',
                 'rm -f /etc/apt/sources.list.d/autopkgtest.list /etc/apt/preferences.d/90autopkgtest; '
                 '(apt-get --quiet update || (sleep 15; apt-get update)) 2>&1'],
                kind='install')

            self.need_apt_reset = False
Exemplo n.º 2
0
def cmd_reboot(c, ce):
    global downtmp
    cmdnumargs(c, ce, 0, 1)
    if not downtmp:
        bomb("`reboot' when not open")
    if 'reboot' not in caller.hook_capabilities():
        bomb("`reboot' when `reboot' not advertised")

    # save current downtmp; try a few locations, as /var/cache might be r/o
    # (argh Ubuntu touch)
    directories = '/var/cache /home'
    check_exec([
        'sh', '-ec',
        'for d in %s; do if [ -w $d ]; then '
        '  tar --warning=none --create --absolute-names '
        '''    -f $d/autopkgtest-tmpdir.tar '%s'; '''
        '  rm -f /run/autopkgtest-reboot-prepare-mark; '
        '  exit 0; fi; done; exit 1'
        '' % (directories, downtmp)
    ],
               downp=True,
               timeout=copy_timeout)
    adtlog.debug('cmd_reboot: saved current downtmp, rebooting')

    try:
        caller.hook_prepare_reboot()
    except AttributeError:
        pass

    # reboot
    if len(c) > 1 and c[1] == 'prepare-only':
        adtlog.info('state saved, waiting for testbed to reboot...')
    else:
        execute_timeout(
            None, 30,
            auxverb + ['sh', '-c', '(sleep 3; reboot) >/dev/null 2>&1 &'])
    caller.hook_wait_reboot()

    # restore downtmp
    check_exec([
        'sh', '-ec',
        'for d in %s; do '
        'if [ -e $d/autopkgtest-tmpdir.tar ]; then '
        ' tar --warning=none --extract --absolute-names '
        '     -f $d/autopkgtest-tmpdir.tar;'
        ' rm $d/autopkgtest-tmpdir.tar; exit 0; '
        'fi; done; exit 1' % directories
    ],
               downp=True,
               timeout=copy_timeout)
    adtlog.debug('cmd_reboot: restored downtmp after reboot')
Exemplo n.º 3
0
def cmd_auxverb_debug_fail(c, ce):
    cmdnumargs(c, ce)
    try:
        adtlog.info(caller.hook_debug_fail())
    except AttributeError:
        pass
Exemplo n.º 4
0
def parse_click_manifest(manifest, testbed_caps, clickdeps, use_installed,
                         srcdir=None):
    '''Parse test descriptions from a click manifest.

    @manifest: String with the click manifest
    @testbed_caps: List of testbed capabilities
    @clickdeps: paths of click packages that these tests need
    @use_installed: True if test expects the described click to be installed
                    already

    Return (source_dir, list of Test objects, some_skipped). If this encounters
    any invalid restrictions, fields, or test restrictions which cannot be met
    by the given testbed capabilities, the test will be skipped (and reported
    so), and not be included in the result.

    If srcdir is given, use that as source for the click package, and return
    that as first return value. Otherwise, locate and download the source from
    the click's manifest into a temporary directory and use that.

    This may raise an InvalidControl exception.
    '''
    try:
        manifest_j = json.loads(manifest)
        test_j = manifest_j.get('x-test', {})
    except ValueError as e:
        raise InvalidControl(
            '*', 'click manifest is not valid JSON: %s' % str(e))
    if not isinstance(test_j, dict):
        raise InvalidControl(
            '*', 'click manifest x-test key must be a dictionary')

    installed_clicks = []
    if use_installed:
        installed_clicks.append(manifest_j.get('name'))

    some_skipped = False
    tests = []

    # It's a dictionary and thus does not have a predictable ordering; sort it
    # to get a predictable list
    for name in sorted(test_j):
        desc = test_j[name]
        adtlog.debug('parsing click manifest test %s: %s' % (name, desc))

        # simple string is the same as { "path": <desc> } without any
        # restrictions, or the special "autopilot" case
        if isinstance(desc, str):
            if name == 'autopilot' and re.match('^[a-z_][a-z0-9_]+$', desc):
                desc = {'autopilot_module': desc}
            else:
                desc = {'path': desc}

        if not isinstance(desc, dict):
            raise InvalidControl(name, 'click manifest x-test dictionary '
                                 'entries must be strings or dicts')

        # autopilot special case: dict with extra depends
        if 'autopilot_module' in desc:
            desc['command'] = 'PYTHONPATH=tests/autopilot:$PYTHONPATH ' \
                'python3 -m autopilot.run run -v -f subunit -o ' \
                '$ADT_ARTIFACTS/%s.subunit ' % name + os.environ.get(
                    'ADT_AUTOPILOT_MODULE', desc['autopilot_module'])
            desc.setdefault('depends', []).insert(
                0, 'ubuntu-ui-toolkit-autopilot')
            desc['depends'].insert(0, 'autopilot-touch')
            if 'allow-stderr' not in desc.setdefault('restrictions', []):
                desc['restrictions'].append('allow-stderr')

        try:
            test = Test(name, desc.get('path'), desc.get('command'),
                        desc.get('restrictions', []), desc.get('features', []),
                        desc.get('depends', []), clickdeps, installed_clicks)
            test.check_testbed_compat(testbed_caps)
            tests.append(test)
        except Unsupported as u:
            u.report()
            some_skipped = True

    if srcdir is None:
        # do we have an x-source/vcs-bzr link?
        if 'x-source' in manifest_j:
            try:
                repo = manifest_j['x-source']['vcs-bzr']
                adtlog.info('checking out click source from %s' % repo)
                d = tempfile.mkdtemp(prefix='adt.clicksrc.')
                atexit.register(shutil.rmtree, d, ignore_errors=True)
                try:
                    subprocess.check_call(['bzr', 'checkout', '--lightweight',
                                           repo, d])
                    srcdir = d
                except subprocess.CalledProcessError as e:
                    adtlog.error('Failed to check out click source from %s: %s'
                                 % (repo, str(e)))
            except KeyError:
                adtlog.error('Click source download from x-source only '
                             'supports "vcs-bzr" repositories')
        else:
            adtlog.error('cannot download click source: manifest does not '
                         'have "x-source"')

    return (srcdir, tests, some_skipped)
Exemplo n.º 5
0
def parse_click_manifest(manifest, testbed_caps, clickdeps, use_installed,
                         srcdir=None):
    '''Parse test descriptions from a click manifest.

    @manifest: String with the click manifest
    @testbed_caps: List of testbed capabilities
    @clickdeps: paths of click packages that these tests need
    @use_installed: True if test expects the described click to be installed
                    already

    Return (source_dir, list of Test objects, some_skipped). If this encounters
    any invalid restrictions, fields, or test restrictions which cannot be met
    by the given testbed capabilities, the test will be skipped (and reported
    so), and not be included in the result.

    If srcdir is given, use that as source for the click package, and return
    that as first return value. Otherwise, locate and download the source from
    the click's manifest into a temporary directory and use that.

    This may raise an InvalidControl exception.
    '''
    try:
        manifest_j = json.loads(manifest)
        test_j = manifest_j.get('x-test', {})
    except ValueError as e:
        raise InvalidControl(
            '*', 'click manifest is not valid JSON: %s' % str(e))
    if not isinstance(test_j, dict):
        raise InvalidControl(
            '*', 'click manifest x-test key must be a dictionary')

    installed_clicks = []
    if use_installed:
        installed_clicks.append(manifest_j.get('name'))

    some_skipped = False
    tests = []

    # It's a dictionary and thus does not have a predictable ordering; sort it
    # to get a predictable list
    for name in sorted(test_j):
        desc = test_j[name]
        adtlog.debug('parsing click manifest test %s: %s' % (name, desc))

        # simple string is the same as { "path": <desc> } without any
        # restrictions, or the special "autopilot" case
        if isinstance(desc, str):
            if name == 'autopilot' and re.match('^[a-z_][a-z0-9_]+$', desc):
                desc = {'autopilot_module': desc}
            else:
                desc = {'path': desc}

        if not isinstance(desc, dict):
            raise InvalidControl(name, 'click manifest x-test dictionary '
                                 'entries must be strings or dicts')

        # autopilot special case: dict with extra depends
        if 'autopilot_module' in desc:
            desc['command'] = \
                'PYTHONPATH=app/tests/autopilot:tests/autopilot:$PYTHONPATH '\
                'python3 -m autopilot.run run -v -f subunit -o ' \
                '$AUTOPKGTEST_ARTIFACTS/%s.subunit ' % name + os.environ.get(
                    'AUTOPKGTEST_AUTOPILOT_MODULE',
                    os.environ.get('ADT_AUTOPILOT_MODULE', desc['autopilot_module']))
            desc.setdefault('depends', []).insert(
                0, 'ubuntu-ui-toolkit-autopilot')
            desc['depends'].insert(0, 'autopilot-touch')
            if 'allow-stderr' not in desc.setdefault('restrictions', []):
                desc['restrictions'].append('allow-stderr')

        try:
            test = Test(name, desc.get('path'), desc.get('command'),
                        desc.get('restrictions', []), desc.get('features', []),
                        desc.get('depends', []), clickdeps, installed_clicks)
            test.check_testbed_compat(testbed_caps)
            tests.append(test)
        except Unsupported as u:
            u.report()
            some_skipped = True

    if srcdir is None:
        # do we have an x-source/vcs-bzr link?
        if 'x-source' in manifest_j:
            try:
                repo = manifest_j['x-source']['vcs-bzr']
                adtlog.info('checking out click source from %s' % repo)
                d = tempfile.mkdtemp(prefix='autopkgtest.clicksrc.')
                atexit.register(shutil.rmtree, d, ignore_errors=True)
                try:
                    subprocess.check_call(['bzr', 'checkout', '--lightweight',
                                           repo, d])
                    srcdir = d
                except subprocess.CalledProcessError as e:
                    adtlog.error('Failed to check out click source from %s: %s'
                                 % (repo, str(e)))
            except KeyError:
                adtlog.error('Click source download from x-source only '
                             'supports "vcs-bzr" repositories')
        else:
            adtlog.error('cannot download click source: manifest does not '
                         'have "x-source"')

    return (srcdir, tests, some_skipped)