How to use the kazoo.exceptions function in kazoo

To help you get started, we’ve selected a few kazoo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wglass / lighthouse / tests / zookeeper_tests.py View on Github external
def test_report_down_no_such_node(self, mock_client):
        zk = ZookeeperDiscovery()
        zk.apply_config(
            {"hosts": ["zk01.int", "zk02.int"], "path": "/lighthouse"}
        )
        zk.connect()
        zk.connected.set()

        zk.client.delete.side_effect = exceptions.NoNodeError

        service = Mock(host="redis1")
        service.name = "webcache"

        zk.report_down(service, 6379)
github Morgan-Stanley / treadmill / lib / python / treadmill / zkutils.py View on Github external
# This will CLOSE the connection and throw a time-out exception after
    # trying max_tries
    zkclient.start(timeout=timeout)
    if chroot:
        acl = zkclient.make_default_acl(None)
        path = []
        chroot_components = chroot.split('/')
        while chroot_components:
            path.append(chroot_components.pop(0))
            if len(path) > 1:
                component = '/'.join(path)
                if not zkclient.exists(component):
                    # TODO: need to compare acls if component exists.
                    try:
                        zkclient.create(component, b'', makepath=True, acl=acl)
                    except kazoo.exceptions.KazooException:
                        _LOGGER.exception('chroot %s does not exist.', chroot)
                        raise

        zkclient.chroot = chroot

    return zkclient
github yahoo / Zake / zake / fake_client.py View on Github external
results.append(result[0])
                        data_watches.extend(result[1])
                        child_watches.extend(result[2])
            except StopTransaction as e:
                for i in range(0, len(results)):
                    results[i] = k_exceptions.RolledBackError()
                if isinstance(e, StopTransactionBadVersion):
                    results.append(k_exceptions.BadVersionError())
                if isinstance(e, StopTransactionNoExists):
                    results.append(k_exceptions.NoNodeError())
                while len(results) != len(self.operations):
                    results.append(k_exceptions.RuntimeInconsistency())
            except (NotImplementedError, AttributeError,
                    RuntimeError, ValueError, TypeError,
                    k_exceptions.ConnectionClosedError,
                    k_exceptions.SessionExpiredError):
                # Allow all these errors to bubble up.
                six.reraise(*sys.exc_info())
            except Exception as e:
                for i in range(0, len(results)):
                    results[i] = k_exceptions.RolledBackError()
                results.append(e)
                while len(results) != len(self.operations):
                    results.append(k_exceptions.RuntimeInconsistency())
            else:
                self._storage.inform(self._client, child_watches, data_watches)
                self.committed = True
            return results
github yahoo / Zake / zake / fake_client.py View on Github external
with try_txn_lock(self._lock):
            self._check_tx_state()
            # Delay all watch firing until we are sure that it succeeded.
            results = []
            child_watches = []
            data_watches = []
            try:
                with self._storage.transaction():
                    for op in self.operations:
                        result = op()
                        results.append(result[0])
                        data_watches.extend(result[1])
                        child_watches.extend(result[2])
            except StopTransaction as e:
                for i in range(0, len(results)):
                    results[i] = k_exceptions.RolledBackError()
                if isinstance(e, StopTransactionBadVersion):
                    results.append(k_exceptions.BadVersionError())
                if isinstance(e, StopTransactionNoExists):
                    results.append(k_exceptions.NoNodeError())
                while len(results) != len(self.operations):
                    results.append(k_exceptions.RuntimeInconsistency())
            except (NotImplementedError, AttributeError,
                    RuntimeError, ValueError, TypeError,
                    k_exceptions.ConnectionClosedError,
                    k_exceptions.SessionExpiredError):
                # Allow all these errors to bubble up.
                six.reraise(*sys.exc_info())
            except Exception as e:
                for i in range(0, len(results)):
                    results[i] = k_exceptions.RolledBackError()
                results.append(e)
github Nextdoor / ndserviceregistry / nd_service_registry / registration.py View on Github external
If the path does not exist, raise the exception and allow the
        _update_state() method to handle it.
        """
        try:
            log.debug('[%s] Registering...' % self._path)
            self._zk.retry(self._zk.create, self._path,
                           value=self._encoded_data,
                           ephemeral=self._ephemeral, makepath=False)
            log.info('[%s] Registered with data: %s' %
                     (self._path, self._encoded_data))
        except kazoo.exceptions.NoNodeError:
            # The underlying path does not exist. Raise this exception, and
            # _update_state() handle it.
            raise
        except kazoo.exceptions.NodeExistsError:
            # Node exists ... possible this callback got called multiple
            # times
            pass
        except kazoo.exceptions.NoAuthError:
            log.error('[%s] No authorization to create node.' % self._path)
        except Exception as e:
            log.error(RegistrationBase.GENERAL_EXC_MSG % (self._path, e))
github linkedin / iris / src / iris / coordinator / kazoo.py View on Github external
def get_current_master(self):
        try:
            contenders = self.lock.contenders()
        except kazoo.exceptions.KazooException:
            logger.exception('Failed getting contenders')
            return None

        if contenders:
            return self.address_to_tuple(contenders[0])
        else:
            return None
github openstack / taskflow / taskflow / jobs / backends / impl_zookeeper.py View on Github external
def state(self):
        owner = self.board.find_owner(self)
        job_data = {}
        try:
            raw_data, _data_stat = self._client.get(self.path)
            job_data = misc.decode_json(raw_data)
        except k_exceptions.NoNodeError:
            pass
        except k_exceptions.SessionExpiredError:
            excp.raise_with_cause(
                excp.JobFailure,
                "Can not fetch the state of %s,"
                " session expired" % (self.uuid))
        except self._client.handler.timeout_exception:
            excp.raise_with_cause(
                excp.JobFailure,
                "Can not fetch the state of %s,"
                " operation timed out" % (self.uuid))
        except k_exceptions.KazooException:
            excp.raise_with_cause(
                excp.JobFailure,
                "Can not fetch the state of %s,"
                " internal error" % (self.uuid))
        if not job_data:
            # No data this job has been completed (the owner that we might have
github openstack / kolla-ansible / docker / kolla-toolbox / kolla_zookeeper.py View on Github external
path=dict(required=True, type='str'),
            value=dict(required=False, default=None, type='str')
        )
    )

    try:
        zk_host = module.params.pop('zk_host')
        zk_port = module.params.pop('zk_port')
        path = module.params.pop('path')
        value = module.params.pop('value')

        changed = False
        with zk_connection(zk_host, zk_port) as zk:
            try:
                zk.get(path)
            except kazoo.exceptions.NoNodeError:
                if value is None:
                    zk.create(path, makepath=True)
                else:
                    zk.create(path, value=value.encode(), makepath=True)
                changed = True

        module.exit_json(changed=changed)
    except Exception:
        module.exit_json(failed=True, changed=True,
                         msg=repr(traceback.format_exc()))