Merge "[OVN] Accept OVS system-id as non UUID formatted string" into stable/ussuri

This commit is contained in:
Zuul 2022-01-04 09:38:45 +00:00 committed by Gerrit Code Review
commit 7bca2cc526
2 changed files with 38 additions and 5 deletions

View File

@ -14,12 +14,12 @@
import collections
import re
import uuid
from neutron_lib import constants as n_const
from oslo_concurrency import lockutils
from oslo_log import log
from oslo_utils import netutils
from oslo_utils import uuidutils
from ovsdbapp.backend.ovs_idl import event as row_event
from ovsdbapp.backend.ovs_idl import vlog
import six
@ -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."""
@ -185,9 +187,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):
@ -245,8 +254,9 @@ 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')
ext_ids = {
ovn_const.OVN_AGENT_METADATA_ID_KEY: uuidutils.generate_uuid()}
# Generate unique, but consistent metadata id for chassis name
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

@ -13,10 +13,12 @@
# limitations under the License.
import collections
import uuid
import mock
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
@ -322,3 +324,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)