aws-greengrass / aws-greengrass-client-device-auth

Apache License 2.0
2 stars 3 forks source link

feat(uat): implement unsubscribe for python paho client #347

Closed eschastlivtsev closed 1 year ago

eschastlivtsev commented 1 year ago

Description of changes:

Why is this change necessary:

How was this change tested: Manual run of mqtt-client-control and python client. MQTT connect, subscribe, unsubscribe, publish, delivery of received MQTT message and disconnect are successful. Linking and shutdown steps are successful.

Test results: Python Paho client output

client-python-paho.exe python-paho-agent
[DEBUG] 2023-06-27 18:51:18.939 asyncio - Using selector: SelectSelector
[INFO ] 2023-06-27 18:51:18.944 GRPCLib - Initialize gRPC library
[INFO ] 2023-06-27 18:51:18.945 GRPCLink - Making gPRC client connection with 127.0.0.1:47619 as python-paho-agent...
[INFO ] 2023-06-27 18:51:19.532 GRPCLink - Client connection with Control is established, local address is 127.0.0.1
[DEBUG] 2023-06-27 18:51:19.534 grpc._cython.cygrpc - Using AsyncIOEngine.POLLER as I/O engine
[INFO ] 2023-06-27 18:51:19.774 MQTTLib - Initialize Paho MQTT library
[INFO ] 2023-06-27 18:51:19.775 GRPCLink - Handle gRPC requests
[INFO ] 2023-06-27 18:51:19.779 GRPCControlServer - Server awaiting termination
[INFO ] 2023-06-27 18:51:22.893 GRPCControlServer - createMqttConnection: clientId Python_Paho_Client broker a3t8vwpkw3sltg-ats.iot.eu-west-1.amazonaws.com:8883
[INFO ] 2023-06-27 18:51:23.136 MqttConnection - Creating MQTT 5 client with TLS
[INFO ] 2023-06-27 18:51:23.137 MqttConnection - MQTT connection ID 0 connecting...
[DEBUG] 2023-06-27 18:51:23.600 AsyncioHelper - On socket open
[DEBUG] 2023-06-27 18:51:23.601 AsyncioHelper - On socket register write
[DEBUG] 2023-06-27 18:51:23.604 AsyncioHelper - On socket unregister write
[INFO ] 2023-06-27 18:51:23.795 MqttConnection - MQTT connection ID 0 connected, client id Python_Paho_Client
[DEBUG] 2023-06-27 18:51:29.063 GRPCControlServer - Subscription: filter test/topic QoS 0 noLocal 0 retainAsPublished 0 retainHandling 2
[INFO ] 2023-06-27 18:51:29.064 GRPCControlServer - SubscribeMqtt connection_id 0
[DEBUG] 2023-06-27 18:51:29.068 AsyncioHelper - On socket register write
[DEBUG] 2023-06-27 18:51:29.070 AsyncioHelper - On socket unregister write
[DEBUG] 2023-06-27 18:51:29.194 MqttConnection - Subscribed on filters 'test/topic' with QoS 0 no local False retain as published False retain handing 2 with message id 1
[INFO ] 2023-06-27 18:51:34.235 GRPCControlServer - PublishMqtt connection_id 0 topic test/topic retain 0
[DEBUG] 2023-06-27 18:51:34.236 AsyncioHelper - On socket register write
[DEBUG] 2023-06-27 18:51:34.242 AsyncioHelper - On socket unregister write
[DEBUG] 2023-06-27 18:51:34.346 MqttConnection - onMessage message b'Hello World!' from topic 'test/topic'
[INFO ] 2023-06-27 18:51:34.347 GRPCDiscoveryClient - Sending OnReceiveMessage request agent_id 'python-paho-agent' connection_id 0 message b'Hello World!' on topic 'test/topic'
[DEBUG] 2023-06-27 18:51:34.374 MqttConnection - Published on topic 'test/topic' QoS 1 retain 0 with rc 0 message id 2
[DEBUG] 2023-06-27 18:51:39.403 GRPCControlServer - Unsubscription: filter test/topic
[INFO ] 2023-06-27 18:51:39.403 GRPCControlServer - UnsubscribeMqtt connection_id 0
[DEBUG] 2023-06-27 18:51:39.410 AsyncioHelper - On socket register write
[DEBUG] 2023-06-27 18:51:39.413 AsyncioHelper - On socket unregister write
[DEBUG] 2023-06-27 18:51:39.577 MqttConnection - Unsubscribed from filters 'test/topic' with message id 3
[INFO ] 2023-06-27 18:51:54.592 GRPCControlServer - CloseMqttConnection connection_id 0 reason 4
[INFO ] 2023-06-27 18:51:54.597 MqttConnection - Disconnect MQTT connection with reason code 4
[DEBUG] 2023-06-27 18:51:54.598 AsyncioHelper - On socket register write
[INFO ] 2023-06-27 18:51:54.599 GRPCDiscoveryClient - Sending OnMqttDisconnect request agent_id 'python-paho-agent' connection_id 0 error 'None'
[DEBUG] 2023-06-27 18:51:54.633 AsyncioHelper - On socket unregister write
[DEBUG] 2023-06-27 18:51:54.633 AsyncioHelper - On socket close
[INFO ] 2023-06-27 18:51:54.651 GRPCControlServer - shutdownAgent: reason That's it.
[INFO ] 2023-06-27 18:51:54.658 GRPCControlServer - Server termination done
[INFO ] 2023-06-27 18:51:54.660 GRPCLink - Shutdown gPRC link
[INFO ] 2023-06-27 18:51:54.688 Main - Execution done successfully

Mqtt Client Control output

java -Dmqtt_client_id=Python_Paho_Client -Dmqtt_broker_addr=a3t8vwpkw3sltg-ats.iot.eu-west-1.amazonaws.com -Dmqtt_client_ca_file=creds_aws/rootCA.pem -Dmqtt_client_cert_file=creds_aws/thingCert.crt -Dmqtt_client_key_file=creds_aws/privKey.key -jar target/aws-greengrass-testing-mqtt-client-control.jar 47619 true true
[INFO ] 2023-06-27 18:50:07.614 [main] ExampleControl - Control: port 47619, with TLS, MQTT v5
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
[INFO ] 2023-06-27 18:50:11.592 [main] EngineControlImpl - MQTT client control gRPC server started, listening on 47619
[INFO ] 2023-06-27 18:51:19.486 [grpc-default-executor-0] GRPCDiscoveryServer - RegisterAgent: agentId python-paho-agent
[INFO ] 2023-06-27 18:51:19.547 [grpc-default-executor-0] GRPCDiscoveryServer - DiscoveryClient: agentId python-paho-agent address 127.0.0.1 port 53020
[INFO ] 2023-06-27 18:51:19.561 [grpc-default-executor-0] EngineControlImpl - Created new agent control for python-paho-agent on 127.0.0.1:53020
[INFO ] 2023-06-27 18:51:19.745 [grpc-default-executor-0] ExampleControl - Agent python-paho-agent is connected
[INFO ] 2023-06-27 18:51:19.768 [pool-2-thread-1] AgentTestScenario - Playing test scenario for agent id python-paho-agent
[INFO ] 2023-06-27 18:51:24.023 [pool-2-thread-1] AgentControlImpl - Created connection with id 0 CONNACK 'sessionPresent: false
reasonCode: 0
receiveMaximum: 100
maximumQoS: 1
retainAvailable: true
maximumPacketSize: 149504
wildcardSubscriptionsAvailable: true
subscriptionIdentifiersAvailable: false
sharedSubscriptionsAvailable: true
serverKeepAlive: 60
topicAliasMaximum: 8
'
[INFO ] 2023-06-27 18:51:24.025 [pool-2-thread-1] AgentControlImpl - createMqttConnection: MQTT connectionId 0 created
[INFO ] 2023-06-27 18:51:24.032 [pool-2-thread-1] AgentTestScenario - MQTT connection with id 0 is established
[INFO ] 2023-06-27 18:51:29.048 [pool-2-thread-1] AgentControlImpl - SubscribeMqtt: subscribe on connection 0
[INFO ] 2023-06-27 18:51:29.207 [pool-2-thread-1] AgentTestScenario - Subscribe response: connectionId 0 reason codes [0] reason string ''
[INFO ] 2023-06-27 18:51:34.223 [pool-2-thread-1] AgentControlImpl - PublishMqtt: publishing on connectionId 0 topic test/topic
[INFO ] 2023-06-27 18:51:34.357 [grpc-default-executor-0] GRPCDiscoveryServer - OnReceiveMessage: agentId python-paho-agent connectionId 0 topic test/topic QoS 0
[INFO ] 2023-06-27 18:51:34.363 [grpc-default-executor-0] AgentTestScenario - Message received on agentId python-paho-agent connectionId 0 topic test/topic QoS 0 content <ByteString@2bc260a3 size=12 contents="Hello World!">
[INFO ] 2023-06-27 18:51:34.383 [pool-2-thread-1] AgentTestScenario - Published connectionId 0 reason code 0 reason string ''
[INFO ] 2023-06-27 18:51:39.393 [pool-2-thread-1] AgentControlImpl - UnsubscribeMqtt: unsubscribe on connectionId 0
[INFO ] 2023-06-27 18:51:39.581 [pool-2-thread-1] AgentTestScenario - Unsubscribe response: connectionId 0 reason codes [0] reason string ''
[INFO ] 2023-06-27 18:51:54.613 [grpc-default-executor-0] GRPCDiscoveryServer - OnMqttDisconnect: agentId python-paho-agent connectionId 0 disconnect 'reasonCode: 0
' error ''
[INFO ] 2023-06-27 18:51:54.614 [grpc-default-executor-0] AgentTestScenario - MQTT disconnected on agentId python-paho-agent connectionId 0 disconnect 'reasonCode: 0
' error ''
[INFO ] 2023-06-27 18:51:54.642 [pool-2-thread-1] AgentControlImpl - closeMqttConnection: MQTT connectionId 0 closed
[INFO ] 2023-06-27 18:51:54.659 [pool-2-thread-1] AgentControlImpl - shutdown request sent successfully
[INFO ] 2023-06-27 18:51:54.673 [grpc-default-executor-1] GRPCDiscoveryServer - UnregisterAgent: agentId python-paho-agent reason Agent shutdown by OTF request 'That's it.'
[INFO ] 2023-06-27 18:51:54.679 [grpc-default-executor-1] ExampleControl - Agent python-paho-agent is disconnected

Any additional information or context required to review the change:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.