~brian-murray/auto-upgrade-testing/use-proposed-dist-upgrader

« back to all changes in this revision

Viewing changes to upgrade_testing/preparation/_hostprep.py

  • Committer: Tarmac
  • Author(s): Max Brustkern
  • Date: 2016-06-13 17:28:44 UTC
  • mfrom: (71.4.38 local-autopkgtest)
  • Revision ID: tarmac-20160613172844-zockv240qncmn30p
Add the ability to use locally installed autopkgtest or specify a specific git version via environment variables.

Approved by platform-qa-bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
from collections import namedtuple
25
25
from contextlib import contextmanager
 
26
from distutils.spawn import find_executable
26
27
from textwrap import dedent
27
28
 
28
29
from upgrade_testing.configspec import test_source_retriever
30
31
from upgrade_testing.provisioning import run_command_with_logged_output
31
32
from upgrade_testing.configspec import get_file_data_location
32
33
 
 
34
DEFAULT_GIT_URL = 'git://anonscm.debian.org/autopkgtest/autopkgtest.git'
 
35
 
33
36
logger = logging.getLogger(__name__)
34
37
 
35
38
 
38
41
TestrunTempFiles = namedtuple(
39
42
    'TestrunTempFiles', [
40
43
        'adt_base_path',
 
44
        'adt_cmd',
41
45
        'run_config_file',
42
46
        'testrun_tmp_dir',
43
47
        'unbuilt_dir',
73
77
        post_path = os.path.join(temp_dir, 'post_scripts')
74
78
        _copy_script_files(testsuite.post_upgrade_tests.location, post_path)
75
79
 
 
80
        adt_base_path, adt_cmd = _get_adt_path(temp_dir)
 
81
 
76
82
        yield TestrunTempFiles(
77
 
            adt_base_path=_grab_git_version_autopkgtest(temp_dir),
 
83
            adt_base_path=adt_base_path,
 
84
            adt_cmd=adt_cmd,
78
85
            run_config_file=run_config_path,
79
86
            # Should we create a dir so that it won't interfer?
80
87
            unbuilt_dir=temp_dir,
165
172
    return dir_tree
166
173
 
167
174
 
168
 
def _grab_git_version_autopkgtest(tmp_dir):
169
 
    # Grab the git version of autopkgtest so that we can use the latest
170
 
    # features (i.e. reboot-prepare).
171
 
    # This is needed as 3.14+ is not in vivid.
172
 
    # TODO: Remove this need by grabbing it from backports or universe.
173
 
    git_url = 'git://anonscm.debian.org/autopkgtest/autopkgtest.git'
174
 
    git_trunk_path = os.path.join(tmp_dir, 'local_autopkgtest')
175
 
    git_command = ['git', 'clone', git_url, git_trunk_path]
176
 
 
177
 
    run_command_with_logged_output(git_command)
178
 
 
179
 
    return git_trunk_path
 
175
def _get_adt_path(tmp_dir):
 
176
    # Check if we need to get a git version of autopkgtest
 
177
    # (If environment variables are set or a local version can't be found)
 
178
    git_url = os.environ.get('AUTOPKGTEST_GIT_REPO', None)
 
179
    git_hash = os.environ.get('AUTOPKGTEST_GIT_HASH', None)
 
180
    local_adt = _get_local_adt()
 
181
    if git_url or git_hash or local_adt is None:
 
182
        git_url = git_url or DEFAULT_GIT_URL
 
183
        logger.info('Fetching autopkgtest from git url: %s', git_url)
 
184
        git_trunk_path = os.path.join(tmp_dir, 'local_autopkgtest')
 
185
        git_command = ['git', 'clone', git_url, git_trunk_path]
 
186
        retval = run_command_with_logged_output(git_command)
 
187
        if retval != 0:
 
188
            raise ChildProcessError('{} exited with status {}'.format(
 
189
                git_command, retval))
 
190
        if git_hash:
 
191
            logger.info('Checking out specific git hash: %s', git_hash)
 
192
            git_hash_command = [
 
193
                'git',
 
194
                '--git-dir', os.path.join(git_trunk_path, '.git'),
 
195
                '--work-tree', git_trunk_path,
 
196
                'checkout', git_hash,
 
197
            ]
 
198
            run_command_with_logged_output(git_hash_command)
 
199
        adt_path = os.path.join(git_trunk_path, 'tools')
 
200
        adt_cmd = os.path.join(git_trunk_path, 'run-from-checkout')
 
201
    else:
 
202
        logger.info('Using installed autopkgtest:')
 
203
        run_command_with_logged_output(['dpkg-query', '-W', 'autopkgtest'])
 
204
        adt_path, adt_cmd = local_adt
 
205
        adt_cmd = os.path.join(adt_path, adt_cmd)
 
206
    return (adt_path, adt_cmd)
 
207
 
 
208
 
 
209
def _get_local_adt():
 
210
    path = find_executable('adt-run')
 
211
    if path:
 
212
        return path.rsplit('/', 1)
 
213
    return None