Skip to content

Commit 5b40de7

Browse files
authored
Merge pull request #47 from stackhpc/upstream/yoga-2023-05-29
Synchronise yoga with upstream
2 parents 4143852 + 0a590e5 commit 5b40de7

File tree

8 files changed

+75
-84
lines changed

8 files changed

+75
-84
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/db/db_base_plugin_v2.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,18 @@ def _update_subnetpool_dict(orig_pool, new_pool):
110110
return updated
111111

112112

113+
def _port_query_hook(context, original_model, query):
114+
# Apply the port query only in non-admin and non-advsvc context
115+
if ndb_utils.model_query_scope_is_project(context, original_model):
116+
query = query.join(models_v2.Network,
117+
models_v2.Network.id == models_v2.Port.network_id)
118+
return query
119+
120+
113121
def _port_filter_hook(context, original_model, conditions):
114122
# Apply the port filter only in non-admin and non-advsvc context
115123
if ndb_utils.model_query_scope_is_project(context, original_model):
116124
conditions |= and_(
117-
models_v2.Port.network_id == models_v2.Network.id,
118125
models_v2.Network.project_id == context.project_id)
119126
return conditions
120127

@@ -150,7 +157,7 @@ def __new__(cls, *args, **kwargs):
150157
model_query.register_hook(
151158
models_v2.Port,
152159
"port",
153-
query_hook=None,
160+
query_hook=_port_query_hook,
154161
filter_hook=_port_filter_hook,
155162
result_filters=None)
156163
return super(NeutronDbPluginV2, cls).__new__(cls, *args, **kwargs)

neutron/db/securitygroups_db.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,6 @@ def delete_security_group(self, context, id):
253253
if sg['name'] == 'default' and not context.is_admin:
254254
raise ext_sg.SecurityGroupCannotRemoveDefault()
255255

256-
# Check if there are rules with remote_group_id ponting to
257-
# the security_group to be deleted
258-
rules_ids_as_remote = self._get_security_group_rules_by_remote(
259-
context=context, remote_id=id,
260-
)
261-
262256
self._registry_publish(resources.SECURITY_GROUP,
263257
events.BEFORE_DELETE,
264258
exc_cls=ext_sg.SecurityGroupInUse, id=id,
@@ -291,20 +285,6 @@ def delete_security_group(self, context, id):
291285
context, resource_id=id, states=(sec_group,),
292286
metadata={'security_group_rule_ids': sgr_ids,
293287
'name': sg['name']}))
294-
for rule in rules_ids_as_remote:
295-
registry.publish(
296-
resources.SECURITY_GROUP_RULE,
297-
events.AFTER_DELETE,
298-
self,
299-
payload=events.DBEventPayload(
300-
context,
301-
resource_id=rule['id'],
302-
metadata={'security_group_id': rule['security_group_id'],
303-
'remote_group_id': rule['remote_group_id'],
304-
'rule': rule
305-
}
306-
)
307-
)
308288

309289
@db_api.retry_if_session_inactive()
310290
def update_security_group(self, context, id, security_group):
@@ -391,23 +371,6 @@ def _get_port_security_group_bindings(self, context,
391371
self._make_security_group_binding_dict,
392372
filters=filters, fields=fields)
393373

394-
def _get_security_group_rules_by_remote(self, context, remote_id):
395-
return model_query.get_collection(
396-
context, sg_models.SecurityGroupRule,
397-
self._make_security_group_rule_dict,
398-
filters={'remote_group_id': [remote_id]},
399-
fields=['id',
400-
'remote_group_id',
401-
'security_group_id',
402-
'direction',
403-
'ethertype',
404-
'protocol',
405-
'port_range_min',
406-
'port_range_max',
407-
'normalized_cidr'
408-
]
409-
)
410-
411374
@db_api.retry_if_session_inactive()
412375
def _delete_port_security_group_bindings(self, context, port_id):
413376
with db_api.CONTEXT_WRITER.using(context):

neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ def subscribe(self):
253253
registry.subscribe(self._create_security_group,
254254
resources.SECURITY_GROUP,
255255
events.AFTER_CREATE)
256+
registry.subscribe(self._delete_security_group_precommit,
257+
resources.SECURITY_GROUP,
258+
events.PRECOMMIT_DELETE)
256259
registry.subscribe(self._delete_security_group,
257260
resources.SECURITY_GROUP,
258261
events.AFTER_DELETE)
@@ -265,9 +268,6 @@ def subscribe(self):
265268
registry.subscribe(self._process_sg_rule_notification,
266269
resources.SECURITY_GROUP_RULE,
267270
events.BEFORE_DELETE)
268-
registry.subscribe(self._process_sg_rule_after_del_notification,
269-
resources.SECURITY_GROUP_RULE,
270-
events.AFTER_DELETE)
271271

272272
def _clean_hash_ring(self, *args, **kwargs):
273273
admin_context = n_context.get_admin_context()
@@ -384,6 +384,14 @@ def _create_security_group(self, resource, event, trigger, payload):
384384
self._ovn_client.create_security_group(context,
385385
security_group)
386386

387+
def _delete_security_group_precommit(self, resource, event, trigger,
388+
payload):
389+
context = n_context.get_admin_context()
390+
security_group_id = payload.resource_id
391+
for sg_rule in self._plugin.get_security_group_rules(
392+
context, filters={'remote_group_id': [security_group_id]}):
393+
self._ovn_client.delete_security_group_rule(context, sg_rule)
394+
387395
def _delete_security_group(self, resource, event, trigger, payload):
388396
context = payload.context
389397
security_group_id = payload.resource_id
@@ -441,12 +449,6 @@ def _process_sg_rule_notification(
441449
context,
442450
sg_rule)
443451

444-
def _process_sg_rule_after_del_notification(
445-
self, resource, event, trigger, payload):
446-
context = payload.context
447-
sg_rule = payload.metadata['rule']
448-
self._ovn_client.delete_security_group_rule(context, sg_rule)
449-
450452
def _sg_has_rules_with_same_normalized_cidr(self, sg_rule):
451453
compare_keys = [
452454
'ethertype', 'direction', 'protocol',

neutron/services/logapi/drivers/ovn/driver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def _remove_acls_log(self, pgs, ovn_txn, log_name=None):
142142
if hasattr(acl, 'label'):
143143
columns['label'] = 0
144144
ovn_txn.add(self.ovn_nb.db_remove(
145-
"ACL", acl_uuid, 'options', 'log-related'))
145+
"ACL", acl_uuid, 'options', 'log-related',
146+
if_exists=True))
146147
ovn_txn.add(self.ovn_nb.db_set(
147148
"ACL", acl_uuid, *columns.items()))
148149
acl_changes += 1

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)

neutron/tests/unit/db/test_securitygroups_db.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -404,38 +404,6 @@ def test_security_group_precommit_and_after_delete_event(self):
404404
self.assertEqual([mock.ANY, mock.ANY],
405405
payload.metadata.get('security_group_rule_ids'))
406406

407-
def test_security_group_rule_after_delete_event_for_remot_group(self):
408-
sg1_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)
409-
sg2_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)
410-
411-
fake_rule = copy.deepcopy(FAKE_SECGROUP_RULE)
412-
fake_rule['security_group_rule']['security_group_id'] = sg1_dict['id']
413-
fake_rule['security_group_rule']['remote_group_id'] = sg2_dict['id']
414-
fake_rule['security_group_rule']['remote_ip_prefix'] = None
415-
remote_rule = self.mixin.create_security_group_rule(
416-
self.ctx, fake_rule)
417-
418-
with mock.patch.object(registry, "publish") as mock_publish:
419-
self.mixin.delete_security_group(self.ctx, sg2_dict['id'])
420-
mock_publish.assert_has_calls(
421-
[mock.call('security_group', 'before_delete',
422-
mock.ANY, payload=mock.ANY),
423-
mock.call('security_group', 'precommit_delete',
424-
mock.ANY,
425-
payload=mock.ANY),
426-
mock.call('security_group', 'after_delete',
427-
mock.ANY,
428-
payload=mock.ANY),
429-
mock.call('security_group_rule', 'after_delete',
430-
mock.ANY,
431-
payload=mock.ANY)])
432-
rule_payload = mock_publish.mock_calls[3][2]['payload']
433-
self.assertEqual(remote_rule['id'], rule_payload.resource_id)
434-
self.assertEqual(sg1_dict['id'],
435-
rule_payload.metadata['security_group_id'])
436-
self.assertEqual(sg2_dict['id'],
437-
rule_payload.metadata['remote_group_id'])
438-
439407
def test_security_group_rule_precommit_create_event_fail(self):
440408
registry.subscribe(fake_callback, resources.SECURITY_GROUP_RULE,
441409
events.PRECOMMIT_CREATE)

neutron/tests/unit/services/logapi/drivers/ovn/test_driver.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
FAKE_CFG_RATE = 123
2929
FAKE_CFG_BURST = 321
30+
FAKE_LABEL = 1
3031

3132

3233
class TestOVNDriverBase(base.BaseTestCase):
@@ -113,6 +114,7 @@ def __init__(self, name=None, **acl_dict):
113114
acl_defaults_dict = {
114115
"name": [name] if name else [],
115116
"action": ovn_const.ACL_ACTION_ALLOW_RELATED,
117+
"label": FAKE_LABEL
116118
}
117119
self.__dict__ = {**acl_defaults_dict, **acl_dict}
118120

@@ -247,6 +249,19 @@ def _mock_lookup(_pg_table, acl_uuid, default):
247249
self.assertEqual(len(pg_dict["acls"]) - 1,
248250
self._nb_ovn.db_set.call_count)
249251

252+
# This test is enforcing the use of if_exists so that we don't get
253+
# unexpected errors while doing parallel operations like erasing log
254+
# objects and security groups
255+
@mock.patch.object(ovn_driver.LOG, 'info')
256+
def test__remove_acls_log_only_if_exists(self, m_info):
257+
pg_dict = self._fake_pg_dict(acls=['acl1', 'acl2', 'acl3'])
258+
259+
def _only_if_exists(_pg_table, acl_uuid, col, val, if_exists):
260+
self.assertTrue(if_exists)
261+
262+
self._nb_ovn.db_remove.side_effect = _only_if_exists
263+
self._log_driver._remove_acls_log([pg_dict], self._nb_ovn.transaction)
264+
250265
@mock.patch.object(ovn_driver.LOG, 'info')
251266
def test__remove_acls_log_with_log_name(self, m_info):
252267
pg_dict = self._fake_pg_dict(acls=['acl1', 'acl2', 'acl3', 'acl4'])

0 commit comments

Comments
 (0)