Skip to content

Commit 539e156

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fix not working use_random_fully config option" into stable/yoga
2 parents 99b712b + f1db48a commit 539e156

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

neutron/agent/linux/iptables_manager.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class IptablesManager(object):
304304
# run iptables-restore without it.
305305
use_table_lock = False
306306

307-
# Flag to denote iptables supports --random-fully argument
307+
# Flag to denote iptables --random-fully option enabled
308308
_random_fully = None
309309

310310
def __init__(self, state_less=False, use_ipv6=False, nat=True,
@@ -495,10 +495,11 @@ def random_fully(self):
495495
return self._random_fully
496496

497497
version = self._get_version()
498-
self.__class__._random_fully = utils.is_version_greater_equal(
498+
499+
random_fully_support = utils.is_version_greater_equal(
499500
version, n_const.IPTABLES_RANDOM_FULLY_VERSION)
500501

501-
self._random_fully = self._random_fully and \
502+
self.__class__._random_fully = random_fully_support and \
502503
cfg.CONF.AGENT.use_random_fully
503504

504505
return self._random_fully

neutron/tests/unit/agent/linux/test_iptables_manager.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,3 +1395,37 @@ def test_initialize_nat_table(self):
13951395
iptables.initialize_nat_table()
13961396
self.assertIn('nat', iptables.ipv4)
13971397
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

Comments
 (0)