Skip to content

Commit e8b1dcd

Browse files
authored
Add IP remove warnings for VRF commands (sonic-net#2351)
Added IP address remove warnings when performing various VRF commands i.e., - vrf bind - vrf unbind - del vrf
1 parent 40cc8e1 commit e8b1dcd

File tree

3 files changed

+104
-6
lines changed

3 files changed

+104
-6
lines changed

config/main.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -4979,6 +4979,7 @@ def bind(ctx, interface_name, vrf_name):
49794979
else:
49804980
config_db.set_entry(table_name, interface_name, {"vrf_name": vrf_name})
49814981

4982+
click.echo("Interface {} IP disabled and address(es) removed due to binding VRF {}.".format(interface_name, vrf_name))
49824983
#
49834984
# 'unbind' subcommand
49844985
#
@@ -5014,7 +5015,8 @@ def unbind(ctx, interface_name):
50145015
config_db.set_entry(table_name, interface_name, subintf_entry)
50155016
else:
50165017
config_db.set_entry(table_name, interface_name, None)
5017-
5018+
5019+
click.echo("Interface {} IP disabled and address(es) removed due to unbinding VRF.".format(interface_name))
50185020
#
50195021
# 'ipv6' subgroup ('config interface ipv6 ...')
50205022
#
@@ -5188,7 +5190,7 @@ def del_vrf(ctx, vrf_name):
51885190
else:
51895191
del_interface_bind_to_vrf(config_db, vrf_name)
51905192
config_db.set_entry('VRF', vrf_name, None)
5191-
5193+
click.echo("VRF {} deleted and all associated IP addresses removed.".format(vrf_name))
51925194

51935195
@vrf.command('add_vrf_vni_map')
51945196
@click.argument('vrfname', metavar='<vrf-name>', required=True, type=str)

tests/show_vrf_test.py

+88-4
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,99 @@ def test_vrf_bind_unbind(self):
6666

6767
obj = {'config_db':db.cfgdb}
6868

69+
expected_output_unbind = "Interface Ethernet4 IP disabled and address(es) removed due to unbinding VRF.\n"
6970
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["unbind"], ["Ethernet4"], obj=obj)
7071
print(result.exit_code, result.output)
7172
assert result.exit_code == 0
7273
assert 'Ethernet4' not in db.cfgdb.get_table('INTERFACE')
74+
assert result.output == expected_output_unbind
7375

76+
expected_output_unbind = "Interface Loopback0 IP disabled and address(es) removed due to unbinding VRF.\n"
7477
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["unbind"], ["Loopback0"], obj=obj)
7578
print(result.exit_code, result.output)
7679
assert result.exit_code == 0
7780
assert 'Loopback0' not in db.cfgdb.get_table('LOOPBACK_INTERFACE')
78-
81+
assert result.output == expected_output_unbind
82+
83+
expected_output_unbind = "Interface Vlan40 IP disabled and address(es) removed due to unbinding VRF.\n"
7984
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["unbind"], ["Vlan40"], obj=obj)
8085
print(result.exit_code, result.output)
8186
assert result.exit_code == 0
8287
assert 'Vlan40' not in db.cfgdb.get_table('VLAN_INTERFACE')
83-
88+
assert result.output == expected_output_unbind
89+
90+
expected_output_unbind = "Interface PortChannel0002 IP disabled and address(es) removed due to unbinding VRF.\n"
8491
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["unbind"], ["PortChannel0002"], obj=obj)
8592
print(result.exit_code, result.output)
8693
assert result.exit_code == 0
8794
assert 'PortChannel002' not in db.cfgdb.get_table('PORTCHANNEL_INTERFACE')
95+
assert result.output == expected_output_unbind
8896

97+
expected_output_unbind = "Interface Eth36.10 IP disabled and address(es) removed due to unbinding VRF.\n"
8998
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["unbind"], ["Eth36.10"], obj=obj)
9099
print(result.exit_code, result.output)
91100
assert result.exit_code == 0
92101
assert ('vrf_name', 'Vrf102') not in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Eth36.10']
102+
assert result.output == expected_output_unbind
93103

104+
expected_output_unbind = "Interface Ethernet0.10 IP disabled and address(es) removed due to unbinding VRF.\n"
94105
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["unbind"], ["Ethernet0.10"], obj=obj)
95106
print(result.exit_code, result.output)
96107
assert result.exit_code == 0
97108
assert ('vrf_name', 'Vrf101') not in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Ethernet0.10']
109+
assert result.output == expected_output_unbind
98110

111+
expected_output_unbind = "Interface Po0002.101 IP disabled and address(es) removed due to unbinding VRF.\n"
99112
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["unbind"], ["Po0002.101"], obj=obj)
100113
print(result.exit_code, result.output)
101114
assert result.exit_code == 0
102115
assert ('vrf_name', 'Vrf103') not in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Po0002.101']
116+
assert result.output == expected_output_unbind
103117

118+
vrf_obj = {'config_db':db.cfgdb, 'namespace':db.db.namespace}
119+
120+
expected_output_bind = "Interface Ethernet0 IP disabled and address(es) removed due to binding VRF Vrf1.\n"
121+
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["bind"], ["Ethernet0", "Vrf1"], obj=vrf_obj)
122+
assert result.exit_code == 0
123+
assert result.output == expected_output_bind
124+
assert ('Vrf1') in db.cfgdb.get_table('INTERFACE')['Ethernet0']['vrf_name']
125+
126+
expected_output_bind = "Interface Loopback0 IP disabled and address(es) removed due to binding VRF Vrf101.\n"
127+
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["bind"], ["Loopback0", "Vrf101"], obj=vrf_obj)
128+
assert result.exit_code == 0
129+
assert result.output == expected_output_bind
130+
assert ('Vrf101') in db.cfgdb.get_table('LOOPBACK_INTERFACE')['Loopback0']['vrf_name']
131+
132+
expected_output_bind = "Interface Vlan40 IP disabled and address(es) removed due to binding VRF Vrf101.\n"
133+
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["bind"], ["Vlan40", "Vrf101"], obj=vrf_obj)
134+
assert result.exit_code == 0
135+
assert result.output == expected_output_bind
136+
assert ('Vrf101') in db.cfgdb.get_table('VLAN_INTERFACE')['Vlan40']['vrf_name']
137+
138+
expected_output_bind = "Interface PortChannel0002 IP disabled and address(es) removed due to binding VRF Vrf101.\n"
139+
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["bind"], ["PortChannel0002", "Vrf101"], obj=vrf_obj)
140+
assert result.exit_code == 0
141+
assert result.output == expected_output_bind
142+
assert ('Vrf101') in db.cfgdb.get_table('PORTCHANNEL_INTERFACE')['PortChannel0002']['vrf_name']
143+
144+
expected_output_bind = "Interface Eth36.10 IP disabled and address(es) removed due to binding VRF Vrf102.\n"
145+
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["bind"], ["Eth36.10", "Vrf102"], obj=vrf_obj)
146+
assert result.exit_code == 0
147+
assert result.output == expected_output_bind
148+
assert ('Vrf102') in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Eth36.10']['vrf_name']
149+
150+
expected_output_bind = "Interface Ethernet0.10 IP disabled and address(es) removed due to binding VRF Vrf103.\n"
151+
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["bind"], ["Ethernet0.10", "Vrf103"], obj=vrf_obj)
152+
assert result.exit_code == 0
153+
assert result.output == expected_output_bind
154+
assert ('Vrf103') in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Ethernet0.10']['vrf_name']
155+
156+
expected_output_bind = "Interface Po0002.101 IP disabled and address(es) removed due to binding VRF Vrf1.\n"
157+
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["bind"], ["Po0002.101", "Vrf1"], obj=vrf_obj)
158+
assert result.exit_code == 0
159+
assert result.output == expected_output_bind
160+
assert ('Vrf1') in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Po0002.101']['vrf_name']
104161

105-
#Bind click CLI cannot be tested as it tries to connecte to statedb
106-
#for verification of all IP address delete before applying new vrf configuration
107162
jsonfile_config = os.path.join(mock_db_path, "config_db")
108163
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config
109164

@@ -124,3 +179,32 @@ def test_vrf_bind_unbind(self):
124179
dbconnector.dedicated_dbs = {}
125180
assert result.exit_code == 0
126181
assert result.output == expected_output
182+
183+
def test_vrf_del(self):
184+
runner = CliRunner()
185+
db = Db()
186+
vrf_obj = {'config_db':db.cfgdb, 'namespace':db.db.namespace}
187+
188+
expected_output_del = "VRF Vrf1 deleted and all associated IP addresses removed.\n"
189+
result = runner.invoke(config.config.commands["vrf"].commands["del"], ["Vrf1"], obj=vrf_obj)
190+
assert result.exit_code == 0
191+
assert result.output == expected_output_del
192+
assert ('Vrf1') not in db.cfgdb.get_table('VRF')
193+
194+
expected_output_del = "VRF Vrf101 deleted and all associated IP addresses removed.\n"
195+
result = runner.invoke(config.config.commands["vrf"].commands["del"], ["Vrf101"], obj=vrf_obj)
196+
assert result.exit_code == 0
197+
assert result.output == expected_output_del
198+
assert ('Vrf101') not in db.cfgdb.get_table('VRF')
199+
200+
expected_output_del = "VRF Vrf102 deleted and all associated IP addresses removed.\n"
201+
result = runner.invoke(config.config.commands["vrf"].commands["del"], ["Vrf102"], obj=vrf_obj)
202+
assert result.exit_code == 0
203+
assert result.output == expected_output_del
204+
assert ('Vrf102') not in db.cfgdb.get_table('VRF')
205+
206+
expected_output_del = "VRF Vrf103 deleted and all associated IP addresses removed.\n"
207+
result = runner.invoke(config.config.commands["vrf"].commands["del"], ["Vrf103"], obj=vrf_obj)
208+
assert result.exit_code == 0
209+
assert result.output == expected_output_del
210+
assert ('Vrf103') not in db.cfgdb.get_table('VRF')

tests/subintf_test.py

+12
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,18 @@ def test_subintf_vrf_bind_unbind(self):
173173
assert ('Ethernet0.102') in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
174174
assert db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Ethernet0.102']['admin_status'] == 'up'
175175

176+
expected_output_bind = "Interface Ethernet0.102 IP disabled and address(es) removed due to binding VRF Vrf1.\n"
176177
vrf_obj = {'config_db':db.cfgdb, 'namespace':db.db.namespace}
177178
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["bind"], ["Ethernet0.102", "Vrf1"], obj=vrf_obj)
178179
assert result.exit_code == 0
179180
assert ('Vrf1') in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Ethernet0.102']['vrf_name']
181+
assert result.output == expected_output_bind
180182

183+
expected_output_unbind = "Interface Ethernet0.102 IP disabled and address(es) removed due to unbinding VRF.\n"
181184
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["unbind"], ["Ethernet0.102"], obj=vrf_obj)
182185
assert result.exit_code == 0
183186
assert ('vrf_name') not in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Ethernet0.102']
187+
assert result.output == expected_output_unbind
184188

185189
result = runner.invoke(config.config.commands["subinterface"].commands["del"], ["Ethernet0.102"], obj=obj)
186190
print(result.exit_code, result.output)
@@ -193,13 +197,17 @@ def test_subintf_vrf_bind_unbind(self):
193197
assert result.exit_code == 0
194198
assert ('Eth0.1002') in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
195199

200+
expected_output_bind = "Interface Eth0.1002 IP disabled and address(es) removed due to binding VRF Vrf1.\n"
196201
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["bind"], ["Eth0.1002", "Vrf1"], obj=vrf_obj)
197202
assert result.exit_code == 0
198203
assert ('Vrf1') in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Eth0.1002']['vrf_name']
204+
assert result.output == expected_output_bind
199205

206+
expected_output_unbind = "Interface Eth0.1002 IP disabled and address(es) removed due to unbinding VRF.\n"
200207
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["unbind"], ["Eth0.1002"], obj=vrf_obj)
201208
assert result.exit_code == 0
202209
assert ('vrf_name') not in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Eth0.1002']
210+
assert result.output == expected_output_unbind
203211

204212
result = runner.invoke(config.config.commands["subinterface"].commands["del"], ["Eth0.1002"], obj=obj)
205213
print(result.exit_code, result.output)
@@ -212,13 +220,17 @@ def test_subintf_vrf_bind_unbind(self):
212220
assert result.exit_code == 0
213221
assert ('Po0004.1004') in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
214222

223+
expected_output_bind = "Interface Po0004.1004 IP disabled and address(es) removed due to binding VRF Vrf1.\n"
215224
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["bind"], ["Po0004.1004", "Vrf1"], obj=vrf_obj)
216225
assert result.exit_code == 0
217226
assert ('Vrf1') in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Po0004.1004']['vrf_name']
227+
assert result.output == expected_output_bind
218228

229+
expected_output_unbind = "Interface Po0004.1004 IP disabled and address(es) removed due to unbinding VRF.\n"
219230
result = runner.invoke(config.config.commands["interface"].commands["vrf"].commands["unbind"], ["Po0004.1004"], obj=vrf_obj)
220231
assert result.exit_code == 0
221232
assert ('vrf_name') not in db.cfgdb.get_table('VLAN_SUB_INTERFACE')['Po0004.1004']
233+
assert result.output == expected_output_unbind
222234

223235
result = runner.invoke(config.config.commands["subinterface"].commands["del"], ["Po0004.1004"], obj=obj)
224236
print(result.exit_code, result.output)

0 commit comments

Comments
 (0)