networkupstools / nut

The Network UPS Tools repository. UPS management protocol Informational RFC 9271 published by IETF at https://www.rfc-editor.org/info/rfc9271 Please star NUT on GitHub, this helps with sponsorships!
https://networkupstools.org/
Other
1.99k stars 349 forks source link

Augeas support completion #657

Open aquette opened 5 years ago

aquette commented 5 years ago

while looking back at Augeas for #656, I remembered that there were a number of things still to be done:

aquette commented 5 years ago

side note: tests are failing on my system:

$ augparse -I ./ ./tests/test_nut.aug Test failure:./tests/test_nut.aug:20.0-25.37: Expected: { { } { "testups" { "driver" = "dummy-ups" } { "port" = "auto" } { "desc" = ""Dummy UPS"" } } }

Actual: { { } { "testups" { "driver" = "dummy-ups" } { "port" = "auto" } { "desc" = "Dummy UPS" } } }

Syntax error in lens definition Failed to load ./tests/test_nut.aug

aquette commented 5 years ago

on the test failure: I just had news from Raphael Pinson. He confirmed what I saw, that is IniFile.indented_entry handles quotes (and double quotes) in a specific way that can't be modified. The best would be to look elsewhere (Shellvars) to see how it is managed.

Ref: https://github.com/hercules-team/augeas/blob/master/lenses/shellvars.aug#L39

jimklimov commented 5 months ago

@aquette : wrapping my head around the test as it exists today:

let ups_conf  = "
[testups]
    driver = dummy-ups
    port = auto
    desc = \"Dummy UPS\"
"

test NutUpsConf.ups_lns get ups_conf = 
    { }
    { "testups" 
        { "driver" = "dummy-ups"   }
        { "port"   = "auto" }
        { "desc"   = "\"Dummy UPS\""    } }

still yielding the discrepancy you saw:

nut/scripts/augeas$ ./gen-nutupsconf-aug.py ; make ; augparse -I ./ ./tests/test_nut.aug && echo PASSED

cd ../.. && /bin/bash ./config.status scripts/augeas/nutupsmonconf.aug
config.status: creating scripts/augeas/nutupsmonconf.aug
Test failure:./tests/test_nut.aug:20.0-25.37:
 Expected:
{
  {  }
  { "testups"
    { "driver" = "dummy-ups" }
    { "port" = "auto" }
    { "desc" = ""Dummy UPS"" }
  }
}

 Actual:
{
  {  }
  { "testups"
    { "driver" = "dummy-ups" }
    { "port" = "auto" }
    { "desc" = "Dummy UPS" }
  }
}

Syntax error in lens definition
Failed to load ./tests/test_nut.aug

BUT: Why do we expect the double quotes inside the desc value? If they were to be escaped, there should be more slashes. If they were to be a single token of two words, augeas already does the right thing... no?

jimklimov commented 5 months ago

Generally it seems quite complicated to conjure up lenses that would support several quotes in the same line, whether "plaintext" lines with multiple tokens like CERTIDENT "My server" "Db Pass W0rd" or escaped inside single text tokens like desc = "A \"Dummy\" UPS" which NUT parser allows but augeas struggles with.

Hmm, maybe the much-hyped AI could suggest some options? :-D

jimklimov commented 5 months ago

With the PR above, I've added a scripts/augeas/tests/test_nut_fixme.aug file with some test cases that currently fail for existing NUT augeas lens definitions and inputs that should be valid for NUT.

Conversely, I think one case in the main test file is passing despite being invalid:

desc "\"Some text\"

The trailing \" would be part of the token enclosed into the first opening double-quote. There is no ending quote so the line is... unfinished? Multi-line? Aborted by default?

UPDATE: Also added a test_nut_flaky.aug that passes on some distros and fails on others - even where same versions of augeas tools are involved.