Merge lp:~canonical-platform-qa/autopilot/cpo-base-classes-fix into lp:autopilot
| Status: | Merged |
|---|---|
| Approved by: | Christopher Lee on 2015-05-08 |
| Approved revision: | 578 |
| Merged at revision: | 554 |
| Proposed branch: | lp:~canonical-platform-qa/autopilot/cpo-base-classes-fix |
| Merge into: | lp:autopilot |
| Diff against target: |
590 lines (+399/-24) 9 files modified
apparmor/click.rules (+0/-12) autopilot/introspection/_object_registry.py (+68/-6) autopilot/introspection/_search.py (+35/-0) autopilot/tests/functional/test_introspection_features.py (+47/-2) autopilot/tests/unit/test_introspection_object_registry.py (+147/-1) autopilot/tests/unit/test_introspection_search.py (+94/-0) debian/autopilot-touch.dirs (+0/-1) debian/autopilot-touch.install (+0/-1) debian/changelog (+8/-1) |
| To merge this branch: | bzr merge lp:~canonical-platform-qa/autopilot/cpo-base-classes-fix |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| PS Jenkins bot | continuous-integration | Approve on 2015-05-07 | |
| Christopher Lee (community) | 2015-04-28 | Needs Information on 2015-05-06 | |
|
Review via email:
|
|||
Commit Message
CPO base classes fix
Description of the Change
CPO base classes fix
| Christopher Lee (veebers) wrote : | # |
| Federico Gimenez (fgimenez) wrote : | # |
Hi Chris, yes, I totally agree that adding the MRO stuff to the combine method is changing its initial behaviour. I added it after trying to make the current tests pass, I've commented in the code trying to make it clear.
Using the combine method to put together arbitrary tuples was giving at first an error about a cyclic dependency, one of the elements of the tuple was the class itself.
TypeError: a __bases__ item causes an inheritance cycle
This can be solved by passing the original class itself to the method, and checking that it is not a member of the collections being merged. At this point, we could continue treating the combine method as an abstract information merger. But after this, a second error arose:
TypeError: Cannot create a consistent method resolution order (MRO)
So that, to combine them appropriately, the method has to know which is the right order, and this information can be obtained from the classes MROs.
Unless I'm missing something it seems that the combine method has to know that it is combining classes, moreover it needs to know that the return value is going to be the bases tuple of one of the parameters. IMO the responsibility is well delimited, maybe we could split it.
Anyway, I'll try to implement the tests that you mention, thanks a lot Chris!
| Federico Gimenez (fgimenez) wrote : | # |
I've already added the tests for the current implementation of _combine_
While writing them I've noticed that when two classes had the same mro the order wasn't deterministic, I've added another function for having a more fine-grained control. Currently the classes in the original __bases__ tuple have lower index than the extensions in the resulting tuple, this can be changed.
Thanks,
| Christopher Lee (veebers) wrote : | # |
Looking good guys, just a couple of comments inline.
As per the changes I made to day; I was thinking about how to handle detecting and choosing the correct base class when there was multiple inheritance involved (i.e. multiple CPO inheritance).
I came to the conclusion that it is bad form to change things under the cover in this fashion as it can be misleading and cause unexpected changes.
Instead I've opted for issuing a warning when this is detected with the option to upgrade this to raising an error in the new future (i.e. when we can be certain we don't break everyone with this new enforcement rule.)
I was of 2 minds making it raise an exception straight off, but I feel that it was to heavy handed at this stage.
What do you guys think?
I've done some small scale testing locally and the address book and unity8 tests pass as expected. I would love to see this go through the gatekeeper to see the results there.
| Federico Gimenez (fgimenez) wrote : | # |
Thanks Chris, I've addressed the issues you mentioned, putting this in review
| PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:569
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 570. By Federico Gimenez on 2015-04-30
-
Fixed flake8
| Vincent Ladeuil (vila) wrote : | # |
> Looking good guys, just a couple of comments inline.
>
> As per the changes I made to day; I was thinking about how to handle detecting
> and choosing the correct base class when there was multiple inheritance
> involved (i.e. multiple CPO inheritance).
>
> I came to the conclusion that it is bad form to change things under the cover
> in this fashion as it can be misleading and cause unexpected changes.
/me nods
> Instead I've opted for issuing a warning when this is detected with the option
> to upgrade this to raising an error in the new future (i.e. when we can be
> certain we don't break everyone with this new enforcement rule.)
I would prefer raising an error than fixing the base class too.
Misuse of the CPO is a bug, clients should be fixed.
Especially when looking at Leo's branches fixing this issue in several clients, the fix seems light enough that it's worth breaking the clients so they are fixed asap.
A warning may be missed and the client test suites will not be fixed until it's noticed.
>
> I was of 2 minds making it raise an exception straight off, but I feel that it
> was to heavy handed at this stage.
> What do you guys think?
Let's collect some test results to get a better understanding ;)
>
> I've done some small scale testing locally and the address book and unity8
> tests pass as expected. I would love to see this go through the gatekeeper to
> see the results there.
+1
Looking at http://
| PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:570
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
| PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:569
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 571. By Federico Gimenez on 2015-04-30
-
More on comment about the classes ordering
| PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:571
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 572. By Federico Gimenez on 2015-05-01
-
merged vila's branch with packaging fix
| PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:572
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 573. By Federico Gimenez on 2015-05-04
-
Removing validate_
dbus_object method in the extesnsions before adding to the bases to preserve the original method resolution - 574. By Federico Gimenez on 2015-05-04
-
Fixed changelog
- 575. By Federico Gimenez on 2015-05-04
-
changelog signature
- 576. By Federico Gimenez on 2015-05-04
-
Fixed unit test
| Federico Gimenez (fgimenez) wrote : | # |
I've uploaded some fixes for errors spotted in the gatekeeper jobs. These were related to the breadth-first nature of method resolution: given one class that doesn't have a validate_
The solution adopted is removing the validate_
| PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:576
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
| Christopher Lee (veebers) wrote : | # |
I'm really not a fan of modifying the classes in such a way, perhaps it's indicating that we're going down the wrong path and we need to find a better solution.
That being said the 2 tests that failed due to _try_custom_
I'm just trying to get my local devices etc. setup so I can test this, but I think that if we instead change the warning to an error (yes, I was wrong there it should have always been an error :-) ). and use the updated addresss book (i.e. the one that is passing the correct base_emulator in aka Leos branch) we shouldn't need to modify the class attributes like we are here.
I'll try to post the results when I get them, but at this rate it's going to take ages (my device is acting up.)
[1] http://
| Christopher Lee (veebers) wrote : | # |
Follow up:
I ran the fixed (i.e. Leos base_emulator update branch) and non fixed address book tests, the fixed worked well, the non-fixed exhibited the error we see.
We should remove the additional code that removes the method attribute and change the warning into an error (probably RuntimeError? or ValueError?).
- 577. By Federico Gimenez on 2015-05-06
-
The validate_
dbus_object method is not removed from extensions classes before adding them to cpos; raised exception instead of logging warning when the emulator_base does not match the base extension - 578. By Federico Gimenez on 2015-05-06
-
Updated error message
| Federico Gimenez (fgimenez) wrote : | # |
>
> We should remove the additional code that removes the method attribute and
> change the warning into an error (probably RuntimeError? or ValueError?).
Done, regarding the exception after talking with vila we have gone for ValueError, it can be changed of course. I've also updated the unit tests accordingly.
Cheers!
| PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:578
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
| PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:578
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
| PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:578
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://

Hi Federico, you'll see that I added some tests but haven't filled them in.
While back-filling the tests but stopped short of actually implementing them; mainly because the way you've made the fix is different to what I originally had and my initial thoughts wouldn't work :-)
Could you take a look at writing the tests? My current concern with the current implementation is that _combine_ base_and_ extensions has to know about class stuff (__bases__ and mro) where as the previous method only dealt with tuples of information.
Not only does this mean that it didn't need to know more than 'merge these tuples' it was easy to write tests for (again, just dealing with tuples if data, could be strings etc.).
Also, without a test in place I'm not sure that the sorting of the mro is the correct thing to do.
While I didn't have a test in place to prove it, the intention of the purely tuple approach is that it kept the expected order of merging 2 bases.