Merge "Set metering iptables chain not found LOG level to WARNING"

This commit is contained in:
Zuul 2020-11-20 11:46:59 +00:00 committed by Gerrit Code Review
commit 144c70f896
3 changed files with 31 additions and 18 deletions

View File

@ -775,7 +775,15 @@ class IptablesManager(object):
args.append('-Z')
if self.namespace:
args = ['ip', 'netns', 'exec', self.namespace] + args
current_table = self.execute(args, run_as_root=True)
# Execute iptables command in the linux host.
# When routers migrate from a host,an exception might happen here,
# and we do not care about it. Therefore, we do not need to log
# this error in production environments. Only when debug mode is
# enabled is that we need to log the error. This is used to avoid
# generating alarms that will be ignored by operators.
current_table = self.execute(
args, run_as_root=True, log_fail_as_error=cfg.CONF.debug)
current_lines = current_table.split('\n')
for line in current_lines[2:]:

View File

@ -506,9 +506,12 @@ class IptablesMeteringDriver(abstract_driver.MeteringAbstractDriver):
chain_acc = rm.iptables_manager.get_traffic_counters(
chain, wrap=False, zero=True)
except RuntimeError:
LOG.exception('Failed to get traffic counters, '
'router: %s', router)
except RuntimeError as e:
LOG.warning('Failed to get traffic counters for router [%s] due '
'to [%s]. This error message can happen when routers '
'are migrated; therefore, most of the times they can '
'be ignored.', router, e)
routers_to_reconfigure.add(router['id'])
return {}
return chain_acc

View File

@ -1020,34 +1020,36 @@ class IptablesManagerStateFulTestCase(IptablesManagerBaseTestCase):
expected_calls_and_values = [
(mock.call(['iptables', '-t', 'filter', '-L', 'OUTPUT',
'-n', '-v', '-x', '-w', '10'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
TRAFFIC_COUNTERS_DUMP),
(mock.call(['iptables', '-t', 'raw', '-L', 'OUTPUT', '-n',
'-v', '-x', '-w', '10'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
''),
(mock.call(['iptables', '-t', 'mangle', '-L', 'OUTPUT', '-n',
'-v', '-x', '-w', '10'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
''),
(mock.call(['iptables', '-t', 'nat', '-L', 'OUTPUT', '-n',
'-v', '-x', '-w', '10'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
''),
]
if self.use_ipv6:
expected_calls_and_values.append(
(mock.call(['ip6tables', '-t', 'raw', '-L', 'OUTPUT',
'-n', '-v', '-x', '-w', '10'], run_as_root=True),
'-n', '-v', '-x', '-w', '10'], run_as_root=True,
log_fail_as_error=False),
''))
expected_calls_and_values.append(
(mock.call(['ip6tables', '-t', 'filter', '-L', 'OUTPUT',
'-n', '-v', '-x', '-w', '10'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
TRAFFIC_COUNTERS_DUMP))
expected_calls_and_values.append(
(mock.call(['ip6tables', '-t', 'mangle', '-L', 'OUTPUT',
'-n', '-v', '-x', '-w', '10'], run_as_root=True),
'-n', '-v', '-x', '-w', '10'], run_as_root=True,
log_fail_as_error=False),
''))
exp_packets *= 2
exp_bytes *= 2
@ -1068,36 +1070,36 @@ class IptablesManagerStateFulTestCase(IptablesManagerBaseTestCase):
expected_calls_and_values = [
(mock.call(['iptables', '-t', 'filter', '-L', 'OUTPUT',
'-n', '-v', '-x', '-w', '10', '-Z'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
TRAFFIC_COUNTERS_DUMP),
(mock.call(['iptables', '-t', 'raw', '-L', 'OUTPUT', '-n',
'-v', '-x', '-w', '10', '-Z'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
''),
(mock.call(['iptables', '-t', 'mangle', '-L', 'OUTPUT', '-n',
'-v', '-x', '-w', '10', '-Z'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
''),
(mock.call(['iptables', '-t', 'nat', '-L', 'OUTPUT', '-n',
'-v', '-x', '-w', '10', '-Z'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
'')
]
if self.use_ipv6:
expected_calls_and_values.append(
(mock.call(['ip6tables', '-t', 'raw', '-L', 'OUTPUT',
'-n', '-v', '-x', '-w', '10', '-Z'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
''))
expected_calls_and_values.append(
(mock.call(['ip6tables', '-t', 'filter', '-L', 'OUTPUT',
'-n', '-v', '-x', '-w', '10', '-Z'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
TRAFFIC_COUNTERS_DUMP))
expected_calls_and_values.append(
(mock.call(['ip6tables', '-t', 'mangle', '-L', 'OUTPUT',
'-n', '-v', '-x', '-w', '10', '-Z'],
run_as_root=True),
run_as_root=True, log_fail_as_error=False),
''))
exp_packets *= 2
exp_bytes *= 2