Skip to content

Commit bbbafe1

Browse files
committed
[ovn] Avoid unwanted ACL_NOT_FOUND error when deleting log objects
There is the possibility that db_remove raises an error if an ACL was deleted on parallel for other reasons while deleting a log object. On a normal situation, this command would remove the no-longer-needed 'log-related' property, but since the ACL is no longer there, it will raise an error. For this case, it is not problematic to have an ACL deleted mid-operation, so it should not raise any error. Related-Bug: #2019887 Signed-off-by: Elvira García <[email protected]> Change-Id: I154393529134b5861e0ef0283257ef964fe057fd (cherry picked from commit e0a2427)
1 parent 539e156 commit bbbafe1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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/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)