Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nutconf and augeas lenses with support for NUT keywords added between releases 2.6.5 and 2.8.2 #2425

Merged
merged 64 commits into from
May 1, 2024

Conversation

jimklimov
Copy link
Member

@jimklimov jimklimov commented Apr 28, 2024

Closes: #2294

Note: per #657 there is more work to improve flexibility of augeas lenses - simple cases should work, but not all combos that NUT own parser supports.

Note: It seems that per initial codebase import (from 2013-ish branch to NUT v2.8.2) the sprawl of C++ header/class/test code is an internal detail of nutconf CLI tool - not a library delivered for external consumer linking. As such, there are no concerns currently about API versioning, backwards compatibility, variable/method name changes, etc. which would impact any code not visible from NUT repo itself and its regular builds. This frees up hands for refactoring like this, but eventually it could be useful to document and release the library for NUT configuration management... maybe? Or would the CLI suffice for external integrations?

… envvar support

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…isting methods [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
… classes to config files [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…eclarations

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…tification

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…nutconf/nutconf-cli.cpp: rename nut::UpsmonConfiguration::Monitor::isMaster => isPrimary [networkupstools#840]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…n to discard double-quotes from content for a fallback comparison

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ool> with NUT boolean keyword support

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…Ident (for upsd.conf, upsmon.conf...) [networkupstools#2402]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…Host (for upsmon.conf...) [networkupstools#2402]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…oduce and unit-test a BoolInt helper class [networkupstools#2402]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…s with a bool01 toggle (and test it)

Allows to enable/disable comparison of bool value to int 0/1 values.

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…s with toString() and << for practical use (and test it)

It seems that the assignment operator to string can only be done in
the std::string class - a casting operator does not suffice, so the
next best things are streaming and explicit methods to emit strings.

While at it, also implement assignment into BoolInt objects via <<

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…es [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…h BoolInt fields

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…on::getFlag() and setFlag() methods [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…on::getBool() and setBool() method set [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…on::getBoolInt() and setBoolInt() method set [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…omatic setBool()/getBool() [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
….*" supportability in UpsConfiguration class [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
… "upsd.conf" keywords introduced between NUT 2.6.5 and 2.8.2 [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
… NutConfigUnitTest::check() with the option to discard double-quotes from content (paths) for a fallback comparison

Primarily useful to check this new check() method itself.
And because nutwriter.cpp implementation was updated to always use
double-quotes for the string values with paths (looking forward to
running on MacOS and Windows).

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…nutconf_ut.cpp: handle and test "upsmon.conf" keywords introduced between NUT 2.6.5 and 2.8.2 [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…nutconf_ut.cpp: handle and test "nut.conf" keywords introduced between NUT 2.6.5 and 2.8.2 [networkupstools#2294]

Note that "nut.conf" options follow shell syntax, unlike most other NUT config files

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…nutconf_ut.cpp: handle and test "ups.conf" keywords introduced between NUT 2.6.5 and 2.8.2 [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…on::getIntHex() and setIntHex() methods [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…Configuration and test different parsing variants [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…on::getDouble() and setDouble() methods [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov jimklimov added impacts-release-2.8.2 Issues reported against NUT release 2.8.2 (maybe vanilla or with minor packaging tweaks) augeas Configuration file parser (reader, writer) multi-tool for scripting, etc. labels Apr 28, 2024
@jimklimov jimklimov added this to the 2.8.3 milestone Apr 28, 2024
@jimklimov jimklimov requested a review from aquette April 28, 2024 22:17
@jimklimov jimklimov added this to In Progress in SmartNUT via automation Apr 28, 2024
…xplicit call to operator via "if (b == true)" [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ases [networkupstools#657]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…that probably should have failed [networkupstools#657]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
… "may be used uninitialized in this function" warnings [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov
Copy link
Member Author

jimklimov commented Apr 29, 2024

Hmm, this typeid equality check seems to exceed the capabilities of older compilers (centos7 - https://ci.networkupstools.org/job/nut/job/nut/job/PR-2425/6/artifact/.ci.MD5_f52f7a4bde4e35935a6dd5c50b706166.build.log.gz or Ubuntu Trusty https://ci.networkupstools.org/job/nut/job/nut/job/PR-2425/6/artifact/.ci.MD5_6151b77274dd5261710fbd7a7f634ff8.build.log.gz in a recent CI run):

nutconf.cpp:59:16: error: invalid operands to binary expression ('const std::type_info' and 'const std::type_info')
        if (typeid(T) == typeid(bool)) {
            ~~~~~~~~~ ^  ~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/bits/stl_pair.h:214:5: note: candidate template ignored: could not match 'pair<type-parameter-0-0, type-parameter-0-1>' against 'const std::type_info'
    operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
    ^
nutwriter.cpp:296:2: error: invalid operands to binary expression ('const std::type_info' and 'const std::type_info')
        SHELL_CONFIG_DIRECTIVEX("ALLOW_NO_DEVICE",              bool,                   config.allowNoDevice,   false);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nutwriter.cpp:94:24: note: expanded from macro 'SHELL_CONFIG_DIRECTIVEX'
                        if (typeid(arg_val) == typeid(bool&)) { \
                            ~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~

Wondering if it is not beyond salvation... is there some equals() method? Or some missed include...

…info> before using typeid [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov
Copy link
Member Author

Not all systems were created equal... How does augeas decide this, when other regex parsers fail to match the beast to slash. Would escaped \\t\\r\\n of sorts (see last chars) help?

Syntax error in lens definition
./nutupsconf.aug:296.0-.99:Failed to compile ups_entry
/usr/local/share/augeas/lenses/dist/inifile.aug:269.34-.40:exception: The key regexp /((((((((((((chroot)|(driverpath))|(maxstartdelay))|(maxretry))|(nowait))|(retrydelay))|(pollinterval))|(synchronous))|(user))|(group))|(debug_min))|(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((driver)|(port))|(sdorder))|(desc))|(nolock))|(ignorelb))|(maxstartdelay))|(synchronous))|(user))|(group))|(debug_min))|(BYPASS))|(CHRG_addr))|(CHRG_noro))|(CHRG_regtype))|(CP))|(CS))|(DISCHRG_addr))|(DISCHRG_noro))|(DISCHRG_regtype))|(FSD_addr))|(FSD_noro))|(FSD_pulse_duration))|(FSD_regtype))|(HB_addr))|(HB_noro))|(HB_regtype))|(ID))|(LB))|(LB_addr))|(LB_noro))|(LB_regtype))|(LowBatt))|(OB_addr))|(OB_noro))|(OB_regtype))|(OL))|(OL_addr))|(OL_noro))|(OL_regtype))|(OffDelay))|(OnDelay))|(RB))|(RB_addr))|(RB_noro))|(RB_regtype))|(SD))|(advanced_eco_mode))|(advorder))|(alarm_control))|(allow_duplicates))|(authPassword))|(authProtocol))|(authtype))|(awd))|(batteryPercentage))|(battery_alarm))|(battery_max))|(battery_min))|(battery_number))|(battery_open_status_check))|(battery_voltage_reports_one_pack))|(battext))|(battvoltmult))|(baud_rate))|(baudrate))|(bus))|(busport))|(bypass_alarm))|(bypass_forbidding))|(bypass_when_off))|(cable))|(cablepower))|(chargetime))|(community))|(constant_phase_angle))|(converter_mode))|(cshdelay))|(databits))|(daysoff))|(daysweek))|(dev_slave_id))|(device))|(device_mfr))|(device_model))|(disable_fix_report_desc))|(do_convert_deci))|(dumbterm))|(eco_mode))|(explore))|(fake_lowbatt))|(fault_1))|(fault_2))|(fault_3))|(fault_4))|(fault_5))|(flash))|(frequency))|(fruid))|(full_update))|(hb))|(houroff))|(houron))|(i2c_address))|(idleload))|(ignoresab))|(input_fault_voltage))|(input_timeout))|(interruptonly))|(interruptsize))|(langid_fix))|(lb))|(limited_runtime_on_battery))|(linevoltage))|(load\.off))|(load\.on))|(load\.status))|(loadPercentage))|(localcalculation))|(login))|(lowbatt))|(manufacturer))|(max_bypass_freq))|(max_bypass_volt))|(max_load))|(max_polls_without_data))|(maxreport))|(methodOfFlowControl))|(mfr))|(mibs))|(min_bypass_freq))|(min_bypass_volt))|(mincharge))|(minruntime))|(mod_byte_to_s))|(mod_byte_to_us))|(mod_resp_to_s))|(mod_resp_to_us))|(model))|(modelname))|(nobt))|(nohang))|(nombattvolt))|(nominal_cell_voltage))|(norating))|(noscanlangid))|(notification))|(notransferoids))|(novendor))|(nowarn_noimp))|(numOfBytesFromUPS))|(number_of_battery_cells))|(offdelay))|(oldmac))|(ondelay))|(onlinedischarge))|(onlinedischarge_calibration))|(onlinedischarge_log_throttle_hovercharge))|(onlinedischarge_log_throttle_sec))|(onlinedischarge_onbattery))|(output_pace))|(output_phase_angle))|(output_voltages))|(parity))|(password))|(pins_shutdown_mode))|(pollfreq))|(pollonly))|(porttype))|(powerup))|(prefix))|(prgshut))|(privPassword))|(privProtocol))|(product))|(productid))|(protocol))|(rebootdelay))|(recharge_time))|(repeater_disable_strict_start))|(reset_to_default))|(response_timeout_ms))|(rio_slave_id))|(rules))|(runtime_full))|(runtime_half))|(runtimecal))|(sdtime))|(sdtype))|(secLevel))|(secName))|(semistaticfreq))|(sensorid))|(ser_baud_rate))|(ser_data_bit))|(ser_parity))|(ser_stop_bit))|(serial))|(serialnumber))|(series))|(shutdownArguments))|(shutdown_delay))|(shutdown_duration))|(shutdown_timer))|(silent))|(site_fault_detection))|(slave_address))|(slaveid))|(snmp_retries))|(snmp_timeout))|(snmp_version))|(startdelay))|(status_only))|(stayoff))|(stopbits))|(subdriver))|(subscribe))|(symmetrathreephase))|(testing))|(testtime))|(timeout))|(ttymode))|(type))|(ups\.delay\.shutdown))|(ups\.delay\.start))|(upsid))|(upstype))|(usb_config_index))|(usb_hid_desc_index))|(usb_hid_ep_in))|(usb_hid_ep_out))|(usb_hid_rep_index))|(usb_set_altinterface))|(usd))|(use_crlf))|(use_pre_lf))|(username))|(validationSequence))|(vendor))|(vendorid))|(voltage))|(wait))|(waitbeforereconnect))|(work_range_type))|(wugrace)))|((default|override)\.[^:=#	

 ]+)/ matches a '/' which is used to separate nodes.

…ex [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov
Copy link
Member Author

Hm... seems the universal augeas parser for handling configs portably is not portable itself as an engine. Same NUT lens and test files fail or pass with different messages, sometimes regardless of augeas versions (one is passing, but older/newer ones fail).

… override.* expressions [networkupstools#2294]

Such possibility makes augtools-1.12.0 upset (fixed since 1.13.0,
see hercules-team/augeas#668 for details)

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov
Copy link
Member Author

jimklimov commented Apr 29, 2024

I guess I'll have to disable the augeas self-test by default again, let the scope of issue #657 deal with it. Was inclined to cut off by release version, but augeas-1.12.0 on Debian and FreeBSD behave differently vs. same NUT test codebase...

First will try to separate a "flaky" test with default.* pattern handling into a non-default file to use in manual tests but not run blindly everywhere.

This passes on various linuxes but fails on FreeBSD and OpenBSD workers (used to fail similarly on Ubuntu but then somehow the syntax got wedged to augeas' liking):

~/nut/scripts/augeas$ ./gen-nutupsconf-aug.py ; make ; augparse --trace -I ./ ./tests/test_nut_flaky.aug && echo PASSED
Module ./tests/test_nut_flaky.aug loaded
Module ./nutupsconf.aug loaded
Module /usr/local/share/augeas/lenses/dist/inifile.aug loaded
Module /usr/local/share/augeas/lenses/dist/util.aug loaded
Module /usr/local/share/augeas/lenses/dist/sep.aug loaded
Module /usr/local/share/augeas/lenses/dist/rx.aug loaded
Module /usr/local/share/augeas/lenses/dist/quote.aug loaded
Module /usr/local/share/augeas/lenses/dist/build.aug loaded
./tests/test_nut_flaky.aug:21.0-27.47:exception thrown in test
./tests/test_nut_flaky.aug:21.5-.37:exception: Get did not match entire input
    Lens: /usr/local/share/augeas/lenses/dist/inifile.aug:497.25-.43:
    Error encountered at 6:0 (71 characters into string)
    <\n\tdesc = "Dummy UPS Driver"\n|=|\tdefault.battery.voltage.hig>

    Tree generated so far:
    /testups
/testups/driver = "dummy-ups"
/testups/port = "auto"
/testups/desc = "Dummy UPS Driver"


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

…e which passes on some distros and fails on others [networkupstools#657]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ragmas to hush warnings about macro code [networkupstools#2294]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…on some distros so far [networkupstools#657]

Add make targets for custom testing though

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov
Copy link
Member Author

Yeah, so after all - the quick way forward with this was to keep augeas self-check ability in cold storage as far as regular builds are concerned. It should be a bit more facilitated for developers now though.

@jimklimov jimklimov merged commit 8d1e049 into networkupstools:master May 1, 2024
30 checks passed
SmartNUT automation moved this from In Progress to Done May 1, 2024
@jimklimov jimklimov deleted the issue-2294 branch May 1, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
augeas Configuration file parser (reader, writer) multi-tool for scripting, etc. impacts-release-2.8.2 Issues reported against NUT release 2.8.2 (maybe vanilla or with minor packaging tweaks) nutconf NUT configuration library and tool portability We want NUT to build and run everywhere possible
Projects
SmartNUT
  
Done
Development

Successfully merging this pull request may close these issues.

Support new NUT vocabulary in nutconf
1 participant