[augeas-devel] bug/feature request - support shell functions in shellvars.aug

David Lutterkort lutter at redhat.com
Thu Jul 1 00:35:22 UTC 2010


Hi Chris,

On Wed, 2010-06-30 at 01:40 -0400, Chris Sears wrote:
> I'd like to to be able to parse an ifcfg file that contains a function
> using shellvars.aug. This doesn't seem to be supported currently. 
> 
> 
> Here's an example of the ifcfg file:
> 
> 
> ================ begin ifcfg-eth0 =================
> # VMware VMXNET3 Ethernet Controller
> DEVICE=eth0
> BOOTPROTO=static
> ONBOOT=yes
> IPADDR=192.168.10.91
> NETMASK=255.255.255.0
> 
> 
> check_link_down() {
>  return 1;
> }
> ================ end ifcfg-eth0 =================

I share Matt's misgivings about doing the above in an ifcfg file - it
breaks all kinds of tools, from netcf to NetworkManager. The right
solution is to not try and parse the above, and flag it as an error.

Having said that, the challenge you will face is that curly braces can
be nested in the function (since you can say, e.g. '{ ls | grep
augeas.h }' inside the function.

If you're willing to ignore that, you could get away with pretending
there are no '}' in a function body, and parsing the whole function
should be fairly straightforward.

> I took a stab at patching shellvars.aug, but I'm stuck with the
> following error...
> 
> 
> [root at s-rhel-server-54-64 dist]# augtool
> ls /files/etc/sysconfig/network-scripts/ifcfg-eth0
> #comment = VMware VMXNET3 Ethernet Controller
> DEVICE = eth0
> BOOTPROTO = static
> ONBOOT = yes
> IPADDR = 192.168.10.91
> NETMASK = 255.255.255.0
> error: Invalid path expression
> error: garbage at end of path expression
> error: /files/etc/sysconfig/network-scripts/ifcfg-eth0/check_link_down(|=|)/*
> error: Invalid path expression
> error: garbage at end of path expression
> error: /files/etc/sysconfig/network-scripts/ifcfg-eth0/check_link_down(|=|)
> check_link_down()/ = 255.255.255.0
> 
> 
> If anyone has advice on the error or would be willing to open a ticket
> on the bug/feature, I would appreciate it.

This looks like a genuine bug to me. Can you file that in the bug
tracker ? The issue is that the '(' and ')' in the path need to be
escaped, otherwise the xpath interpreter tries to call a function
'check_link_down' internally, which does not exist.

You can work around this by changing your lens to not use the '()' as
part of the label (i.e., do not match it with the 'key' in your lens;
instead use 'del', which will omit it from the tree)

David






More information about the augeas-devel mailing list