-
Notifications
You must be signed in to change notification settings - Fork 819
[config]Static routes to config_db #1534
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
Changes from 6 commits
47696b9
7de1946
eb87991
93220d9
cab6c7a
fbff2e4
1a02681
6392385
91723c8
091082b
bc26317
605f455
5e41d96
e4b14b0
11d74e9
847399f
319a3ea
bc14735
fb6d0eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import os | ||
| import traceback | ||
| from unittest import mock | ||
|
|
||
| from click.testing import CliRunner | ||
|
|
||
| import config.main as config | ||
| import show.main as show | ||
| from .utils import get_result_and_return_code | ||
| from utilities_common.db import Db | ||
|
|
||
| ROUTE_UPDATE_STR = ''' | ||
| Added static route 1.2.3.4/32 | ||
| Added static route 2.2.3.4/32 | ||
| Added static route 3.2.3.4/32 | ||
| ''' | ||
|
|
||
|
|
||
| class TestStaticRoutes(object): | ||
| @classmethod | ||
| def setup_class(cls): | ||
| os.environ['UTILITIES_UNIT_TESTING'] = "1" | ||
| print("SETUP") | ||
|
|
||
| '''Add''' | ||
| def test_add_simple_static_route(self): | ||
| db = Db() | ||
| runner = CliRunner() | ||
| obj = {'config_db':db.cfgdb} | ||
|
|
||
| # config route add prefix 1.2.3.4/32 nexthop 30.0.0.5 | ||
| result = runner.invoke(config.config.commands["route"].commands["add"], \ | ||
| ["prefix", "1.2.3.4/32", "nexthop", "30.0.0.5"], obj=obj) | ||
| print(result.exit_code, result.output) | ||
| assert ('1.2.3.4/32') in db.cfgdb.get_table('STATIC_ROUTE') | ||
| assert db.cfgdb.get_entry('STATIC_ROUTE', '1.2.3.4/32') == {"nexthop": "30.0.0.5"} | ||
|
|
||
| def test_add_vrf_static_route(self): | ||
| db = Db() | ||
| runner = CliRunner() | ||
| obj = {'config_db':db.cfgdb} | ||
|
|
||
| # config route add prefix 2.2.3.4/32 nexthop 30.0.0.6 | ||
|
||
| result = runner.invoke(config.config.commands["route"].commands["add"], \ | ||
| ["prefix", "vrf", "Vrfblue", "2.2.3.4/32", "nexthop", "30.0.0.6"], obj=obj) | ||
| print(result.exit_code, result.output) | ||
| assert ('2.2.3.4/32') in db.cfgdb.get_table('STATIC_ROUTE') | ||
| assert db.cfgdb.get_entry('STATIC_ROUTE', '2.2.3.4/32') == {"nexthop": "30.0.0.6", "vrf_name": "Vrfblue"} | ||
|
|
||
| def test_add_dest_vrf_static_route(self): | ||
| db = Db() | ||
| runner = CliRunner() | ||
| obj = {'config_db':db.cfgdb} | ||
|
|
||
| # config route add prefix 3.2.3.4/32 nexthop 30.0.0.6 | ||
|
||
| result = runner.invoke(config.config.commands["route"].commands["add"], \ | ||
| ["prefix", "3.2.3.4/32", "nexthop", "vrf", "Vrfred", "30.0.0.6"], obj=obj) | ||
| print(result.exit_code, result.output) | ||
| assert ('3.2.3.4/32') in db.cfgdb.get_table('STATIC_ROUTE') | ||
| assert db.cfgdb.get_entry('STATIC_ROUTE', '3.2.3.4/32') == {"nexthop": "30.0.0.6", "nexthop_vrf": "Vrfred"} | ||
|
||
|
|
||
| '''Del''' | ||
| def test_del_simple_static_route(self): | ||
| db = Db() | ||
| runner = CliRunner() | ||
| obj = {'config_db':db.cfgdb} | ||
|
|
||
| # config route del prefix 1.2.3.4/32 nexthop 30.0.0.5 | ||
| result = runner.invoke(config.config.commands["route"].commands["del"], \ | ||
| ["prefix", "1.2.3.4/32", "nexthop", "30.0.0.5"], obj=obj) | ||
| print(result.exit_code, result.output) | ||
| assert not ('1.2.3.4/32') in db.cfgdb.get_table('STATIC_ROUTE') | ||
|
|
||
| def test_del_vrf_static_route(self): | ||
| db = Db() | ||
| runner = CliRunner() | ||
| obj = {'config_db':db.cfgdb} | ||
|
|
||
| # config route del prefix 2.2.3.4/32 nexthop 30.0.0.6 | ||
| result = runner.invoke(config.config.commands["route"].commands["del"], \ | ||
| ["prefix", "vrf", "Vrfblue", "2.2.3.4/32", "nexthop", "30.0.0.6"], obj=obj) | ||
| print(result.exit_code, result.output) | ||
| assert not ('2.2.3.4/32') in db.cfgdb.get_table('STATIC_ROUTE') | ||
|
|
||
| def test_del_dest_vrf_static_route(self): | ||
| db = Db() | ||
| runner = CliRunner() | ||
| obj = {'config_db':db.cfgdb} | ||
|
|
||
| # config route del prefix 3.2.3.4/32 nexthop 30.0.0.6 | ||
| result = runner.invoke(config.config.commands["route"].commands["del"], \ | ||
| ["prefix", "3.2.3.4/32", "nexthop", "vrf", "Vrfred", "30.0.0.6"], obj=obj) | ||
| print(result.exit_code, result.output) | ||
| assert not ('3.2.3.4/32') in db.cfgdb.get_table('STATIC_ROUTE') | ||
|
|
||
| @classmethod | ||
| def teardown_class(cls): | ||
| os.environ['UTILITIES_UNIT_TESTING'] = "0" | ||
| print("TEARDOWN") | ||
|
|
||
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.
can you add the support for multi asic ?
Similar to how it is done for interface command https://github.com/Azure/sonic-utilities/blob/08337aa7637b290bb8407c38b2a5dbe3e8383b3e/config/main.py#L2359
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.
@arlakshm, can we add multiasic as another enhancement PR?
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.
@prsunny, Sure. Can we create an issue or task to track this?
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.
Created issue - #1608