Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: fix issues 198 & 203 #204

Merged

Conversation

ymorin-orange
Copy link
Member

@ymorin-orange ymorin-orange commented Nov 8, 2024

Changes:


How to test:

  1. The fix for python/status: crash when modem not fully connected #198 is hard to validate, as the condition seldom occurs in practice...
  2. Test the fix for python/its-vehicle: messages not propagated from remote broker to local broker #203:
    1. install its-vehicle and its dependencies
    2. configure its-vehicle with both a remote and a local MQTT broker
    3. run its-vehicle
    4. observe the quadkeys in the topic of messages received by the remote broker
    5. send a message to the remote broker, on a topic which quadkeys is close to the messages above

Expected results:

  1. its-status does not crash anymore
  2. the message sent in step v. is received on the local broker

Some modems will report partial cellular connection details, especially
during the startup phase, at which point the modem considers the
connection to be established, but does not yet report what techniology
is used.

Fixes: Orange-OpenSource#198

Signed-off-by: Yann E. MORIN <yann.morin@orange.com>
Commit c482cb1 (python/vehicle: use iot3.core.mqtt) introduced a
regression in the propagation of messages from the remote broker to
the local one.

The API for the IoT3 Core SDK extensively uses keywords rather than
positional parameters, and although this was properly accounted when
publishing messages on the remote broker, this was overlooked when
publishing messages on the local broker.

Such an issue would have raised an exception, and we would have caught
it quite easily. Alas, in an attempt at being robust when decoding the
received messages, we decided for a blanket coverage of all exceptions,
no matter what. This indeed hid the TypeError exception that is raised
when improperly calling the SDK...

So, now, we could just catch KeyError when looking up the source_uuid
field, but that would assume the message was decoded as a dict, which we
have no guarantee it was. If that were not the case, i.e.e the message
is not an ITS message, and contains any other JSON object that is not a
dictionary, that would _also_ raise TypeError, so we would have to catch
it anyway to ignore it. And we would not have been able to notice the
TypeError raised by improperly calling the SDK either anyway...

Sigh...

For now, just fix calling the SDK; we'll handle the rest later (Famous
Last Words™)...

Fixes: Orange-OpenSource#203

Signed-off-by: Yann E. MORIN <yann.morin@orange.com>
@ymorin-orange ymorin-orange added the Python Python code label Nov 8, 2024
@ymorin-orange ymorin-orange added this to the Sprint 4 milestone Nov 8, 2024
@ymorin-orange ymorin-orange requested a review from tigroo November 8, 2024 08:52
@ymorin-orange ymorin-orange self-assigned this Nov 8, 2024
@@ -193,7 +193,7 @@ def msg_cb(
payload_d.get("source_uuid", None) != self.cfg["instance-id"]
or self.cfg["mirror-self"]
):
self.mqtt_mirror.publish(topic, payload)
self.mqtt_mirror.publish(topic=topic, payload=payload)
Copy link
Collaborator

Choose a reason for hiding this comment

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

it really fix something?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it does. As the commit log mentions, the API expects keyword-only arguments, not positional arguments.

And this fix is the one that fixes propagating messages to the local broker (issue #203).

@ymorin-orange ymorin-orange merged commit d183c04 into Orange-OpenSource:master Nov 8, 2024
36 checks passed
@ymorin-orange ymorin-orange deleted the yem/gh-198-203 branch November 12, 2024 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Python Python code
Projects
Status: Done
2 participants