Skip to content

Commit e6dce50

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "[OVN] Create the SG rules revision number registers" into stable/2023.1
2 parents 437cadc + 1a3e059 commit e6dce50

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ def _create_security_group_precommit(self, resource, event, trigger,
403403
context, security_group['id'],
404404
ovn_const.TYPE_SECURITY_GROUPS,
405405
std_attr_id=security_group['standard_attr_id'])
406+
for sg_rule in security_group['security_group_rules']:
407+
ovn_revision_numbers_db.create_initial_revision(
408+
context, sg_rule['id'],
409+
ovn_const.TYPE_SECURITY_GROUP_RULES,
410+
std_attr_id=sg_rule['standard_attr_id'])
406411

407412
def _create_security_group(self, resource, event, trigger, payload):
408413
context = payload.context

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,9 @@ def create_security_group(self, context, security_group):
24432443
self.is_allow_stateless_supported())
24442444
db_rev.bump_revision(
24452445
context, security_group, ovn_const.TYPE_SECURITY_GROUPS)
2446+
for sg_rule in security_group['security_group_rules']:
2447+
db_rev.bump_revision(
2448+
context, sg_rule, ovn_const.TYPE_SECURITY_GROUP_RULES)
24462449

24472450
def _add_port_to_drop_port_group(self, port, txn):
24482451
txn.add(self._nb_idl.pg_add_ports(ovn_const.OVN_DROP_PORT_GROUP_NAME,

neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_resources.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from neutron.common.ovn import utils
2727
from neutron.common import utils as n_utils
2828
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf as ovn_config
29+
from neutron.db import ovn_revision_numbers_db as rev_db
2930
from neutron.tests.functional import base
3031

3132

@@ -922,6 +923,25 @@ def test_port_security_port_group(self):
922923
self._verify_port_acls(port_id, expected_acls_with_sg_ps_enabled)
923924

924925

926+
class TestSecurityGroups(base.TestOVNFunctionalBase):
927+
928+
def test_security_group_creation_and_deletion(self):
929+
sg = self._make_security_group(self.fmt)['security_group']
930+
rev_num = rev_db.get_revision_row(self.context, sg['id'])
931+
self.assertEqual(1, rev_num.revision_number)
932+
for sg_rule in sg['security_group_rules']:
933+
rev_num = rev_db.get_revision_row(self.context, sg_rule['id'])
934+
self.assertEqual(0, rev_num.revision_number)
935+
936+
self._delete('security-groups', sg['id'])
937+
self.assertIsNone(rev_db.get_revision_row(self.context, sg['id']))
938+
# NOTE(ralonsoh): the deletion of the revision numbers of the SG rules
939+
# will be fixed in a follow-up patch.
940+
# for sg_rule in sg['security_group_rules']:
941+
# self.assertIsNone(rev_db.get_revision_row(self.context,
942+
# sg_rule['id']))
943+
944+
925945
class TestDNSRecords(base.TestOVNFunctionalBase):
926946
_extension_drivers = ['port_security', 'dns']
927947

neutron/tests/unit/db/test_db_base_plugin_v2.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,20 @@ def _make_port(self, fmt, net_id, expected_res_status=None, **kwargs):
592592
self._check_http_response(res)
593593
return self.deserialize(fmt, res)
594594

595+
def _make_security_group(self, fmt, name=None, expected_res_status=None,
596+
project_id=None, is_admin=False):
597+
name = name or 'sg-{}'.format(uuidutils.generate_uuid())
598+
project_id = project_id or self._tenant_id
599+
data = {'security_group': {'name': name,
600+
'description': name,
601+
'project_id': project_id}}
602+
sg_req = self.new_create_request('security-groups', data, fmt)
603+
sg_res = sg_req.get_response(self.api)
604+
if expected_res_status:
605+
self.assertEqual(expected_res_status, sg_res.status_int)
606+
self._check_http_response(sg_res)
607+
return self.deserialize(fmt, sg_res)
608+
595609
def _create_qos_rule(self, fmt, qos_policy_id, rule_type, max_kbps=None,
596610
max_burst_kbps=None, dscp_mark=None, min_kbps=None,
597611
direction=constants.EGRESS_DIRECTION,

neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,12 @@ def _test__create_security_group(
289289
for c in self.nb_ovn.pg_acl_add.call_args_list:
290290
self.assertEqual(expected, c[1]["action"])
291291

292-
mock_bump.assert_called_once_with(
293-
mock.ANY, self.fake_sg, ovn_const.TYPE_SECURITY_GROUPS)
292+
calls = [mock.call(mock.ANY, self.fake_sg,
293+
ovn_const.TYPE_SECURITY_GROUPS)]
294+
for sg_rule in self.fake_sg['security_group_rules']:
295+
calls.append(mock.call(mock.ANY, sg_rule,
296+
ovn_const.TYPE_SECURITY_GROUP_RULES))
297+
mock_bump.assert_has_calls(calls)
294298

295299
def test__create_security_group_stateful_supported(self):
296300
self._test__create_security_group(True, True)

0 commit comments

Comments
 (0)