Merge lp:~cprov/charms/trusty/adt-cloud-worker/py3-venv-switch into lp:~canonical-ci-engineering/charms/trusty/adt-cloud-worker/trunk

Proposed by Celso Providelo
Status: Merged
Merged at revision: 5
Proposed branch: lp:~cprov/charms/trusty/adt-cloud-worker/py3-venv-switch
Merge into: lp:~canonical-ci-engineering/charms/trusty/adt-cloud-worker/trunk
Diff against target: 74 lines (+28/-10)
3 files modified
hooks/actions.py (+23/-7)
hooks/services.py (+1/-0)
templates/upstart.conf (+4/-3)
To merge this branch: bzr merge lp:~cprov/charms/trusty/adt-cloud-worker/py3-venv-switch
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
Review via email: mp+251853@code.launchpad.net

Description of the change

Supporting python3 codebase on trusty with virtualenv.

Dependencies are installed from pypi (internet) if the charm does not get fed with files/pip-cache.

We will populate the cache in the mojo spec, later.

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'files'
=== modified file 'hooks/actions.py'
--- hooks/actions.py 2015-03-04 18:34:06 +0000
+++ hooks/actions.py 2015-03-05 01:17:46 +0000
@@ -7,13 +7,7 @@
7from charmhelpers.core import hookenv7from charmhelpers.core import hookenv
88
99
10REQUIRED_PACKAGES = [10REQUIRED_PACKAGES = ['bzr', 'python-virtualenv', 'python3-dev']
11 'bzr',
12 # py2 dependencies as a temporary hack-to-production.
13 'python-kombu',
14 'python-configparser',
15 'python-swiftclient',
16]
17SERVICE_DIR = '/srv/adt-cloud-worker'11SERVICE_DIR = '/srv/adt-cloud-worker'
1812
19config = hookenv.config()13config = hookenv.config()
@@ -35,3 +29,25 @@
35 config_file = config['config-file']29 config_file = config['config-file']
36 with open(os.path.join(SERVICE_DIR, '.adt-service.conf'), 'w') as f:30 with open(os.path.join(SERVICE_DIR, '.adt-service.conf'), 'w') as f:
37 f.write(base64.b64decode(config_file))31 f.write(base64.b64decode(config_file))
32
33def install_python_packages(service_name):
34 hookenv.log('Installing python packages...')
35 env_dir = os.path.join(SERVICE_DIR, 've')
36 subprocess.call(['virtualenv', '-p', 'python3', env_dir])
37
38 pip_cache = os.path.join(hookenv.charm_dir(), 'files', 'pip-cache')
39 requirements = os.path.join(SERVICE_DIR, 'requirements.txt')
40 if os.path.exists(pip_cache):
41 hookenv.log('Installing from download cache.')
42 subprocess.call(['%s/bin/pip' % env_dir,
43 'install',
44 '--no-index',
45 '--find-links={}'.format(pip_cache),
46 '-r', requirements])
47 else:
48 hookenv.log('Installing from pypi.')
49 subprocess.call(['%s/bin/pip' % env_dir,
50 'install', '-r', requirements])
51
52 subprocess.call(['%s/bin/pip' % env_dir,
53 'install', '--no-deps', '-e', SERVICE_DIR])
3854
=== modified file 'hooks/services.py'
--- hooks/services.py 2015-03-04 16:14:33 +0000
+++ hooks/services.py 2015-03-05 01:17:46 +0000
@@ -16,6 +16,7 @@
16 'data_ready': [16 'data_ready': [
17 actions.install_packages,17 actions.install_packages,
18 actions.get_cloud_worker_branch,18 actions.get_cloud_worker_branch,
19 actions.install_python_packages,
19 actions.get_config_file,20 actions.get_config_file,
20 helpers.render_template(21 helpers.render_template(
21 source='upstart.conf',22 source='upstart.conf',
2223
=== modified file 'templates/upstart.conf'
--- templates/upstart.conf 2015-03-04 18:34:06 +0000
+++ templates/upstart.conf 2015-03-05 01:17:46 +0000
@@ -14,8 +14,9 @@
14env SERVICE_DIR=/srv/adt-cloud-worker14env SERVICE_DIR=/srv/adt-cloud-worker
1515
16script16script
17
17 mkdir -p ${SERVICE_DIR}/logs18 mkdir -p ${SERVICE_DIR}/logs
18 # XXX cprov: respect py3 project choice once we have proper dependencies19 chdir ${SERVICE_DIR}
19 # available.20 exec ./ve/bin/python3 adt-cloud-worker.py >> logs/adt-cloud-worker.log 2>&1
20 exec python ${SERVICE_DIR}/adt-cloud-worker.py -c ${SERVICE_DIR}/.adt-service.conf >> ${SERVICE_DIR}/logs/adt-cloud-worker.log 2>&121
21end script22end script

Subscribers

People subscribed via source and target branches