-
-
Notifications
You must be signed in to change notification settings - Fork 395
INSTCMD and SET VAR status tracking implementation #659
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
Conversation
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]>
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]>
implement support for status tracking in upscmd and upsrw Signed-off-by: Arnaud Quette <[email protected]>
Note on the [DO NOT MERGE YET] / WIP: |
Signed-off-by: Arnaud Quette <[email protected]>
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]>
There was a problem hiding this 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]>
Signed-off-by: Arnaud Quette <[email protected]>
Signed-off-by: Arnaud Quette <[email protected]>
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]>
Signed-off-by: Arnaud Quette <[email protected]>
Signed-off-by: Arnaud Quette <[email protected]>
There was a problem hiding this 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...
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only confusing thing is that now |
hmm... right, I'll do that, later today. |
hi fellows, |
FYI, travis failed on git fetch. relaunched to get the green... |
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 So, first, let's find a common field. setvar
instcmd
Does this seem reasonable to you? |
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. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 ")) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@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? ;) |
Resolved merge conflicts vs. master, that arose as other small PRs got merged. |
hi all |
Signed-off-by: Arnaud Quette <[email protected]>
Signed-off-by: Arnaud Quette <[email protected]>
* 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]>
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]