@@ -239,19 +239,34 @@ def test_get_devices_info_veth_same_namespaces(self):
239239 self .assertEqual (veth1_2 ['index' ], veth1_1_link )
240240
241241
242- class ListIpRulesTestCase (functional_base .BaseSudoTestCase ):
243-
244- RULE_TABLES = {'default' : 253 , 'main' : 254 , 'local' : 255 }
242+ class BaseIpRuleTestCase (functional_base .BaseSudoTestCase ):
245243
246244 def setUp (self ):
247- super (ListIpRulesTestCase , self ).setUp ()
245+ super ().setUp ()
248246 self .namespace = 'ns_test-' + uuidutils .generate_uuid ()
249247 self .ns = priv_ip_lib .create_netns (self .namespace )
250248 self .addCleanup (self ._remove_ns )
251249
252250 def _remove_ns (self ):
253251 priv_ip_lib .remove_netns (self .namespace )
254252
253+ def _check_rules (self , rules , parameters , values , exception_string = None ,
254+ raise_exception = True ):
255+ for rule in rules :
256+ if all (rule .get (parameter ) == value
257+ for parameter , value in zip (parameters , values )):
258+ return True
259+ else :
260+ if raise_exception :
261+ self .fail ('Rule with %s was expected' % exception_string )
262+ else :
263+ return False
264+
265+
266+ class ListIpRulesTestCase (BaseIpRuleTestCase ):
267+
268+ RULE_TABLES = {'default' : 253 , 'main' : 254 , 'local' : 255 }
269+
255270 def test_list_default_rules_ipv4 (self ):
256271 rules_ipv4 = priv_ip_lib .list_ip_rules (self .namespace , 4 )
257272 self .assertEqual (3 , len (rules_ipv4 ))
@@ -291,28 +306,7 @@ def test_list_rules_ipv6(self):
291306 self .fail ('Rule added (2001:db8::1/64, table 20) not found' )
292307
293308
294- class RuleTestCase (functional_base .BaseSudoTestCase ):
295-
296- def setUp (self ):
297- super (RuleTestCase , self ).setUp ()
298- self .namespace = 'ns_test-' + uuidutils .generate_uuid ()
299- self .ns = priv_ip_lib .create_netns (self .namespace )
300- self .addCleanup (self ._remove_ns )
301-
302- def _remove_ns (self ):
303- priv_ip_lib .remove_netns (self .namespace )
304-
305- def _check_rules (self , rules , parameters , values , exception_string = None ,
306- raise_exception = True ):
307- for rule in rules :
308- if all (rule .get (parameter ) == value
309- for parameter , value in zip (parameters , values )):
310- return True
311- else :
312- if raise_exception :
313- self .fail ('Rule with %s was expected' % exception_string )
314- else :
315- return False
309+ class AddIpRulesTestCase (BaseIpRuleTestCase ):
316310
317311 def test_add_rule_ip (self ):
318312 ip_addresses = ['192.168.200.250' , '2001::250' ]
@@ -439,6 +433,23 @@ def test_add_rule_exists(self):
439433 self .assertEqual (4 , len (rules ))
440434
441435
436+ class DeleteIpRulesTestCase (BaseIpRuleTestCase ):
437+
438+ def test_delete_rule_no_entry (self ):
439+ iif = 'iif_device'
440+ priv_ip_lib .create_interface (iif , self .namespace , 'dummy' )
441+
442+ try :
443+ # This should not raise for a non-existent entry
444+ priv_ip_lib .delete_ip_rule (self .namespace , iifname = iif )
445+ except Exception :
446+ self .fail ('Delete IP rule threw unexpected exception' )
447+
448+ rules = ip_lib .list_ip_rules (self .namespace , 4 )
449+ # There are always 3 rules by default
450+ self .assertEqual (3 , len (rules ))
451+
452+
442453class GetIpAddressesTestCase (functional_base .BaseSudoTestCase ):
443454
444455 def _remove_ns (self , namespace ):
@@ -665,6 +676,21 @@ def test_add_multipath_route(self):
665676 n_cons .IP_VERSION_4 , via = multipath )
666677 self ._check_routes (['192.168.0.0/24' ], gateway = multipath )
667678
679+ def test_delete_route_no_entry (self ):
680+ cidr = '192.168.0.0/24'
681+ self .device .addr .add ('10.1.0.1/24' )
682+ try :
683+ # This should not raise for a non-existent entry
684+ priv_ip_lib .delete_ip_route (self .namespace , cidr ,
685+ n_cons .IP_VERSION_4 ,
686+ device = self .device_name )
687+ except Exception :
688+ self .fail ('Delete IP route threw unexpected exception' )
689+
690+ routes = ip_lib .list_ip_routes (self .namespace , n_cons .IP_VERSION_4 )
691+ # There will be a single interface route since we added an IP
692+ self .assertEqual (1 , len (routes ))
693+
668694
669695class GetLinkAttributesTestCase (functional_base .BaseSudoTestCase ):
670696
0 commit comments