Skip to content

Conversation

@talmakion
Copy link
Contributor

Change summary

In my related PR against vyos-1x, I'm adding a sanity-check warning to the bgp-large-community-list validator, but the output is eaten by validate_value.

This change allows validator scripts to request visible output, without completely failing validation. It prints results immediately rather than messing with buf and flagging output at the end, I don't know OCaml well.

Please advise if this change should also be applied to vyos1x-config or if a different method should be used, such as a regex over validator output.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Related PR(s)

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

Copy link
Member

@dmbaturin dmbaturin left a comment

Choose a reason for hiding this comment

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

I agree with the idea to make validator warnings visible but disagree with the idea to use non-zero exit codes for that.

For better or worse, UNIX exit codes have only two kinds of meanings: "executed successfully" (0) and "failed because of some reason" (>0). Specific values of non-zero codes can only be used to clarify the nature of the failure.

I think we can just always relay validator outputs to the user. For example, ignore stdout but always relay validator's stderr to validate_value's stderr so that the validator can use it for warnings.

You can use Unix.open_process_full to get all streams (see https://ocaml.org/manual/5.3/api/Unix.html).

* In related PR against vyos-1x, I add a sanity-check warning to the
  bgp-large-community-list validator, output is eaten by validate_value
* This change allows validator scripts to output warnings on stderr, without
  completely failing validation
@talmakion talmakion force-pushed the feature/T5069/show-validator-warnings branch from 5cff251 to eed5cfb Compare May 7, 2025 17:48
@talmakion
Copy link
Contributor Author

talmakion commented May 7, 2025

Spotted the shell fd redirect:

let chan = Unix.open_process_in (Printf.sprintf "%s \'%s\' 2>&1" c value) in

Removing the redirect, it'll pass through without having to juggle 2 separate pipes potentially overflowing and deadlocking against each other, on the low chance a validator breaks and spews output. After poking through the OCaml libs, open_process_in already only captures stdout and passes stderr right through. This works OK in testing.

However - I imagine that redirect was already there for a reason, are there any known issues with successful chatty validators that I should double check?

(I haven't yet made corresponding changes to the other PR)

@talmakion talmakion requested a review from dmbaturin May 7, 2025 17:55
@jestabro
Copy link
Contributor

jestabro commented May 8, 2025

@talmakion standard practice has been to print warnings from the verify stage of the config mode script in question, instead of trying to report from the validator in the case of success. Granted this may lead to some redundancy of code, but it allows for a natural distinction: silent success, or failure with explanatory details; consequently no output indicates a valid config.

If there are compelling reasons why, in this case, warning output is better suited for validation, then we should consider a proper extension of the validator framework (as discussed briefly with @dmbaturin who has a suggested design). For the current case, let us consider firstly whether moving to the conf_mode script verify stage makes sense.

@talmakion
Copy link
Contributor Author

@jestabro Cheers for the feedback.

In this case, I had considered moving the warning to commit-verify, but ended up settling on doing this in the validator for immediate feedback, with the warning right after the command that caused it. It's pretty common for my workflow to involve large commits when changing policy sections.

However, it's just a warning hinting that something might be wrong. Simply allowing through stderr has probable unwanted side effects, buffering stderr separately involves a bit of complexity plus signalling from the warning source and other parts of my changes are getting janky - for eg, the validators run twice (at set and commit time), so the warning comes up twice, which just looks a bit odd.

I'll rework my changes to generate the warning in verify, instead.

@talmakion talmakion closed this May 9, 2025
@jestabro
Copy link
Contributor

jestabro commented May 9, 2025

@talmakion I presume that we are talking about the same thing, but as you mention 'commit-verify', and want to clarify that I am referring to the verify function in the standard config-mode script structure:
https://docs.vyos.io/en/latest/contributing/development.html#configuration-script-structure-and-behaviour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants