~lutostag/charms/trusty/ci-configurator/simplify-config-repo-updates

« back to all changes in this revision

Viewing changes to hooks/jjb.py

  • Committer: Mario Splivalo
  • Date: 2014-07-02 09:30:44 UTC
  • mfrom: (71.2.4 config-updates)
  • Revision ID: mario.splivalo@canonical.com-20140702093044-4v7yuuzdr3q7ax13
[hopem,mariosplivalo,r=]

    * Adds force-package-install config option.

      When installing packages listed in control.yml, it may be desirable
      to disregard local config changes and force the installation of upgrades.
      Adds the ability to do this via config option, with the default being
      disabled.

    * Adds "distro" as a supported install source for jenkins-job-builder.

      JJB hit Ubuntu in raring. It should be possible to install this without
      the painful offline bundling if charm is deployed to a recent enough Ubuntu.

      Also avoids an import error in gerrit helper by ensuring paramiko is
      installed.

      NOTE: Leaving default for jjb-install-source to install from git as we
      are still installing on precise and 'distro' is >= 13.04 only so leaving
      default as precise-compatible.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
from charmhelpers.core.hookenv import (
12
12
    charm_dir, config, log, relation_ids, relation_get,
13
13
    related_units, ERROR)
14
 
from charmhelpers.fetch import apt_install
15
 
from charmhelpers.core.host import restart_on_change
 
14
from charmhelpers.fetch import apt_install, filter_installed_packages
 
15
from charmhelpers.core.host import lsb_release, restart_on_change
16
16
 
17
17
PACKAGES = ['git', 'python-pip']
18
18
CONFIG_DIR = '/etc/jenkins_jobs'
44
44
 
45
45
def install():
46
46
    """
47
 
    Install jenkins-job-builder from a remote git repository or a locally
48
 
    bundled copy shipped with the charm.
 
47
    Install jenkins-job-builder from a archive, remote git repository or a
 
48
    locally bundled copy shipped with the charm.  Any locally bundled copy
 
49
    overrides 'jjb-install-source' setting.
49
50
    """
50
51
    if not os.path.isdir(CONFIG_DIR):
51
52
        os.mkdir(CONFIG_DIR)
52
 
    apt_install(PACKAGES, fatal=True)
53
53
    src = config('jjb-install-source')
54
54
    tarball = os.path.join(charm_dir(), 'files', TARBALL)
55
55
 
59
59
    elif src.startswith('git://'):
60
60
        log('Installing jenkins-job-builder from remote git: %s.' % src)
61
61
        install_from_git(src)
 
62
    elif src == 'distro':
 
63
        log('Installing jenkins-job-builder from Ubuntu archive.')
 
64
        if lsb_release()['DISTRIB_CODENAME'] in ['precise', 'quantal']:
 
65
            m = ('jenkins-job-builder package only available in Ubuntu 13.04 '
 
66
                'and later.')
 
67
            raise Exception(m)
 
68
        apt_install(filter_installed_packages(['jenkins-job-builder']), fatal=True)
62
69
    else:
63
70
        m = ('Must specify a git url as install source or bundled source with '
64
71
             'the charm.')
80
87
    outdir = os.path.join('/tmp', 'jenkins-job-builder')
81
88
    _clean_tmp_dir(outdir)
82
89
 
 
90
    apt_install(filter_installed_packages(['python-pip']), fatal=True)
83
91
    os.chdir(os.path.dirname(outdir))
84
92
    cmd = ['tar', 'xfz', tarball]
85
93
    subprocess.check_call(cmd)
98
106
    log('*** Installing from remote git repository: %s' % repo)
99
107
    outdir = os.path.join('/tmp', 'jenkins-job-builder')
100
108
    _clean_tmp_dir(outdir)
 
109
    apt_install(filter_installed_packages(['git']), fatal=True)
101
110
    cmd = ['git', 'clone', repo, outdir]
102
111
    subprocess.check_call(cmd)
103
112
    os.chdir(outdir)
309
318
    # install any packages that the repo says we need as dependencies.
310
319
    pkgs = required_packages()
311
320
    if pkgs:
312
 
        apt_install(pkgs, fatal=True)
 
321
        opts = []
 
322
        if config('force-package-install'):
 
323
            opts = [
 
324
                '--option', 'Dpkg::Options::=--force-confnew',
 
325
                '--option', 'Dpkg::Options::=--force-confdef',
 
326
            ]
 
327
        apt_install(pkgs, options=opts, fatal=True)
313
328
 
314
329
 
315
330
def required_packages():