[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [augeas-devel] Problem with put direction on lens



On Wed, 2012-06-13 at 15:41 -0600, Nathaniel Cook wrote:
> I am writing a simple lens to manage the forward zones for power DNS.
> What I have so far is pasted below. My problem is in the put
> direction. Because the file cannot have any empty lines or even a new
> line at the end of the I am having a hard time adding the first entry
> from an empty file. If you run the tests you will get this error from
> the put test.
> 
> tests/test_pdnsr_forward_zones.aug:30.1-35.35:exception thrown in test
> tests/test_pdnsr_forward_zones.aug:30.7-34.70:exception: None of the
> alternatives in the union match
>     Lens: /usr/share/augeas/lenses/pdnsr_forward_zones.aug:27.13-.43:
>     Error encountered at path
> 
> 
> Any Ideas on how I can resolve this error?

Sorry it took me so long to respond to this - vacations and other things
intruded.

Your problem is a real headscratcher, but after figuring it out, it's
quite obvious, see below ;)

> module Pdnsr_forward_zones =
> 	autoload xfm
> ...
> (************************************************************************
>  *                       PARTS
>  *************************************************************************)
> 	let server = [ label "server" . store Rx.ipv4 ]
> 	let zone = store Rx.word
> 	let eol = [ Util.del_str "\n" ]
> 	
> (************************************************************************
>  *                       ENTRY
>  *************************************************************************)
> 	let entry =  [ label "zone" . zone . Sep.equal .  Build.opt_list
> server Sep.comma ]
> 
> 
> (************************************************************************
>  *                        LENS & FILTER
>  *************************************************************************)
> 	let lns  =  ((entry . eol)* . entry) | eol

Note that a file that starts with an empty line is not legal; that also
means that you can't put a tree that starts with { }

> 	test  Pdnsr_forward_zones.lns put empty  after
> 		set "/zone[ .  = 'zone1.com' ]" "zone1.com";
> 		set "/zone[ . = 'zone1.com' ]/server[ . = '10.1.1.20' ]" "10.1.1.20";
> 		set "/zone[ . = 'zone1.com' ]/server[ . = '10.1.1.25' ]" "10.1.1.25"
> 	 = "zone1.com=10.1.1.20,10.1.1.25"

The tree you get here is actually

        { }
        { "zone" = "zone1.com" { ... } }

IOW, there really is no way to match lns to that tree ...

There's a few ways in which you can address that: (1) remove the [ ... ]
in eol so that it does not produce a tree node, (2) add a label like
".empty" to eol nodes and rm that in your put test or (3) change the
lens so that it allows empty lines (and lines with only comments) - I
actually had a brief look at the PowerDNS code that reads config files,
and it seems to me as if it would deal with blank lines just fine.

David




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]