~yellow/charms/oneiric/buildbot-slave/trunk

« back to all changes in this revision

Viewing changes to hooks/install

  • Committer: Gary Poster
  • Date: 2012-02-10 21:49:40 UTC
  • mfrom: (12.2.1 buildbot-slave)
  • Revision ID: gary.poster@canonical.com-20120210214940-rfcy8e1pc9cnw9kd
[r=bac] run as buildbot, from Gary, plus fixed and new tests from frankban

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    apt_get_install,
8
8
    command,
9
9
    get_config,
 
10
    install_extra_repository,
10
11
    log,
11
12
    log_entry,
12
13
    log_exit,
13
14
    run,
14
15
    )
 
16
from local import (
 
17
    config_json,
 
18
    create_slave,
 
19
    )
15
20
import os
16
21
import shlex
17
22
import subprocess
40
45
 
41
46
def wget(source, path):
42
47
    target = os.path.join('/tmp', path)
43
 
    command('wget', '-O', target, source)
 
48
    run('wget', '-O', target, source)
44
49
    return target
45
50
 
46
51
 
47
52
def hg_fetch(source, path):
48
53
    apt_get_install('mercurial')
49
54
    target = tempfile.mktemp()
50
 
    command('hg', 'clone', source, target)
 
55
    run('hg', 'clone', source, target)
51
56
    return os.path.join(target, path)
52
57
 
53
58
 
54
59
def git_fetch(source, path):
55
60
    apt_get_install('git')
56
61
    target = tempfile.mktemp()
57
 
    command('git', 'clone', source, target)
 
62
    run('git', 'clone', source, target)
58
63
    return os.path.join(target, path)
59
64
 
60
65
 
81
86
    method = config.get('script-retrieval-method')
82
87
    url = config.get('script-url')
83
88
    path = config.get('script-path')
84
 
    args = config.get('script-args')
 
89
    # This is a naive substitution.  We can make it more sophisticated
 
90
    # if we discover we need it.  For now, simplicity wins.
 
91
    args = config.get('script-args', '').format(**config)
 
92
    buildbot_pkg = config.get('buildbot-pkg')
 
93
    extra_repo = config.get('extra-repository')
 
94
    buildbot_dir = config.get('installdir')
 
95
 
 
96
    if extra_repo:
 
97
        install_extra_repository(extra_repo)
 
98
 
 
99
    if buildbot_pkg:
 
100
        log('Installing ' + buildbot_pkg)
 
101
        apt_get_install(buildbot_pkg)
 
102
        log('Creating initial buildbot slave in ' + buildbot_dir)
 
103
        create_slave('temporary', 'temporary', buildbot_dir=buildbot_dir)
 
104
 
 
105
    config_json.set(config)
 
106
 
85
107
    retrieve = METHODS.get(method)
86
108
    if retrieve and url and path:
 
109
        # Make buildbot user have a shell by editing /etc/passwd.
 
110
        # Otherwise you cannot ssh as this user, which some scripts
 
111
        # need (e.g. those that create lxc containers).  We choose sh as
 
112
        # a standard and basic "system" shell.
 
113
        run('usermod', '-s', '/bin/sh', 'buildbot')
87
114
        sys.exit(handle_script(retrieve, url, path, args))
88
115
 
89
116