Skip to content

Commit cd13da3

Browse files
Added support for mode attribute in IP config commands and updated the
related testcase removed the fucntionality for checking vlan status to assign IP Address It will now assign IP Address if the port is in 'routed' mode else it won't assign Signed-off-by: Muhammad Umar Asad <[email protected]> xFlow Research Inc.
1 parent 02b1e8a commit cd13da3

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

config/main.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4321,11 +4321,21 @@ def add(ctx, interface_name, ip_addr, gw):
43214321
if interface_name is None:
43224322
ctx.fail("'interface_name' is None!")
43234323

4324-
# Add a validation to check this interface is not a member in vlan before
4325-
# changing it to a router port
4326-
vlan_member_table = config_db.get_table('VLAN_MEMBER')
4327-
if (interface_is_in_vlan(vlan_member_table, interface_name)):
4328-
click.echo("Interface {} is a member of vlan\nAborting!".format(interface_name))
4324+
portchannel_member_table = config_db.get_table('PORTCHANNEL_MEMBER')
4325+
4326+
if interface_is_in_portchannel(portchannel_member_table, interface_name):
4327+
ctx.fail("{} is configured as a member of portchannel."
4328+
.format(interface_name))
4329+
4330+
# Add a validation to check this interface is in routed mode before
4331+
# assigning an IP address to it
4332+
interface_mode = "routed"
4333+
interface_data = config_db.get_entry('PORT',interface_name)
4334+
if "mode" in interface_data:
4335+
interface_mode = interface_data["mode"]
4336+
4337+
if interface_mode != "routed":
4338+
click.echo("Interface {} is not in routed mode.\nRemove the vlans assigned to it and changed mode to routed\nAborting".format(interface_name))
43294339
return
43304340

43314341
try:

config/switchport.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ def switchport():
1818
@click.argument("port", metavar="port", required=True)
1919
@clicommon.pass_db
2020
def switchport_mode(db, type, port):
21-
"""switchport mode help commands\nmode_type can either be:\n\t -> access \n\t -> trunk \n\t -> routed"""
21+
"""switchport mode help commands. mode_type can either be:
22+
-> access
23+
-> trunk
24+
-> routed"""
2225

2326
ctx = click.get_current_context()
2427

@@ -53,8 +56,7 @@ def switchport_mode(db, type, port):
5356
if (is_port and clicommon.interface_is_in_portchannel(portchannel_member_table, port)):
5457
ctx.fail("{} is part of portchannel!".format(port))
5558

56-
port_table_data = db.cfgdb.get_table('PORT')
57-
port_data = port_table_data[port]
59+
port_data = db.cfgdb.get_entry('PORT',port)
5860

5961
# mode type is either access or trunk
6062
if type != "routed":

config/vlan.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ def add_vlan_member(db, vid, port, untagged, multiple, except_flag):
250250

251251
# checking mode status of port if its access, trunk or routed
252252
if is_port:
253-
port_table_data = db.cfgdb.get_table('PORT')
254-
port_data = port_table_data[port]
253+
port_data = config_db.get_entry('PORT',port)
255254

256255
if "mode" not in port_data:
257256
ctx.fail("{} is in routed mode!\nUse switchport mode command to change port mode".format(port))

tests/vlan_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ def test_config_set_router_port_on_member_interface(self):
12481248
["Ethernet4", "10.10.10.1/24"], obj=obj)
12491249
print(result.exit_code, result.output)
12501250
assert result.exit_code == 0
1251-
assert 'Interface Ethernet4 is a member of vlan' in result.output
1251+
assert 'Interface Ethernet4 is not in routed mode.\nRemove the vlans assigned to it and changed mode to routed' in result.output
12521252

12531253
def test_config_vlan_add_member_of_portchannel(self):
12541254
runner = CliRunner()

0 commit comments

Comments
 (0)