Bug fixes

Change-Id: I67349475a93d523795bbeeb28e45a0d3e416028f
diff --git a/common/utils/consulhelpers.py b/common/utils/consulhelpers.py
index 681aaf4..2f1efd8 100644
--- a/common/utils/consulhelpers.py
+++ b/common/utils/consulhelpers.py
@@ -52,4 +52,4 @@
 
 
 if __name__ == '__main__':
-    get_endpoint_from_consul('10.100.198.220:8500', 'kafka')
+    print get_endpoint_from_consul('10.100.198.220:8500', 'kafka')
diff --git a/kafka/kafka-consumer.py b/kafka/kafka-consumer.py
index 7ed354d..3f405d8 100644
--- a/kafka/kafka-consumer.py
+++ b/kafka/kafka-consumer.py
@@ -20,7 +20,7 @@
 
 
 class ConsumerExample(object):
-    def __init__(self, consul_endpoint, topic='voltha-heartbeat', runtime=60):
+    def __init__(self, consul_endpoint, topic="heartbeat.voltha", runtime=60):
         self.topic = topic
         self.runtime = runtime
         self.kafka_endpoint = get_endpoint_from_consul(consul_endpoint,
@@ -55,6 +55,7 @@
             c = Consumer(self._client, self.topic, partition,
                          self.msg_processor)
             self._consumer_list.append(c)
+            # log.info('consumer-started', topic=self.topic, partition=partition)
             d = c.start(OFFSET_LATEST)
             d.addBoth(_note_consumer_stopped, c)
             self._consumer_d_list.append(d)
@@ -93,7 +94,8 @@
 
     def msg_processor(self, consumer, msglist):
         for msg in msglist:
-            log.info('proc', msg=msg)
+            log.info(msg)
+
 
 def parse_options():
     parser = ArgumentParser("Consume kafka messages")
@@ -103,7 +105,7 @@
 
     parser.add_argument("-t", "--topic",
                         help="topic to listen from",
-                        default='voltha-heartbeat')
+                        default="heartbeat.voltha")
 
     parser.add_argument("-r", "--runtime",
                         help="total runtime",
@@ -117,6 +119,7 @@
                '%(levelname)s:%(process)d:%(message)s',
         level=logging.INFO
     )
+
     args = parse_options()
 
     consumer_example = ConsumerExample(args.consul, args.topic,
diff --git a/netconf/protoc_plugins/proto2yang.py b/netconf/protoc_plugins/proto2yang.py
index 7539efb..fc887a6 100755
--- a/netconf/protoc_plugins/proto2yang.py
+++ b/netconf/protoc_plugins/proto2yang.py
@@ -35,7 +35,6 @@
 
 import sys
 
-from jinja2 import Template
 from google.protobuf.compiler import plugin_pb2 as plugin
 from google.protobuf.descriptor_pb2 import DescriptorProto, \
     FieldDescriptorProto
@@ -45,16 +44,20 @@
 
 from google.protobuf.descriptor import FieldDescriptor
 
-template_yang = Template("""
+import jinja2
+env = jinja2.Environment(extensions=["jinja2.ext.do",], trim_blocks=True, lstrip_blocks=True)
+
+template_yang = env.from_string("""
 module ietf-{{ module.name }} {
 
     {% macro set_module_prefix(type) %}
+        {% set found = [] %}
         {% for t in module.data_types %}
             {% if t.type == type %}
                 {% if t.module != module.name %} {{ t.module }}:{{ type }};
                 {% else %} {{ type }};
                 {% endif %}
-                {% set found=True %}
+                {% do found.append(1) %}
             {% endif %}
         {% if loop.last %}
             {% if not found %} {{ type }}; {% endif %}
@@ -252,7 +255,7 @@
 
     {% endfor %}
 }
-""", trim_blocks=True, lstrip_blocks=True)
+""")
 
 
 def traverse_field_options(fields, prefix):
diff --git a/tests/itests/docutests/build_md_test.py b/tests/itests/docutests/build_md_test.py
index a16efe7..d8c888c 100644
--- a/tests/itests/docutests/build_md_test.py
+++ b/tests/itests/docutests/build_md_test.py
@@ -205,8 +205,7 @@
                 'grpc_server.start {event: started',
                 'main.<lambda> {event: twisted-reactor-started',
                 'main.startup_components {event: started-internal-services,',
-                'kafka_proxy.send_message {event: Sending message Heartbeat '
-                'message',
+                'kafka_proxy.start {event: started,',
                 'coordinator._backoff {retry_in: 5, event: consul-not-up,'
             ]
 
@@ -398,7 +397,8 @@
             expected_services = ['consul-rest', 'fluentd-intake',
                                  'chameleon-rest', 'voltha-grpc',
                                  'voltha-health',
-                                 'consul-8600', 'zookeeper', 'consul', 'kafka']
+                                 'consul-8600', 'zookeeper', 'consul',
+                                 'kafka']
 
             cmd = command_defs['consul_get_services']
             out, err, rc = run_command_to_completion_with_raw_stdout(cmd)
@@ -441,7 +441,7 @@
 
             # Verify kafka client is receiving the messages
             print "Verify kafka client is receiving the heartbeat messages ..."
-            expected_pattern = ['voltha-heartbeat', 'Heartbeat message']
+            expected_pattern = ['heartbeat.voltha', 'heartbeat']
             cmd = command_defs['kafka_client_run_10_secs']
             kafka_client_output = run_long_running_command_with_timeout(cmd,
                                                                         20)
@@ -461,7 +461,7 @@
                   "..."
             expected_output = ['voltha_1', 'fluentd_1', 'consul_1',
                                'registrator_1', 'kafka_1', 'zookeeper_1',
-                               'chameleon_1']
+                               'chameleon_1', 'ofagent_1', 'netconf_1']
             cmd = command_defs['docker_compose_logs']
             docker_compose_logs = run_long_running_command_with_timeout(cmd, 5,
                                                                         0)
@@ -722,8 +722,8 @@
         expected_output = [
             "(.*)registrator_1(.*)Listening for Docker events",
             "(.*)voltha_1(.*)main.heartbeat {status: up, uptime:",
-            "(.*)voltha_1(.*)kafka_proxy.send_message {event: Successfully "
-            "sent message Heartbeat message",
+            "(.*)voltha_1(.*)kafka_proxy.send_message(.*)event: "
+            "sent-kafka-msg",
             "(.*)fluentd_1(.*)listening fluent socket on",
             "(.*)chameleon_1(.*)main.startup_components {event: "
             "started-internal-services, instance_id: compose_chameleon_1}",
diff --git a/tests/itests/docutests/test_utils.py b/tests/itests/docutests/test_utils.py
index a0b2422..f987b0f 100644
--- a/tests/itests/docutests/test_utils.py
+++ b/tests/itests/docutests/test_utils.py
@@ -81,8 +81,9 @@
             if return_word_number_x_of_each_line != -1:
                 ansi_escape = re.compile(r'\x1b[^m]*m')
                 line = ansi_escape.sub('', line)
-                captured_stdout.append(
-                    line.split()[return_word_number_x_of_each_line])
+                if len(line.split()) > return_word_number_x_of_each_line:
+                    captured_stdout.append(
+                        line.split()[return_word_number_x_of_each_line])
             else:
                 captured_stdout.append(line)
             if time.time() - t0 > timeout: