Fix compatability with new oslo.messaging

A recent change to oslo.messaging to redact contexts before sending them
to a notification bus broke masakari due to the invalid default for
read_deleted. This ensures that a "None" value for read_deleted ends up
being interpreted as a 'none'.

Related-bug: #2030976
Change-Id: Ic9b895601f301c1e9ba135766493d4234fa9b50b
This commit is contained in:
Jay Faulkner 2023-09-08 12:54:34 -07:00
parent 09d595849d
commit 6a48417607
2 changed files with 11 additions and 1 deletions

View File

@ -117,7 +117,12 @@ class RequestContext(context.RequestContext):
LOG.debug('Arguments dropped when creating context: %s',
str(kwargs))
self.read_deleted = read_deleted
if read_deleted is None:
# If we did not get a value for read_deleted, ensure we default
# it to "no" as code expects it to be a string.
self.read_deleted = 'no'
else:
self.read_deleted = read_deleted
self.remote_address = remote_address
if not timestamp:
timestamp = timeutils.utcnow()

View File

@ -57,6 +57,11 @@ class ContextTestCase(test.NoDBTestCase):
ctxt.read_deleted = 'no'
self.assertEqual('no', ctxt.read_deleted)
def test_request_context_read_deleted_none(self):
ctxt = context.RequestContext('111',
'222')
self.assertEqual('no', ctxt.read_deleted)
def test_request_context_read_deleted_invalid(self):
self.assertRaises(ValueError,
context.RequestContext,