Merge lp:~nskaggs/autopilot/catch-stateerror-printtree into lp:autopilot

Proposed by Nicholas Skaggs
Status: Superseded
Proposed branch: lp:~nskaggs/autopilot/catch-stateerror-printtree
Merge into: lp:autopilot
Diff against target: 60 lines (+27/-6)
2 files modified
autopilot/introspection/dbus.py (+9/-6)
autopilot/tests/unit/test_introspection_features.py (+18/-0)
To merge this branch: bzr merge lp:~nskaggs/autopilot/catch-stateerror-printtree
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Max Brustkern (community) Approve
Thomi Richards (community) Needs Fixing
Chris Gagnon (community) Needs Fixing
Review via email: mp+204976@code.launchpad.net

This proposal has been superseded by a proposal from 2014-03-20.

Commit message

Ignore statenotfound errors in print_tree

Description of the change

Dumping the object tree with print_tree often fails to complete due to StateNotFound errors. This modifies the print call to catch these errors and continue to print the largest possible tree. Other errors could be considered as well to try and print as complete a dump as possible.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Chris Gagnon (chris.gagnon) wrote :

This needs tests

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

@ChrisGagnon, I'll try playing with AssertRaises to add a test for this path.

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Setting this back to a WIP MP since we all agree that it needs tests before being merged.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi

at the end of your test, could you please add an assertion for the error message you expect to see?

Please set this MP back to 'Needs review' when you want another review.

Thanks

review: Needs Fixing
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Argh, bzr lost my changes I made.. they never pushed I see. I'll redo.

437. By Nicholas Skaggs

revert accidental whitespace removal

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Max Brustkern (nuclearbob) wrote :

Seems reasonable to me.

review: Approve
438. By Nicholas Skaggs

leaving sorting alone, but otherwise dropping gettr for direct print from dict

439. By Nicholas Skaggs

%r for prints

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

I have concerns this may have introduced an issue with print_tree, which is not shown by the tests. The dump seems to get stuck in the regression loop. Namely the change from

for p in sorted(self.get_properties()):

to

for prop, value in sorted(self.get_properties().items()):

is the likely cause.

Can someone help setup a test object that contains a larger tree to vet these changes a bit better?

We create a fake object like so:

        fake_object = DBusIntrospectionObject(
            dict(id=[0, 123], path=[0, '/some/path'], text=[0, 'Hello']),
            '/some/path',
            Mock()
        )

I tried making the dict larger but failed. I'm missing something basic; how can i make a tree like this?

            == /some/path ==
            id: 123
            path: '/some/path'
            text: 'Hello'
                == /some/path/child ==
               id: 456
               path: '/some/path/child'
               text: 'Hello Child'
                == /some/path/child2 ==
               id: 789
               path: '/some/path/child2'
               text: 'Hello Child2'
            == /some/other/path ==
            id: 542
            path: '/some/other/path'
            text: 'Hello'

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi,

I doubt that turning this:

for p in sorted(self.get_properties()):

into this:

for prop, value in sorted(self.get_properties().items()):

Is the cause of your problems. You're correct though - we need a better way to create fake proxy objects. This is something I've been thinking about for a looong time.

I suggest that you merge in my branch, which already has many of the changes in here, and add your exception handling and test code.

440. By Nicholas Skaggs

merge thomi's tweaks

441. By Nicholas Skaggs

tweak merge

442. By Nicholas Skaggs

fix spacing :-)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/introspection/dbus.py'
2--- autopilot/introspection/dbus.py 2014-03-11 16:39:25 +0000
3+++ autopilot/introspection/dbus.py 2014-03-19 22:17:49 +0000
4@@ -651,12 +651,15 @@
5 output.write("\n")
6 output.write("%s== %s ==\n" % (indent, self._path))
7 # print properties
8- for p in sorted(self.get_properties()):
9- output.write("%s%s: %s\n" % (indent, p, repr(getattr(self, p))))
10- # print children
11- if maxdepth is None or _curdepth < maxdepth:
12- for c in self.get_children():
13- c.print_tree(output, maxdepth, _curdepth + 1)
14+ try:
15+ for prop, value in sorted(self.get_properties().items()):
16+ output.write("%s%s: %r\n" % (indent, prop, value))
17+ # print children
18+ if maxdepth is None or _curdepth < maxdepth:
19+ for c in self.get_children():
20+ c.print_tree(output, maxdepth, _curdepth + 1)
21+ except StateNotFoundError as error:
22+ output.write("%sError: %s\n" % (indent, error))
23
24 @contextmanager
25 def no_automatic_refreshing(self):
26
27=== modified file 'autopilot/tests/unit/test_introspection_features.py'
28--- autopilot/tests/unit/test_introspection_features.py 2014-03-11 17:36:53 +0000
29+++ autopilot/tests/unit/test_introspection_features.py 2014-03-19 22:17:49 +0000
30@@ -55,6 +55,7 @@
31 _object_passes_filters,
32 CustomEmulatorBase,
33 DBusIntrospectionObject,
34+ StateNotFoundError,
35 )
36 from autopilot.utilities import sleep
37
38@@ -305,6 +306,23 @@
39 text: 'Hello'
40 """))
41
42+ def test_print_tree_exception(self):
43+ """print_tree with StateNotFound exception"""
44+
45+ fake_object = self._print_test_fake_object()
46+ child = Mock()
47+ child.print_tree.side_effect = StateNotFoundError('child')
48+
49+ with patch.object(fake_object, 'get_children', return_value=[child]):
50+ out = StringIO()
51+ print_func = lambda: fake_object.print_tree(out)
52+ self.assertThat(print_func, Not(Raises(StateNotFoundError)))
53+ self.assertEqual(out.getvalue(), dedent("""\
54+ == /some/path ==
55+ id: 123
56+ Error: Object not found with name 'child'.
57+ """))
58+
59 def test_print_tree_fileobj(self):
60 """print_tree with file object output"""
61

Subscribers

People subscribed via source and target branches