Skip to content

Commit e5de3b1

Browse files
committed
tests: include more readable mqtt logs in Get Logs keyword
Signed-off-by: Reuben Miller <reuben.d.miller@gmail.com>
1 parent 5dcb430 commit e5de3b1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/RobotFramework/libraries/ThinEdgeIO/ThinEdgeIO.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ def get_logs(
154154
except Exception as ex: # pylint: disable=broad-except
155155
log.warning("Failed to get device managed object. %s", ex)
156156

157+
# Log mqtt messages separately so it is easier to read/debug
158+
try:
159+
self.log_mqtt_messages("#", date_from)
160+
except Exception as ex:
161+
log.warning("Failed to retrieve mqtt logs. %s", ex, exc_info=True)
162+
157163
try:
158164
# Get agent log files (if they exist)
159165
log.info("tedge agent logs: /var/log/tedge/agent/*")
@@ -512,6 +518,18 @@ def _assert_mqtt_topic_messages(
512518

513519
return messages
514520

521+
def log_mqtt_messages(self, topic: str = "#", date_from: Union[datetime, float] = None, **kwargs):
522+
items = self.mqtt_match_messages(
523+
topic=topic,
524+
date_from=date_from,
525+
**kwargs,
526+
)
527+
entries = [
528+
f'{item["message"]["tst"].replace("+0000", ""):32} {item["message"]["topic"]:70} {bytes.fromhex(item["payload_hex"]).decode("utf8")}'
529+
for item in items
530+
]
531+
log.info("---- mqtt messages ----\n%s", "\n".join(entries))
532+
515533
@keyword("Should Have MQTT Messages")
516534
def mqtt_should_have_topic(
517535
self,

0 commit comments

Comments
 (0)