[OVN] Accept OVS system-id as non UUID formatted string

Accept OVS system-id non UUID formatted strings. The OVN metadata
agent will generate a unique UUID from the OVS system-id. If this
string is a UUID, this value will be used. If not, the OVN metadata
agent will generate a UUID based on the provided string.

This patch amends [1].

[1]https://review.opendev.org/c/openstack/neutron/+/819634

Closes-Bug: #1952550

Conflicts:
	neutron/agent/ovn/metadata/agent.py
        neutron/tests/unit/agent/ovn/metadata/test_agent.py

Change-Id: I42a8a767a6ef9454419b26f80339394759644faf
(cherry picked from commit 79037c9516)
(cherry picked from commit 6da4432fed)
This commit is contained in:
Rodolfo Alonso Hernandez 2021-12-20 14:14:20 +00:00
parent 1810171806
commit b07eeb2789
2 changed files with 35 additions and 4 deletions

View File

@ -48,6 +48,8 @@ OVN_VIF_PORT_TYPES = ("", "external", )
MetadataPortInfo = collections.namedtuple('MetadataPortInfo', ['mac',
'ip_addresses'])
OVN_METADATA_UUID_NAMESPACE = uuid.UUID('d34bf9f6-da32-4871-9af8-15a4626b41ab')
def _sync_lock(f):
"""Decorator to block all operations for a global sync call."""
@ -203,9 +205,16 @@ class MetadataAgent(object):
def _load_config(self):
self.chassis = self._get_own_chassis_name()
try:
self.chassis_id = uuid.UUID(self.chassis)
except ValueError:
# OVS system-id could be a non UUID formatted string.
self.chassis_id = uuid.uuid5(OVN_METADATA_UUID_NAMESPACE,
self.chassis)
self.ovn_bridge = self._get_ovn_bridge()
LOG.debug("Loaded chassis %s and ovn bridge %s.",
self.chassis, self.ovn_bridge)
LOG.info("Loaded chassis name %s (UUID: %s) and ovn bridge %s.",
self.chassis, self.chassis_id, self.ovn_bridge)
@_sync_lock
def resync(self):
@ -263,9 +272,8 @@ class MetadataAgent(object):
# NOTE(lucasagomes): db_add() will not overwrite the UUID if
# it's already set.
table = ('Chassis_Private' if self.has_chassis_private else 'Chassis')
chassis_id = uuid.UUID(self._get_own_chassis_name())
# Generate unique, but consistent metadata id for chassis name
agent_id = uuid.uuid5(chassis_id, 'metadata_agent')
agent_id = uuid.uuid5(self.chassis_id, 'metadata_agent')
ext_ids = {ovn_const.OVN_AGENT_METADATA_ID_KEY: str(agent_id)}
self.sb_idl.db_add(table, self.chassis, 'external_ids',
ext_ids).execute(check_error=True)

View File

@ -14,10 +14,12 @@
import collections
from unittest import mock
import uuid
from neutron_lib import constants as n_const
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslo_utils import uuidutils
from neutron.agent.linux import ip_lib
from neutron.agent.linux.ip_lib import IpAddrCommand as ip_addr
@ -323,3 +325,24 @@ class TestMetadataAgent(base.BaseTestCase):
expected_dps = ['0', '1', '2']
self._test_update_chassis_metadata_networks_helper(
dp, remove, expected_dps, txn_called=False)
def test__load_config(self):
# Chassis name UUID formatted string. OVN bridge "br-ovn".
valid_uuid_str = uuidutils.generate_uuid()
self.agent.ovs_idl.db_get.return_value.execute.side_effect = [
{'system-id': valid_uuid_str}, {'ovn-bridge': 'br-ovn'}]
self.agent._load_config()
self.assertEqual(valid_uuid_str, self.agent.chassis)
self.assertEqual(uuid.UUID(valid_uuid_str), self.agent.chassis_id)
self.assertEqual('br-ovn', self.agent.ovn_bridge)
# Chassis name non UUID formatted string. OVN bridge not defined,
# "br-int" assigned by default.
self.agent.ovs_idl.db_get.return_value.execute.side_effect = [
{'system-id': 'RandomName1'}, {}]
self.agent._load_config()
generated_uuid = uuid.uuid5(agent.OVN_METADATA_UUID_NAMESPACE,
'RandomName1')
self.assertEqual('RandomName1', self.agent.chassis)
self.assertEqual(generated_uuid, self.agent.chassis_id)
self.assertEqual('br-int', self.agent.ovn_bridge)