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
1=== added directory 'files'
2=== modified file 'hooks/actions.py'
3--- hooks/actions.py 2015-03-04 18:34:06 +0000
4+++ hooks/actions.py 2015-03-05 01:17:46 +0000
5@@ -7,13 +7,7 @@
6 from charmhelpers.core import hookenv
7
8
9-REQUIRED_PACKAGES = [
10- 'bzr',
11- # py2 dependencies as a temporary hack-to-production.
12- 'python-kombu',
13- 'python-configparser',
14- 'python-swiftclient',
15-]
16+REQUIRED_PACKAGES = ['bzr', 'python-virtualenv', 'python3-dev']
17 SERVICE_DIR = '/srv/adt-cloud-worker'
18
19 config = hookenv.config()
20@@ -35,3 +29,25 @@
21 config_file = config['config-file']
22 with open(os.path.join(SERVICE_DIR, '.adt-service.conf'), 'w') as f:
23 f.write(base64.b64decode(config_file))
24+
25+def install_python_packages(service_name):
26+ hookenv.log('Installing python packages...')
27+ env_dir = os.path.join(SERVICE_DIR, 've')
28+ subprocess.call(['virtualenv', '-p', 'python3', env_dir])
29+
30+ pip_cache = os.path.join(hookenv.charm_dir(), 'files', 'pip-cache')
31+ requirements = os.path.join(SERVICE_DIR, 'requirements.txt')
32+ if os.path.exists(pip_cache):
33+ hookenv.log('Installing from download cache.')
34+ subprocess.call(['%s/bin/pip' % env_dir,
35+ 'install',
36+ '--no-index',
37+ '--find-links={}'.format(pip_cache),
38+ '-r', requirements])
39+ else:
40+ hookenv.log('Installing from pypi.')
41+ subprocess.call(['%s/bin/pip' % env_dir,
42+ 'install', '-r', requirements])
43+
44+ subprocess.call(['%s/bin/pip' % env_dir,
45+ 'install', '--no-deps', '-e', SERVICE_DIR])
46
47=== modified file 'hooks/services.py'
48--- hooks/services.py 2015-03-04 16:14:33 +0000
49+++ hooks/services.py 2015-03-05 01:17:46 +0000
50@@ -16,6 +16,7 @@
51 'data_ready': [
52 actions.install_packages,
53 actions.get_cloud_worker_branch,
54+ actions.install_python_packages,
55 actions.get_config_file,
56 helpers.render_template(
57 source='upstart.conf',
58
59=== modified file 'templates/upstart.conf'
60--- templates/upstart.conf 2015-03-04 18:34:06 +0000
61+++ templates/upstart.conf 2015-03-05 01:17:46 +0000
62@@ -14,8 +14,9 @@
63 env SERVICE_DIR=/srv/adt-cloud-worker
64
65 script
66+
67 mkdir -p ${SERVICE_DIR}/logs
68- # XXX cprov: respect py3 project choice once we have proper dependencies
69- # available.
70- exec python ${SERVICE_DIR}/adt-cloud-worker.py -c ${SERVICE_DIR}/.adt-service.conf >> ${SERVICE_DIR}/logs/adt-cloud-worker.log 2>&1
71+ chdir ${SERVICE_DIR}
72+ exec ./ve/bin/python3 adt-cloud-worker.py >> logs/adt-cloud-worker.log 2>&1
73+
74 end script

Subscribers

People subscribed via source and target branches