@@ -66,44 +66,99 @@ def test_vrf_bind_unbind(self):
66
66
67
67
obj = {'config_db' :db .cfgdb }
68
68
69
+ expected_output_unbind = "Interface Ethernet4 IP disabled and address(es) removed due to unbinding VRF.\n "
69
70
result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Ethernet4" ], obj = obj )
70
71
print (result .exit_code , result .output )
71
72
assert result .exit_code == 0
72
73
assert 'Ethernet4' not in db .cfgdb .get_table ('INTERFACE' )
74
+ assert result .output == expected_output_unbind
73
75
76
+ expected_output_unbind = "Interface Loopback0 IP disabled and address(es) removed due to unbinding VRF.\n "
74
77
result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Loopback0" ], obj = obj )
75
78
print (result .exit_code , result .output )
76
79
assert result .exit_code == 0
77
80
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 "
79
84
result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Vlan40" ], obj = obj )
80
85
print (result .exit_code , result .output )
81
86
assert result .exit_code == 0
82
87
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 "
84
91
result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["PortChannel0002" ], obj = obj )
85
92
print (result .exit_code , result .output )
86
93
assert result .exit_code == 0
87
94
assert 'PortChannel002' not in db .cfgdb .get_table ('PORTCHANNEL_INTERFACE' )
95
+ assert result .output == expected_output_unbind
88
96
97
+ expected_output_unbind = "Interface Eth36.10 IP disabled and address(es) removed due to unbinding VRF.\n "
89
98
result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Eth36.10" ], obj = obj )
90
99
print (result .exit_code , result .output )
91
100
assert result .exit_code == 0
92
101
assert ('vrf_name' , 'Vrf102' ) not in db .cfgdb .get_table ('VLAN_SUB_INTERFACE' )['Eth36.10' ]
102
+ assert result .output == expected_output_unbind
93
103
104
+ expected_output_unbind = "Interface Ethernet0.10 IP disabled and address(es) removed due to unbinding VRF.\n "
94
105
result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Ethernet0.10" ], obj = obj )
95
106
print (result .exit_code , result .output )
96
107
assert result .exit_code == 0
97
108
assert ('vrf_name' , 'Vrf101' ) not in db .cfgdb .get_table ('VLAN_SUB_INTERFACE' )['Ethernet0.10' ]
109
+ assert result .output == expected_output_unbind
98
110
111
+ expected_output_unbind = "Interface Po0002.101 IP disabled and address(es) removed due to unbinding VRF.\n "
99
112
result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Po0002.101" ], obj = obj )
100
113
print (result .exit_code , result .output )
101
114
assert result .exit_code == 0
102
115
assert ('vrf_name' , 'Vrf103' ) not in db .cfgdb .get_table ('VLAN_SUB_INTERFACE' )['Po0002.101' ]
116
+ assert result .output == expected_output_unbind
103
117
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' ]
104
161
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
107
162
jsonfile_config = os .path .join (mock_db_path , "config_db" )
108
163
dbconnector .dedicated_dbs ['CONFIG_DB' ] = jsonfile_config
109
164
@@ -124,3 +179,32 @@ def test_vrf_bind_unbind(self):
124
179
dbconnector .dedicated_dbs = {}
125
180
assert result .exit_code == 0
126
181
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' )
0 commit comments