Skip to content

(PUP-4629) Return values instead of augeas paths during the match operation#3952

Merged
joshcooper merged 1 commit intopuppetlabs:masterfrom
mmarod:fix/master/augeas_match_use_value
Jul 8, 2015
Merged

(PUP-4629) Return values instead of augeas paths during the match operation#3952
joshcooper merged 1 commit intopuppetlabs:masterfrom
mmarod:fix/master/augeas_match_use_value

Conversation

@mmarod
Copy link

@mmarod mmarod commented May 19, 2015

This fixes PUP-4629 by using aug.get to return the values of the paths returned by the aug.match operation.

@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch from 8aa8fe2 to a37cb80 Compare May 19, 2015 15:53
@puppetcla
Copy link

CLA signed by all contributors.

@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch from a37cb80 to 1f64f39 Compare May 19, 2015 17:54
@peterhuene
Copy link
Contributor

Hi @mmarod. Thanks for the contribution!

@lutter and @domcleal: as you're both more knowledgeable about the augeas provider than I am, does this change make sense to either of you?

Note to reviewers: the AppVeyor failure is the known rdoc failure and can be ignored.

@domcleal
Copy link
Contributor

I can see where you're going with this, but changing the behaviour of match isn't a good idea as it could easily break existing manifests (and is different to what aug_match actually does).

I would suggest adding a get command with this behaviour instead (although in Augeas' API, get won't work for multiple nodes, but having it do so here might be OK).

@domcleal
Copy link
Contributor

I would suggest adding a get command with this behaviour instead

Oh, we do have it, apologies.

Maybe call it something else then if you'd like support for returning an array of values, e.g. getm (to emulate setm, clearm etc.)

@mmarod
Copy link
Author

mmarod commented May 20, 2015

Adding a getm seems reasonable but it seems like it might be unnecessary. It boils down to what the intent of the match <MATCH_PATH> == <AN_ARRAY> is really meant to do. Is it supposed to compare labels or values?

I would argue that the match <MATCH_PATH> != <AN_ARRAY> and match <MATCH_PATH> == <AN_ARRAY> controls in onlyif do not currently do what the Puppet type reference says they should do. AN_ARRAY is described as ['a string, 'another'] which could never actually be returned when calling aug.match. It would instead return ['/files/something/some_param[1]', '/files/something/some_param[2]'] which is not useful to match against.

If we are trying to make the controls in onlyif mimic exacty what augeas does, then we should add a getm parameter. However, it seems to me (according to the type ref) that match <MATCH_PATH> == <AN_ARRAY> was meant to solve this problem in the first place.

@domcleal
Copy link
Contributor

I'd say that's a documentation bug and that changing the provider behaviour is a) going to be incompatible, so would have to live in master for some time, and b) would differ from Augeas.

I think mimicking Augeas' API is quite important, as many users will test how Augeas responds via augtool, so to change the return value from a standard API call or command is surprising.

This is a very useful feature, particularly so the == and include operators work more naturally, but I don't think changing an existing command is the way to do it.

@mmarod
Copy link
Author

mmarod commented May 20, 2015

Fair enough

@mmarod
Copy link
Author

mmarod commented May 20, 2015

If we are trying to mimic augeas commands exactly -- how should getm be implemented? There does not seem to be a built in getm command. It seems running a match and then passing each result into a get is the only way to retrieve all of the values in an augeas path.

@domcleal
Copy link
Contributor

Yes, that'd be the way to do it.

@peterhuene
Copy link
Contributor

Hi @mmarod Thanks for pushing up a new commit! Would you mind squashing the two commits into one (basically amending the original commit)?

@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch 2 times, most recently from 1528450 to 14c5e4b Compare May 21, 2015 17:27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't affect the code, but for clarity, change match to getm. (Ditto below.)

@domcleal
Copy link
Contributor

Looks good to me. Would you also mind adding the include and not_include operators to getm while we're here? I think they're likely to be useful.

@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch 2 times, most recently from 37fac9a to 3b9f816 Compare May 22, 2015 14:26
@domcleal
Copy link
Contributor

👍 looks good, and tests well.

@domcleal
Copy link
Contributor

Oh, the only thing I'd add is that the commit message doesn't quite reflect what it does any more, since the match behaviour's been left unchanged. Would you mind updating that?

@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch from 3b9f816 to 04a21c7 Compare May 22, 2015 15:34
@lutter
Copy link
Contributor

lutter commented May 22, 2015

I am a little late to the party, but how about calling that new operator values ? That seems to express pretty well what it's supposed to do, and there won't be any way to confuse it with existing augtool commands.

@mmarod
Copy link
Author

mmarod commented May 22, 2015

values seems a bit less confusing to me. Since getm isn't a true augeas API call anyway it shouldn't make a difference whether we call it getm or values. What do you think @domcleal ?

@domcleal
Copy link
Contributor

Good suggestion, works for me!

@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch from 9652880 to 58f52cf Compare May 25, 2015 22:00
@peterhuene
Copy link
Contributor

@domcleal and @lutter: could either one of you review @mmarod's changes one last time to make sure this looks good (as I'm no augeas provider expert) before we merge this? Thanks!

@domcleal
Copy link
Contributor

Looks fine to me, although the commit message is incorrect again, s/getm/values/. Could be fixed on merge.

@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch from 58f52cf to 35cee76 Compare May 27, 2015 13:30
@mmarod
Copy link
Author

mmarod commented May 27, 2015

Fixed the commit message again

@domcleal
Copy link
Contributor

👍 thanks @mmarod!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this loop be replaced by an invocation of Array#map aka #collect?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea... I updated it

@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch from dc0199b to 7ef9afd Compare June 2, 2015 20:53
@joshcooper
Copy link
Contributor

The appveyor failures are a known issue https://tickets.puppetlabs.com/browse/PUP-4537 and can be ignored.

@mmarod
Copy link
Author

mmarod commented Jun 25, 2015

So it's been a while since this is seemingly ready to go -- What is the hold up?

@joshcooper
Copy link
Contributor

@mmarod We've had to cancel the last three community PR triage sessions while preparing for the Puppet 4.2.0 release. We'll resume next 10am PDT, Wednesday, June 1, so it should be merged soon.

@joshcooper
Copy link
Contributor

@mmarod one minor nit, could you update the commit message to describe how values can be used as a result of this change? A real-world example would be really useful. Thank you!

@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch from 7ef9afd to 1c8c87a Compare June 30, 2015 20:47
@joshcooper
Copy link
Contributor

@mmarod thanks for updating that, the example is very helpful. Could you shorten the subject line to follow our convention as described in https://github.com/puppetlabs/puppet/blob/master/CONTRIBUTING.md:

(PUP-1234) Make the example in CONTRIBUTING imperative and concrete

Without this patch applied the example commit message in the CONTRIBUTING
document is not a concrete example.

I'm happy to fix that up if you're busy. Thank you again!

@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch from 1c8c87a to f7e35ac Compare July 6, 2015 19:43
@mmarod
Copy link
Author

mmarod commented Jul 6, 2015

No problem -- Let me know how it looks.

@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch from f7e35ac to 81f2378 Compare July 6, 2015 19:46
This patch allows comparisons against values. Previously, comparisons
could only be performed against labels.

Example usage would be to ensure that augeas only runs if the values of
cfg_file using the Nagios lens do not match a list of known values.

augeas { 'configure-nagios-cfg_file':
  incl    => '/etc/nagios/nagios.cfg',
  lens    => 'NagiosCfg.lns',
  changes => [ "rm cfg_file",
               "ins cfg_file",
               "set cfg_file[1] /etc/nagios/commands.cfg",
               "ins cfg_file after /files/etc/nagios/nagios.cfg/cfg_file[last()]",
               "set cfg_file[2] /etc/nagios/anotherconfig.cfg" ],
  onlyif  => "values cfg_file != ['/etc/nagios/commands.cfg', '/etc/nagios/anotherconfig.cfg']"
}
@mmarod mmarod force-pushed the fix/master/augeas_match_use_value branch from 81f2378 to f8ddf88 Compare July 6, 2015 19:47
@joshcooper joshcooper merged commit f8ddf88 into puppetlabs:master Jul 8, 2015
@joshcooper
Copy link
Contributor

Thank you @mmarod for your contribution! This will be released in puppet 4.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants