-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switchport Mode & CLI Modified Fix #3247
Merged
+2,019
−401
Merged
Changes from all commits
Commits
Show all changes
97 commits
Select commit
Hold shift + click to select a range
3cc50b9
Switchport Modified Code as per suggestion
sabakram 92fdc98
Fix for Vlan.py & Command Reference Supported Commands
sabakram 7607552
Fix for error
sabakram c7cb85b
MOde fix
sabakram 03952a4
Vlan_test.py fix for fails
sabakram 79ad984
Fix for default mode fails
sabakram 0326712
Fix for errors
sabakram 48d7110
Removed default mode routed
sabakram 6f272ef
Fix for testcase backward compatibility
sabakram ba29d9d
Fix for typo
sabakram 06694c3
Add testcases for code coverage
sabakram abc580c
Fix for code coverage
sabakram ec5d62f
Fix for testcase failures
sabakram 93b64aa
Fix for Portchannel VLAN with swSwitchport modes testcase
sabakram d1f665e
Fix for Portchannel does not exist error
sabakram becd26d
Fix for typo
sabakram a851e9e
Fix for portchannel vlan tagging mode
sabakram 4bc4077
Add testcases for code coverage
sabakram e7eaef9
Fix for vlan add portchannel member with switchport modes
sabakram bacc2de
Fix for switchport mode successfully switched message
sabakram d9e3134
Fix for switchport mode message
sabakram e35b1e6
Fix for portchannel creation error
sabakram 2347170
Fix for portchannel creation failure
sabakram a384bd1
Adjusted testcases for code coverage
sabakram 8184b04
Updated PORTCHANNEL cases
sabakram b4463ef
Updated PORTCHANNEL
sabakram e48edf5
Add test cases for code coverage
sabakram 0c7ed5e
Fix for test case errors
sabakram 8a0d7c3
Fix for db object error
sabakram fec4ba4
Fix for portchannel ip add test case failure
sabakram 465b9ca
Fix for alias interface
sabakram e86a6d9
Fix for etp
sabakram 57a04e8
Fix for alias mode test case failure
sabakram 4fee806
Cover cli-common code coverage
sabakram 554405f
Fix for db object error
sabakram fa7bd53
Interface Alias Mode
sabakram 4bc59b3
Fixing Alias Issues
sabakram 5ed04f5
Fix for Port name error in ALias mode
sabakram d1df5b7
Fix for Jsonpatch & Port Alias
sabakram afafd6a
Fix for patch name error
sabakram 983fdd1
Fix for JSON patch error test case
sabakram ec2768a
Fix for ALias
sabakram fde3d19
Fixing JsonPatchConflict
sabakram 3398b5c
Refix above
sabakram 33cb52a
Fix for Asserstion Error
sabakram ceba62f
Fix for JsonConflict & ValueError
sabakram 0e7de8c
Fix for Conflicts
sabakram 1333873
Merge branch 'master' into Switchport_Modifed
sabakram cf6cf3b
Fix for json errors
sabakram 17a96ee
Fix for pre-commit
sabakram 26e783a
Fixing pre-commit & logical errors
sabakram 293df59
Fixing Flake8 error
sabakram b262908
Fixing errors
sabakram 56c25af
Fixing error
sabakram be5e31b
fix for add delete interface
sabakram cf244e8
fix for unit tests
sabakram 5083543
fix for classmethod
sabakram ea3dd2c
fix classmethod
sabakram 6ff82cc
fix mpl_test
sabakram 1afac82
mpl test fix
sabakram 6a154b0
fix vlan test
sabakram ea295ae
modified vlan test
sabakram 1ba000a
test vlan delete fix
sabakram b190faf
fix error message
sabakram 308ad3f
Code Coverage
sabakram d926e85
Fixing Runner
sabakram accd560
Fixing port alias
sabakram 82fe3c0
Alias Fix
sabakram 5eed6b6
Alias coverage
sabakram 39eadca
ALias & Json patch
sabakram e90ec40
Indent Error Fix
sabakram c43ee87
Fix for Port Alias
sabakram 849b55c
Fixing ALias
sabakram 0bfe5a7
Fixing ALias
sabakram df71024
Fixing ALiass
sabakram 654bc79
Fixed ALias & Json Patch
sabakram 763f992
fix error messages
sabakram 65801e2
fix coverage
sabakram 08b7d6b
fix unit tests
sabakram e5797e3
fixed the unit tests
sabakram 8f461ba
fixed switchport status
sabakram 7d4ed50
fix test vlan
sabakram f457616
fix yang validation
sabakram 9cb7ee9
fix add vlan test
sabakram d94af23
fix switchport
sabakram 3f43e37
fixed vlan
sabakram bdc536b
fix unit test
sabakram f8b510c
Fix for JSON Patch
sabakram fb4e581
Json Patch fixes
sabakram 706a895
json patch
sabakram 961f896
json patch
sabakram 55ded95
Fix json
sabakram f45232e
vlan validation
sabakram f481f1a
undo the argument
sabakram 990df3f
Revert extras
sabakram 51e4bfa
Fixing Error
sabakram bd7bd55
fixed python static errors
sabakram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import click | ||
from .utils import log | ||
import utilities_common.cli as clicommon | ||
|
||
# | ||
# 'switchport' mode ('config switchport ...') | ||
# | ||
|
||
|
||
@click.group(cls=clicommon.AbbreviationGroup, name='switchport', invoke_without_command=False) | ||
def switchport(): | ||
"""Switchport mode configuration tasks""" | ||
pass | ||
|
||
|
||
@switchport.command("mode") | ||
@click.argument("type", metavar="<mode_type>", required=True, type=click.Choice(["access", "trunk", "routed"])) | ||
@click.argument("port", metavar="port", required=True) | ||
@clicommon.pass_db | ||
def switchport_mode(db, type, port): | ||
"""switchport mode help commands.Mode_type can be access or trunk or routed""" | ||
|
||
ctx = click.get_current_context() | ||
|
||
log.log_info("'switchport mode {} {}' executing...".format(type, port)) | ||
mode_exists_status = True | ||
|
||
# checking if port name with alias exists | ||
if clicommon.get_interface_naming_mode() == "alias": | ||
alias = port | ||
iface_alias_converter = clicommon.InterfaceAliasConverter(db) | ||
port = iface_alias_converter.alias_to_name(alias) | ||
|
||
if clicommon.is_port_mirror_dst_port(db.cfgdb, port): | ||
ctx.fail("{} is configured as mirror destination port".format(port)) | ||
|
||
if clicommon.is_valid_port(db.cfgdb, port): | ||
is_port = True | ||
elif clicommon.is_valid_portchannel(db.cfgdb, port): | ||
is_port = False | ||
else: | ||
ctx.fail("{} does not exist".format(port)) | ||
|
||
portchannel_member_table = db.cfgdb.get_table('PORTCHANNEL_MEMBER') | ||
|
||
if (is_port and clicommon.interface_is_in_portchannel(portchannel_member_table, port)): | ||
ctx.fail("{} is part of portchannel!".format(port)) | ||
|
||
if is_port: | ||
port_data = db.cfgdb.get_entry('PORT', port) | ||
else: | ||
port_data = db.cfgdb.get_entry('PORTCHANNEL', port) | ||
|
||
# mode type is either access or trunk | ||
if type != "routed": | ||
|
||
if "mode" in port_data: | ||
existing_mode = port_data["mode"] | ||
else: | ||
mode_exists_status = False | ||
|
||
if (is_port and clicommon.is_port_router_interface(db.cfgdb, port)) or \ | ||
(not is_port and clicommon.is_pc_router_interface(db.cfgdb, port)): | ||
ctx.fail("Remove IP from {} to change mode!".format(port)) | ||
|
||
if not mode_exists_status: | ||
port_data["mode"] = type | ||
if is_port: | ||
db.cfgdb.set_entry("PORT", port, port_data) | ||
# if not port then is a port channel | ||
elif not is_port: | ||
db.cfgdb.set_entry("PORTCHANNEL", port, port_data) | ||
|
||
if mode_exists_status: | ||
if existing_mode == "routed": | ||
# if the port in an interface | ||
if is_port: | ||
db.cfgdb.mod_entry("PORT", port, {"mode": "{}".format(type)}) | ||
# if not port then is a port channel | ||
elif not is_port: | ||
db.cfgdb.mod_entry("PORTCHANNEL", port, {"mode": "{}".format(type)}) | ||
|
||
if existing_mode == type: | ||
ctx.fail("{} is already in {} mode".format(port, type)) | ||
else: | ||
if existing_mode == "access" and type == "trunk": | ||
pass | ||
if existing_mode == "trunk" and type == "access": | ||
if clicommon.interface_is_tagged_member(db.cfgdb, port): | ||
ctx.fail( | ||
"{} is in {} mode and have tagged member(s).\nRemove " | ||
"tagged member(s) from {} to switch to {} mode".format(port, existing_mode, port, type)) | ||
if is_port: | ||
db.cfgdb.mod_entry("PORT", port, {"mode": "{}".format(type)}) | ||
# if not port then is a port channel | ||
elif not is_port: | ||
db.cfgdb.mod_entry("PORTCHANNEL", port, {"mode": "{}".format(type)}) | ||
|
||
click.echo("{} switched to {} mode".format(port, type)) | ||
|
||
# if mode type is routed | ||
else: | ||
|
||
if clicommon.interface_is_tagged_member(db.cfgdb, port): | ||
ctx.fail("{} has tagged member(s). \nRemove them to change mode to {}".format(port, type)) | ||
|
||
if clicommon.interface_is_untagged_member(db.cfgdb, port): | ||
ctx.fail("{} has untagged member. \nRemove it to change mode to {}".format(port, type)) | ||
|
||
if "mode" in port_data: | ||
existing_mode = port_data["mode"] | ||
else: | ||
mode_exists_status = False | ||
|
||
if not mode_exists_status: | ||
port_data["mode"] = type | ||
if is_port: | ||
db.cfgdb.set_entry("PORT", port, port_data) | ||
|
||
# if not port then is a port channel | ||
elif not is_port: | ||
db.cfgdb.set_entry("PORTCHANNEL", port, port_data) | ||
pass | ||
|
||
if mode_exists_status: | ||
if existing_mode == type: | ||
ctx.fail("{} is already in {} mode".format(port, type)) | ||
else: | ||
if is_port: | ||
db.cfgdb.mod_entry("PORT", port, {"mode": "{}".format(type)}) | ||
# if not port then is a port channel | ||
elif not is_port: | ||
db.cfgdb.mod_entry("PORTCHANNEL", port, {"mode": "{}".format(type)}) | ||
|
||
click.echo("{} switched to {} mode".format(port, type)) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this checked now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have added a check for switchport mode routed, a routed port fulfill this behavior that a interface has a vlan membership or not. So this check becomes redundant after addition of new check.