コード例 #1
0
ファイル: test_auth.py プロジェクト: gaopeiliang/aioetcd3
 async def setUp(self):
     self.endpoints = "127.0.0.1:2379"
     self.unauthenticated_client = client(endpoint=self.endpoints)
     await self.cleanUp()
     await switch_auth_on(self.unauthenticated_client)
     self.client_client = client(endpoint=self.endpoints,
                                 username="******",
                                 password="******")
     self.root_client = client(endpoint=self.endpoints,
                               username="******",
                               password="******")
コード例 #2
0
ファイル: test_watch.py プロジェクト: gaopeiliang/aioetcd3
 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
コード例 #3
0
ファイル: test_auth.py プロジェクト: gaopeiliang/aioetcd3
 async def test_wrong_password(self):
     wrong_password_client = client(endpoint=self.endpoints,
                                    username="******",
                                    password="******")
     with self.assertRaises(AuthError) as exc:
         await wrong_password_client.get("/foo")
     assert repr(exc.exception) == "`{}`: reason: `{}`".format(
         exc.exception.code, exc.exception.details)
コード例 #4
0
def worker(producer: Iterator[Tuple[int, Any]],
           output: Callable,
           cl: Client = None,
           myid: str = None):
    """
    A worker receives a stream of Messages, but only processes Messages having
    an ID that belongs to a partition assigned to the worker.

    Workers collaborate in order to agree which workers are assigned which
    partitions.

    Params

    ------
    producer
    A Generator returning MessageId, Message Pairs

    output
    ------
    A function to which Messages procesed by this worker are passed. Probably a
    Method on a thread-safe object which aggregates Messages.

    Test a single worker here; we test mutliple workers in __main___:
    >>> p = [(4, 4), (5, 5), (6, 6)]
    >>> from cranial.messaging.test.test_coordinator import _fake_client
    >>> c = _fake_client(PREFIX)
    >>> run(init(c))
    >>> result = []
    >>> o = result.append
    >>> worker(p, o, c)
    >>> result
    [4, 5, 6]
    """
    cl = cl or client(endpoint="localhost:2379")
    myid = myid or str(uuid4())
    run(register(cl, myid))
    parts = {}  # type: Dict

    last_checkin = 0  # type: float

    for i, msg in producer:
        if time() - last_checkin > CHECKIN:
            run(respond(cl, myid, parts))
            parts, total_parts = run(req_parts(cl, myid))
            logging.info('Worker %s was assigned %s', myid, parts)
            last_checkin = time()
        for p, last_id in parts.items():
            # @TODO Support non-numeric partition ids.
            if i % total_parts == int(p) and i > (last_id or -1):
                ok = run(set_checkpoint(cl, p, i))
                if ok:
                    parts[p] = i
                    output(msg or i)
                break
コード例 #5
0
ファイル: test_auth.py プロジェクト: gaopeiliang/aioetcd3
    async def test_wrong_token(self):
        await self.create_kv_for_test()
        await self.root_client.role_grant_permission(name='client',
                                                     key_range='/foo',
                                                     permission=PER_RW)

        new_client = client(endpoint=self.endpoints,
                            username="******",
                            password="******")
        value, meta = await self.client_client.get('/foo')
        self.assertEqual(value, b'/foo')

        # Put invalid token
        new_client._metadata = (("token", "invalid_token"), )
        with self.assertRaises(Unauthenticated) as exc:
            await new_client.get("/foo")
コード例 #6
0
ファイル: test_auth.py プロジェクト: gaopeiliang/aioetcd3
    async def setUp(self):
        endpoints = "127.0.0.1:2379"
        self.client = client(endpoint=endpoints)

        set_grpc_cipher()
        auth_etcd_url = "127.0.0.1:2378"
        self.root_client = ssl_client(
            endpoint=auth_etcd_url,
            ca_file="test/cfssl/ca.pem",
            cert_file="test/cfssl/client-root.pem",
            key_file="test/cfssl/client-root-key.pem")

        self.client_client = ssl_client(endpoint=auth_etcd_url,
                                        ca_file="test/cfssl/ca.pem",
                                        cert_file="test/cfssl/client.pem",
                                        key_file="test/cfssl/client-key.pem")

        await self.cleanUp()
コード例 #7
0
ファイル: test_watch.py プロジェクト: vzex/aioetcd3
 async def setUp(self):
     self.endpoints = "127.0.0.1:2379"
     self.client = client(endpoint=self.endpoints)
     await self.cleanUp()
コード例 #8
0
 def setUp(self):
     endpoints = "127.0.0.1:2379"
     self.client = client(endpoint=endpoints)
コード例 #9
0
ファイル: etcd.py プロジェクト: the-cc-dev/traefik-proxy
 def _default_client(self):
     etcd_service = urlparse(self.etcd_url)
     return client(endpoint=str(etcd_service.hostname) + ":" +
                   str(etcd_service.port))