Merge lp:~soren/nova/run-from-checkout into lp:~hudson-openstack/nova/trunk

Proposed by Soren Hansen
Status: Merged
Approved by: Vish Ishaya
Approved revision: 266
Merged at revision: 270
Proposed branch: lp:~soren/nova/run-from-checkout
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 220 lines (+99/-4)
10 files modified
bin/nova-api (+10/-0)
bin/nova-api-new (+11/-0)
bin/nova-compute (+11/-0)
bin/nova-dhcpbridge (+7/-4)
bin/nova-import-canonical-imagestore (+8/-0)
bin/nova-instancemonitor (+10/-0)
bin/nova-manage (+9/-0)
bin/nova-network (+11/-0)
bin/nova-objectstore (+11/-0)
bin/nova-volume (+11/-0)
To merge this branch: bzr merge lp:~soren/nova/run-from-checkout
Reviewer Review Type Date Requested Status
Vish Ishaya (community) Approve
termie (community) Approve
Review via email: mp+34842@code.launchpad.net

Description of the change

It's annoying and confusing to have to set PYTHONPATH to point to your
development tree before you run any of the scripts.

If you're lucky, it just fails (because you don't have nova in the default
search path (i.e. don't have them installed in /usr/lib/blah)) so that you can
fix it up.

If you're less lucky, you spend at least a couple of minutes wondering
why the cool changes you made to one of the nova modules don't take effect
until you realise it's because it's using the nova stuff in /usr/lib.

So, to save myself (and probably others) a bit of time, this patch adds
a snippet to each of the scripts in bin/ to detect this and set up the PYTHONPATH.

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

lgtm

review: Approve
Revision history for this message
Vish Ishaya (vishvananda) wrote :

But the bin files were down to only about one line of actual code!!! :) But seriously, I have been burned by this plenty of times myself. This seems like a reasonable way to deal with the annoyance.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/nova-api'
2--- bin/nova-api 2010-08-19 01:25:16 +0000
3+++ bin/nova-api 2010-09-08 09:29:39 +0000
4@@ -22,9 +22,19 @@
5 """
6
7 import logging
8+import os
9+import sys
10 from tornado import httpserver
11 from tornado import ioloop
12
13+# If ../nova/__init__.py exists, add ../ to Python search path, so that
14+# it will override what happens to be installed in /usr/(local/)lib/python...
15+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
16+ os.pardir,
17+ os.pardir))
18+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
19+ sys.path.insert(0, possible_topdir)
20+
21 from nova import flags
22 from nova import server
23 from nova import utils
24
25=== modified file 'bin/nova-api-new'
26--- bin/nova-api-new 2010-08-19 18:53:44 +0000
27+++ bin/nova-api-new 2010-09-08 09:29:39 +0000
28@@ -21,6 +21,17 @@
29 Nova API daemon.
30 """
31
32+import os
33+import sys
34+
35+# If ../nova/__init__.py exists, add ../ to Python search path, so that
36+# it will override what happens to be installed in /usr/(local/)lib/python...
37+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
38+ os.pardir,
39+ os.pardir))
40+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
41+ sys.path.insert(0, possible_topdir)
42+
43 from nova import api
44 from nova import flags
45 from nova import utils
46
47=== modified file 'bin/nova-compute'
48--- bin/nova-compute 2010-08-19 00:39:12 +0000
49+++ bin/nova-compute 2010-09-08 09:29:39 +0000
50@@ -21,6 +21,17 @@
51 Twistd daemon for the nova compute nodes.
52 """
53
54+import os
55+import sys
56+
57+# If ../nova/__init__.py exists, add ../ to Python search path, so that
58+# it will override what happens to be installed in /usr/(local/)lib/python...
59+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
60+ os.pardir,
61+ os.pardir))
62+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
63+ sys.path.insert(0, possible_topdir)
64+
65 from nova import twistd
66 from nova.compute import service
67
68
69=== modified file 'bin/nova-dhcpbridge'
70--- bin/nova-dhcpbridge 2010-08-19 00:39:12 +0000
71+++ bin/nova-dhcpbridge 2010-09-08 09:29:39 +0000
72@@ -25,10 +25,13 @@
73 import os
74 import sys
75
76-#TODO(joshua): there is concern that the user dnsmasq runs under will not
77-# have nova in the path. This should be verified and if it is
78-# not true the ugly line below can be removed
79-sys.path.append(os.path.abspath(os.path.join(__file__, "../../")))
80+# If ../nova/__init__.py exists, add ../ to Python search path, so that
81+# it will override what happens to be installed in /usr/(local/)lib/python...
82+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
83+ os.pardir,
84+ os.pardir))
85+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
86+ sys.path.insert(0, possible_topdir)
87
88 from nova import flags
89 from nova import rpc
90
91=== modified file 'bin/nova-import-canonical-imagestore'
92--- bin/nova-import-canonical-imagestore 2010-08-20 01:24:59 +0000
93+++ bin/nova-import-canonical-imagestore 2010-09-08 09:29:39 +0000
94@@ -29,6 +29,14 @@
95 import sys
96 import urllib2
97
98+# If ../nova/__init__.py exists, add ../ to Python search path, so that
99+# it will override what happens to be installed in /usr/(local/)lib/python...
100+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
101+ os.pardir,
102+ os.pardir))
103+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
104+ sys.path.insert(0, possible_topdir)
105+
106 from nova import flags
107 from nova import utils
108 from nova.objectstore import image
109
110=== modified file 'bin/nova-instancemonitor'
111--- bin/nova-instancemonitor 2010-08-19 00:39:12 +0000
112+++ bin/nova-instancemonitor 2010-09-08 09:29:39 +0000
113@@ -21,9 +21,19 @@
114 Daemon for Nova RRD based instance resource monitoring.
115 """
116
117+import os
118 import logging
119+import sys
120 from twisted.application import service
121
122+# If ../nova/__init__.py exists, add ../ to Python search path, so that
123+# it will override what happens to be installed in /usr/(local/)lib/python...
124+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
125+ os.pardir,
126+ os.pardir))
127+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
128+ sys.path.insert(0, possible_topdir)
129+
130 from nova import twistd
131 from nova.compute import monitor
132
133
134=== modified file 'bin/nova-manage'
135--- bin/nova-manage 2010-08-20 01:24:59 +0000
136+++ bin/nova-manage 2010-09-08 09:29:39 +0000
137@@ -22,9 +22,18 @@
138 Connects to the running ADMIN api in the api daemon.
139 """
140
141+import os
142 import sys
143 import time
144
145+# If ../nova/__init__.py exists, add ../ to Python search path, so that
146+# it will override what happens to be installed in /usr/(local/)lib/python...
147+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
148+ os.pardir,
149+ os.pardir))
150+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
151+ sys.path.insert(0, possible_topdir)
152+
153 from nova import flags
154 from nova import utils
155 from nova.auth import manager
156
157=== modified file 'bin/nova-network'
158--- bin/nova-network 2010-08-19 00:39:12 +0000
159+++ bin/nova-network 2010-09-08 09:29:39 +0000
160@@ -21,6 +21,17 @@
161 Twistd daemon for the nova network nodes.
162 """
163
164+import os
165+import sys
166+
167+# If ../nova/__init__.py exists, add ../ to Python search path, so that
168+# it will override what happens to be installed in /usr/(local/)lib/python...
169+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
170+ os.pardir,
171+ os.pardir))
172+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
173+ sys.path.insert(0, possible_topdir)
174+
175 from nova import flags
176 from nova import twistd
177
178
179=== modified file 'bin/nova-objectstore'
180--- bin/nova-objectstore 2010-08-19 00:39:12 +0000
181+++ bin/nova-objectstore 2010-09-08 09:29:39 +0000
182@@ -21,6 +21,17 @@
183 Twisted daemon for nova objectstore. Supports S3 API.
184 """
185
186+import os
187+import sys
188+
189+# If ../nova/__init__.py exists, add ../ to Python search path, so that
190+# it will override what happens to be installed in /usr/(local/)lib/python...
191+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
192+ os.pardir,
193+ os.pardir))
194+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
195+ sys.path.insert(0, possible_topdir)
196+
197 from nova import flags
198 from nova import utils
199 from nova import twistd
200
201=== modified file 'bin/nova-volume'
202--- bin/nova-volume 2010-08-19 00:39:12 +0000
203+++ bin/nova-volume 2010-09-08 09:29:39 +0000
204@@ -21,6 +21,17 @@
205 Twistd daemon for the nova volume nodes.
206 """
207
208+import os
209+import sys
210+
211+# If ../nova/__init__.py exists, add ../ to Python search path, so that
212+# it will override what happens to be installed in /usr/(local/)lib/python...
213+possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
214+ os.pardir,
215+ os.pardir))
216+if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
217+ sys.path.insert(0, possible_topdir)
218+
219 from nova import twistd
220 from nova.volume import service
221