~pwlars/adt-continuous-deployer/clean-up-core-images

« back to all changes in this revision

Viewing changes to ci_automation/mojo.py

  • Committer: Ubuntu CI Bot
  • Author(s): Celso Providelo
  • Date: 2015-04-05 00:52:30 UTC
  • mfrom: (26.1.4 trunk)
  • Revision ID: ubuntu_ci_bot-20150405005230-28uxx7spktpe527o
Refactor the functions spread around by target subsystem (mojo, juju, branch, *utils*) into a ci_automation module, so they can be easily reused in multiple scripts. [r=Joe Talbott]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2015 Canonical
 
2
#
 
3
# This program is free software: you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation, either version 3 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
#
 
16
 
 
17
"""CI Automation: mojo helpers."""
 
18
 
 
19
 
 
20
import os
 
21
import subprocess
 
22
import sys
 
23
 
 
24
from . import (
 
25
    branch,
 
26
    utils,
 
27
)
 
28
 
 
29
 
 
30
SERIES = 'trusty'
 
31
 
 
32
 
 
33
def project_exists(project):
 
34
    '''Check the provided mojo project exists.'''
 
35
    args = [
 
36
        'mojo',
 
37
        'project-list',
 
38
        '-n',
 
39
    ]
 
40
    out = subprocess.check_output(args)
 
41
 
 
42
    if project in out.decode('utf8').split('\n'):
 
43
        return True
 
44
    else:
 
45
        return False
 
46
 
 
47
 
 
48
def new_workspace(project, stage, branch, name):
 
49
    '''Create a fresh mojo workspace for the given project'''
 
50
    args = [
 
51
        'mojo',
 
52
        'workspace-new',
 
53
        '--project', project,
 
54
        '--stage={}'.format(stage),
 
55
        '--series', SERIES,
 
56
        branch,
 
57
        name,
 
58
    ]
 
59
    utils.check_call(args)
 
60
 
 
61
 
 
62
def deploy(project, stage, branch, manifest, juju_home):
 
63
    '''Deploy the given mojo project.'''
 
64
    workspace_name = os.path.basename(juju_home)
 
65
    env = os.environ.copy()
 
66
    env['JUJU_HOME'] = juju_home
 
67
 
 
68
    # Run juju status before trying to deploy as a safe workaround
 
69
    # (https://bugs.launchpad.net/juju-deployer/+bug/1368403)
 
70
    args = ['juju', 'status']
 
71
    utils.check_call(args, env=env)
 
72
 
 
73
    args = [
 
74
        'mojo',
 
75
        'run',
 
76
        '--project', project,
 
77
        '--series', SERIES,
 
78
        '--stage', stage,
 
79
        # Mojo 0.1.6 (ppa) does not like it, so -golive manifests
 
80
        # are currently blocked.
 
81
        # '--manifest-file', manifest,
 
82
        branch,
 
83
        workspace_name,
 
84
    ]
 
85
 
 
86
    utils.check_call(args, env=env)