-
Notifications
You must be signed in to change notification settings - Fork 647
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
Add SAG implementation #2881
Open
superchild
wants to merge
14
commits into
sonic-net:master
Choose a base branch
from
superchild:sag-dev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add SAG implementation #2881
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5379d74
Add SAG command
superchild 0a328a7
Add SAG field in mock CFG_DB table
superchild 3d30fd7
Fix failed test cases
superchild daf162e
Merge branch 'master' into sag-dev
superchild 8ec7be0
Refine CONFIG_DB field according to yang model change
superchild d9591b7
Refine command argument and display foramt
superchild c9f131d
Merge branch 'master' into sag-dev
superchild c355afe
Fix using incorrect context
superchild 28a1396
Merge branch 'master' into sag-dev
superchild 96fea21
Merge branch 'master' into sag-dev
superchild 97d9ce4
Fix vlan_test error
superchild 6480c97
Refine code according to review comments
superchild ad5790f
Remove checking for disabling SAG on VLAN
superchild bb579f1
Merge branch 'master' into sag-dev
superchild 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
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
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,89 @@ | ||
import pytest | ||
import os | ||
import logging | ||
from click.testing import CliRunner | ||
|
||
import config.main as config | ||
import show.main as show | ||
from utilities_common.db import Db | ||
from importlib import reload | ||
|
||
show_sag_output="""\ | ||
Static Anycast Gateway Information | ||
MacAddress Interfaces | ||
----------------- ------------ | ||
00:11:22:33:44:55 Vlan1000 | ||
""" | ||
|
||
class TestSag(object): | ||
@classmethod | ||
def setup_class(cls): | ||
os.environ['UTILITIES_UNIT_TESTING'] = "1" | ||
print("SETUP") | ||
|
||
def test_config_add_sag_with_existed_mac(self): | ||
runner = CliRunner() | ||
db = Db() | ||
|
||
result = runner.invoke(config.config.commands["static-anycast-gateway"].commands["mac_address"].commands["add"], | ||
["00:22:33:44:55:66"], obj=db) | ||
assert result.exit_code != 0, f"sag invalid mac with code {type(result.exit_code)}:{result.exit_code} Output:{result.output}" | ||
assert {"gateway_mac": "00:11:22:33:44:55"} == db.cfgdb.get_entry("SAG", "GLOBAL") | ||
|
||
def test_config_del_add_invalid_sag_mac_address(self): | ||
runner = CliRunner() | ||
db = Db() | ||
|
||
result = runner.invoke(config.config.commands["static-anycast-gateway"].commands["mac_address"].commands["del"], | ||
obj=db) | ||
assert result.exit_code == 0, f"sag invalid mac with code {type(result.exit_code)}:{result.exit_code} Output:{result.output}" | ||
assert not db.cfgdb.get_entry("SAG", "GLOBAL") | ||
|
||
result = runner.invoke(config.config.commands["static-anycast-gateway"].commands["mac_address"].commands["add"], | ||
["01:22:33:44:55:66"], obj=db) | ||
assert result.exit_code != 0, f"sag invalid mac with code {type(result.exit_code)}:{result.exit_code} Output:{result.output}" | ||
assert {"gateway_mac": "01:11:22:33:44:55"} != db.cfgdb.get_entry("SAG", "GLOBAL") | ||
|
||
def test_config_del_add_sag_mac_address(self): | ||
runner = CliRunner() | ||
db = Db() | ||
|
||
result = runner.invoke(config.config.commands["static-anycast-gateway"].commands["mac_address"].commands["del"], | ||
obj=db) | ||
assert result.exit_code == 0, f"sag invalid mac with code {type(result.exit_code)}:{result.exit_code} Output:{result.output}" | ||
assert not db.cfgdb.get_entry("SAG", "GLOBAL") | ||
|
||
result = runner.invoke(config.config.commands["static-anycast-gateway"].commands["mac_address"].commands["add"], | ||
["00:22:33:44:55:66"], obj=db) | ||
assert result.exit_code == 0, f"sag invalid mac with code {type(result.exit_code)}:{result.exit_code} Output:{result.output}" | ||
assert {"gateway_mac": "00:22:33:44:55:66"} == db.cfgdb.get_entry("SAG", "GLOBAL") | ||
|
||
def test_config_enable_sag_on_vlan_interface(self): | ||
runner = CliRunner() | ||
db = Db() | ||
|
||
result = runner.invoke(config.config.commands["vlan"].commands["static-anycast-gateway"].commands["enable"], | ||
["2000"], obj=db) | ||
assert result.exit_code == 0, f"sag invalid vlan with code {type(result.exit_code)}:{result.exit_code} Output:{result.output}" | ||
assert {"static_anycast_gateway": "true"}.items() <= db.cfgdb.get_entry("VLAN_INTERFACE", "Vlan2000").items() | ||
|
||
def test_config_disable_sag_on_vlan_interface(self): | ||
runner = CliRunner() | ||
db = Db() | ||
|
||
result = runner.invoke(config.config.commands["vlan"].commands["static-anycast-gateway"].commands["disable"], | ||
["1000"], obj=db) | ||
assert result.exit_code == 0, f"sag invalid vlan with code {type(result.exit_code)}:{result.exit_code} Output:{result.output}" | ||
assert {"static_anycast_gateway": "false"}.items() <= db.cfgdb.get_entry("VLAN_INTERFACE", "Vlan1000").items() | ||
|
||
def test_show_sag_mac(self): | ||
runner = CliRunner() | ||
result = runner.invoke(show.cli.commands["static-anycast-gateway"], []) | ||
assert result.exit_code == 0, f"invalid show sag with code {type(result.exit_code)}:{result.exit_code} Output:{result.output}" | ||
assert result.output == show_sag_output | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
os.environ['UTILITIES_UNIT_TESTING'] = "0" | ||
print("TEARDOWN") | ||
|
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.
@Junchao-Mellanox
The argument is removed.