def create(self, path, value=b"", acl=None, ephemeral=False, sequence=False, makepath=False): if not isinstance(path, six.string_types): raise TypeError("path must be a string") if not isinstance(value, six.binary_type): raise TypeError("value must be a byte string") if acl: raise NotImplementedError(_NO_ACL_MSG) data_watches = [] child_watches = [] with self.storage.lock: if sequence: path = utils.normpath(path, keep_trailing=True) else: path = utils.normpath(path, keep_trailing=False) if makepath: for parent_path in utils.partition_path(path)[0:-1]: if parent_path not in self.storage: result = self.create(parent_path) data_watches.extend(result[1]) child_watches.extend(result[2]) created, parents, path = self.storage.create( path, value=value, sequence=sequence, ephemeral=ephemeral, session_id=self.session_id) if parents: event = k_states.WatchedEvent(type=k_states.EventType.CHILD, state=k_states.KeeperState.CONNECTED, path=path) child_watches.append((parents, event)) if created: event = k_states.WatchedEvent(type=k_states.EventType.CREATED, state=k_states.KeeperState.CONNECTED, path=path) data_watches.append(([path], event)) return (path, data_watches, child_watches)
def ensure_path(self, path): self.verify() if not isinstance(path, six.string_types): raise TypeError("path must be a string") path = utils.normpath(path) for piece in utils.partition_path(path): try: self.create(piece) except k_exceptions.NodeExistsError: pass
def setUp(self): super(ZakeJobboardTest, self).setUp() self.client, self.board = self._create_board() self.bad_paths = [self.board.path, self.board.trash_path] self.bad_paths.extend(zake_utils.partition_path(self.board.path))
def setUp(self): super(TestZookeeperJobs, self).setUp() self.client, self.board = create_board() self.addCleanup(self.board.close) self.bad_paths = [self.board.path] self.bad_paths.extend(zake_utils.partition_path(self.board.path))