Fix incorrect error when topic not found

Story: 2003668
Task: 26186
Change-Id: I4df9e4373544a26c41ff4b0e8f6a0d68eccd0d78
This commit is contained in:
Adrian Czarnecki 2018-09-05 11:41:33 +02:00
parent 1731018f06
commit 3f530c85e8
2 changed files with 7 additions and 7 deletions

View File

@ -61,9 +61,9 @@ class KafkaHealthCheck(base.BaseHealthCheck):
CONF.kafka.alarm_state_transitions_topic)
for topic in topics:
for_topic = topic in kafka_client.topic_partitions
if not for_topic:
error_str = 'Kafka: Topic {0} not found'.format(for_topic)
topic_exists = topic in kafka_client.topics
if not topic_exists:
error_str = 'Kafka: Topic {0} not found'.format(topic)
LOG.error(error_str)
return False, str(error_str)
return True, 'OK'

View File

@ -59,7 +59,7 @@ class TestKafkaHealthCheckLogic(base.BaseTestCase):
@mock.patch('monasca_api.healthcheck.kafka_check.client.KafkaClient')
def test_should_fail_missing_topic(self, kafka_client):
kafka = mock.Mock()
kafka.topic_partitions = ['topic1']
kafka.topics = ['topic1']
kafka_client.return_value = kafka
kafka_health = kc.KafkaHealthCheck()
@ -71,9 +71,9 @@ class TestKafkaHealthCheckLogic(base.BaseTestCase):
@mock.patch('monasca_api.healthcheck.kafka_check.client.KafkaClient')
def test_should_pass(self, kafka_client):
kafka = mock.Mock()
kafka.topic_partitions = (self.mocked_topics,
self.mocked_event_topic,
self.mocked_alarm_state_topic)
kafka.topics = [self.mocked_topics,
self.mocked_event_topic,
self.mocked_alarm_state_topic]
kafka_client.return_value = kafka
kafka_health = kc.KafkaHealthCheck()