コード例 #1
0
 def mock_get_children(path: str):
     if not mock_exists(path):
         raise NoNodeError(f"{path} not found")
     return [
         p.replace(path + "/", "") for p in nodes.keys()
         if p.startswith(path) and p != path
     ]
コード例 #2
0
 def test_get_brokers_empty_cluster(self, mock_client):
     with ZK(self.cluster_config) as zk:
         zk.get_children = mock.Mock(side_effect=NoNodeError())
         actual_with_no_node_error = zk.get_brokers()
         expected_with_no_node_error = {}
         zk.get_children.assert_called_with("/brokers/ids")
         assert actual_with_no_node_error == expected_with_no_node_error
コード例 #3
0
 def _get(path):
     if path == '/brokers/ids/123':
         return '123', object()
     elif path == '/brokers/ids/321':
         return None, None
     else:
         raise NoNodeError()
コード例 #4
0
ファイル: test_zk.py プロジェクト: stephamon/otter
 def test_release_nonodeerror(self):
     """
     release_eff deletes child stored in self._node and sets it to None
     if delete raises NoNodeError
     """
     self.lock._node = "/testlock/prefix0000000001"
     seq = [(DeleteNode(path=self.lock._node,
                        version=-1), conste(NoNodeError()))]
     self.assertIsNone(perform_sequence(seq, self.lock.release_eff()))
     self.assertIsNone(self.lock._node)
コード例 #5
0
    def test_get_nonexistent_topic_config(self, mock_client):
        """
        Test getting configuration for topics that don't exist.
        """

        with ZK(self.cluster_config) as zk:
            zk.zk.get = mock.Mock(side_effect=NoNodeError())
            zk.get_topics = mock.Mock(return_value={})
            with pytest.raises(NoNodeError):
                zk.get_topic_config("some_topic")
コード例 #6
0
 def _check_version(self, path, version):
     if path not in self.nodes:
         return fail(NoNodeError("{} does not exist".format(path)))
     if version != -1:
         current_version = self.nodes[path][1]
         if current_version != version:
             return fail(BadVersionError(
                 "When operating on {}, version {} was specified by "
                 "version {} was found".format(path, version,
                                               current_version)))
コード例 #7
0
    def test_get_topic_config_8(self, mock_client):
        """
        Test getting configuration for topics created in Kafa prior to 0.9.0.
        """

        with ZK(self.cluster_config) as zk:
            zk.zk.get = mock.Mock(side_effect=NoNodeError())
            zk.get_topics = mock.Mock(return_value={"some_topic": {}})
            actual = zk.get_topic_config("some_topic")
            expected = {"config": {}}
            assert actual == expected
コード例 #8
0
ファイル: test_list_groups.py プロジェクト: me2d/kafka-utils
    def test_get_zookeeper_groups_error(self, mock_print):
        with self.mock_kafka_info() as (mock_ZK, _):
            obj = mock_ZK.return_value.__enter__.return_value
            obj.__exit__.return_value = False
            cluster_config = mock.Mock(zookeeper='some_ip')
            obj.get_children.side_effect = NoNodeError("Boom!")

            ListGroups.get_zookeeper_groups(cluster_config)
            mock_print.assert_any_call(
                "Error: No consumers node found in zookeeper",
                file=sys.stderr,
            )
コード例 #9
0
ファイル: runner.py プロジェクト: mackong/izk
 def _get(self, path):
     try:
         node_data, _ = self.zkcli.get(path)
     except NoNodeError:
         raise NoNodeError('%s does not exist' % (path))
     else:
         if node_data is not None:
             try:
                 node_data = node_data.decode('utf-8')
             except UnicodeDecodeError:
                 pass
             return node_data
コード例 #10
0
    def mock_delete(path: str):
        if not mock_exists(path):
            raise NoNodeError(f"{path} not found")

        # Recursive delete in any form
        for node_path, watchers in nodes.items():
            if node_path.startswith(path) and path != node_path:
                assert False, NOT_SUPPORTED_YET

        watchers = nodes.pop(path)
        for watcher in watchers:
            event = WatchedEvent(EventType.DELETED, path, KazooState.CONNECTED)
            watcher(event)
コード例 #11
0
    def test_unsubscribe_no_node_error(self, zk):
        zk_obj = zk.return_value
        zk_obj.delete_topic_partitions.side_effect = NoNodeError("Boom!")

        unsubscriber = ZookeeperUnsubscriber(zk_obj)
        unsubscriber.unsubscribe_topic(
            'some_group',
            'topic1',
            [0, 1, 2],
            self.topics_partitions,
        )

        assert zk_obj.delete_topic_partitions.called
コード例 #12
0
ファイル: runner.py プロジェクト: mackong/izk
    def _tree(self, path, level, full):
        padding = '│   ' * (level - 1) + '├── ' if level else ''
        print_path = path if full else (path.rsplit('/')[-1] or '/')

        try:
            nodes = self.zkcli.get_children(path)

            if nodes:
                print_path = colored.stylize(print_path, PARENT_ZNODE_STYLE)
            print(padding + print_path)

            for node in nodes:
                node = path + node if path == '/' else path + '/' + node
                self._tree(node, level+1, full)
        except NoNodeError as exc:
            raise NoNodeError('%s does not exist' % (path))
コード例 #13
0
ファイル: runner.py プロジェクト: mackong/izk
    def delete(self, path):
        """Delete a leaf ZNode

        Usage: delete <path>
        Example: delete /test/node

        """
        if ask_for_confirmation("You're about to delete %s. Proceed?" % (path)):
            try:
                self.zkcli.delete(path)
            except NotEmptyError:
                msg = (
                    'Cannot delete %s as it still contains nodes. '
                    'Use the `rmr` command if you really want to proceed.') % (path)
                raise NotEmptyError(msg)
            except NoNodeError:
                raise NoNodeError('%s does not exist' % (path))
コード例 #14
0
ファイル: runner.py プロジェクト: mackong/izk
    def ls(self, path):
        """Display the children of a ZNode

        Usage: ls <path>
        Example: ls /test

        """
        try:
            nodes = self.zkcli.get_children(path)
        except NoNodeError:
            raise NoNodeError('%s does not exist' % (path))

        nodes = sorted(nodes)
        fmt_nodes = []
        for node in nodes:
            if self.zkcli.get_children('/'.join((path, node))):
                node = colored.stylize(node, PARENT_ZNODE_STYLE)
            fmt_nodes.append(node)

        nodes = columnize(fmt_nodes, NODES_PER_LINE)
        return nodes
コード例 #15
0
    def safe_get_value(self, path: str) -> str:
        """
        Check that node exists and return its value if not empty or null.

        *Args:*\n
            _path_ - node path \n

        *Returns:*\n
            Value of the node \n

        *Raises:*\n
            _NoNodeError_ - parent node doesn't exist.\n

        *Example:*\n
            | Connect To Zookeeper | 127.0.0.1: 2181 |
            | Safe Get Value | /my/favorite/node |
        """
        if self.exists(path):
            self.check_node_value_existence(path)
            return self.get_value(path)
        raise NoNodeError(f'There is no node {path} in zookeeper')
コード例 #16
0
ファイル: slave.py プロジェクト: hubiyong/pykit
    def apply(self):
        self.zk_journal_id_set, _ = self.journal_id_set.get()

        for journal_id in self._get_uncommitted_journal_ids():

            try:
                if self.zk_journal_id_set[PURGED].has(journal_id):
                    raise NoNodeError(
                        'journal {jid:0>10} has been deleted'.format(
                            jid=journal_id))

                jour, _ = self.journal.get(journal_id)

            except NoNodeError:
                logger.warn('journal not found journal id: {jid:0>10}'.format(
                    jid=journal_id))
                self._set_all_records()
                return

            self.storage.apply_jour(jour)
            self.storage.add_to_journal_id_set(COMMITTED, journal_id)
コード例 #17
0
def zoo_keeper_client_with_almost_done(
        zoo_keeper_client: KazooClient) -> KazooClient:
    zoo_keeper_client.get_children.return_value = [DATASET_PATH]
    # And then it's gone!
    zoo_keeper_client.get.side_effect = NoNodeError()
    return zoo_keeper_client
コード例 #18
0
ファイル: test_task_store.py プロジェクト: zaitsevlab/paasta
    def test_update_task(self, mock_zk_client):
        zk_task_store = ZKTaskStore(
            service_name="a",
            instance_name="b",
            framework_id="c",
            system_paasta_config=mock.Mock(),
        )

        # Happy case - task exists, no conflict on update.
        fake_znodestat = mock.Mock(version=1)
        zk_task_store.zk_client.get.return_value = (
            '{"health": "healthy"}',
            fake_znodestat,
        )
        new_params = zk_task_store.update_task("task_id", is_draining=True)
        assert new_params.is_draining is True
        assert new_params.health == "healthy"

        # Second happy case - no task exists.
        fake_znodestat = mock.Mock(version=1)
        zk_task_store.zk_client.get.side_effect = NoNodeError()
        new_params = zk_task_store.update_task("task_id", is_draining=True)
        assert new_params.is_draining is True
        assert new_params.health is None

        # Someone changed our data out from underneath us.
        zk_task_store.zk_client.get.reset_mock()
        zk_task_store.zk_client.set.reset_mock()
        zk_task_store.zk_client.get.side_effect = [
            ('{"health": "healthy"}', mock.Mock(version=1)),
            ('{"health": "healthy", "offer": "offer"}', mock.Mock(version=2)),
            (
                '{"health": "healthy", "offer": "offer", "resources": "resources"}',
                mock.Mock(version=3),
            ),
        ]
        zk_task_store.zk_client.set.side_effect = [
            BadVersionError,
            BadVersionError,
            None,
        ]
        new_params = zk_task_store.update_task("task_id", is_draining=True)
        assert zk_task_store.zk_client.get.call_count == 3
        zk_task_store.zk_client.get.assert_has_calls([
            mock.call("/task_id"),
            mock.call("/task_id"),
            mock.call("/task_id")
        ])
        assert zk_task_store.zk_client.set.call_count == 3
        zk_task_store.zk_client.set.assert_has_calls([
            mock.call("/task_id", mock.ANY, version=1),
            mock.call("/task_id", mock.ANY, version=2),
            mock.call("/task_id", mock.ANY, version=3),
        ])
        assert new_params.is_draining is True
        assert new_params.health == "healthy"
        assert new_params.offer == "offer"
        assert new_params.resources == "resources"

        # Data wasn't there when we read it, but then was when we tried to create it
        zk_task_store.zk_client.get.reset_mock()
        zk_task_store.zk_client.set.reset_mock()
        zk_task_store.zk_client.create.reset_mock()
        zk_task_store.zk_client.get.side_effect = [
            NoNodeError,
            ('{"health": "healthy"}', mock.Mock(version=1)),
        ]
        zk_task_store.zk_client.create.side_effect = [NodeExistsError]
        zk_task_store.zk_client.set.side_effect = [None]
        new_params = zk_task_store.update_task("task_id", is_draining=True)
        assert zk_task_store.zk_client.get.call_count == 2
        zk_task_store.zk_client.get.assert_has_calls(
            [mock.call("/task_id"),
             mock.call("/task_id")])
        assert zk_task_store.zk_client.create.call_count == 1
        zk_task_store.zk_client.create.assert_has_calls(
            [mock.call("/task_id", mock.ANY)])
        assert zk_task_store.zk_client.set.call_count == 1
        zk_task_store.zk_client.set.assert_has_calls(
            [mock.call("/task_id", mock.ANY, version=1)])
        assert new_params.is_draining is True
        assert new_params.health == "healthy"
        assert new_params.offer is None
コード例 #19
0
ファイル: test_zk.py プロジェクト: stephamon/otter
 def hacked_set(path, value):
     return fail(NoNodeError())
コード例 #20
0
ファイル: test_zk.py プロジェクト: stephamon/otter
 def get(self, path):
     """Get content of the node, and stat info."""
     if path not in self.nodes:
         return fail(NoNodeError("{} does not exist".format(path)))
     content, version = self.nodes[path]
     return succeed((content, ZNodeStatStub(version=version)))
コード例 #21
0
 def test_get_miss(self, udp_db, zk):
     zk.get.side_effect = NoNodeError()
     res = udp_db.get(user_id="john", process_id="evi")
     assert res is None
コード例 #22
0
 def test_delete_miss(self, udp_db, zk):
     zk.delete.side_effect = NoNodeError()
     with pytest.raises(ProcessGraphNotFoundException):
         udp_db.delete(user_id="john", process_id="evi1")
コード例 #23
0
def zoo_keeper_client_no_node(zoo_keeper_client: KazooClient) -> KazooClient:
    zoo_keeper_client.exists.return_value = None
    zoo_keeper_client.get_children.side_effect = NoNodeError()
    return zoo_keeper_client