Skip to content

Commit

Permalink
Fix unit tests, LGTM
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Jun 3, 2022
1 parent 6b6feda commit 42051c9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
14 changes: 13 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,19 @@ def add_portchannel_member(ctx, portchannel_name, port_name):
if clicommon.is_port_mirror_dst_port(db, port_name):
ctx.fail("{} is configured as mirror destination port".format(port_name))

# Dont allow a port to be member of port channel if it is configured with an IP address
# Check if the member interface given by user is valid in the namespace.
if port_name.startswith("Ethernet") is False or interface_name_is_valid(db, port_name) is False:
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")

# Dont proceed if the port channel name is not valid
if is_portchannel_name_valid(portchannel_name) is False:
ctx.fail("{} is invalid!, name should have prefix '{}' and suffix '{}'"
.format(portchannel_name, CFG_PORTCHANNEL_PREFIX, CFG_PORTCHANNEL_NO))

# Dont proceed if the port channel does not exist
if is_portchannel_present_in_db(db, portchannel_name) is False:
ctx.fail("{} is not present.".format(portchannel_name))

for key,value in db.get_table('INTERFACE').items():
if type(key) == tuple:
continue
Expand Down
2 changes: 1 addition & 1 deletion config/validated_config_db_connector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import jsonpatch

from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
from swsscommon.swsscommon import ConfigDBConnector
from generic_config_updater.generic_updater import GenericUpdater, ConfigFormat

class ValidatedConfigDBConnector(ConfigDBConnector):
Expand Down
10 changes: 5 additions & 5 deletions tests/portchannel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_add_portchannel_with_invalid_name(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>'" in result.output
assert 'does not satisfy the constraint "PortChannel[0-9]{1,4}"' in result.output

def test_delete_portchannel_with_invalid_name(self):
runner = CliRunner()
Expand All @@ -35,7 +35,7 @@ def test_delete_portchannel_with_invalid_name(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>'" in result.output
assert "can't remove a non-existent object" in result.output

def test_add_existing_portchannel_again(self):
runner = CliRunner()
Expand All @@ -59,7 +59,7 @@ def test_delete_non_existing_portchannel(self):
print(result.exit_code)
print(result.output)
assert result.exit_code != 0
assert "Error: PortChannel0005 is not present." in result.output
assert "can't remove a non-existent object" in result.output

def test_add_portchannel_member_with_invalid_name(self):
runner = CliRunner()
Expand All @@ -71,7 +71,7 @@ def test_add_portchannel_member_with_invalid_name(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>'" in result.output
assert 'does not satisfy the constraint "PortChannel[0-9]{1,4}"' in result.output

def test_delete_portchannel_member_with_invalid_name(self):
runner = CliRunner()
Expand All @@ -83,7 +83,7 @@ def test_delete_portchannel_member_with_invalid_name(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>'" in result.output
assert "can't remove a non-existent object" in result.output

def test_add_non_existing_portchannel_member(self):
runner = CliRunner()
Expand Down

0 comments on commit 42051c9

Please sign in to comment.