Beispiel #1
0
 async def watch_1():
     asserts = [(EVENT_TYPE_CREATE, b'/foo/1', b'1'),
                (EVENT_TYPE_CREATE, b'/foo/2', b'2'),
                (EVENT_TYPE_MODIFY, b'/foo/1', b'2'),
                (EVENT_TYPE_MODIFY, b'/foo/2', b'3'),
                (EVENT_TYPE_DELETE, b'/foo/1',None),
                (EVENT_TYPE_DELETE, b'/foo/2',None)]
     async with self.client.watch_scope(range_prefix('/foo/')) as response:
         f1.set_result(None)
         async for e in response:
             _check_event(e, asserts.pop(0))
             if not asserts:
                 break
Beispiel #2
0
 async def watch_service_event(self):
     etcd_client = self.connect_etcd()
     prefix = range_prefix('/eha/service/')
     while True:
         try:
             async with etcd_client.watch_scope(prefix) as resp:
                 async for event in resp:
                     await self.handle_service_event(event)
         except asyncio.CancelledError:
             break
         except Exception:
             self.logger.warning('seems etcd not avaliable, wait 5 seconds')
             await asyncio.sleep(5)
Beispiel #3
0
 async def _run_test_with_auth(self, test):
     default_client = self.client
     await switch_auth_on(default_client)
     root_client = client(endpoint=self.endpoints, username="******", password="******")
     await root_client.role_grant_permission(name='client', key_range=range_prefix('/foo'), permission=PER_RW)
     self.client = client(endpoint=self.endpoints, username="******", password="******")
     try:
         await test()
     finally:
         await switch_auth_off(
             root_client,
             default_client
         )
         await root_client.close()
         await self.client.close()
         self.client = default_client
Beispiel #4
0
 async def watch_2():
     asserts = [((EVENT_TYPE_CREATE, b'/foo/1', b'1'),
                (EVENT_TYPE_CREATE, b'/foo/2', b'2'),),
                ((EVENT_TYPE_MODIFY, b'/foo/1', b'2'),),
                ((EVENT_TYPE_MODIFY, b'/foo/2', b'3'),),
                ((EVENT_TYPE_DELETE, b'/foo/1',None),
                (EVENT_TYPE_DELETE, b'/foo/2',None))]
     async with self.client.watch_scope(range_prefix('/foo/'), batch_events=True)\
             as response:
         f2.set_result(None)
         async for es in response:
             batch = asserts.pop(0)
             self.assertEqual(len(es), len(batch))
             for e, a in zip(es, batch):
                 _check_event(e, a)
             if not asserts:
                 break
Beispiel #5
0
    async def get_all_routes(self):
        """Fetch and return all the routes associated by JupyterHub from the
        proxy.

        **Subclasses must define this method**

        Should return a dictionary of routes, where the keys are
        routespecs and each value is a dict of the form::

          {
            'routespec': the route specification ([host]/path/)
            'target': the target host URL (proto://host) for this route
            'data': the attached data dict for this route (as specified in add_route)
          }
        """
        all_routes = {}
        routes = await self.etcd_client.range(
            range_prefix(self.etcd_jupyterhub_prefix))

        for key, value, _ in routes:
            # Strip the "/jupyterhub" prefix from the routespec
            routespec = key.decode().replace(self.etcd_jupyterhub_prefix, "")
            target = value.decode()

            value, _ = await self.etcd_client.get(target)
            if value is None:
                data = None
            else:
                data = value.decode()

            all_routes[routespec] = {
                "routespec": routespec,
                "target": target,
                "data": data,
            }

        return all_routes