forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*Added checking of static routes, related to the interface, before deleting of the last IP entry to prevent deleting the RIF if a static route is present in the system. Signed-off-by: Maksym Belei <Maksym_Belei@jabil.com>
- Loading branch information
maksymbelei95
authored
Apr 26, 2021
1 parent
41d8ddc
commit c3963c5
Showing
7 changed files
with
288 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
show_ip_route_with_static_expected_output = """\ | ||
Codes: K - kernel route, C - connected, S - static, R - RIP, | ||
O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, | ||
T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, | ||
F - PBR, f - OpenFabric, | ||
> - selected route, * - FIB route, q - queued, r - rejected, b - backup | ||
VRF Vrf11: | ||
S>* 20.0.0.1/32 [1/0] is directly connected, Ethernet2, weight 1, 00:40:18 | ||
VRF default: | ||
S>* 0.0.0.0/0 [200/0] via 192.168.111.3, eth0, weight 1, 19:51:57 | ||
S>* 20.0.0.1/32 [1/0] is directly connected, Ethernet4 (vrf Vrf11), weight 1, 00:38:52 | ||
S>* 20.0.0.4/32 [1/0] is directly connected, PortChannel2, weight 1, 00:38:52 | ||
S>* 20.0.0.8/32 [1/0] is directly connected, Vlan2, weight 1, 00:38:52 | ||
""" | ||
|
||
show_ipv6_route_with_static_expected_output = """\ | ||
Codes: K - kernel route, C - connected, S - static, R - RIPng, | ||
O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, | ||
v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, | ||
f - OpenFabric, | ||
> - selected route, * - FIB route, q - queued, r - rejected, b - backup | ||
VRF Vrf11: | ||
S>* fe80::/24 [1/0] is directly connected, Vlan4, weight 1, 00:00:04 | ||
VRF default: | ||
S>* 20c0:a800:0:21::/64 [20/0] is directly connected, PortChannel4, 2d22h02m | ||
S>* fe80::/32 [1/0] is directly connected, Ethernet8 (vrf Vrf11), weight 1, 00:00:04 | ||
""" |
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,158 @@ | ||
import os | ||
import sys | ||
import pytest | ||
import mock | ||
from importlib import reload | ||
|
||
from click.testing import CliRunner | ||
|
||
from utilities_common.db import Db | ||
|
||
modules_path = os.path.join(os.path.dirname(__file__), "..") | ||
test_path = os.path.join(modules_path, "tests") | ||
sys.path.insert(0, modules_path) | ||
sys.path.insert(0, test_path) | ||
mock_db_path = os.path.join(test_path, "int_ip_input") | ||
|
||
|
||
class TestIntIp(object): | ||
@pytest.fixture(scope="class", autouse=True) | ||
def setup_class(cls): | ||
print("SETUP") | ||
os.environ['UTILITIES_UNIT_TESTING'] = "1" | ||
import config.main as config | ||
reload(config) | ||
yield | ||
print("TEARDOWN") | ||
os.environ["UTILITIES_UNIT_TESTING"] = "0" | ||
from .mock_tables import dbconnector | ||
dbconnector.dedicated_dbs = {} | ||
|
||
@pytest.mark.parametrize('setup_single_bgp_instance', | ||
['ip_route_for_int_ip'], indirect=['setup_single_bgp_instance']) | ||
def test_config_int_ip_rem( | ||
self, | ||
get_cmd_module, | ||
setup_single_bgp_instance): | ||
(config, show) = get_cmd_module | ||
jsonfile_config = os.path.join(mock_db_path, "config_db.json") | ||
from .mock_tables import dbconnector | ||
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config | ||
|
||
runner = CliRunner() | ||
db = Db() | ||
obj = {'config_db': db.cfgdb} | ||
|
||
# remove vlan IP`s | ||
with mock.patch('utilities_common.cli.run_command') as mock_run_command: | ||
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], | ||
["Ethernet16", "192.168.10.1/24"], obj=obj) | ||
print(result.exit_code, result.output) | ||
assert result.exit_code == 0 | ||
assert mock_run_command.call_count == 1 | ||
|
||
@pytest.mark.parametrize('setup_single_bgp_instance', | ||
['ip_route_for_int_ip'], indirect=['setup_single_bgp_instance']) | ||
def test_config_int_ip_rem_static( | ||
self, | ||
get_cmd_module, | ||
setup_single_bgp_instance): | ||
(config, show) = get_cmd_module | ||
jsonfile_config = os.path.join(mock_db_path, "config_db") | ||
from .mock_tables import dbconnector | ||
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config | ||
|
||
runner = CliRunner() | ||
db = Db() | ||
obj = {'config_db': db.cfgdb} | ||
|
||
with mock.patch('utilities_common.cli.run_command') as mock_run_command: | ||
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], | ||
["Ethernet2", "192.168.0.1/24"], obj=obj) | ||
print(result.exit_code, result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: Cannot remove the last IP entry of interface Ethernet2. A static ip route is still bound to the RIF." in result.output | ||
assert mock_run_command.call_count == 0 | ||
|
||
with mock.patch('utilities_common.cli.run_command') as mock_run_command: | ||
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], | ||
["Ethernet8", "192.168.3.1/24"], obj=obj) | ||
print(result.exit_code, result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: Cannot remove the last IP entry of interface Ethernet8. A static ipv6 route is still bound to the RIF." in result.output | ||
assert mock_run_command.call_count == 0 | ||
|
||
with mock.patch('utilities_common.cli.run_command') as mock_run_command: | ||
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], | ||
["Vlan2", "192.168.1.1/21"], obj=obj) | ||
print(result.exit_code, result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: Cannot remove the last IP entry of interface Vlan2. A static ip route is still bound to the RIF." in result.output | ||
assert mock_run_command.call_count == 0 | ||
|
||
with mock.patch('utilities_common.cli.run_command') as mock_run_command: | ||
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], | ||
["PortChannel2", "10.0.0.56/31"], obj=obj) | ||
print(result.exit_code, result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: Cannot remove the last IP entry of interface PortChannel2. A static ip route is still bound to the RIF." in result.output | ||
assert mock_run_command.call_count == 0 | ||
|
||
with mock.patch('utilities_common.cli.run_command') as mock_run_command: | ||
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], | ||
["Ethernet4", "192.168.4.1/24"], obj=obj) | ||
print(result.exit_code, result.output) | ||
assert result.exit_code == 0 | ||
assert mock_run_command.call_count == 1 | ||
|
||
class TestIntIpMultiasic(object): | ||
@pytest.fixture(scope="class", autouse=True) | ||
def setup_class(cls): | ||
print("SETUP") | ||
os.environ['UTILITIES_UNIT_TESTING'] = "1" | ||
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic" | ||
from .mock_tables import dbconnector | ||
from .mock_tables import mock_multi_asic | ||
reload(mock_multi_asic) | ||
dbconnector.load_namespace_config() | ||
yield | ||
print("TEARDOWN") | ||
os.environ["UTILITIES_UNIT_TESTING"] = "0" | ||
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" | ||
# change back to single asic config | ||
from .mock_tables import dbconnector | ||
from .mock_tables import mock_single_asic | ||
reload(mock_single_asic) | ||
dbconnector.dedicated_dbs = {} | ||
dbconnector.load_namespace_config() | ||
|
||
@pytest.mark.parametrize('setup_multi_asic_bgp_instance', | ||
['ip_route_for_int_ip'], indirect=['setup_multi_asic_bgp_instance']) | ||
def test_config_int_ip_rem_static_multiasic( | ||
self, | ||
get_cmd_module, | ||
setup_multi_asic_bgp_instance): | ||
(config, show) = get_cmd_module | ||
jsonfile_config = os.path.join(mock_db_path, "config_db") | ||
from .mock_tables import dbconnector | ||
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config | ||
|
||
runner = CliRunner() | ||
db = Db() | ||
obj = {'config_db': db.cfgdb, 'namespace': 'test_ns'} | ||
|
||
with mock.patch('utilities_common.cli.run_command') as mock_run_command: | ||
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], | ||
["Ethernet2", "192.168.0.1/24"], obj=obj) | ||
print(result.exit_code, result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: Cannot remove the last IP entry of interface Ethernet2. A static ip route is still bound to the RIF." in result.output | ||
assert mock_run_command.call_count == 0 | ||
|
||
with mock.patch('utilities_common.cli.run_command') as mock_run_command: | ||
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], | ||
["Ethernet8", "192.168.3.1/24"], obj=obj) | ||
print(result.exit_code, result.output) | ||
assert result.exit_code != 0 | ||
assert "Error: Cannot remove the last IP entry of interface Ethernet8. A static ipv6 route is still bound to the RIF." in result.output | ||
assert mock_run_command.call_count == 0 |
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,41 @@ | ||
{ | ||
"INTERFACE|Ethernet16": { | ||
"NULL": "NULL" | ||
}, | ||
"INTERFACE|Ethernet16|192.168.10.1/24": { | ||
"NULL": "NULL" | ||
}, | ||
"INTERFACE|Ethernet2": { | ||
"NULL": "NULL" | ||
}, | ||
"INTERFACE|Ethernet2|192.168.0.1/24": { | ||
"NULL": "NULL" | ||
}, | ||
"INTERFACE|Ethernet4": { | ||
"NULL": "NULL" | ||
}, | ||
"INTERFACE|Ethernet4|192.168.4.1/24": { | ||
"NULL": "NULL" | ||
}, | ||
"INTERFACE|Ethernet4|192.168.100.1/24": { | ||
"NULL": "NULL" | ||
}, | ||
"INTERFACE|Ethernet8": { | ||
"NULL": "NULL" | ||
}, | ||
"INTERFACE|Ethernet8|192.168.3.1/24": { | ||
"NULL": "NULL" | ||
}, | ||
"PORTCHANNEL_INTERFACE|PortChannel2": { | ||
"NULL": "NULL" | ||
}, | ||
"PORTCHANNEL_INTERFACE|PortChannel2|10.0.0.56/31": { | ||
"NULL": "NULL" | ||
}, | ||
"VLAN_INTERFACE|Vlan2": { | ||
"proxy_arp": "enabled" | ||
}, | ||
"VLAN_INTERFACE|Vlan2|192.168.1.1/21": { | ||
"NULL": "NULL" | ||
} | ||
} |
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