diff --git a/config/main.py b/config/main.py index f1c996b865..b5b766243a 100644 --- a/config/main.py +++ b/config/main.py @@ -34,7 +34,7 @@ from utilities_common import util_base from swsscommon import swsscommon from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, ConfigDBPipeConnector, \ - validate_interface_name_length, iface_name_max_length + is_interface_name_valid, IFACE_NAME_MAX_LEN from utilities_common.db import Db from utilities_common.intf_filter import parse_interface_in_filter from utilities_common import bgp_util @@ -438,7 +438,7 @@ def is_portchannel_name_valid(portchannel_name): if (portchannel_name[CFG_PORTCHANNEL_PREFIX_LEN:].isdigit() is False or int(portchannel_name[CFG_PORTCHANNEL_PREFIX_LEN:]) > CFG_PORTCHANNEL_MAX_VAL) : return False - if not validate_interface_name_length(portchannel_name): + if not is_interface_name_valid(portchannel_name): return False return True @@ -2441,7 +2441,7 @@ def add_portchannel(ctx, portchannel_name, min_links, fallback, fast_rate): if ADHOC_VALIDATION: if is_portchannel_name_valid(portchannel_name) != True: ctx.fail("{} is invalid!, name should have prefix '{}' and suffix '{}' and its length should not exceed {} characters" - .format(portchannel_name, CFG_PORTCHANNEL_PREFIX, CFG_PORTCHANNEL_NO,iface_name_max_length())) + .format(portchannel_name, CFG_PORTCHANNEL_PREFIX, CFG_PORTCHANNEL_NO, IFACE_NAME_MAX_LEN)) if is_portchannel_present_in_db(db, portchannel_name): ctx.fail("{} already exists!".format(portchannel_name)) # TODO: MISSING CONSTRAINT IN YANG MODEL @@ -5875,8 +5875,8 @@ def add_vrf(ctx, vrf_name): config_db = ValidatedConfigDBConnector(ctx.obj['config_db']) if not vrf_name.startswith("Vrf") and not (vrf_name == 'mgmt') and not (vrf_name == 'management'): ctx.fail("'vrf_name' must begin with 'Vrf' or named 'mgmt'/'management' in case of ManagementVRF.") - if not validate_interface_name_length(vrf_name): - ctx.fail("'vrf_name' length should not exceed {} characters".format(iface_name_max_length())) + if not is_interface_name_valid(vrf_name): + ctx.fail("'vrf_name' length should not exceed {} characters".format(IFACE_NAME_MAX_LEN)) if is_vrf_exists(config_db, vrf_name): ctx.fail("VRF {} already exists!".format(vrf_name)) elif (vrf_name == 'mgmt' or vrf_name == 'management'): @@ -5895,8 +5895,8 @@ def del_vrf(ctx, vrf_name): config_db = ValidatedConfigDBConnector(ctx.obj['config_db']) if not vrf_name.startswith("Vrf") and not (vrf_name == 'mgmt') and not (vrf_name == 'management'): ctx.fail("'vrf_name' must begin with 'Vrf' or named 'mgmt'/'management' in case of ManagementVRF.") - if not validate_interface_name_length(vrf_name): - ctx.fail("'vrf_name' length should not exceed {} characters".format((iface_name_max_length()))) + if not is_interface_name_valid(vrf_name): + ctx.fail("'vrf_name' length should not exceed {} characters".format((IFACE_NAME_MAX_LEN))) syslog_table = config_db.get_table("SYSLOG_SERVER") syslog_vrf_dev = "mgmt" if vrf_name == "management" else vrf_name for syslog_entry, syslog_data in syslog_table.items(): @@ -6904,7 +6904,7 @@ def add_loopback(ctx, loopback_name): if ADHOC_VALIDATION: if is_loopback_name_valid(loopback_name) is False: ctx.fail("{} is invalid, name should have prefix '{}' and suffix '{}' and should not exceed {} characters" - .format(loopback_name, CFG_LOOPBACK_PREFIX, CFG_LOOPBACK_NO, iface_name_max_length())) + .format(loopback_name, CFG_LOOPBACK_PREFIX, CFG_LOOPBACK_NO, IFACE_NAME_MAX_LEN)) lo_intfs = [k for k, v in config_db.get_table('LOOPBACK_INTERFACE').items() if type(k) != tuple] if loopback_name in lo_intfs: @@ -7651,8 +7651,8 @@ def add_subinterface(ctx, subinterface_name, vid): if interface_alias is None: ctx.fail("{} invalid subinterface".format(interface_alias)) - if not validate_interface_name_length(interface_alias): - ctx.fail("Subinterface name length should not exceed {} characters".format(iface_name_max_length())) + if not is_interface_name_valid(interface_alias): + ctx.fail("Subinterface name length should not exceed {} characters".format(IFACE_NAME_MAX_LEN)) if interface_alias.startswith("Po") is True: intf_table_name = CFG_PORTCHANNEL_PREFIX diff --git a/config/vxlan.py b/config/vxlan.py index 2e5da9a387..54793eebf8 100644 --- a/config/vxlan.py +++ b/config/vxlan.py @@ -3,7 +3,7 @@ from jsonpatch import JsonPatchConflict from .validated_config_db_connector import ValidatedConfigDBConnector -from swsscommon.swsscommon import validate_interface_name_length, iface_name_max_length +from swsscommon.swsscommon import is_interface_name_valid, IFACE_NAME_MAX_LEN ADHOC_VALIDATION = True # @@ -25,8 +25,8 @@ def add_vxlan(db, vxlan_name, src_ip): if ADHOC_VALIDATION: if not clicommon.is_ipaddress(src_ip): ctx.fail("{} invalid src ip address".format(src_ip)) - if not validate_interface_name_length(vxlan_name): - ctx.fail("'vxlan_name' length should not exceed {} characters".format(iface_name_max_length())) + if not is_interface_name_valid(vxlan_name): + ctx.fail("'vxlan_name' length should not exceed {} characters".format(IFACE_NAME_MAX_LEN)) vxlan_keys = db.cfgdb.get_keys('VXLAN_TUNNEL') if not vxlan_keys: @@ -320,4 +320,3 @@ def del_vxlan_map_range(db, vxlan_name, vlan_start, vlan_end, vni_start): config_db.set_entry('VXLAN_TUNNEL_MAP', mapname, None) except JsonPatchConflict as e: ctx.fail("Invalid ConfigDB. Error: {}".format(e)) - diff --git a/tests/config_test.py b/tests/config_test.py index b1714f5cb9..ba548fce1b 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -2776,8 +2776,8 @@ def test_add_loopback_with_invalid_name_adhoc_validation(self): print(result.exit_code) print(result.output) assert result.exit_code != 0 - assert "Error: Loopback0000 is invalid, name should have prefix 'Loopback' and suffix '<0-999>' and should \ - not exceed 11 characters" in result.output + assert "Error: Loopback0000 is invalid, name should have prefix 'Loopback' and suffix '<0-999>' and " \ + "should not exceed 15 characters" in result.output def test_del_nonexistent_loopback_adhoc_validation(self): config.ADHOC_VALIDATION = True diff --git a/tests/portchannel_test.py b/tests/portchannel_test.py index 5fdae9d51c..d1223bd771 100644 --- a/tests/portchannel_test.py +++ b/tests/portchannel_test.py @@ -46,15 +46,15 @@ def test_add_portchannel_with_invalid_name_adhoc_validation(self): print(result.exit_code) print(result.output) assert result.exit_code != 0 - assert "Error: PortChan005 is invalid!, name should have prefix 'PortChannel' and suffix '<0-9999>' and \ - its length should not exceed 15 characters" in result.output + assert "Error: PortChan005 is invalid!, name should have prefix 'PortChannel' and suffix '<0-9999>' " \ + "and its length should not exceed 15 characters" in result.output result = runner.invoke(config.config.commands["portchannel"].commands["add"], ["PortChanl00000"], obj=obj) print(result.exit_code) print(result.output) assert result.exit_code != 0 - assert "Error: PortChanl00000 is invalid!, name should have prefix 'PortChannel' and suffix '<0-9999>' and \ - its length should not exceed 15 characters" in result.output + assert "Error: PortChanl00000 is invalid!, name should have prefix 'PortChannel' and suffix '<0-9999>' and " \ + "its length should not exceed 15 characters" in result.output @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_set_entry", mock.Mock(side_effect=JsonPatchConflict)) @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) diff --git a/tests/vlan_test.py b/tests/vlan_test.py index 01c6dbbbeb..8b0ce1b617 100644 --- a/tests/vlan_test.py +++ b/tests/vlan_test.py @@ -581,7 +581,7 @@ def test_config_vlan_add_member_with_invalid_long_name(self): print(result.exit_code) print(result.output) assert result.exit_code != 0 - assert "Error: Invalid VLAN ID 123456789012 (1-4094)" in result.output + assert "Error: Invalid VLAN ID 123456789012 (2-4094)" in result.output def test_config_vlan_add_member_with_nonexist_vlanid(self): runner = CliRunner() diff --git a/tests/vrf_test.py b/tests/vrf_test.py index 2b4d5429e3..61939f0e95 100644 --- a/tests/vrf_test.py +++ b/tests/vrf_test.py @@ -117,7 +117,7 @@ def test_vrf_bind_unbind(self): vrf_obj['state_db'] = state_db expected_output_unbind = "Interface Eth36.10 IP disabled and address(es) removed due to unbinding VRF.\n" - T1 = threading.Thread( target = self.update_statedb, args = (state_db, db.db.STATE_DB, _hash)) + T1 = threading.Thread( target = self.update_statedb, args = (state_db, db.db.STATE_DB, _hash)) T1.start() result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["unbind"], ["Eth36.10"], obj=vrf_obj) T1.join() @@ -269,7 +269,7 @@ def test_invalid_vrf_name(self): assert expected_output in result.output expected_output = """\ -Error: 'vrf_name' length should not exceed 16 characters +Error: 'vrf_name' length should not exceed 15 characters """ result = runner.invoke(config.config.commands["vrf"].commands["add"], ["VrfNameTooLong!!!"], obj=obj) assert result.exit_code != 0