Ignore keys unsupported by BlazarContext in its creation
BlazarContext class raises an error when the class is instantiated with unspported keys. The class is used as a context for RPC and the RPC is implemented over oslo.messaging. If oslo.messaging automatically adds a new key for the context, the RPC execution fails since the new key is unexpected by BlazarContext and it raises an error. This patch relaxes the limitations in BlazarContext. If unexpected keys are passed for the class instantiation, the class ignores the keys. Change-Id: Ibdca6eead0ee726bc10a07ee43e4ef10110d23e2 Closes-Bug: #1775363
This commit is contained in:
parent
3ed1fdc64a
commit
29e68d8295
|
@ -29,10 +29,9 @@ class BaseContext(object):
|
|||
__mapping = __mapping.__values
|
||||
self.__values = dict(__mapping)
|
||||
self.__values.update(**kwargs)
|
||||
bad_keys = set(self.__values) - self._elements
|
||||
if bad_keys:
|
||||
raise TypeError("Only %s keys are supported. %s given" %
|
||||
(tuple(self._elements), tuple(bad_keys)))
|
||||
not_supported_keys = set(self.__values) - self._elements
|
||||
for k in not_supported_keys:
|
||||
del self.__values[k]
|
||||
|
||||
def __getattr__(self, name):
|
||||
try:
|
||||
|
|
|
@ -36,7 +36,8 @@ class TestContextCreate(tests.TestCase):
|
|||
self.assertEqual(ctx.to_dict(), {"first": 1, "second": 2})
|
||||
|
||||
def test_fail(self):
|
||||
self.assertRaises(TypeError, TestContext, forth=4)
|
||||
ctx = TestContext({'first': 1, "forth": 4}, fifth=5)
|
||||
self.assertEqual(ctx.to_dict(), {"first": 1})
|
||||
|
||||
|
||||
class TestBaseContext(tests.TestCase):
|
||||
|
|
Loading…
Reference in New Issue