@@ -1395,3 +1395,37 @@ def test_initialize_nat_table(self):
1395
1395
iptables .initialize_nat_table ()
1396
1396
self .assertIn ('nat' , iptables .ipv4 )
1397
1397
self .assertIn ('mangle' , iptables .ipv4 )
1398
+
1399
+
1400
+ class IptablesRandomFullyFixture (fixtures .Fixture ):
1401
+ def _setUp (self ):
1402
+ # We MUST save and restore _random_fully because it is a class
1403
+ # attribute and could change state in some tests, which can cause
1404
+ # the other router test cases to randomly fail due to race conditions.
1405
+ self ._random_fully = iptables_manager .IptablesManager ._random_fully
1406
+ iptables_manager .IptablesManager ._random_fully = None
1407
+ self .addCleanup (self ._reset )
1408
+
1409
+ def _reset (self ):
1410
+ iptables_manager .IptablesManager ._random_fully = self ._random_fully
1411
+
1412
+
1413
+ class IptablesManagerDisableRandomFullyTestCase (base .BaseTestCase ):
1414
+
1415
+ def setUp (self ):
1416
+ super (IptablesManagerDisableRandomFullyTestCase , self ).setUp ()
1417
+ self .useFixture (IptablesRandomFullyFixture ())
1418
+ self .execute = mock .patch .object (linux_utils , "execute" ).start ()
1419
+ cfg .CONF .set_override ('use_random_fully' , False , "AGENT" )
1420
+
1421
+ def test_verify_disable_random_fully (self ):
1422
+ expected_calls_and_values = [
1423
+ (mock .call (['iptables' , '--version' ],
1424
+ run_as_root = True , privsep_exec = True ),
1425
+ "iptables v1.6.2" )]
1426
+ tools .setup_mock_calls (self .execute , expected_calls_and_values )
1427
+ iptables_mgrs = [iptables_manager .IptablesManager () for _ in range (3 )]
1428
+ # The random_full properties of all
1429
+ # IptablesManager instances must return False
1430
+ for ipt_mgr in iptables_mgrs :
1431
+ self .assertFalse (ipt_mgr .random_fully )
0 commit comments