|
| 1 | +*** Settings *** |
| 2 | +Resource ../../../resources/common.resource |
| 3 | +Library ThinEdgeIO |
| 4 | +Library Cumulocity |
| 5 | + |
| 6 | +Test Teardown Custom Teardown |
| 7 | + |
| 8 | +Test Tags theme:mqtt theme:c8y adapter:docker |
| 9 | + |
| 10 | + |
| 11 | +*** Variables *** |
| 12 | +${PARENT_SN} ${EMPTY} |
| 13 | +${CHILD_SN} ${EMPTY} |
| 14 | + |
| 15 | + |
| 16 | +*** Test Cases *** |
| 17 | +Username/password authentication to local broker without TLS - mosquitto bridge |
| 18 | + [Setup] No TLS Setup use_builtin_bridge=false |
| 19 | + Check system health including c8y |
| 20 | + |
| 21 | +Username/password authentication to local broker without TLS - built-in bridge |
| 22 | + [Setup] No TLS Setup use_builtin_bridge=true |
| 23 | + Check system health including c8y |
| 24 | + |
| 25 | +Username/password authentication to local broker with TLS - mosquitto bridge |
| 26 | + [Setup] TLS Setup use_builtin_bridge=false |
| 27 | + Check system health including c8y |
| 28 | + |
| 29 | +Username/password authentication to local broker with TLS - built-in bridge |
| 30 | + [Setup] TLS Setup use_builtin_bridge=true |
| 31 | + Check system health including c8y |
| 32 | + |
| 33 | +Username/password + certificate authentication to local broker - mosquitto bridge |
| 34 | + [Setup] TLS and Client Cert Setup use_builtin_bridge=false |
| 35 | + Check system health including c8y |
| 36 | + |
| 37 | +Username/password + certificate authentication to local broker - built-in bridge |
| 38 | + [Setup] TLS and Client Cert Setup use_builtin_bridge=true |
| 39 | + Check system health including c8y |
| 40 | + |
| 41 | + |
| 42 | +*** Keywords *** |
| 43 | +Check system health including c8y |
| 44 | + ThinEdgeIO.Set Device Context ${PARENT_SN} |
| 45 | + ThinEdgeIO.Service Should Be Running mosquitto |
| 46 | + ThinEdgeIO.Service Should Be Running tedge-mapper-c8y |
| 47 | + ThinEdgeIO.Service Should Be Running tedge-agent |
| 48 | + ThinEdgeIO.Service Should Be Running c8y-firmware-plugin |
| 49 | + |
| 50 | + ThinEdgeIO.Set Device Context ${CHILD_SN} |
| 51 | + ThinEdgeIO.Service Should Be Stopped mosquitto |
| 52 | + ThinEdgeIO.Service Should Be Stopped tedge-mapper-c8y |
| 53 | + ThinEdgeIO.Service Should Be Running tedge-agent |
| 54 | + ThinEdgeIO.Service Should Be Stopped c8y-firmware-plugin |
| 55 | + |
| 56 | + # tedge mqtt pub/sub sanity check |
| 57 | + ${output}= Execute Command tedge mqtt pub test-topic test-message stderr=${True} |
| 58 | + Should Not Contain ${output} Failed to connect to broker |
| 59 | + ${output}= Execute Command tedge mqtt sub test --duration 1s stderr=${True} |
| 60 | + Should Not Contain ${output} Failed to connect to broker |
| 61 | + |
| 62 | + # Validate the device exists in the cloud |
| 63 | + Cumulocity.Device Should Exist ${PARENT_SN} |
| 64 | + |
| 65 | + # Cumulocity sanity check |
| 66 | + ThinEdgeIO.Set Device Context ${CHILD_SN} |
| 67 | + ThinEdgeIO.Execute Command tedge mqtt pub te/device/main///m/ '{"temperature": 29.8}' |
| 68 | + ${measurements}= Cumulocity.Device Should Have Measurements value=temperature series=temperature |
| 69 | + Should Be Equal As Numbers ${measurements[0]["temperature"]["temperature"]["value"]} ${29.8} |
| 70 | + |
| 71 | + Cumulocity.Should Have Services name=tedge-mapper-c8y status=up |
| 72 | + Cumulocity.Should Have Services name=tedge-agent status=up |
| 73 | + Cumulocity.Should Have Services name=c8y-firmware-plugin status=up |
| 74 | + |
| 75 | +No TLS Setup |
| 76 | + [Arguments] ${use_builtin_bridge} |
| 77 | + |
| 78 | + # Parent |
| 79 | + ${PARENT_SN}= Setup bootstrap_args=--no-secure register=${True} connect=${False} |
| 80 | + Set Test Variable $PARENT_SN |
| 81 | + ${PARENT_HOSTNAME}= Execute Command hostname strip=${True} |
| 82 | + |
| 83 | + Execute Command sudo tedge config set mqtt.bridge.built_in ${use_builtin_bridge} |
| 84 | + Execute Command mosquitto_passwd -c -b /etc/mosquitto/pwfile testuser testpassword |
| 85 | + |
| 86 | + Transfer To Device ${CURDIR}/unencrypted-listener.conf /etc/mosquitto/conf.d/ |
| 87 | + Configure MQTT client host=127.0.0.1 port=1884 |
| 88 | + |
| 89 | + Connect Mapper c8y |
| 90 | + |
| 91 | + # Child |
| 92 | + ${CHILD_SN}= Setup bootstrap_args=--no-secure register=${False} connect=${False} |
| 93 | + Set Test Variable $CHILD_SN |
| 94 | + |
| 95 | + Execute Command sudo tedge config set mqtt.device_topic_id "device/${CHILD_SN}//" |
| 96 | + Configure MQTT client host=${PARENT_HOSTNAME} port=1884 |
| 97 | + Start Service tedge-agent |
| 98 | + |
| 99 | +TLS Setup |
| 100 | + [Arguments] ${use_builtin_bridge} |
| 101 | + |
| 102 | + # Parent |
| 103 | + ${PARENT_SN}= Setup bootstrap_args=--secure register=${True} connect=${False} |
| 104 | + Set Test Variable $PARENT_SN |
| 105 | + ${PARENT_HOSTNAME}= Execute Command hostname strip=${True} |
| 106 | + |
| 107 | + Execute Command sudo tedge config set mqtt.bridge.built_in ${use_builtin_bridge} |
| 108 | + Execute Command mosquitto_passwd -c -b /etc/mosquitto/pwfile testuser testpassword |
| 109 | + |
| 110 | + Transfer To Device ${CURDIR}/encrypted-listener.conf /etc/mosquitto/conf.d/ |
| 111 | + Configure MQTT client host=127.0.0.1 port=8884 |
| 112 | + # Remove the certificate based authentication settings |
| 113 | + Execute Command sudo tedge config unset mqtt.client.auth.cert_file |
| 114 | + Execute Command sudo tedge config unset mqtt.client.auth.key_file |
| 115 | + |
| 116 | + # Copy CA from the parent to child |
| 117 | + ${ca}= Execute Command cat "$(tedge config get mqtt.client.auth.ca_file)" |
| 118 | + |
| 119 | + Connect Mapper c8y |
| 120 | + |
| 121 | + # Child |
| 122 | + ${CHILD_SN}= Setup bootstrap_args=--no-secure register=${False} connect=${False} |
| 123 | + Set Test Variable $CHILD_SN |
| 124 | + |
| 125 | + Execute Command sudo tedge config set mqtt.device_topic_id "device/${CHILD_SN}//" |
| 126 | + Execute Command sudo tedge config set mqtt.client.auth.ca_file /etc/mosquitto/ca_certificates/ca.crt |
| 127 | + Execute Command echo "${ca}" | sudo tee "$(tedge config get mqtt.client.auth.ca_file)" |
| 128 | + Configure MQTT client host=${PARENT_HOSTNAME} port=8884 |
| 129 | + Start Service tedge-agent |
| 130 | + |
| 131 | +TLS and Client Cert Setup |
| 132 | + [Arguments] ${use_builtin_bridge} |
| 133 | + |
| 134 | + # Parent |
| 135 | + ${PARENT_SN}= Setup bootstrap_args=--secure register=${True} connect=${False} |
| 136 | + Set Test Variable $PARENT_SN |
| 137 | + ${PARENT_HOSTNAME}= Execute Command hostname strip=${True} |
| 138 | + |
| 139 | + Execute Command sudo tedge config set mqtt.bridge.built_in ${use_builtin_bridge} |
| 140 | + Execute Command mosquitto_passwd -c -b /etc/mosquitto/pwfile testuser testpassword |
| 141 | + |
| 142 | + Transfer To Device ${CURDIR}/cert-pass-listener.conf /etc/mosquitto/conf.d/ |
| 143 | + Configure MQTT client host=127.0.0.1 port=8885 |
| 144 | + |
| 145 | + # Copy CA, certificate and key from the parent to child |
| 146 | + ${ca}= Execute Command cat "$(tedge config get mqtt.client.auth.ca_file)" |
| 147 | + ${cert}= Execute Command cat "$(tedge config get mqtt.client.auth.cert_file)" |
| 148 | + ${key}= Execute Command cat "$(tedge config get mqtt.client.auth.key_file)" |
| 149 | + |
| 150 | + Connect Mapper c8y |
| 151 | + |
| 152 | + # Child |
| 153 | + ${CHILD_SN}= Setup bootstrap_args=--no-secure register=${False} connect=${False} |
| 154 | + Set Test Variable $CHILD_SN |
| 155 | + |
| 156 | + Execute Command sudo tedge config set mqtt.device_topic_id "device/${CHILD_SN}//" |
| 157 | + Execute Command sudo tedge config set mqtt.client.auth.ca_file /etc/mosquitto/ca_certificates/ca.crt |
| 158 | + Execute Command sudo tedge config set mqtt.client.auth.cert_file /setup/client.crt |
| 159 | + Execute Command sudo tedge config set mqtt.client.auth.key_file /setup/client.key |
| 160 | + Execute Command echo "${ca}" | sudo tee "$(tedge config get mqtt.client.auth.ca_file)" |
| 161 | + Execute Command echo "${cert}" | sudo tee "$(tedge config get mqtt.client.auth.cert_file)" |
| 162 | + Execute Command echo "${key}" | sudo tee "$(tedge config get mqtt.client.auth.key_file)" |
| 163 | + |
| 164 | + Configure MQTT client host=${PARENT_HOSTNAME} port=8885 |
| 165 | + Start Service tedge-agent |
| 166 | + |
| 167 | +Configure MQTT client |
| 168 | + [Arguments] ${host} ${port} |
| 169 | + Execute Command echo testpassword > /etc/tedge/.password |
| 170 | + Execute Command sudo tedge config set mqtt.client.auth.username testuser |
| 171 | + Execute Command sudo tedge config set mqtt.client.auth.password_file /etc/tedge/.password |
| 172 | + Execute Command sudo tedge config set mqtt.client.host ${host} |
| 173 | + Execute Command sudo tedge config set mqtt.client.port ${port} |
| 174 | + |
| 175 | +Custom Teardown |
| 176 | + Get Logs name=${PARENT_SN} |
| 177 | + Get Logs name=${CHILD_SN} |
0 commit comments