Merge lp://staging/~julian-edwards/maas/forwarders-config-writer into lp://staging/~maas-committers/maas/trunk

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: no longer in the source branch.
Merged at revision: 2001
Proposed branch: lp://staging/~julian-edwards/maas/forwarders-config-writer
Merge into: lp://staging/~maas-committers/maas/trunk
Diff against target: 297 lines (+258/-0)
5 files modified
buildout.cfg (+1/-0)
src/maasserver/management/commands/edit_named_options.py (+124/-0)
src/maasserver/tests/test_commands_edit_named_options.py (+129/-0)
src/provisioningserver/dns/config.py (+1/-0)
versions.cfg (+3/-0)
To merge this branch: bzr merge lp://staging/~julian-edwards/maas/forwarders-config-writer
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+206670@code.staging.launchpad.net

Commit message

Add a command utility that amends the named.conf.options file so that it includes the maas forwarders config. Intended to be called from packaging when installing maas.

Description of the change

This branch adds a helper for the packaging so that the named.conf.options file can be edited to include the maas forwarders config.

It introduces a new dependency called iscpy, which can parse and edit ISC-style config files, like the ones that named uses. Sadly it's not packaged so I am going to have to get roaksoax on the case :)

When it runs it goes to great lengths to make sure nothing bad is going to happen. There's a bunch of checks that everything parsed OK, and additionally it tries to make a backup of the existing file. The backup file name has got a timestamp in it, so this can be re-run for ever with no losses incurred. If the backup fails, no changes get made in the original file.

I spent a lot of time making the tests nice and readable. I hope you appreciate it!

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Glad you got this to work. There's always a certain comfort about having a third party worry about a problem like this.

Hang on.

Hang on...

Question: are we not writing docstrings anymore? That's fine, whatever. But if we're doing a new thing, nobody told me.

.

In parse_file, given the agoraphobiagenic broadness of the exceptions, could you at least report, in one way or another, the original exception message as raised by iscpy?

.

In set_up_include_statement, I have a vague memory of there being a reason why neither os.path.join nor posixpath.join was appropriate here... worth a comment maybe?

.

I see no mention of what it means if you already had a ‘forwarders’ setting. And yet we overwrite it. Worth saying?

.

Why the vague implicit-bool-based test “options_block.get('forwarders', None)” in remove_forwarders? Are you saying that if there's an empty string rather than None, it should not be removed? Would "'forwarders' in options_block" not produce the right answer?

.

In back_up_existing_file, could you print/log the original exception message as raised from iscpy?

.

Moving on to the tests, test_exits_when_no_file_to_edit relies on there being no file called 'foo'. I think it would make more sense to do this in a temporary directory.

.

In test_exits_when_fails_to_make_backup, is Mock not more convenient than defining a function? Also, isn't the realistic thing to do to raise an IOError object, rather than the IOError class?

.

In test_normal_operation, would glob() be an easier way to get the backup file?

review: Approve
Revision history for this message
Julian Edwards (julian-edwards) wrote :

Thank you for the review!

On Monday 17 Feb 2014 11:11:38 you wrote:
> Review: Approve
>
> Glad you got this to work. There's always a certain comfort about having a
> third party worry about a problem like this.
>
> Hang on.
>
> Hang on...
>
> Question: are we not writing docstrings anymore? That's fine, whatever.
> But if we're doing a new thing, nobody told me.

Write them judiciously. In other words, does it add value? If it does do it,
if not, don't.

Most of the functions here are what I factored out to make the handle() func
less of an eyesore, but it made the whole thing longer and harder to read.
*shrug*

> In parse_file, given the agoraphobiagenic broadness of the exceptions, could
> you at least report, in one way or another, the original exception message
> as raised by iscpy?

Ah yes, good point.

> In set_up_include_statement, I have a vague memory of there being a reason
> why neither os.path.join nor posixpath.join was appropriate here... worth a
> comment maybe?

I can't honestly remember either. The reason I did it the way I did was
partly for readability and partly because it's a text file not an argument to
a function that needs a path.

> I see no mention of what it means if you already had a ‘forwarders’ setting.
> And yet we overwrite it. Worth saying?

There's already a comment, did you miss it or did I not write enough?

        # Remove existing forwarders, it's a syntax error to have more
        # than one in the combined configuration for named.

> Why the vague implicit-bool-based test “options_block.get('forwarders',
> None)” in remove_forwarders? Are you saying that if there's an empty
> string rather than None, it should not be removed? Would "'forwarders' in
> options_block" not produce the right answer?

I've simplified it, thanks. Lyme brain... :(

> In back_up_existing_file, could you print/log the original exception message
> as raised from iscpy?

It's not raised from iscpy, but yes I am now printing the IOError message,
thanks for pointing it out.

> Moving on to the tests, test_exits_when_no_file_to_edit relies on there
> being no file called 'foo'. I think it would make more sense to do this in
> a temporary directory.

Indeed, fixed!

> In test_exits_when_fails_to_make_backup, is Mock not more convenient than
> defining a function? Also, isn't the realistic thing to do to raise an
> IOError object, rather than the IOError class?

I had forgotten about Mock.side_effect, so I wrote the func meaning to come
back to it later and.... forgot!

Also, yes, I need to raise an object, good spot.

> In test_normal_operation, would glob() be an easier way to get the backup
> file?

I did think about that originally but I have a vague aversion to using it in
tests as it means there's some indeterminate part somewhere. I think this way
is better as it knows we only have two files so if we remove the known one,
the remaining one must be the backup file.

Thanks again!

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

> > Question: are we not writing docstrings anymore? That's fine, whatever.
> > But if we're doing a new thing, nobody told me.
>
> Write them judiciously. In other words, does it add value? If it does do it,
> if not, don't.

You did, however, write some top comments that explained what the methods were for — that's exactly what should be in a docstring.

> > I see no mention of what it means if you already had a ‘forwarders’ setting.
> > And yet we overwrite it. Worth saying?
>
> There's already a comment, did you miss it or did I not write enough?
>
> # Remove existing forwarders, it's a syntax error to have more
> # than one in the combined configuration for named.

That says it's an error to have more than one. But it doesn't say where that pre-existing one would come from, and why it is safe to delete it. Might cause future maintainers to miss subtleties.

Revision history for this message
Julian Edwards (julian-edwards) wrote :

On Tuesday 18 Feb 2014 09:20:13 you wrote:
> > > Question: are we not writing docstrings anymore? That's fine, whatever.
> > > But if we're doing a new thing, nobody told me.
> >
> > Write them judiciously. In other words, does it add value? If it does do
> > it, if not, don't.
>
> You did, however, write some top comments that explained what the methods
> were for — that's exactly what should be in a docstring.

Oh sorry, I see what you mean now. Yes, they were left over from refactored
blocks, which now look like they ought to be docstrings. So now they are.

> > > I see no mention of what it means if you already had a ‘forwarders’
> > > setting.> >
> > > And yet we overwrite it. Worth saying?
> >
> > There's already a comment, did you miss it or did I not write enough?
> >
> > # Remove existing forwarders, it's a syntax error to have more
> > # than one in the combined configuration for named.
>
> That says it's an error to have more than one. But it doesn't say where
> that pre-existing one would come from

Not sure how I could know that :)

>, and why it is safe to delete it.
> Might cause future maintainers to miss subtleties.

I've mentioned that the old value is going to be in the backup file made
(exactly why I was careful about making a backup).

cheers.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.