Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.zookeeper = KazooClient(hosts="%s:%d" % zookeeper_endpoint.address)
self.zookeeper.start()
try:
self.zookeeper.delete(TEST_NODE_PATH)
except NoNodeError:
pass
self.zookeeper.create(TEST_NODE_PATH, b"")
base_path=ZK_USERS_PATH,
uid=uid
)
try:
log.info('Deleting ZK path `%s`', zk_uid_path)
zk.delete(zk_uid_path)
except kazoo.exceptions.NoNodeError:
# It is possible that the user was removed by another master running
# this script.
log.warn('ZK node `%s` no longer exists.', zk_uid_path)
# Finally we can remove /dcos/users which should be empty at this point
try:
log.info('Removing legacy ZK path `%s`.', ZK_USERS_PATH)
zk.delete(ZK_USERS_PATH)
except kazoo.exceptions.NoNodeError:
# It is possible that the user was removed by another master running
# this script.
log.warn('ZK node `%s` no longer exists.', ZK_USERS_PATH)
zk.stop()
log.info('Migration completed.')
def _lock_and_get_entry(self, entry_node: str) -> Optional[Tuple[bytes, ZnodeStat]]:
try:
lock_path = f"{self.locks_path}/{entry_node}"
self.locked_entry_nodes.add(entry_node)
self.client.create(lock_path, value=self.id, ephemeral=True)
except NodeExistsError:
self.locked_entry_nodes.add(entry_node)
return None
try:
return self.client.get(f"{self.entries_path}/{entry_node}")
except NoNodeError:
self.client.delete(lock_path)
return None
def _delete_group_handler(async_result, timeout,
timeout_exception, group_id):
try:
async_result.get(block=True, timeout=timeout)
except timeout_exception as e:
utils.raise_with_cause(coordination.OperationTimedOut,
encodeutils.exception_to_unicode(e),
cause=e)
except exceptions.NoNodeError:
raise coordination.GroupNotCreated(group_id)
except exceptions.NotEmptyError:
raise coordination.GroupNotEmpty(group_id)
except exceptions.ZookeeperError as e:
utils.raise_with_cause(tooz.ToozError,
encodeutils.exception_to_unicode(e),
cause=e)
hints = \
{
'id': kid,
'cluster': cluster
}
#
# - the number displayed by the tools (e.g shared.docker-proxy #4) is that monotonic integer
# derived from zookeeper
#
hints.update(json.loads(js))
seq = hints['seq']
if not subset or seq in subset:
pods['%s #%d' % (cluster, seq)] = hints
except NoNodeError:
pass
ms = 1000 * (time.time() - ts)
logger.debug('<- zookeeper (%d pods, %d ms)' % (len(pods), int(ms)))
return pods
def get_boost_values(zk_boost_path: str, zk: KazooClient) -> BoostValues:
# Default values, non-boost.
end_time: float = 0
boost_factor: float = 1.0
expected_load: float = 0
try:
end_time = float(zk.get(zk_boost_path + "/end_time")[0].decode("utf-8"))
boost_factor = float(zk.get(zk_boost_path + "/factor")[0].decode("utf-8"))
expected_load = float(
zk.get(zk_boost_path + "/expected_load")[0].decode("utf-8")
)
except NoNodeError:
# If we can't read boost values from zookeeper
return BoostValues(end_time=0, boost_factor=1.0, expected_load=0)
return BoostValues(
end_time=end_time, boost_factor=boost_factor, expected_load=expected_load
)
def test_unset_node(self):
path = '%s/test_unset_node' % self.sandbox
self.ndsr.set_node(path)
self.ndsr.unset(path)
self.assertRaises(exceptions.NoNodeError,
self.ndsr._zk.get, path)
def delete(self, path, version=-1, recursive=False):
if not isinstance(path, six.string_types):
raise TypeError("path must be a string")
data_watches = []
child_watches = []
path = utils.normpath(path)
with self.storage.lock:
if path not in self.storage:
raise k_exceptions.NoNodeError("Node %s does not exist"
% (path))
path_version = self.storage[path]['version']
if version != -1 and path_version != version:
raise k_exceptions.BadVersionError("Version mismatch"
" (%s != %s)"
% (version, path_version))
if recursive:
paths = [path]
children = self.storage.get_children(path, only_direct=False)
for child_path in six.iterkeys(children):
paths.append(child_path)
else:
children = self.storage.get_children(path, only_direct=False)
if children:
raise k_exceptions.NotEmptyError("Path %s is not-empty"
" (%s children exist)"
def exists_completion(result):
try:
stat = result.get()
except self.DISCONNECT_EXCEPTIONS:
self._once(KazooState.CONNECTED, wait_exists)
return
except ke.NoNodeError:
wait_exists()
return
except ke.KazooException as e:
log.warning('Unexpected exists_completion result: (%s)%s' % (type(e), e))
return
if stat:
do_monitor()
replay = self.replay_name[seed]
if seed in self.protected_access and len(self.protected_access[seed]) > 0:
pa_pid, pa_server = self.findPidServerFromSeed(seed)
for pa in self.protected_access[seed]:
json_dump = json.dumps(pa, default=utils.jdefault)
self.addLogEvent(pa_server, pa_pid, "CB", forensicEvents.USER_MEM_LEAK,
json_dump , low_priority=True)
if pa.cpl == 0 and pa.length >=4 and self.master_cfg.track_protected_access:
self.lgr.critical('4 byte write by kernel from magic page %s' % json_dump)
log = self.getEntry(seed, True)
self.lgr.debug('targetLog Logging cb %s replay %s size of log is %d' % (cb, replay, len(log)))
self.lgr.debug(log)
if not debugBinary:
try:
self.rpm.replayDone(cb, replay, log, self.rules)
except kazoo.exceptions.NoNodeError:
self.lgr.error('could not create replay done node');
self.ts.pop(seed, None)
if debugBinary and not self.debug_event[seed]:
# add throw to let any waiting ida clients know nothing landed. dumb up the cb suffix
self.throw_mgr.addThrow(cb+'_01', replay, self.szk.getTargetName(), 'no faults', 'NO_EVENT')
self.rpm.doneDebug(replay)
elif seed in self.replay_name:
replay = self.replay_name[seed]
self.lgr.debug('targetLog, player/pov <%s> exits before cb starts? rules is %s' % (replay, self.rules))
self.previous_replay_name[seed] = replay
if self.cfg.cfe:
event_type = forensicEvents.LAUNCH_ERROR
self.addLogEvent(cell_name, pid, comm, event_type, 'player exits before cb starts, TLV error?')
''' call it done '''
log = self.getEntry(seed, True)
package = self.szk.getLatestLocalPackage(self.lgr)