Skip to content

Commit

Permalink
handle comments
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Blyschak <[email protected]>
  • Loading branch information
stepanblyschak committed Oct 17, 2024
1 parent 93a4b0e commit dc09bad
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
20 changes: 10 additions & 10 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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'):
Expand All @@ -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():
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions config/vxlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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:
Expand Down Expand Up @@ -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))

4 changes: 2 additions & 2 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/portchannel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/vlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/vrf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dc09bad

Please sign in to comment.