-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validations checks while adding a member to PortChannel and removing …
…a member from a Portchannel (#1328) * Validations checks while adding a member to PortChannel and removing a member from a Portchannel Added below validation checks when user the configures a port as member a portchannel: 1. Check if the given portchannel name is valid or not 2. Check if the given portchannel name exists in CONFIG_DB 3. Check if the given port is configured with an IP address or not 4. Check if the given port is configured with with VLAN membership or not 5. Check if the given port is already member of a portchannel 6. Check if the given port speed matches the speed of existing members 7. Check if the given port MTU matches the speed of existing members Added below validation checks when user the removes member port from a portchannel: 1. Check if the given portchannel name is valid or not 2. Check if the given portchannel name exists in exists in CONFIG_DB or not 3. Check if the given port is member of the given portchannel or not Signed-off-by: Akhilesh Samineni <akhilesh.samineni@broadcom.com>
- Loading branch information
1 parent
b18ef5a
commit dba8fcb
Showing
3 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import os | ||
import traceback | ||
|
||
from click.testing import CliRunner | ||
|
||
import config.main as config | ||
import show.main as show | ||
from utilities_common.db import Db | ||
|
||
class TestPortChannel(object): | ||
@classmethod | ||
def setup_class(cls): | ||
os.environ['UTILITIES_UNIT_TESTING'] = "1" | ||
print("SETUP") | ||
|
||
def test_add_portchannel_member_with_invalid_name(self): | ||
runner = CliRunner() | ||
db = Db() | ||
obj = {'db':db.cfgdb} | ||
|
||
# add a portchannel member with invalid portchannel name | ||
result = runner.invoke(config.config.commands["portchannel"].commands["member"].commands["add"], ["PortChan005", "Ethernet0"], obj=obj) | ||
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 | ||
|
||
def test_delete_portchannel_member_with_invalid_name(self): | ||
runner = CliRunner() | ||
db = Db() | ||
obj = {'db':db.cfgdb} | ||
|
||
# delete a portchannel member with invalid portchannel name | ||
result = runner.invoke(config.config.commands["portchannel"].commands["member"].commands["del"], ["PortChan005", "Ethernet0"], obj=obj) | ||
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 | ||
|
||
def test_add_non_existing_portchannel_member(self): | ||
runner = CliRunner() | ||
db = Db() | ||
obj = {'db':db.cfgdb} | ||
|
||
# add a portchannel member with portchannel is not yet created | ||
result = runner.invoke(config.config.commands["portchannel"].commands["member"].commands["add"], ["PortChannel0005", "Ethernet0"], obj=obj) | ||
print(result.exit_code) | ||
print(result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: PortChannel0005 is not present." in result.output | ||
|
||
def test_delete_non_existing_portchannel_member(self): | ||
runner = CliRunner() | ||
db = Db() | ||
obj = {'db':db.cfgdb} | ||
|
||
# delete a portchannel member with portchannel is not yet created | ||
result = runner.invoke(config.config.commands["portchannel"].commands["member"].commands["del"], ["PortChannel0005", "Ethernet0"], obj=obj) | ||
print(result.exit_code) | ||
print(result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: PortChannel0005 is not present." in result.output | ||
|
||
def test_add_portchannel_member_which_has_ipaddress(self): | ||
runner = CliRunner() | ||
db = Db() | ||
obj = {'db':db.cfgdb} | ||
|
||
# add a portchannel member with port which has ip-address | ||
result = runner.invoke(config.config.commands["portchannel"].commands["member"].commands["add"], ["PortChannel1001", "Ethernet0"], obj=obj) | ||
print(result.exit_code) | ||
print(result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: Ethernet0 has ip address 14.14.0.1/24 configured" in result.output | ||
|
||
def test_add_portchannel_member_which_is_member_of_vlan(self): | ||
runner = CliRunner() | ||
db = Db() | ||
obj = {'db':db.cfgdb} | ||
|
||
# add a portchannel member with port which is member of Vlan | ||
result = runner.invoke(config.config.commands["portchannel"].commands["member"].commands["add"], ["PortChannel1001", "Ethernet24"], obj=obj) | ||
print(result.exit_code) | ||
print(result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: Ethernet24 Interface configured as VLAN_MEMBER under vlan : Vlan2000" in result.output | ||
|
||
def test_add_portchannel_member_which_is_member_of_another_po(self): | ||
runner = CliRunner() | ||
db = Db() | ||
obj = {'db':db.cfgdb} | ||
|
||
# add a portchannel member with port which is member of another PO | ||
result = runner.invoke(config.config.commands["portchannel"].commands["member"].commands["add"], ["PortChannel1001", "Ethernet116"], obj=obj) | ||
print(result.exit_code) | ||
print(result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: Ethernet116 Interface is already member of PortChannel0002 " in result.output | ||
|
||
def test_delete_portchannel_member_which_is_member_of_another_po(self): | ||
runner = CliRunner() | ||
db = Db() | ||
obj = {'db':db.cfgdb} | ||
|
||
# delete a portchannel member with port which is member of another PO | ||
result = runner.invoke(config.config.commands["portchannel"].commands["member"].commands["del"], ["PortChannel1001", "Ethernet116"], obj=obj) | ||
print(result.exit_code) | ||
print(result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: Ethernet116 is not a member of portchannel PortChannel1001" in result.output | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
os.environ['UTILITIES_UNIT_TESTING'] = "0" | ||
print("TEARDOWN") |