Merge lp:~laney/ubuntu-test-cases/dbus-etc-machine-id into lp:ubuntu-test-cases/desktop

Proposed by Iain Lane
Status: Merged
Approved by: Francis Ginther
Approved revision: 50
Merged at revision: 50
Proposed branch: lp:~laney/ubuntu-test-cases/dbus-etc-machine-id
Merge into: lp:ubuntu-test-cases/desktop
Diff against target: 75 lines (+27/-8)
2 files modified
testsuites/usit/dbus_machine_id/test.py (+17/-7)
testsuites/usit/no_rofs_machine_id/test.py (+10/-1)
To merge this branch: bzr merge lp:~laney/ubuntu-test-cases/dbus-etc-machine-id
Reviewer Review Type Date Requested Status
Francis Ginther Approve
Review via email: mp+253320@code.launchpad.net

This proposal supersedes a proposal from 2015-03-17.

Description of the change

D-Bus uses /etc/machine-id and the other file is no longer necessary.

Do we need to keep backwards compatibility?

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

This test isn't specific to new releases, right? In that case the fallback code is necessary to maintain functionality on trusty, utopic, etc.

So looks good as-is.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'testsuites/usit/dbus_machine_id/test.py'
2--- testsuites/usit/dbus_machine_id/test.py 2013-01-03 23:28:37 +0000
3+++ testsuites/usit/dbus_machine_id/test.py 2015-03-18 09:17:55 +0000
4@@ -27,7 +27,8 @@
5
6
7 class MachineIdTest(unittest.TestCase):
8- MACHINE_ID_FILE = '/var/lib/dbus/machine-id'
9+ MACHINE_ID_FILE = '/etc/machine-id'
10+ MACHINE_ID_FILE_FALLBACK = '/var/lib/dbus/machine-id'
11
12 # Expected age of the file is 5 minutes (300 seconds) which is an arbitrary
13 # value sane in VM with low resources as well as bare metal environments
14@@ -35,14 +36,23 @@
15
16 def test_machine_id(self):
17 """Machine Id is there and log content and age."""
18- logging.info('Checking that machine id file {!r} exists...'
19- .format(self.MACHINE_ID_FILE))
20- self.assertTrue(os.path.exists(self.MACHINE_ID_FILE))
21+ logging.info('Checking that machine id file {!r} or {!r} exists...'
22+ .format(self.MACHINE_ID_FILE,
23+ self.MACHINE_ID_FILE_FALLBACK))
24
25 logging.info('Reading file...')
26- with open(self.MACHINE_ID_FILE) as f:
27- machine_id = f.read().rstrip()
28- logging.info('The machine id is {!r}'.format(machine_id))
29+ try:
30+ with open(self.MACHINE_ID_FILE) as f:
31+ machine_id = f.read().rstrip()
32+ logging.info('The machine id is {!r}'.format(machine_id))
33+ except IOError:
34+ logging.info('Couldn\'t open {!r}, trying {!r}'
35+ .format(self.MACHINE_ID_FILE,
36+ self.MACHINE_ID_FILE_FALLBACK))
37+ with open(self.MACHINE_ID_FILE_FALLBACK) as f:
38+ self.MACHINE_ID_FILE = self.MACHINE_ID_FILE_FALLBACK
39+ machine_id = f.read().rstrip()
40+ logging.info('The machine id is {!r}'.format(machine_id))
41
42 logging.info('Getting last modification time...')
43 mtime = os.path.getmtime(self.MACHINE_ID_FILE)
44
45=== modified file 'testsuites/usit/no_rofs_machine_id/test.py'
46--- testsuites/usit/no_rofs_machine_id/test.py 2013-01-03 23:28:37 +0000
47+++ testsuites/usit/no_rofs_machine_id/test.py 2015-03-18 09:17:55 +0000
48@@ -26,17 +26,26 @@
49
50
51 class NoRofsMachineId(unittest.TestCase):
52- MACHINE_ID_FILE = 'var/lib/dbus/machine-id'
53+ MACHINE_ID_FILE = 'etc/machine-id'
54+ MACHINE_ID_FILE_FALLBACK = 'var/lib/dbus/machine-id'
55 ROFS_DIR = '/rofs'
56
57 def test_no_rofs_machine_id(self):
58 """Machine ID doesn't exist on the rofs."""
59 rofs_machine_id = os.path.join(self.ROFS_DIR, self.MACHINE_ID_FILE)
60+ rofs_machine_id_fallback = os.path.join(self.ROFS_DIR,
61+ self.MACHINE_ID_FILE_FALLBACK)
62 logging.info("Checking that machine id file under {} ({}) "
63 "doesn't exist"
64 .format(self.ROFS_DIR, rofs_machine_id))
65 self.assertFalse(os.path.exists(rofs_machine_id),
66 'Machine ID file ({}) exists'.format(rofs_machine_id))
67+ logging.info("Checking that machine id file under {} ({}) "
68+ "doesn't exist"
69+ .format(self.ROFS_DIR, rofs_machine_id_fallback))
70+ self.assertFalse(os.path.exists(rofs_machine_id_fallback),
71+ 'Machine ID file ({}) exists'
72+ .format(rofs_machine_id_fallback))
73
74 if __name__ == '__main__':
75 logging.basicConfig(level=logging.DEBUG,

Subscribers

People subscribed via source and target branches