Merge lp:~bigdata-dev/charms/trusty/apache-hadoop-plugin/venv into lp:~bigdata-dev/charms/trusty/apache-hadoop-plugin/trunk

Proposed by Cory Johns
Status: Merged
Merged at revision: 109
Proposed branch: lp:~bigdata-dev/charms/trusty/apache-hadoop-plugin/venv
Merge into: lp:~bigdata-dev/charms/trusty/apache-hadoop-plugin/trunk
Diff against target: 128 lines (+24/-11)
8 files modified
hooks/common.py (+10/-1)
hooks/config-changed (+1/-1)
hooks/hadoop-plugin-relation-changed (+1/-1)
hooks/namenode-relation-changed (+1/-1)
hooks/resourcemanager-relation-changed (+1/-1)
hooks/setup.py (+8/-4)
hooks/start (+1/-1)
hooks/stop (+1/-1)
To merge this branch: bzr merge lp:~bigdata-dev/charms/trusty/apache-hadoop-plugin/venv
Reviewer Review Type Date Requested Status
Kevin W Monroe Approve
amir sanjar (community) Approve
Review via email: mp+263018@code.launchpad.net

Description of the change

Use venv for plugin to avoid conflicts with parent charm

To post a comment you must log in.
Revision history for this message
amir sanjar (asanjar) wrote :

+1

review: Approve
Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

I see install_pip went away from setup.py. But I don't see python-pip or bzr being installed anywhere else (or in ./resources/python). Are those not needed anymore?

Revision history for this message
Cory Johns (johnsca) wrote :

virtualenv automatically installs pip

Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

Word. I'm not sure why bzr was ever in there, so I'm good with it going away. LGTM, +1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/common.py'
2--- hooks/common.py 2015-06-25 15:41:48 +0000
3+++ hooks/common.py 2015-06-25 18:54:45 +0000
4@@ -1,4 +1,4 @@
5-#!/usr/bin/env python
6+#!.venv/bin/python
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10@@ -14,12 +14,21 @@
11 Common implementation for all hooks.
12 """
13
14+import os
15 import jujuresources
16 from charmhelpers.core import hookenv
17 from charmhelpers.core import unitdata
18 from charmhelpers.core import charmframework
19
20
21+# ensure that the venv is used for installing resources
22+# (venv is used to ensure library versions needed by plugin
23+# don't conflict with the charm the plugin is supporting)
24+os.environ['PATH'] = os.pathsep.join([
25+ os.path.join(hookenv.charm_dir(), '.venv/bin'),
26+ os.environ['PATH']])
27+
28+
29 def bootstrap_resources():
30 """
31 Install required resources defined in resources.yaml
32
33=== modified file 'hooks/config-changed'
34--- hooks/config-changed 2015-02-09 18:13:28 +0000
35+++ hooks/config-changed 2015-06-25 18:54:45 +0000
36@@ -1,4 +1,4 @@
37-#!/usr/bin/env python
38+#!.venv/bin/python
39 # Licensed under the Apache License, Version 2.0 (the "License");
40 # you may not use this file except in compliance with the License.
41 # You may obtain a copy of the License at
42
43=== modified file 'hooks/hadoop-plugin-relation-changed'
44--- hooks/hadoop-plugin-relation-changed 2015-04-28 13:38:46 +0000
45+++ hooks/hadoop-plugin-relation-changed 2015-06-25 18:54:45 +0000
46@@ -1,4 +1,4 @@
47-#!/usr/bin/env python
48+#!.venv/bin/python
49 # Licensed under the Apache License, Version 2.0 (the "License");
50 # you may not use this file except in compliance with the License.
51 # You may obtain a copy of the License at
52
53=== modified file 'hooks/namenode-relation-changed'
54--- hooks/namenode-relation-changed 2015-05-07 15:27:21 +0000
55+++ hooks/namenode-relation-changed 2015-06-25 18:54:45 +0000
56@@ -1,4 +1,4 @@
57-#!/usr/bin/env python
58+#!.venv/bin/python
59 # Licensed under the Apache License, Version 2.0 (the "License");
60 # you may not use this file except in compliance with the License.
61 # You may obtain a copy of the License at
62
63=== modified file 'hooks/resourcemanager-relation-changed'
64--- hooks/resourcemanager-relation-changed 2015-05-07 15:11:29 +0000
65+++ hooks/resourcemanager-relation-changed 2015-06-25 18:54:45 +0000
66@@ -1,4 +1,4 @@
67-#!/usr/bin/env python
68+#!.venv/bin/python
69 # Licensed under the Apache License, Version 2.0 (the "License");
70 # you may not use this file except in compliance with the License.
71 # You may obtain a copy of the License at
72
73=== modified file 'hooks/setup.py'
74--- hooks/setup.py 2015-06-25 15:41:48 +0000
75+++ hooks/setup.py 2015-06-25 18:54:45 +0000
76@@ -9,6 +9,7 @@
77 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78 # See the License for the specific language governing permissions and
79 # limitations under the License.
80+import os
81 import subprocess
82 from glob import glob
83
84@@ -17,12 +18,15 @@
85 """
86 Do any setup required before the install hook.
87 """
88- install_pip()
89+ setup_venv()
90 install_bundled_resources()
91
92
93-def install_pip():
94- subprocess.check_call(['apt-get', 'install', '-yq', 'python-pip', 'bzr'])
95+def setup_venv():
96+ if not os.path.exists('.venv/bin/python'):
97+ subprocess.check_call(['apt-get', 'install', '-yq', 'python-virtualenv'])
98+ subprocess.check_call(['virtualenv', '.venv'])
99+ execfile('.venv/bin/activate_this.py', {'__file__': '.venv/bin/activate_this.py'})
100
101
102 def install_bundled_resources():
103@@ -30,4 +34,4 @@
104 Install the bundled resources libraries.
105 """
106 archives = glob('resources/python/*')
107- subprocess.check_call(['pip', 'install'] + archives)
108+ subprocess.check_call(['.venv/bin/pip', 'install'] + archives)
109
110=== modified file 'hooks/start'
111--- hooks/start 2015-02-09 18:13:28 +0000
112+++ hooks/start 2015-06-25 18:54:45 +0000
113@@ -1,4 +1,4 @@
114-#!/usr/bin/env python
115+#!.venv/bin/python
116 # Licensed under the Apache License, Version 2.0 (the "License");
117 # you may not use this file except in compliance with the License.
118 # You may obtain a copy of the License at
119
120=== modified file 'hooks/stop'
121--- hooks/stop 2015-02-09 18:13:28 +0000
122+++ hooks/stop 2015-06-25 18:54:45 +0000
123@@ -1,4 +1,4 @@
124-#!/usr/bin/env python
125+#!.venv/bin/python
126 # Licensed under the Apache License, Version 2.0 (the "License");
127 # you may not use this file except in compliance with the License.
128 # You may obtain a copy of the License at

Subscribers

People subscribed via source and target branches

to all changes: