Skip to content

Commit

Permalink
Merge pull request #2410 from reubenmiller/tests-print-mqtt-logs
Browse files Browse the repository at this point in the history
tests: include more readable mqtt logs in Get Logs keyword
  • Loading branch information
reubenmiller authored Nov 6, 2023
2 parents 1373b00 + 98b5c91 commit efd5d33
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions tests/RobotFramework/libraries/ThinEdgeIO/ThinEdgeIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def get_logs(
except Exception as ex: # pylint: disable=broad-except
log.warning("Failed to get device managed object. %s", ex)

# Log mqtt messages separately so it is easier to read/debug
try:
self.log_mqtt_messages("#", date_from)
except Exception as ex:
log.warning("Failed to retrieve mqtt logs. %s", ex, exc_info=True)

try:
# Get agent log files (if they exist)
log.info("tedge agent logs: /var/log/tedge/agent/*")
Expand Down Expand Up @@ -495,8 +501,7 @@ def _assert_mqtt_topic_messages(
)

messages = [
bytes.fromhex(item["payload_hex"]).decode("utf8")
# item["message"]["payload"]
bytes.fromhex(item["payload_hex"]).decode("utf8", errors="replace")
for item in items
]

Expand All @@ -512,6 +517,18 @@ def _assert_mqtt_topic_messages(

return messages

def log_mqtt_messages(self, topic: str = "#", date_from: Union[datetime, float] = None, **kwargs):
items = self.mqtt_match_messages(
topic=topic,
date_from=date_from,
**kwargs,
)
entries = [
f'{item["message"]["tst"].replace("+0000", ""):32} {item["message"]["topic"]:70} {bytes.fromhex(item["payload_hex"]).decode("utf8", errors="replace")}'
for item in items
]
log.info("---- mqtt messages ----\n%s", "\n".join(entries))

@keyword("Should Have MQTT Messages")
def mqtt_should_have_topic(
self,
Expand Down

1 comment on commit efd5d33

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
356 0 3 356 100 59m0.878s

Please sign in to comment.