Skip to content

Conversation

aquette
Copy link
Member

@aquette aquette commented Feb 4, 2019

This implements the instant commands (instcmd) and variables settings (setvar) status tracking, to get the actual execution status from the driver. Support in upscmd and upsrw is also included.

Other pull requests will address the remaining bits of implementation, such as libnutclient, and bindings

Ref: #656

Signed-off-by: Arnaud Quette [email protected]

This commit implements the instant commands (instcmd) and variables settings
(setvar) status tracking, to get the actual execution status from the driver

Signed-off-by: Arnaud Quette <[email protected]>
Signed-off-by: Arnaud Quette <[email protected]>
Following Daniele Pezzini thorough review, sanitize and improve the code, and
also complete documentation

Signed-off-by: Arnaud Quette <[email protected]>
@aquette aquette requested review from clepple, jimklimov and zykh February 4, 2019 13:43
implement support for status tracking in upscmd and upsrw

Signed-off-by: Arnaud Quette <[email protected]>
@aquette aquette added the WIP label Feb 4, 2019
@aquette aquette changed the title INSTCMD and SET VAR status tracking implementation [DO NOT MERGE YET] INSTCMD and SET VAR status tracking implementation Feb 4, 2019
@aquette
Copy link
Member Author

aquette commented Feb 4, 2019

Note on the [DO NOT MERGE YET] / WIP:
I've forgotten that I really want to finalize decision on the UUID implementation...

There is no need to condition CMDSET_STATUS commands received by upsd from the
driver, on cmdset_status_enabled, since what matters is the presence of a list
and id

Signed-off-by: Arnaud Quette <[email protected]>
Signed-off-by: Arnaud Quette <[email protected]>
replaced the initial rxi/uuid4 library used by a cross platform version. Though
more basic, it is enough for our needs, at least for now

Signed-off-by: Arnaud Quette <[email protected]>
@aquette aquette removed the WIP label Feb 4, 2019
@aquette aquette changed the title [DO NOT MERGE YET] INSTCMD and SET VAR status tracking implementation INSTCMD and SET VAR status tracking implementation Feb 4, 2019
Copy link
Contributor

@zykh zykh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for addressing those issues, @aquette... here a few more, for your pleasure

Signed-off-by: Arnaud Quette <[email protected]>
Signed-off-by: Arnaud Quette <[email protected]>
Signed-off-by: Arnaud Quette <[email protected]>
Add upscli_sendline_timeout and upscli_readline_timeout, beside from the
classic blocking versions. Also make a common define for timeout, and use it
in upsclient and nut-scanner

Signed-off-by: Arnaud Quette <[email protected]>
Copy link
Member

@clepple clepple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have added this first comment to the review as well: https://github.com/networkupstools/nut/pull/659/files/87f59e7c009efe0fc2da9fba33d11ab31a61ffa8..a619455687f98d3dc2b2c83628ca4fa14cf39076#r255510222

Somewhat cosmetic changes, but I figure since these files are being changed...

zykh added 4 commits February 11, 2019 23:23
Rename the default timeout used in network operations by upsclient and nut-scanner to be more specific: from DEFAULT_TIMEOUT to DEFAULT_NETWORK_TIMEOUT.
Plus, make the default timeout used when retrieving the result of an INSTCMD/SET VAR with TRACKING enabled a common #define'd value (DEFAULT_TRACKING_TIMEOUT), and use it also to publish the default value of the -t option in the help messages of upscmd and upsrw.

As suggested by Charles Lepple.
Also, remove some nesting in tracking_del().
To keep things simple, at least for now, only generate manpages and not html pages (and, as such, don't even think of using our linkman AsciiDoc macro with those functions, to avoid dead links).
- addition of upscli_{read,send}line_timeout(),
- upscli_cleanup() -> upcli_cleanup(void)

Note: only increase 'current' and not 'age', because the upscli_cleanup() change could (potentially) make it not compatible with previous versions.
@zykh
Copy link
Contributor

zykh commented Feb 12, 2019

Thanks @clepple, @aquette.

I've merged the tracking branch into the cmdset_status one and addressed those remaining issues (hopefully in a reasonable way... let me know if this is not the case).

Copy link
Member

@clepple clepple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zykh thanks for implementing the defaults commit.
@aquette looks good overall.

@clepple
Copy link
Member

clepple commented Feb 12, 2019

The only confusing thing is that now upscmd against dummy-ups in dummy/file mode fails when request tracking is on - the driver publishes a list of commands from the file, but does not allow them to "execute". Testing with upsrw worked better against dummy-ups, where I could suspend the driver to simulate high load.

@zykh
Copy link
Contributor

zykh commented Feb 13, 2019

hmm... right, dummy-ups's instcmd() always returns STAT_INSTCMD_UNKNOWN for the lone supported command (load.off): should we make it succeed? (actually implementing configurable instant commands seems worth a new issue)
We should also fix the (up until now ignored) return codes of the various drivers that were not fully ported to the new (in 2007) return codes for setvar() and instcmd() (e.g. setvar() of usbhid-ups and ... *cough* *cough* ... nutdrv_qx, which inherited it from usbhid-ups)...
Ah.. perhaps we should also warn that not only the server, but also the drivers need to support the TRACKING command, for the -w option of upscmd / upsrw to work as expected.

I'll do that, later today.

@aquette
Copy link
Member Author

aquette commented Feb 13, 2019

hi fellows,
agreed for the need to complete drivers, that's a due thing.
as for dummy-ups and instcmd/setvar, I've a plan to address that cleanly too (not yet actually thought about the how), but it's indeed another ticket.

@aquette
Copy link
Member Author

aquette commented Feb 13, 2019

FYI, travis failed on git fetch. relaunched to get the green...

@zykh
Copy link
Contributor

zykh commented Feb 14, 2019

I was all set to update the various drivers, but stumbled upon this...

Drivers that already use all the STAT_* return codes have slightly different (and contradictory) behaviours, also in conflict with the documentation of STAT_* values in upshandler.h.

So, first, let's find a common field.

setvar

event STAT_SET value returned
unknown var STAT_SET_INVALID
var is not writable STAT_SET_INVALID
invalid value for var STAT_SET_INVALID
tried to set the var, but failed STAT_SET_FAILED
other unspecified errors STAT_SET_UNKNOWN
successfully set the var STAT_SET_HANDLED

instcmd

event STAT_INSTCMD value returned
unknown/invalid command STAT_INSTCMD_INVALID
invalid optional param for command STAT_INSTCMD_INVALID
tried the command, but it failed STAT_SET_FAILED
other unspecified errors STAT_INSTCMD_UNKNOWN
successfully set the var STAT_INSTCMD_HANDLED

Does this seem reasonable to you?

@aquette
Copy link
Member Author

aquette commented Feb 14, 2019

For instcmd and my last patch on eaton marlin and hpe mib, I assumed that STAT_INSTCMD_INVALID is "invalid optional or missing mandatory param for command". As an example, load.off jas a default value but can be provided one. Load.off.delay has a mandatory param.
As a general note, I was also thinking about extending the return codes list, but that needed an audit of all drivers. So you @zykh have better visibility than me

Copy link
Member

@jimklimov jimklimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally ok, some nits and sanity-check challenges commented...

# libupsclient version information
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
libupsclient_la_LDFLAGS = -version-info 4:0:0
libupsclient_la_LDFLAGS = -version-info 5:0:0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self (and others): this impacts library filename and packaging/dependencies.

if (
!tracking_enabled ||
/* sanity check on the size: "OK TRACKING " + UUID4_LEN */
strlen(buf) != (UUID4_LEN - 1 + strlen("OK TRACKING "))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my reading of standards and docs in UUID-related codebases, at least two correct spellings of an UUID value are possible: the hexadecimal string broken by dashes in correct positions, or just the all-hex string (shorter).

Our updated header defines UUID4_LEN as "(Minimum) Size that a string must have to hold a UUID4", catering for the dashed spelling.

What if the user passes a valid non-dashed version (so strlen(buf) would be shorter than expected here)?
Should we convert one to another (if all hexes and length==X, then add dashes)?

At the very least, I think we should avoid surprises by documenting that the current code requires the particular spelling of UUID string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it's worth: the intent is not to have real UUID v4, but more something (a key) unique enough to avoid collisions. Whatever the user passes has to be valid, and was supposed to have been provided before. If he passes random string, or non dashed ID or whatever, this will be truncated and discarded.

@jimklimov
Copy link
Member

@zykh @aquette (@clepple ?) : I see you've had quite a discussion above about updating other drivers to this new paradigm, fixing dummy-ups and error code handling... is this planned as part of this PR (or, does lack of those fixes block merging this codebase "as is" into the master?)

If yes, maybe we should mark this PR as a DNMY (Do not merge yet) for the time being, to avoid an eager mis-click? ;)

@jimklimov
Copy link
Member

Resolved merge conflicts vs. master, that arose as other small PRs got merged.

@aquette
Copy link
Member Author

aquette commented Feb 25, 2019

hi all
back from vacations today, I was expecting that this PR would have been merged :D
I'll check and address your comments @jimklimov, thx.
@zykh any news on the drivers update front?
@jimklimov the followups are planned for separate PRs (including the libnutclient update related to the present PR)

Signed-off-by: Arnaud Quette <[email protected]>
@aquette
Copy link
Member Author

aquette commented Feb 26, 2019

all, I'm now going to merge this PR, to unblock followups (esp. the libnutclient implementation of this from @boricj )
@zykh : if you feel that are remainders for the drivers, let's track it into a separate ticket.
thanks to all for your comments and help on this topic!

@aquette aquette merged commit d5e2902 into master Feb 26, 2019
jimklimov pushed a commit to jimklimov/nut that referenced this pull request Apr 1, 2019
* INSTCMD and SET VAR status tracking implementation

This commit implements the instant commands (instcmd) and variables settings
(setvar) status tracking, to get the actual execution status from the driver

Signed-off-by: Arnaud Quette <[email protected]>

* Missing Revision history

Signed-off-by: Arnaud Quette <[email protected]>

* Fix nut-names.txt modification that should not be here

Signed-off-by: Arnaud Quette <[email protected]>

* Augeas support: add CMDSETSTATUSDELAY for upsd.conf

Signed-off-by: Arnaud Quette <[email protected]>

* INSTCMD and SET VAR status tracking completion

Following Daniele Pezzini thorough review, sanitize and improve the code, and
also complete documentation

Signed-off-by: Arnaud Quette <[email protected]>

* INSTCMD and SET VAR status tracking completion

implement support for status tracking in upscmd and upsrw

Signed-off-by: Arnaud Quette <[email protected]>

* upscmd/upsrw: delay retries for status tracking

Signed-off-by: Arnaud Quette <[email protected]>

* Remove comment

There is no need to condition CMDSET_STATUS commands received by upsd from the
driver, on cmdset_status_enabled, since what matters is the presence of a list
and id

Signed-off-by: Arnaud Quette <[email protected]>

* Complete comment

Signed-off-by: Arnaud Quette <[email protected]>

* UUID v4 implementation

replaced the initial rxi/uuid4 library used by a cross platform version. Though
more basic, it is enough for our needs, at least for now

Signed-off-by: Arnaud Quette <[email protected]>

* status_info should be static

Signed-off-by: Arnaud Quette <[email protected]>

* No need for else, since fatalx is called before

Signed-off-by: Arnaud Quette <[email protected]>

* Suppress \n from debug output

Signed-off-by: Arnaud Quette <[email protected]>

* Group sanity checks

Signed-off-by: Arnaud Quette <[email protected]>

* Get rid of dynamic memory allocation

Signed-off-by: Arnaud Quette <[email protected]>

* Improve and enforce the use of UUID4_LEN

Signed-off-by: Arnaud Quette <[email protected]>

* Comment on the size of dest for nut_uuid_v4()

Signed-off-by: Arnaud Quette <[email protected]>

* Move structures and defines to more appropriate places

Signed-off-by: Arnaud Quette <[email protected]>

* Add functions with timeout

Add upscli_sendline_timeout and upscli_readline_timeout, beside from the
classic blocking versions. Also make a common define for timeout, and use it
in upsclient and nut-scanner

Signed-off-by: Arnaud Quette <[email protected]>

* upscmd/upsrw: add a timeout option

Signed-off-by: Arnaud Quette <[email protected]>

* Basic homebrew UUID v4 implementation

Signed-off-by: Arnaud Quette <[email protected]>

* Prefer to use static buffer for UUID

Signed-off-by: Arnaud Quette <[email protected]>

* log actual result of instcmd / setvar

Signed-off-by: Arnaud Quette <[email protected]>

* Fix tracking ID reporting due to static memory changes

Signed-off-by: Arnaud Quette <[email protected]>

* upsclient: use unsigned int for timeouts

Also, explicit that upscli_cleanup() takes no argument.

* upscmd/upsrw: use unsigned int for timeout + our str_to_uint() for it

Also, slightly reword the help message for `-t` (timeout) option, in order to clarify which is the unit (seconds) used for the provided value.

* upscmd/upsrw: don't sleep after receiving a non-PENDING CMDSET_STATUS

Also, remove some nesting in do_cmd() and do_set().

* net-protocol: clarify the format of GET CMDSET_STATUS + <status_id>

<status_id> is not optional to get the status of a command/setvar with CMDSET_STATUS, so drop the [square brackets] from it.
Also drop "quotes" in SET CMDSET_STATUS's <value>, since it's expected to be a single word.

Plus, fix markup of INSTMCD's <cmdparam> parameter.

* sock-protocol: align case and markup of command parameters

* dstate: fix handling of INSTCMD's optional parameters

We should still support the old `INSTCMD <cmdname> [<cmdparam>]` format, and not only consider <cmdparam> when also `STATUS_ID <id>` is provided.

Also, fix the format of our sock-protocol commands mentioned in comments, and add function names to debug info.

* common: document the recently added things

* upsd: in INSTCMD/SET handlers, also accept NULL for status_id

Plus:
- use a simpler approach to test if status_id is not empty,
- align the way the SET command is built to the one used for the INSTCMD command.

* upsd: drop unnecessary/unused global

* upsd: move sanity checks of cmdset_status_get() after declaration of vars

Also, drop some nesting in that function.

* Move from CMDSET_STATUS / STATUS_ID to TRACKING

This is just a big, big rename, no code changes.

* upsd: refine the tracking API

Add a couple of functions to change in a predictable way the value of the general enablement of tracking and make it visible only inside upsd.c.
Also, move the tracking type (tracking_t) and the list of items inside upsd.c.

* net-protocol: also return TRACKING between OK and <id>, for INSTCMD/SET VAR

* dstate: *really* fix handling of INSTCMD's optional parameters

Erroring out on `INSTCMD <cmdname>` doesn't seem like a good idea...

* common: massage default timeouts

Rename the default timeout used in network operations by upsclient and nut-scanner to be more specific: from DEFAULT_TIMEOUT to DEFAULT_NETWORK_TIMEOUT.
Plus, make the default timeout used when retrieving the result of an INSTCMD/SET VAR with TRACKING enabled a common #define'd value (DEFAULT_TRACKING_TIMEOUT), and use it also to publish the default value of the -t option in the help messages of upscmd and upsrw.

As suggested by Charles Lepple.

* upsd: ignore case of UUID4 in tracking API

Also, remove some nesting in tracking_del().

* libupsclient: generate manpages for upscli_{read,send}line_timeout()

To keep things simple, at least for now, only generate manpages and not html pages (and, as such, don't even think of using our linkman AsciiDoc macro with those functions, to avoid dead links).

* libupsclient: bump version as per recent changes

- addition of upscli_{read,send}line_timeout(),
- upscli_cleanup() -> upcli_cleanup(void)

Note: only increase 'current' and not 'age', because the upscli_cleanup() change could (potentially) make it not compatible with previous versions.

* upscmd/upsrw: warn that also the drivers need to support TRACKING, for -w

* Fix typo and spelling

Signed-off-by: Arnaud Quette <[email protected]>

* Add check around atoi() conversion

Signed-off-by: Arnaud Quette <[email protected]>
@jimklimov jimklimov deleted the cmdset_status branch March 29, 2022 12:13
@jimklimov jimklimov added this to the 2.8.0 milestone Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants