Exemple #1
0
    def test_initial_read_exceptions(self):
        LOG.debug("test_initial_read_exceptions")

        etcdv3._client = client = stub_etcd.Client()
        client.add_read_exception(e3e.Etcd3Exception())
        client.add_read_exception(e3e.InternalServerError())
        client.add_read_exception(e3e.ConnectionFailedError())
        client.add_read_exception(e3e.PreconditionFailedError())
        elector = election.Elector("test_basic", "/bloop", interval=5, ttl=15)
        self._wait_and_stop(client, elector)
Exemple #2
0
    def post(self, *args, **kwargs):
        """helper method for HTTP POST

        :param args:
        :param kwargs:
        :return: json response
        """
        try:
            resp = self.session.post(*args, **kwargs)
            if resp.status_code in _EXCEPTIONS_BY_CODE:
                raise _EXCEPTIONS_BY_CODE[resp.status_code](resp.reason)
            if resp.status_code != requests.codes['ok']:
                raise exceptions.Etcd3Exception(resp.reason)
        except requests.exceptions.Timeout as ex:
            raise exceptions.ConnectionTimeoutError(six.text_type(ex))
        except requests.exceptions.ConnectionError as ex:
            raise exceptions.ConnectionFailedError(six.text_type(ex))
        return resp.json()
Exemple #3
0
    def test_exception_detail_logging(self):
        LOG.debug("test_exception_detail_logging")

        with mock.patch.object(
                log.getLogger(
                    'networking_calico.plugins.ml2.drivers.calico.election'),
                'warning') as mock_lw:
            etcdv3._client = client = stub_etcd.Client()
            exc = e3e.Etcd3Exception(detail_text="Unauthorised user")
            client.add_read_exception(exc)
            elector = election.Elector("test_basic",
                                       "/bloop",
                                       interval=5,
                                       ttl=15)
            self._wait_and_stop(client, elector)

            # Check that Etcd3Exception detail was logged.
            mock_lw.assert_called_with('Failed to %s - key %s: %r:\n%s',
                                       'read current master', '/bloop', exc,
                                       'Unauthorised user')