Merge lp:~jtv/pyjuju/maas-anon-urls into lp:pyjuju
Status: | Work in progress |
---|---|
Proposed branch: | lp:~jtv/pyjuju/maas-anon-urls |
Merge into: | lp:pyjuju |
Prerequisite: | lp:~jtv/pyjuju/makefile-fixups |
Diff against target: |
460 lines (+265/-72) 4 files modified
Makefile (+27/-17) README (+1/-1) juju/providers/maas/files.py (+79/-10) juju/providers/maas/tests/test_files.py (+158/-44) |
To merge this branch: | bzr merge lp:~jtv/pyjuju/maas-anon-urls |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gavin Panella (community) | Approve | ||
Kapil Thangavelu | Pending | ||
Review via email: mp+149911@code.launchpad.net |
Commit message
Change file storage in the MAAS provider so that MAAS gets the chance to specify a file's download URL.
Description of the change
This change was discussed with all of Red Squad. For the full background, see bug 1123986 and https:/
Currently when the MAAS provider is asked for the download URL of an uploaded file, it just computes a standard URL for that file on the MAAS API. But in order to be able to separate namespaces for different users (and juju environments), we need to give MAAS more room to assign its own URLs.
And so, this change makes get_url() ask the MAAS API for the correct URL. If it finds it's talking to an older MAAS which doesn't support that, it still falls back to the old way of doing things. But if MAAS provides a URL for the file, that's the one that it will pass on to nodes that need access.
I went with inlineCallbacks here, even though many people dislike it for its unhelpful tracebacks. I did that because it allowed me to break up functions along traditional lines of abstraction. I'm adding just enough complexity that a hodgepodge of nested function definitions and clever chaining was making it hard to see what was going on.
You'll notice that get_url now returns Deferred, instead of the URL itself. Luckily the code (well, outside the MAAS provider itself of course!) does not make assumptions about this. It correctly runs the function through the Twisted reactor. There is no documentation to say that that is wrong, so I can only infer that this was always intended to be possible.
Possible, yes, but not optimal. There would be other ways of getting at the file data when talking to a new MAAS (it's actually contained in the file information that get_url downloads). And we might cache the knowledge of which MAAS we're talking to, and we might cache URLs, and so on. But we believe those to be secondary concerns. Our reasons are:
1. juju-core will not have any of these problems. It will go straight to the file information and return the file's contents, or its URL, immediately.
2. We urgently need to fix an inability to run two juju environments on one MAAS, so that takes precedence.
3. Amdahl's Law: if this isn't the bottleneck, it's not the right place to optimize.
4. Knuth's Law: optimizing the process would also increase complexity and thus risk.
My biggest worry is in the error handling. Development was strictly TDD, but with this much layercake in the way there is a risk of "circular reasoning" between the test expectations and the test doubles. We'll have to test thoroughly in the Q/A lab. In particular, the "not found" case will be exercised when we test the new provider code against an old MAAS. Since both of the "404" situations that come up go through the same code, that one scenario will validate both.
Jeroen
Unmerged revisions
- 648. By Jeroen T. Vermeulen
-
Hide the FakeFileStorage factory for 404s in another factory. Sigh.
- 647. By Jeroen T. Vermeulen
-
A single 404 isn't enough to trigger an exception on a get() any more. Patch out the get_url call where 404s are ignored.
- 646. By Jeroen T. Vermeulen
-
Tiny fixup.
- 645. By Jeroen T. Vermeulen
-
Merge trunk.
- 644. By Jeroen T. Vermeulen
-
Simplified Twisted http error handling, as per review.
- 643. By Jeroen T. Vermeulen
-
anon_url has become anon_resource_uri.
- 642. By Jeroen T. Vermeulen
-
Review changes.
- 641. By Jeroen T. Vermeulen
-
Tweaks to error handling.
- 640. By Jeroen T. Vermeulen
-
Extract download method.
- 639. By Jeroen T. Vermeulen
-
Get lint-checking etc. to work.
158 + meta_url = self._base_url + name
This generates urls like "/MAAS/ api/1.0/ files/provider- state" (note the missing slash at the end of the url) that gets redirected to "/MAAS/ api/1.0/ files/provider- state/" . (See this extract from apache2's log: http:// paste.ubuntu. com/1705131/). It's probably better to generate the proper url directly.