예제 #1
0
 async def test_watch_handler_error(self):
     s = store.new_store(store.meta_namespace_key_func)
     g = Reflector(TestLW.__new__(TestLW), V1Pod, s, 0)
     fw = watch.new_fake()
     await fw.stop()
     with self.assertRaises(Exception):
         await g._watch_handler(fw, {}, asyncio.Queue())
예제 #2
0
    async def test_run_until(self):
        s = store.new_store(store.meta_namespace_key_func)
        fw = watch.new_fake()

        def list_func(options):
            return V1PodList(metadata=V1ListMeta(resource_version="1"), items=[])

        lister_watcher = TestLW(list_func, lambda _: fw)
        r = Reflector(lister_watcher, V1Pod, s, 0)
        task = asyncio.ensure_future(r.run())
        await fw.add(V1Pod(metadata=V1ObjectMeta(name="bar")))
        task.cancel()

        async def aw():
            async for _ in fw:
                self.fail("Watch left open after stopping the watch")

        await asyncio.wait_for(aw(), wait.FOREVER_TEST_TIMEOUT)
예제 #3
0
    async def test_watch_handler(self):
        s = store.new_store(store.meta_namespace_key_func)
        g = Reflector(TestLW.__new__(TestLW), V1Pod, s, 0)
        fw = watch.new_fake()
        await s.add(V1Pod(metadata=V1ObjectMeta(name="foo")))
        await s.add(V1Pod(metadata=V1ObjectMeta(name="bar")))

        async def aw():
            await fw.add(V1Service(metadata=V1ObjectMeta(name="rejected")))
            await fw.delete(V1Pod(metadata=V1ObjectMeta(name="foo")))
            await fw.modify(
                V1Pod(metadata=V1ObjectMeta(name="bar", resource_version="55"))
            )
            await fw.add(
                V1Pod(metadata=V1ObjectMeta(name="baz", resource_version="32"))
            )
            await fw.stop()

        asyncio.ensure_future(aw())
        options = {}
        await g._watch_handler(fw, options, asyncio.Queue())

        def mk_pod(id_, rv):
            return V1Pod(metadata=V1ObjectMeta(name=id_, resource_version=rv))

        table = [
            {"pod": mk_pod("foo", ""), "exists": False},
            {"pod": mk_pod("rejected", ""), "exists": False},
            {"pod": mk_pod("bar", "55"), "exists": True},
            {"pod": mk_pod("baz", "32"), "exists": True},
        ]
        for item in table:
            obj = s.get(item["pod"])
            exists = obj is not None
            self.assertIs(exists, item["exists"])
            if not exists:
                continue
            self.assertEqual(
                obj.metadata.resource_version, item["pod"].metadata.resource_version
            )

        self.assertEqual(options["resource_version"], "32")
        self.assertEqual(g.last_sync_resource_version(), "32")
예제 #4
0
    async def test_close_watch_on_error(self):
        pod = V1Pod(metadata=V1ObjectMeta(name="bar"))
        fw = watch.new_fake()

        def list_func(options):
            return V1PodList(metadata=V1ListMeta(resource_version="1"), items=[])

        lister_watcher = TestLW(list_func, lambda _: fw)
        r = Reflector(
            lister_watcher, V1Pod, store.new_store(store.meta_namespace_key_func), 0
        )
        asyncio.ensure_future(r.list_and_watch())
        await fw.error(pod)

        async def aw():
            async for _ in fw:
                self.fail("Watch left open after cancellation")

        await asyncio.wait_for(aw(), wait.FOREVER_TEST_TIMEOUT)
예제 #5
0
 async def test_cache(self):
     await self.do_test_store(new_store(test_store_key_func))
예제 #6
0
 async def test_resync_queue(self):
     s = store.new_store(store.meta_namespace_key_func)
     g = Reflector(TestLW.__new__(TestLW), V1Pod, s, 0.001)
     a, _ = g._resync_queue()
     await asyncio.wait_for(a.get(), wait.FOREVER_TEST_TIMEOUT)
예제 #7
0
def new_informer(lw, obj_type, resync_period, h):
    client_state = store.new_store(deletion_handling_meta_namespace_key_func)
    return client_state, _new_informer(lw, obj_type, resync_period, h, client_state)