From 1ed8a268819b19fe959057da1ab88c0b293294a1 Mon Sep 17 00:00:00 2001 From: Rogger Vasquez Date: Wed, 6 Jul 2022 16:26:53 -0500 Subject: [PATCH 1/2] rpk: fix add-partition error handling bug --- src/go/rpk/pkg/cli/cmd/topic/add_partitions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go b/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go index fbabe92a3772..d6b208d78aa0 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go +++ b/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go @@ -62,7 +62,7 @@ func NewAddPartitionsCommand(fs afero.Fs) *cobra.Command { if errors.Is(e, kerr.InvalidPartitions) && num > 0 { msg = fmt.Sprintf("INVALID_PARTITIONS: unable to add %d partitions due to hardware constraints", num) } else { - msg = err.Error() + msg = e.Error() } exit1 = true } From 446cd282c7a853344759aaa7d271e3689b1acbb8 Mon Sep 17 00:00:00 2001 From: Rogger Vasquez Date: Wed, 6 Jul 2022 16:42:38 -0500 Subject: [PATCH 2/2] tests: add test for unfeasible number of partitions --- tests/rptest/clients/rpk.py | 4 ++++ tests/rptest/tests/rpk_topic_test.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/tests/rptest/clients/rpk.py b/tests/rptest/clients/rpk.py index 4013e9958ebc..e248eae95eb9 100644 --- a/tests/rptest/clients/rpk.py +++ b/tests/rptest/clients/rpk.py @@ -132,6 +132,10 @@ def create_topic(self, topic, partitions=1, replicas=None, config=None): self._check_stdout_success(output) return output + def add_partitions(self, topic, partitions): + cmd = ["add-partitions", topic, "-n", str(partitions)] + return self._run_topic(cmd) + def _check_stdout_success(self, output): """ Helper for topic operations where rpk does not surface errors diff --git a/tests/rptest/tests/rpk_topic_test.py b/tests/rptest/tests/rpk_topic_test.py index ecfcbcb5fbfa..45811e87abab 100644 --- a/tests/rptest/tests/rpk_topic_test.py +++ b/tests/rptest/tests/rpk_topic_test.py @@ -46,6 +46,13 @@ def test_create_topic_with_invalid_config(self, config_type): lambda e: "INVALID_CONFIG" in str(e)): out = self._rpk.create_topic("topic", config={config_type: "foo"}) + @cluster(num_nodes=1) + def test_add_unfeasible_number_of_partitions(self): + with expect_exception(RpkException, + lambda e: "INVALID_REQUEST" in str(e)): + self._rpk.create_topic("topic") + out = self._rpk.add_partitions("topic", 2000000000000) + @cluster(num_nodes=4) def test_produce(self): topic = 'topic'