diff --git a/monasca_api/healthcheck/kafka_check.py b/monasca_api/healthcheck/kafka_check.py index 6eae26ce5..74b8fb369 100644 --- a/monasca_api/healthcheck/kafka_check.py +++ b/monasca_api/healthcheck/kafka_check.py @@ -14,6 +14,7 @@ from oslo_config import cfg from oslo_log import log +from six import PY3 from monasca_api.healthcheck import base from monasca_common.kafka_lib import client @@ -59,6 +60,8 @@ class KafkaHealthCheck(base.BaseHealthCheck): topics = (CONF.kafka.metrics_topic, CONF.kafka.events_topic, CONF.kafka.alarm_state_transitions_topic) + if PY3: + topics = tuple(topic.encode('utf-8') for topic in topics) for topic in topics: topic_exists = topic in kafka_client.topics diff --git a/monasca_api/tests/test_kafka_health_check.py b/monasca_api/tests/test_kafka_health_check.py index a42632508..50626ceea 100644 --- a/monasca_api/tests/test_kafka_health_check.py +++ b/monasca_api/tests/test_kafka_health_check.py @@ -13,6 +13,7 @@ # under the License. import mock +from six import PY3 from monasca_common.kafka_lib import client @@ -26,14 +27,15 @@ CONF = config.CONF class TestKafkaHealthCheckLogic(base.BaseTestCase): mock_kafka_url = 'localhost:1234' - mocked_topics = 'test1' - mocked_event_topic = 'test2' - mocked_alarm_state_topic = 'test3' + mocked_topics = b'test1' + mocked_event_topic = b'test2' + mocked_alarm_state_topic = b'test3' mocked_config = { 'uri': mock_kafka_url, - 'metrics_topic': mocked_topics, - 'events_topic': mocked_event_topic, - 'alarm_state_transitions_topic': mocked_alarm_state_topic + 'metrics_topic': mocked_topics.decode('utf-8') if PY3 else mocked_topics, + 'events_topic': mocked_event_topic.decode('utf-8') if PY3 else mocked_event_topic, + 'alarm_state_transitions_topic': + mocked_alarm_state_topic.decode('utf-8') if PY3 else mocked_alarm_state_topic } def __init__(self, *args, **kwargs):