Merge lp:~joetalbott/utah/add_product_uuid into lp:utah

Proposed by Joe Talbott
Status: Merged
Approved by: Javier Collado
Approved revision: 724
Merged at revision: 726
Proposed branch: lp:~joetalbott/utah/add_product_uuid
Merge into: lp:utah
Diff against target: 86 lines (+39/-2)
2 files modified
utah/client/common.py (+29/-2)
utah/client/tests/test_common.py (+10/-0)
To merge this branch: bzr merge lp:~joetalbott/utah/add_product_uuid
Reviewer Review Type Date Requested Status
Javier Collado (community) Approve
Joe Talbott (community) Needs Resubmitting
Review via email: mp+131407@code.launchpad.net

Description of the change

Add product_uuid for machine under test to the result packet.

To post a comment you must log in.
Revision history for this message
Javier Collado (javier.collado) wrote :

To read files I like to use a context manager to guarantee that the file is closed:

with open(filename) as f:
    product_uuid = f.read().strip()

Besides this, I'm not sure about the expected UUID format, but maybe using a regular
expression is a good idea.

Finally, when is the IOError expected to happen? If it's related to permissions,
then checking the permissions before opening the file might be clearer and explicit.

lp:~joetalbott/utah/add_product_uuid updated
723. By Joe Talbott

Check for read access of product_uuid file rather than try/except

* use 'with' wrapper for file reads
* note that some methods are best-effort.

724. By Joe Talbott

tests - Add test for get_product_uuid().

Revision history for this message
Joe Talbott (joetalbott) wrote :

Updated to address Javier's issues.

I don't think we need to worry about the contents of /sys/class/dmi/id/product_uuid. We do a best-effort attempt to read the file and return whatever is there.

review: Needs Resubmitting
Revision history for this message
Javier Collado (javier.collado) wrote :

Thanks for the update. Looks good to me now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'utah/client/common.py'
--- utah/client/common.py 2012-10-22 08:15:08 +0000
+++ utah/client/common.py 2012-10-25 19:42:18 +0000
@@ -299,18 +299,43 @@
299def get_media_info():299def get_media_info():
300 """300 """
301 Get the contents of the media-info file if available.301 Get the contents of the media-info file if available.
302
303 NOTE: This is only a best-effort approach.
304
305 Returns the contents of the media-info file or None.
302 """306 """
303307
304 filename = '/var/log/installer/media-info'308 filename = '/var/log/installer/media-info'
305309
306 media_info = None310 media_info = None
307311
308 if os.path.exists(filename):312 if os.path.exists(filename) and os.access(filename, os.R_OK):
309 media_info = open(filename, 'r').read()313 with open(filename, 'r') as f:
314 media_info = f.read()
310315
311 return media_info316 return media_info
312317
313318
319def get_product_uuid():
320 """
321 Get the product_uuid of the machine under test.
322
323 NOTE: This is only a best-effort approach.
324
325 Returns the contents of the product_uuid file or None.
326 """
327
328 filename = '/sys/class/dmi/id/product_uuid'
329
330 product_uuid = None
331
332 if os.path.exists(filename) and os.access(filename, os.R_OK):
333 with open(filename) as f:
334 product_uuid = f.read().strip()
335
336 return product_uuid
337
338
314def get_host_info():339def get_host_info():
315 """340 """
316 Get host info, useful for debugging.341 Get host info, useful for debugging.
@@ -321,6 +346,8 @@
321 retval['uname'] = platform.uname()346 retval['uname'] = platform.uname()
322 retval['media-info'] = get_media_info()347 retval['media-info'] = get_media_info()
323348
349 retval['product_uuid'] = get_product_uuid()
350
324 return retval351 return retval
325352
326353
327354
=== modified file 'utah/client/tests/test_common.py'
--- utah/client/tests/test_common.py 2012-09-27 13:55:41 +0000
+++ utah/client/tests/test_common.py 2012-10-25 19:42:18 +0000
@@ -4,6 +4,7 @@
4# REQUIRES that the top level utah package be in the Python path.4# REQUIRES that the top level utah package be in the Python path.
5from utah.client.common import (5from utah.client.common import (
6 get_media_info,6 get_media_info,
7 get_product_uuid,
7 get_host_info,8 get_host_info,
8 run_cmd,9 run_cmd,
9 debug_print,10 debug_print,
@@ -15,6 +16,15 @@
15 """16 """
16 Tests for utah.client.common.17 Tests for utah.client.common.
17 """18 """
19
20 def test_get_product_uuid(self):
21 """ Test that product_uuid is returned when possible. """
22
23 product_uuid = get_product_uuid()
24
25 if os.access('/sys/class/dmi/id/product_uuid', os.R_OK):
26 self.assertIsNotNone(product_uuid)
27
18 def test_get_media_info(self):28 def test_get_media_info(self):
19 """29 """
20 Test that if there is a media-info file that it is parsed.30 Test that if there is a media-info file that it is parsed.

Subscribers

People subscribed via source and target branches