Page MenuHomeVyOS Platform

Validator Does Not Accept Signed Numbers
Closed, ResolvedPublicBUG

Description

The numeric validator does not accept signed numbers, and as a result causes errors with relative metrics in route-maps:

[email protected]# set policy route-map BGP-BACKBONE-OUT rule 10 set metric "+100"
      
  '+100' is not a valid number                                
      
                                                          
                                                                            
  Invalid value
  Value validation failed                                 
  Set failed                                                                                                                                                                                                                                     
[edit]

Details

Difficulty level
Easy (less than an hour)
Version
1.4-rolling-202205290217
Why the issue appeared?
Implementation mistake
Is it a breaking change?
Perfectly compatible
Issue type
Bug (incorrect behavior)

Event Timeline

route-maps support a relative adjustment of the metric (https://github.com/vyos/vyos-1x/blob/current/interface-definitions/policy.xml.in#L1402-L1417)

The validator should support verifying also signed numbers

Signed positive not working

bash
[email protected]:~$ /usr/libexec/vyos/validators/numeric --range -10-10 +4
'+4' is not a valid number
[email protected]:~$ /usr/libexec/vyos/validators/numeric --range -10-10 -5
/usr/libexec/vyos/validators/numeric: unknown option '-5'.
Usage: /usr/libexec/vyos/validators/numeric [OPTIONS] <number>
  --non-negative Check if the number is non-negative (>= 0)
  --positive Check if the number is positive (> 0)
  --range Check if the number is within a range (inclusive)
  --float Allow floating-point numbers
  -help  Display this list of options
  --help  Display this list of options

Signed negative not working

bash
[email protected]:~$ /usr/libexec/vyos/validators/numeric --range -10-10 -- -5
/usr/libexec/vyos/validators/numeric: unknown option '--'.
Usage: /usr/libexec/vyos/validators/numeric [OPTIONS] <number>
  --non-negative Check if the number is non-negative (>= 0)
  --positive Check if the number is positive (> 0)
  --range Check if the number is within a range (inclusive)
  --float Allow floating-point numbers
  -help  Display this list of options
  --help  Display this list of options
[email protected]:~$ /usr/libexec/vyos/validators/numeric --range -10-10 -5
/usr/libexec/vyos/validators/numeric: unknown option '-5'.
Usage: /usr/libexec/vyos/validators/numeric [OPTIONS] <number>
  --non-negative Check if the number is non-negative (>= 0)
  --positive Check if the number is positive (> 0)
  --range Check if the number is within a range (inclusive)
  --float Allow floating-point numbers
  -help  Display this list of options
  --help  Display this list of options
c-po triaged this task as Normal priority.Thu, Jun 16, 7:06 AM
c-po changed Difficulty level from Unknown (require assessment) to Easy (less than an hour).
c-po changed Why the issue appeared? from Will be filled on close to Implementation mistake.

PR: https://github.com/vyos/vyos-utils/pull/4
Adding the additional validator to policy.xml.in allows the smoketest (above) to pass.

Tested and works correct. Thanks @jestabro