@@ -180,31 +180,61 @@ def test_vrf_bind_unbind(self):
180180 assert result .exit_code == 0
181181 assert result .output == expected_output
182182
183- def test_vrf_del (self ):
183+ def test_vrf_add_del (self ):
184184 runner = CliRunner ()
185185 db = Db ()
186186 vrf_obj = {'config_db' :db .cfgdb , 'namespace' :db .db .namespace }
187187
188+ result = runner .invoke (config .config .commands ["vrf" ].commands ["add" ], ["Vrf100" ], obj = vrf_obj )
189+ assert ('Vrf100' ) in db .cfgdb .get_table ('VRF' )
190+ assert result .exit_code == 0
191+
192+ result = runner .invoke (config .config .commands ["vrf" ].commands ["add" ], ["Vrf1" ], obj = vrf_obj )
193+ assert "VRF Vrf1 already exists" in result .output
194+ assert ('Vrf1' ) in db .cfgdb .get_table ('VRF' )
195+ assert result .exit_code != 0
196+
188197 expected_output_del = "VRF Vrf1 deleted and all associated IP addresses removed.\n "
189198 result = runner .invoke (config .config .commands ["vrf" ].commands ["del" ], ["Vrf1" ], obj = vrf_obj )
190199 assert result .exit_code == 0
191200 assert result .output == expected_output_del
192201 assert ('Vrf1' ) not in db .cfgdb .get_table ('VRF' )
193202
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' )
203+ result = runner .invoke (config .config .commands ["vrf" ].commands ["del" ], ["Vrf200" ], obj = vrf_obj )
204+ assert result .exit_code != 0
205+ assert ('Vrf200' ) not in db .cfgdb .get_table ('VRF' )
206+ assert "VRF Vrf200 does not exist" in result .output
205207
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' )
208+ def test_invalid_vrf_name (self ):
209+ db = Db ()
210+ runner = CliRunner ()
211+ obj = {'config_db' :db .cfgdb }
212+ expected_output = """\
213+ Error: 'vrf_name' must begin with 'Vrf' or named 'mgmt'/'management' in case of ManagementVRF.
214+ """
215+ result = runner .invoke (config .config .commands ["vrf" ].commands ["add" ], ["vrf-blue" ], obj = obj )
216+ assert result .exit_code != 0
217+ assert ('vrf-blue' ) not in db .cfgdb .get_table ('VRF' )
218+ assert expected_output in result .output
219+
220+ result = runner .invoke (config .config .commands ["vrf" ].commands ["add" ], ["VRF2" ], obj = obj )
221+ assert result .exit_code != 0
222+ assert ('VRF2' ) not in db .cfgdb .get_table ('VRF' )
223+ assert expected_output in result .output
224+
225+ result = runner .invoke (config .config .commands ["vrf" ].commands ["add" ], ["VrF10" ], obj = obj )
226+ assert result .exit_code != 0
227+ assert ('VrF10' ) not in db .cfgdb .get_table ('VRF' )
228+ assert expected_output in result .output
229+
230+ result = runner .invoke (config .config .commands ["vrf" ].commands ["del" ], ["vrf-blue" ], obj = obj )
231+ assert result .exit_code != 0
232+ assert expected_output in result .output
233+
234+ result = runner .invoke (config .config .commands ["vrf" ].commands ["del" ], ["VRF2" ], obj = obj )
235+ assert result .exit_code != 0
236+ assert expected_output in result .output
237+
238+ result = runner .invoke (config .config .commands ["vrf" ].commands ["del" ], ["VrF10" ], obj = obj )
239+ assert result .exit_code != 0
240+ assert expected_output in result .output
0 commit comments