def test_fail_to_maintain(self): # Become the master after one round LOG.debug("test_become_master_first_time") etcdv3._client = client = stub_etcd.Client() client.add_read_exception(etcdv3.KeyNotFound()) client.add_write_exception(None) client.add_write_exception(e3e.ConnectionFailedError()) elector = election.Elector("test_basic", "/bloop", interval=5, ttl=15) self._wait_and_stop(client, elector)
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)
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()
def test_master_failure(self): LOG.debug("test_master_failure") etcdv3._client = client = stub_etcd.Client() client.add_read_exception(etcdv3.KeyNotFound()) # Now become the master but fail client.add_write_exception(e3e.ConnectionFailedError()) client.add_read_result(key="/bloop", value="value") client.add_read_result(key="/bloop", value=None, action="delete") # Now become the master but fail again client.add_write_exception(e3e.InternalServerError()) # Go back to the beginning again. client.add_read_result(key="/bloop", value="value") client.add_read_result(key="/bloop", value=None, action="delete") client.add_write_exception(None) client.add_write_exception(None) elector = election.Elector("test_basic", "/bloop", interval=5, ttl=15) self._wait_and_stop(client, elector) # We are no longer the master, after being told to stop. self.assertFalse(elector.master())