Merge lp:~jtv/maas/import-from-configured-mirror into lp:maas/trunk
| Status: | Merged |
|---|---|
| Approved by: | Jeroen T. Vermeulen on 2012-11-08 |
| Approved revision: | 1346 |
| Merged at revision: | 1339 |
| Proposed branch: | lp:~jtv/maas/import-from-configured-mirror |
| Merge into: | lp:maas/trunk |
| Diff against target: |
231 lines (+90/-11) 8 files modified
etc/maas/import_ephemerals (+8/-1) scripts/maas-import-ephemerals (+8/-5) scripts/maas-import-pxe-files (+2/-1) src/maasserver/models/nodegroup.py (+10/-1) src/maasserver/tests/test_nodegroup.py (+26/-0) src/maasserver/tests/test_views_settings.py (+5/-2) src/provisioningserver/tasks.py (+8/-1) src/provisioningserver/tests/test_tasks.py (+23/-0) |
| To merge this branch: | bzr merge lp:~jtv/maas/import-from-configured-mirror |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Julian Edwards (community) | Needs Fixing on 2012-11-12 | ||
| Raphaël Badin (community) | 2012-11-08 | Approve on 2012-11-08 | |
|
Review via email:
|
|||
Commit Message
Tell the import scripts, when run as a celery task, what archives to use.
Description of the Change
This ties in with Raphaël's ongoing work: he's changing the UI to manage these same settings. I cribbed the settings' names from lp:~rvb/maas/mirror-settings-re-2
Archive locations are passed to the script through environment variables. The scripts already obeys these variables. The impact on the scripts themselves is altogether quite minimal, but one name in maas-import-
URLs that have not been configured yet fall back on the defaults that are encoded in the import scripts. Missing archive locations are not passed through.
Tests pass for this branch even though it does not incorporate Raphaël's branches, which haven't landed yet. That's because my tests configure the archive settings themselves. In a separate branch, which relies on the synthesis of this branch and Raphaël's, I will add an integration test to establish that the two sets of changes operate on the same configuration items.
My test code repeats make_archive_url. It might be worth abstracting a single make_url somewhere that's available to all apps. But then the sensible step would be to sanitize all code that constructs URLs. A job best left to a separate branch!
Jeroen
| Jeroen T. Vermeulen (jtv) wrote : | # |
> [0]
>
> 96 + config = {
> 97 + name: Config.
> 98 + for name in config_parameters}
> 99 + task_kwargs = {
> 100 + name: value
> 101 + for name, value in config.items()
> 102 + if value is not None}
>
> I don't see why we need to filter out None values…? Also, there is probably
> no need for a second dict comprehension.
True, it can be done with just one. I thought it'd be hard to read, but it's not so bad so I changed it to just one.
I filtered out the None values because I didn't feel like making the “pass None for default” part of the task's signature. Normally it'd be fine but since a Celery task is a fairly special function-call boundary, I wanted to leave it some room for change. I'm not sure it really helps, but it lets the task specify usefully specify a default other than None, and it helped decouple introduction of the new parameters from introduction of the new config items.
> [1]
>
> 233 + archive_settings = {
> 234 + variable: value
> 235 + for variable, value in env.iteritems()
> 236 + if variable.
>
> and
>
> 99 + task_kwargs = {
> 100 + name: value
> 101 + for name, value in config.items()
> 102 + if value is not None}
>
> A word about style here. You may disagree but I'd be in favor of formatting
> that kind of statement this way, mainly because I think it's more readable
>
> task_kwargs = {
> name: value
> for name, value in config.items()
> if value is not None
> }
>
> With your version I get the feeling that the "if value is not None" statement
> is inside the loop, which isn't true.
My editor insists the indentation is the only right way, and I'm reluctant to second-guess it...
The practice of closing a comprehension on the same line goes way back in Launchpad history. I used to do it on a separate line but I think we decided against it eventually. May have been because of controversy over how far a closing bracket (or by extension, brace) should be indented.
> [2]
>
> 144 + archive_options = {
> 145 + arg: value
> 146 + for arg, value in kwargs.items()
> 147 + if arg.endswith(
>
> How about (and this is not only about style ;))
>
> archive_options = {
> arg: value
> for arg, value in kwargs.items()
> if arg in archives
> }
I'll do you one better!
archive_options = {arg: kwargs.get('arg') for arg in archives}
> [3]
>
> > My test code repeats make_archive_url. It might be worth abstracting a
> single make_url somewhere that's available
> > to all apps. But then the sensible step would be to sanitize all code that
> constructs URLs. A job best left to a
> > separate branch!
>
> My code in lp:~rvb/maas/mirror-settings-re-2 could benefit from that too!
A nice little cleanup for when we have time. *Cough* *cough*. :)
Jeroen
- 1346. By Jeroen T. Vermeulen on 2012-11-08
-
Review changes.
| Julian Edwards (julian-edwards) wrote : | # |
On Thursday 08 November 2012 16:07:29 you wrote:
> + config_parameters = {
> + 'http_proxy',
> + 'main_archive',
> + 'ports_archive',
> + 'cloud_
> + }
How many places do we refer to these strings now? About time for some
encapsulation or at least a constant, as this is a recipe for disaster.
Especially when you start doing this in tests:
+ archives = {
+ 'main_archive': make_archive_
+ 'ports_archive': make_archive_
+ 'cloud_
+ }
+ for key, value in archives.items():
+ Config.


Looks good!
[0]
96 + config = { objects. get_config( name)
97 + name: Config.
98 + for name in config_parameters}
99 + task_kwargs = {
100 + name: value
101 + for name, value in config.items()
102 + if value is not None}
I don't see why we need to filter out None values…? Also, there is probably no need for a second dict comprehension.
[1]
233 + archive_settings = { endswith( '_ARCHIVE' )}
234 + variable: value
235 + for variable, value in env.iteritems()
236 + if variable.
and
99 + task_kwargs = {
100 + name: value
101 + for name, value in config.items()
102 + if value is not None}
A word about style here. You may disagree but I'd be in favor of formatting that kind of statement this way, mainly because I think it's more readable
task_kwargs = {
name: value
for name, value in config.items()
if value is not None
}
With your version I get the feeling that the "if value is not None" statement is inside the loop, which isn't true.
[2]
144 + archive_options = { '_archive' )}
145 + arg: value
146 + for arg, value in kwargs.items()
147 + if arg.endswith(
How about (and this is not only about style ;))
archive_options = {
arg: value
for arg, value in kwargs.items()
if arg in archives
}
[3]
> My test code repeats make_archive_url. It might be worth abstracting a single make_url somewhere that's available
> to all apps. But then the sensible step would be to sanitize all code that constructs URLs. A job best left to a
> separate branch!
My code in lp:~rvb/maas/mirror-settings-re-2 could benefit from that too!