[augeas-devel] Why does Augeas fail to create new files?

Mol, Xavier (SCC) xavier.mol at kit.edu
Tue Dec 22 15:58:04 UTC 2015


Hi Raphael.

 

> Your file isn't empty, it contains a single newline, so your lens should be:

> module Word = let lns = [ seq "words" . store Rx.word . Util.eol ] | Util.empty

I still found a way to create an error with that lens! J

 

1) No file to begin with – now fixed.

 

[root ~]# \rm /tmp/word

[root ~]# augtool -t "Word.lns incl /tmp/word"

augtool> set /files/tmp/word/1 eggs

augtool> save

Saved 1 file(s)

 

 

2) Valid file with content exists – worked before already.

 

[root ~]# echo spam >/tmp/word

[root at f01-151-116 ~]# augtool -t "Word.lns incl /tmp/word"

augtool> print /files/tmp/word

/files/tmp/word

/files/tmp/word/1 = "spam"

augtool> set /files/tmp/word/1 eggs

augtool> save

Saved 1 file(s)

 

 

3) Starting with an empty file – fails differently now and wasn't tested before, since it should not be allowed at all.

 

[root ~]# \rm /tmp/word

[root ~]# touch /tmp/word

[root ~]# augtool -t "Word.lns incl /tmp/word"

augtool> errors

  (no errors)

augtool> print /files/tmp/word

/files/tmp/word

augtool> set /files/tmp/word/1 eggs

augtool> save

error: Failed to execute command

saving failed (run 'errors' for details)

augtool> errors

Error in /tmp/word (put_failed)

  None of the alternatives in the union match

  Lens: /usr/share/augeas/lenses/word.aug:4.12-.67:

 

 

According to your statement, "Augeas needs to be able to parse the existing content before modifiying it". Since there were no errors after augtool had started, I assume that is true (zero content parsed successfully thanks to Util.empty). But still, I cannot alter the empty file?! Fun fact about this, Augeas can now create empty files, which it is unable to alter in the next session. It still can set new content within the current section.

 

[root ~]# echo spam >/tmp/word

[root ~]# augtool -t "Word.lns incl /tmp/word"

augtool> print /files/tmp/word

/files/tmp/word

/files/tmp/word/1 = "spam"

augtool> rm /files/tmp/word/1

rm : /files/tmp/word/1 1

augtool> save

Saved 1 file(s)

augtool> set /files/tmp/word/1 eggs

augtool> save

Saved 1 file(s)

augtool> print /files/tmp/word

/files/tmp/word

/files/tmp/word/1 = "eggs"

 

 

Ciao,

Xavier.

 

From: Raphaël Pinson [mailto:raphael.pinson at camptocamp.com] 
Sent: Tuesday, December 22, 2015 4:19 PM
To: Mol, Xavier (SCC)
Cc: augeas-devel at redhat.com
Subject: Re: [augeas-devel] Why does Augeas fail to create new files?

 

 

 

On Tue, Dec 22, 2015 at 4:08 PM, Mol, Xavier (SCC) <xavier.mol at kit.edu> wrote:

Hi all,

I have boiled this problem down as much as possible, ie. down to a module that manages a file with a single word in it (I've learned some more notable things about that, which are listed in PS):

module Word = let lns = [ seq "words" . store Rx.word . Util.eol]


When using this module to create new files, then we get an error:

[root ~]# ls /tmp/word
ls: cannot access /tmp/word: No such file or directory
[root ~]# augtool -t "Word.lns incl /tmp/word"
augtool> set /files/tmp/word/1 spam
augtool> save
error: Failed to execute command
saving failed (run 'errors' for details)
augtool> errors
Error in /tmp/word:1.0 (parse_skel_failed)
  Input string does not match at all
  Lens: /usr/share/augeas/lenses/word.aug:4.12-.54:

 

 

Yes, that is correct. Augeas needs to be able to parse the existing content before modifying it.

 

 



When there already is a valid file, the module works fine:

[root ~]# echo spam >/tmp/word
[root ~]# augtool -t "Word.lns incl /tmp/word"
augtool> print /files/tmp/word
/files/tmp/word
/files/tmp/word/1 = "spam"
augtool> set /files/tmp/word/1 eggs
augtool> save
Saved 1 file(s)
[root ~]# cat /tmp/word
eggs


Honestly, to me this looks like a bug. Even making this sole lens optional, to make an empty file acceptable, doesn't make the module functional (albeit with different error message).

module Word = let lns = [ seq "words" . store Rx.word . Util.eol ]?

[root ~]# augtool -t "Word.lns incl /tmp/word"
augtool> print /files/tmp/word
augtool> set /files/tmp/word/1 spam
augtool> save
error: Failed to execute command
saving failed (run 'errors' for details)
augtool> errors
Error in /tmp/word:1.0 (parse_skel_failed)
  parse can not process entire input
  Lens: /usr/share/augeas/lenses/word.aug:4.12-.55:

 

 

 

 

 

PS)
* There must be a label for this node (either seq, key or label), or the Augeas tree doesn't keep the value and it cannot be altered, too.

 

 

You can technically have label-less nodes, but I wouldn't recommend it indeed.

 

 

Raphaël

 

 

* The lens must match eol, even though the file might not have one - in that situation, end-of-file is matched instead. 'let lns = [ seq "words" . store Rx.word ]' always results in parsing errors ("Get did not match entire input"), even if files are created like 'echo -n word >file'. Though if there is a proper line break before the end of file (echo word >file), the outcome is identical.


> -----Original Message-----
> From: Mol, Xavier (SCC)
> Sent: Thursday, December 17, 2015 1:36 PM
> To: Mol, Xavier (SCC); augeas-devel at redhat.com
> Subject: RE: Why does Augeas fail to create new files?
>
> > ---> Creating an empty node works fine, though this should actually fail in my opinion (an empty file is invalid according to the lens).
> Sorry, I have to correct this. The attached lens definition does allow for an empty file. However, setting lns like this:
>
> let lns = ( empty | comment )* . version . ( empty | comment | rule )*
>
> Hence, requiring at least a line with "version" in it, doesn't change the reported behaviour at all for me.
>
> Ciao,
> Xavier.
>
> > -----Original Message-----
> > From: augeas-devel-bounces at redhat.com [mailto:augeas-devel-bounces at redhat.com] On Behalf Of Mol, Xavier (SCC)
> > Sent: Thursday, December 17, 2015 1:33 PM
> > To: augeas-devel at redhat.com
> > Subject: [augeas-devel] Why does Augeas fail to create new files?
> >
> > Hello Augeas experts,
> >
> > attached you can find the source of a custom lens for Augeas and a file with get and put unit tests; either file is evaluated with augparse
> > successfully. My question is, why can I not create a new file from scratch with that lens, while editing existing files works just fine?
> >
> > In order to test the steps in between, I used augeas-1.4 and augtool:
> >
> > [root ~]# augtool --version
> > augtool 1.4.0 <http://augeas.net/>
> > Copyright (C) 2007-2011 David Lutterkort
> > License LGPLv2+: GNU LGPL version 2.1 or later
> >                  <http://www.gnu.org/licenses/lgpl-2.1.html>
> > This is free software: you are free to change and redistribute it.
> > There is NO WARRANTY, to the extent permitted by law.
> >
> > Written by David Lutterkort
> >
> > [root ~]# augtool
> > augtool> print /augeas/load/StorageAuthzdb/*[label() != "excl"]
> > /augeas/load/StorageAuthzdb/lens = "@StorageAuthzdb"
> > /augeas/load/StorageAuthzdb/incl = "/etc/grid-security/storage-authzdb"
> >
> > ---> Currently, the node included with that lens doesn't exist.
> > augtool> ls /files/etc/grid-security/storage-authzdb
> > augtool> dump-xml /files/etc/grid-security/storage-authzdb
> > <augeas match="/files/etc/grid-security/storage-authzdb"/>
> >
> > ---> Creating an empty node works fine, though this should actually fail in my opinion (an empty file is invalid according to the lens).
> > augtool> touch /files/etc/grid-security/storage-authzdb
> > augtool> save
> > Saved 1 file(s)
> > augtool> ls /files/etc/grid-security
> > storage-authzdb = (none)
> > augtool> dump-xml /files/etc/grid-security/storage-authzdb
> > <augeas match="/files/etc/grid-security/storage-authzdb">
> >   <node label="storage-authzdb" path="/files/etc/grid-security/storage-authzdb"/>
> > </augeas>
> >
> > ---> Saving the minimal change required for a valid storage-authzdb file fails.
> > augtool> set /files/etc/grid-security/storage-authzdb/version "2.1"
> > augtool> dump-xml /files/etc/grid-security/storage-authzdb
> > <augeas match="/files/etc/grid-security/storage-authzdb">
> >   <node label="storage-authzdb" path="/files/etc/grid-security/storage-authzdb">
> >     <node label="version">
> >       <value>2.1</value>
> >     </node>
> >   </node>
> > </augeas>
> > augtool> save
> > error: Failed to execute command
> > saving failed (run 'errors' for details)
> > augtool> errors
> > Error in /etc/grid-security/storage-authzdb:1.0 (parse_skel_failed)
> >   parse can not process entire input
> >   Lens: /usr/share/augeas/lenses/storageauthzdb.aug:34.12-.75:
> >
> >
> > ---> Starting over...
> > [root ~]# rm /etc/grid-security/storage-authzdb
> > rm: remove regular empty file `/etc/grid-security/storage-authzdb'? y
> > [root ~]# augtool
> >
> > ---> Create the desired tree
> > augtool> set /files/etc/grid-security/storage-authzdb/version "2.1"
> >
> > ---> Review what the lens would put as a string, which matches what I expect.
> > augtool> set /in ""
> > augtool> retrieve StorageAuthzdb.lns /in /files/etc/grid-security/storage-authzdb /out
> > augtool> print /out
> > /out = "version 2.1\n"
> >
> > ---> Still saving that output fails
> > augtool> save
> > error: Failed to execute command
> > saving failed (run 'errors' for details)
> > augtool> errors
> > Error in /etc/grid-security/storage-authzdb:1.0 (parse_skel_failed)
> >   parse can not process entire input
> >   Lens: /usr/share/augeas/lenses/storageauthzdb.aug:34.12-.75:
> >
> > ---> Though when the file exists before augtool is used, everything seems to work.
> > [root ~]# echo version 2.1 >/etc/grid-security/storage-authzdb
> > [root ~]# augtool
> > augtool> ls /files/etc/grid-security/storage-authzdb
> > version = 2.1
> > augtool> dump-xml /files/etc/grid-security/storage-authzdb
> > <augeas match="/files/etc/grid-security/storage-authzdb">
> >   <node label="storage-authzdb" path="/files/etc/grid-security/storage-authzdb">
> >     <node label="version">
> >       <value>2.1</value>
> >     </node>
> >   </node>
> > </augeas>
> > augtool> set /files/etc/grid-security/storage-authzdb/version "2.2"
> > augtool> save
> > Saved 1 file(s)
> > [root ~]# cat /etc/grid-security/storage-authzdb
> > version 2.2
> >
> >
> >
> > What am I doing wrong here?
> >
> > Thank you for your time,
> > Xavier.
> >
> >
> > ****
> > Karlsruher Institute of Technology (KIT)
> > Steinbuch Centre for Computing (SCC)
> >
> > B. Sc. Xavier Mol
> > GridKa Storage Administrator and Support Manager
> >
> > Hermann-von-Helmholtz-Platz 1
> > Geb. 449
> > 76344 Eggenstein-Leopoldshafen
> > Phone: +49 721 608 23041
> > Email: xavier.mol at kit.edu
> > www.kit.edu
> > KIT - University of the State of Baden-Württemberg and National Large-scale Research Center of the Helmholtz Association
> > "Since 2010, the KIT has been certified as a family-friendly university."
> > ****


_______________________________________________
augeas-devel mailing list
augeas-devel at redhat.com
https://www.redhat.com/mailman/listinfo/augeas-devel





 

-- 

Raphaël Pinson

Infrastructure Developer & Training Leader

+33 458 482 013

 

Camptocamp France
Savoie Technolac
BP 352
48, avenue du Lac du Bourget
73372 Le Bourget du Lac, Cedex
www.camptocamp.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20151222/83fc01ba/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6401 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20151222/83fc01ba/attachment.p7s>


More information about the augeas-devel mailing list