From 7f496744399adfbe5cd283ae3f49dec7c55b88a1 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Fri, 15 Nov 2019 15:13:32 -0800 Subject: [PATCH] KAFKA-8746: Kibosh must handle an empty JSON string from Trogdor (#7155) When Trogdor wants to clear all the faults injected to Kibosh, it sends the empty JSON object {}. However, Kibosh expects {"faults":[]} instead. Kibosh should handle the empty JSON object, since that's consistent with how Trogdor handles empty JSON fields in general (if they're empty, they can be omitted). We should also have a test for this. Reviewers: David Arthur , Stanislav Kozlovski --- tests/docker/Dockerfile | 4 ++-- tests/kafkatest/services/trogdor/kibosh.py | 9 ++++++--- tests/kafkatest/tests/tools/kibosh_test.py | 10 +++++++--- vagrant/base.sh | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/docker/Dockerfile b/tests/docker/Dockerfile index 66d5c4a6779..b83097b8ffb 100644 --- a/tests/docker/Dockerfile +++ b/tests/docker/Dockerfile @@ -71,8 +71,8 @@ RUN curl -s "$KAFKA_MIRROR/kafka-streams-2.2.1-test.jar" -o /opt/kafka-2.2.1/lib RUN curl -s "$KAFKA_MIRROR/kafka-streams-2.3.0-test.jar" -o /opt/kafka-2.3.0/libs/kafka-streams-2.3.0-test.jar # The version of Kibosh to use for testing. -# If you update this, also update vagrant/base.sy -ARG KIBOSH_VERSION="d85ac3ec44be0700efe605c16289fd901cfdaa13" +# If you update this, also update vagrant/base.sh +ARG KIBOSH_VERSION="8841dd392e6fbf02986e2fb1f1ebf04df344b65a" # Install Kibosh RUN apt-get install fuse diff --git a/tests/kafkatest/services/trogdor/kibosh.py b/tests/kafkatest/services/trogdor/kibosh.py index 47c119e4091..788486fdb37 100644 --- a/tests/kafkatest/services/trogdor/kibosh.py +++ b/tests/kafkatest/services/trogdor/kibosh.py @@ -133,9 +133,12 @@ class KiboshService(Service): :param node: The node. :param spec: An array of FaultSpec objects describing the faults. """ - fault_array = [spec.kibosh_message for spec in specs] - obj = { 'faults': fault_array } - obj_json = json.dumps(obj) + if len(specs) == 0: + obj_json = "{}" + else: + fault_array = [spec.kibosh_message for spec in specs] + obj = { 'faults': fault_array } + obj_json = json.dumps(obj) node.account.create_file(self.control_path, obj_json) def get_fault_json(self, node): diff --git a/tests/kafkatest/tests/tools/kibosh_test.py b/tests/kafkatest/tests/tools/kibosh_test.py index d31be873dc9..f81fe93d1c3 100644 --- a/tests/kafkatest/tests/tools/kibosh_test.py +++ b/tests/kafkatest/tests/tools/kibosh_test.py @@ -70,12 +70,16 @@ class KiboshTest(Test): [self.nodes[0].name], KiboshTest.TARGET, "/foo", 12) node = self.nodes[0] - def check(self, node): + def check(self, node, expected_json): fault_json = self.kibosh.get_fault_json(node) - expected_json = json.dumps({"faults": [spec.kibosh_message]}) self.logger.info("Read back: [%s]. Expected: [%s]." % (fault_json, expected_json)) return fault_json == expected_json + wait_until(lambda: check(self, node, '{"faults":[]}'), + timeout_sec=10, backoff_sec=.2, err_msg="Failed to read back initial empty fault array.") self.kibosh.set_faults(node, [spec]) - wait_until(lambda: check(self, node), + wait_until(lambda: check(self, node, json.dumps({"faults": [spec.kibosh_message]})), timeout_sec=10, backoff_sec=.2, err_msg="Failed to read back fault array.") + self.kibosh.set_faults(node, []) + wait_until(lambda: check(self, node, "{}"), + timeout_sec=10, backoff_sec=.2, err_msg="Failed to read back final empty fault array.") diff --git a/vagrant/base.sh b/vagrant/base.sh index 2445e12cfd3..866a56a6aaf 100755 --- a/vagrant/base.sh +++ b/vagrant/base.sh @@ -18,7 +18,7 @@ set -ex # The version of Kibosh to use for testing. # If you update this, also update tests/docker/Dockerfile -export KIBOSH_VERSION=d85ac3ec44be0700efe605c16289fd901cfdaa13 +export KIBOSH_VERSION=8841dd392e6fbf02986e2fb1f1ebf04df344b65a path_to_jdk_cache() { jdk_version=$1