Exemplo n.º 1
0
class RpkClusterTest(RedpandaTest):
    def __init__(self, ctx):
        super(RpkClusterTest, self).__init__(test_context=ctx)
        self._ctx = ctx
        self._rpk = RpkTool(self.redpanda)

    @cluster(num_nodes=3)
    def test_cluster_info(self):
        def condition():
            brokers = self._rpk.cluster_info()

            if len(brokers) != len(self.redpanda.nodes):
                return False

            advertised_addrs = self.redpanda.brokers()

            ok = True
            for b in brokers:
                ok = ok and \
                    b.address in advertised_addrs

            return ok

        wait_until(condition,
                   timeout_sec=10,
                   backoff_sec=1,
                   err_msg="No brokers found or output doesn't match")
Exemplo n.º 2
0
 def test_metadata_request_contains_all_brokers(self):
     """
     Check if broker list returned from metadata request is complete
     """
     wait_until(lambda: self.controller_present, 10, 1)
     rpk = RpkTool(self.redpanda)
     nodes = rpk.cluster_info()
     assert len(nodes) == 3
     all_ids = [self.redpanda.idx(n) for n in self.redpanda.nodes]
     returned_node_ids = [n.id for n in nodes]
     assert sorted(all_ids) == sorted(returned_node_ids)
Exemplo n.º 3
0
    def test_metadata_request_does_not_contain_failed_node(
            self, failure, node):
        """
        Check if broker list returned from metadata request does not contain node
        which is not alive
        """
        # validate initial conditions
        wait_until(lambda: self.controller_present, 10, 1)
        rpk = RpkTool(self.redpanda)
        nodes = rpk.cluster_info()
        assert len(nodes) == 3
        redpanda_ids = [self.redpanda.idx(n) for n in self.redpanda.nodes]
        node_ids = [n.id for n in nodes]
        assert sorted(redpanda_ids) == sorted(node_ids)

        def get_node():
            if node == 'controller':
                return self.redpanda.controller()
            else:
                n = self.redpanda.nodes[0]
                while n == self.redpanda.controller():
                    n = random.choice(self.redpanda.nodes)
                return n

        node = get_node()
        node_id = self.redpanda.idx(node)
        self.redpanda.logger.info(
            f"Injecting failure on node {node.account.hostname} with id: {node_id}",
        )
        with FailureInjector(self.redpanda) as fi:
            if failure == "isolate":
                fi.inject_failure(
                    FailureSpec(FailureSpec.FAILURE_ISOLATE, node))
            else:
                self.redpanda.stop_node(node)

            rpk = RpkTool(self.redpanda)

            def contains_only_alive_nodes():
                nodes = rpk.cluster_info()
                returned_ids = [n.id for n in nodes]
                return len(nodes) == 2 and node_id not in returned_ids

            wait_until(contains_only_alive_nodes, 30, 1)
Exemplo n.º 4
0
class RpkClusterTest(RedpandaTest):
    def __init__(self, ctx):
        super(RpkClusterTest, self).__init__(test_context=ctx)
        self._ctx = ctx
        self._rpk = RpkTool(self.redpanda)

    @cluster(num_nodes=3)
    def test_cluster_info(self):
        def condition():
            brokers = self._rpk.cluster_info()

            if len(brokers) != len(self.redpanda.nodes):
                return False

            advertised_addrs = self.redpanda.brokers()

            ok = True
            for b in brokers:
                ok = ok and \
                    b.address in advertised_addrs

            return ok

        wait_until(condition,
                   timeout_sec=10,
                   backoff_sec=1,
                   err_msg="No brokers found or output doesn't match")

    @cluster(num_nodes=3)
    def test_debug_bundle(self):
        # The main RpkTool helper runs rpk on the test runner machine -- debug
        # commands are run on redpanda nodes.

        working_dir = "/tmp"
        node = self.redpanda.nodes[0]

        rpk_remote = RpkRemoteTool(self.redpanda, node)
        output = rpk_remote.debug_bundle(working_dir)
        lines = output.split("\n")

        # On error, rpk bundle returns 0 but writes error description to stdout
        output_file = None
        error_lines = []
        any_errs = False
        for l in lines:
            self.logger.info(l)
            if l.strip().startswith("* "):
                error_lines.append(l)
            elif 'errors occurred' in l:
                any_errs = True
            else:
                m = re.match("^Debug bundle saved to '(.+)'$", l)
                if m:
                    output_file = m.group(1)

        # Avoid false passes if our error line scraping gets broken
        # by a format change.
        if any_errs:
            assert error_lines

        filtered_errors = []
        for l in error_lines:
            if "dmidecode" in l:
                # dmidecode doesn't work in ducktape containers, ignore
                # errors about it.
                continue
            else:
                self.logger.error(f"Bad output line: {l}")
                filtered_errors.append(l)

        assert not filtered_errors
        assert output_file is not None

        output_path = os.path.join(working_dir, output_file)
        node.account.copy_from(output_path, working_dir)

        zf = zipfile.ZipFile(output_path)
        files = zf.namelist()
        assert 'redpanda.yaml' in files
        assert 'redpanda.log' in files
        assert 'prometheus-metrics.txt' in files

    @cluster(num_nodes=3)
    def test_get_config(self):
        rpk_bin = self.redpanda.find_binary('rpk')
        node = self.redpanda.nodes[0]

        config_output = self._rpk.admin_config_print(node)

        # Check the output is valid json
        parsed = json.loads("".join(config_output))

        # Check the output contains at least one known config property
        assert 'enable_transactions' in parsed