Merge lp:~bladernr/checkbox/1186259-virtualization-fix into lp:checkbox

Proposed by Jeff Lane 
Status: Merged
Approved by: Daniel Manrique
Approved revision: 2152
Merged at revision: 2152
Proposed branch: lp:~bladernr/checkbox/1186259-virtualization-fix
Merge into: lp:checkbox
Diff against target: 89 lines (+31/-12)
2 files modified
debian/changelog (+4/-1)
scripts/virtualization (+27/-11)
To merge this branch: bzr merge lp:~bladernr/checkbox/1186259-virtualization-fix
Reviewer Review Type Date Requested Status
Daniel Manrique (community) Approve
Review via email: mp+166898@code.launchpad.net

Description of the change

virtualization script no longer chokes when image: is emtpy in the config file, meaning you can actually use hte script in an offline setting. Added some additional error handling to more explicitly trap errors.

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

Looks good. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2013-05-31 15:07:02 +0000
+++ debian/changelog 2013-05-31 21:09:35 +0000
@@ -1,6 +1,9 @@
1checkbox (0.16.4) saucy; urgency=low1checkbox (0.16.4) saucy; urgency=low
22
3 * Incremented version 3 [ Jeff Lane ]
4 * scripts/virtualization: script no longer fails when trying to cast an
5 empty timeout setting in config file to int(). Added additional error
6 handling. (LP: #1186259)
47
5 -- Brendan Donegan <brendan.donegan@canonical.com> Fri, 31 May 2013 16:04:42 +01008 -- Brendan Donegan <brendan.donegan@canonical.com> Fri, 31 May 2013 16:04:42 +0100
69
710
=== modified file 'scripts/virtualization'
--- scripts/virtualization 2013-04-08 23:02:04 +0000
+++ scripts/virtualization 2013-05-31 21:09:35 +0000
@@ -168,6 +168,7 @@
168168
169169
170 def start(self):170 def start(self):
171 logging.debug('Starting KVM Test')
171 status = 1172 status = 1
172 # Create temp directory:173 # Create temp directory:
173174
@@ -176,6 +177,7 @@
176177
177 os.chdir(temp_dir)178 os.chdir(temp_dir)
178 if self.image is None:179 if self.image is None:
180 logging.debug('No image specified, downloading one now.')
179 # Download cloud image181 # Download cloud image
180 self.image = self.download_image()182 self.image = self.download_image()
181183
@@ -219,17 +221,26 @@
219221
220 try:222 try:
221 config.readfp(open(config_file))223 config.readfp(open(config_file))
222 timeout = int(config.get("KVM", "timeout"))
223 image = config.get("KVM", "image")
224 except IOError:224 except IOError:
225 logging.warn("No config file found")225 logging.warn("No config file found")
226 except Exception as exception:226 else:
227 logging.warn(exception)227 try:
228 timeout = int(config.get("KVM", "timeout"))
229 except ValueError:
230 logging.exception('Invalid or Empty timeout in config file. '
231 'Falling back to default')
232 except configparser.NoSectionError as e:
233 logging.exception(e)
234
235 try:
236 image = config.get("KVM", "image")
237 except configparser.NoSectionError:
238 logging.exception('Invalid or Empty image in config file.')
228239
240 if timeout == "":
241 timeout = args.timeout
229 if image == "":242 if image == "":
230 image = args.image243 image = args.image
231 if timeout == "":
232 timeout = args.timeout
233244
234 kvm_test = KVMTest(image, timeout)245 kvm_test = KVMTest(image, timeout)
235 result = kvm_test.start()246 result = kvm_test.start()
@@ -259,11 +270,16 @@
259 kvm_test_parser.set_defaults(func=test_kvm)270 kvm_test_parser.set_defaults(func=test_kvm)
260271
261 args = parser.parse_args()272 args = parser.parse_args()
262273
263 if args.debug:274 try:
264 logging.basicConfig(level=logging.DEBUG)275 if args.debug:
265276 logging.basicConfig(level=logging.DEBUG)
266 args.func(args)277 except AttributeError:
278 pass #avoids exception when trying to run without specifying 'kvm'
279 try:
280 args.func(args)
281 except AttributeError:
282 parser.error('Must specify a test type')
267283
268if __name__ == "__main__":284if __name__ == "__main__":
269 main()285 main()

Subscribers

People subscribed via source and target branches