From b20f983630cafc06b1031fd695733d8dbcbe6462 Mon Sep 17 00:00:00 2001 From: Sam Osterkil Date: Tue, 1 Jun 2021 13:45:34 -0600 Subject: [PATCH] Support value-in-range with keyword This allows syntax checking to pass for fields like vxlan-ttl/vxlan-tos which can be a number in a range OR a string value representing a special meaning (0-255 or "auto", for instance). Without this, you can only pass a --syntax-check for such fields if your value is one of those literally specified because, for instance, "64" is not "auto", "0", or "255": invalid value "64": valid attribute values: ['0', '255'] info: exit status 1 Note that _applying_ such configuration still works, because netlink's acceptance criteria are independent of ifupdown2's. --- ifupdown2/addons/vxlan.py | 6 ++++-- ifupdown2/ifupdown/ifupdownmain.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ifupdown2/addons/vxlan.py b/ifupdown2/addons/vxlan.py index cffacf3..32b62b2 100644 --- a/ifupdown2/addons/vxlan.py +++ b/ifupdown2/addons/vxlan.py @@ -97,12 +97,14 @@ class vxlan(Addon, moduleBase): "help": "specifies the TTL value to use in outgoing packets " "(range 0..255), 0=auto", "default": "0", - "validvals": ["0", "255"], + "validrange": ["0", "255"], + "validvals": ["", "auto"], "example": ['vxlan-ttl 42'], }, "vxlan-tos": { "help": "specifies the ToS value (range 0..255), 1=inherit", - "validvals": ["inherit", "0", "255"], + "validrange": ["0", "255"], + "validvals": ["", "inherit"], "example": ['vxlan-tos 42'], }, "vxlan-mcastgrp": { diff --git a/ifupdown2/ifupdown/ifupdownmain.py b/ifupdown2/ifupdown/ifupdownmain.py index 437eea5..c3ce130 100644 --- a/ifupdown2/ifupdown/ifupdownmain.py +++ b/ifupdown2/ifupdown/ifupdownmain.py @@ -1224,7 +1224,9 @@ class ifupdownMain: def _keyword_number(self, value, validrange=None): try: - int(value) + int_value = int(value) + if validrange is not None: + return int(validrange[0]) <= int_value <= int(validrange[1]) return True except Exception as e: self.logger.debug('keyword: number: %s' % str(e))