Merge pull request #234 from yliaog/master
quick fix of decoding error for BOOKMARK event
This commit is contained in:
commit
e514f69dff
@ -96,7 +96,11 @@ class Watch(object):
|
||||
def unmarshal_event(self, data, return_type):
|
||||
js = json.loads(data)
|
||||
js['raw_object'] = js['object']
|
||||
if return_type and js['type'] != 'ERROR':
|
||||
# BOOKMARK event is treated the same as ERROR for a quick fix of
|
||||
# decoding exception
|
||||
# TODO: make use of the resource_version in BOOKMARK event for more
|
||||
# efficient WATCH
|
||||
if return_type and js['type'] != 'ERROR' and js['type'] != 'BOOKMARK':
|
||||
obj = SimpleNamespace(data=json.dumps(js['raw_object']))
|
||||
js['object'] = self._api_client.deserialize(obj, return_type)
|
||||
if hasattr(js['object'], 'metadata'):
|
||||
|
||||
@ -255,6 +255,19 @@ class WatchTests(unittest.TestCase):
|
||||
self.assertEqual("1", event['object']['metadata']['resourceVersion'])
|
||||
self.assertEqual("1", w.resource_version)
|
||||
|
||||
def test_unmarshal_with_bookmark(self):
|
||||
w = Watch()
|
||||
event = w.unmarshal_event(
|
||||
'{"type":"BOOKMARK","object":{"kind":"Job","apiVersion":"batch/v1"'
|
||||
',"metadata":{"resourceVersion":"1"},"spec":{"template":{'
|
||||
'"metadata":{},"spec":{"containers":null}}},"status":{}}}',
|
||||
'V1Job')
|
||||
self.assertEqual("BOOKMARK", event['type'])
|
||||
# Watch.resource_version is *not* updated, as BOOKMARK is treated the
|
||||
# same as ERROR for a quick fix of decoding exception,
|
||||
# resource_version in BOOKMARK is *not* used at all.
|
||||
self.assertEqual(None, w.resource_version)
|
||||
|
||||
def test_watch_with_exception(self):
|
||||
fake_resp = Mock()
|
||||
fake_resp.close = Mock()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user