|
| 1 | +*** Settings *** |
| 2 | +Resource ../../../resources/common.resource |
| 3 | +Library Cumulocity |
| 4 | +Library ThinEdgeIO |
| 5 | + |
| 6 | +Suite Setup Custom Setup |
| 7 | +Test Teardown Get Logs |
| 8 | + |
| 9 | +Test Tags theme:c8y theme:services theme:operation |
| 10 | + |
| 11 | + |
| 12 | +*** Variables *** |
| 13 | +${DEVICE_SN} ${EMPTY} |
| 14 | +${SERVICE_NAME} dummy-service |
| 15 | +${SERVICE_XID} ${EMPTY} |
| 16 | +${AGENT_XID} ${EMPTY} |
| 17 | +${MAPPER_XID} ${EMPTY} |
| 18 | + |
| 19 | + |
| 20 | +*** Test Cases *** |
| 21 | +Declares and clears an action of a service |
| 22 | + Execute Command tedge mqtt pub -q 1 --retain te/device/main/service/${SERVICE_NAME}/cmd/pause '{}' |
| 23 | + Supported Service Commands Should Be ${SERVICE_XID} PAUSE RESTART |
| 24 | + Cumulocity.Should Contain Supported Operations c8y_ServiceCommand |
| 25 | + |
| 26 | + Execute Command tedge mqtt pub -q 1 --retain te/device/main/service/${SERVICE_NAME}/cmd/pause '' |
| 27 | + Supported Service Commands Should Be ${SERVICE_XID} RESTART |
| 28 | + |
| 29 | +Declares the action of thin-edge's own services |
| 30 | + Supported Service Commands Should Be ${AGENT_XID} RESTART |
| 31 | + Cumulocity.Should Contain Supported Operations c8y_ServiceCommand |
| 32 | + |
| 33 | + Supported Service Commands Should Be ${MAPPER_XID} RESTART |
| 34 | + Cumulocity.Should Contain Supported Operations c8y_ServiceCommand |
| 35 | + |
| 36 | +Restarts a service managed by the init system |
| 37 | + ${before}= Get Service PID ${SERVICE_NAME} |
| 38 | + ${operation}= Create Service Command Operation |
| 39 | + ... ${SERVICE_XID} |
| 40 | + ... {"command":"RESTART","serviceName":"${SERVICE_NAME}","serviceType":"service"} |
| 41 | + Cumulocity.Operation Should Be SUCCESSFUL ${operation} timeout=120 |
| 42 | + |
| 43 | + ${after}= Get Service PID ${SERVICE_NAME} |
| 44 | + Should Not Be Equal ${before} ${after} The service was not restarted |
| 45 | + |
| 46 | +Rejects an action the service has not declared |
| 47 | + ${operation}= Create Service Command Operation |
| 48 | + ... ${SERVICE_XID} |
| 49 | + ... {"command":"COLLECT_MEASUREMENTS","serviceName":"${SERVICE_NAME}","serviceType":"service"} |
| 50 | + Cumulocity.Operation Should Be FAILED |
| 51 | + ... ${operation} |
| 52 | + ... failure_reason=.*has not declared the 'collect_measurements' action.* |
| 53 | + ... timeout=60 |
| 54 | + |
| 55 | +Restarts tedge-agent itself |
| 56 | + ${before}= Get Service PID tedge-agent |
| 57 | + |
| 58 | + ${operation}= Create Service Command Operation |
| 59 | + ... ${AGENT_XID} |
| 60 | + ... {"command":"RESTART","serviceName":"tedge-agent","serviceType":"service"} |
| 61 | + Cumulocity.Operation Should Be SUCCESSFUL ${operation} timeout=180 |
| 62 | + |
| 63 | + ThinEdgeIO.Service Health Status Should Be Up tedge-agent |
| 64 | + ${after}= Get Service PID tedge-agent |
| 65 | + Should Not Be Equal ${before} ${after} tedge-agent was not restarted |
| 66 | + |
| 67 | + |
| 68 | +*** Keywords *** |
| 69 | +Custom Setup |
| 70 | + ${sn}= Setup |
| 71 | + Set Suite Variable $DEVICE_SN ${sn} |
| 72 | + Set Suite Variable $SERVICE_XID ${sn}:device:main:service:${SERVICE_NAME} |
| 73 | + Set Suite Variable $AGENT_XID ${sn}:device:main:service:tedge-agent |
| 74 | + Set Suite Variable $MAPPER_XID ${sn}:device:main:service:tedge-mapper-c8y |
| 75 | + Cumulocity.External Identity Should Exist ${sn} show_info=${False} |
| 76 | + |
| 77 | + # The service is registered under its systemd unit name. |
| 78 | + # Cumulocity sends this name back in the operation, and the workflow passes it to systemctl. |
| 79 | + ThinEdgeIO.Transfer To Device ${CURDIR}/dummy-service.service /etc/systemd/system/ |
| 80 | + Execute Command systemctl daemon-reload && systemctl start ${SERVICE_NAME} |
| 81 | + |
| 82 | + Execute Command |
| 83 | + ... tedge mqtt pub --retain te/device/main/service/${SERVICE_NAME} '{"name":"${SERVICE_NAME}","@type":"service"}' |
| 84 | + Cumulocity.External Identity Should Exist ${SERVICE_XID} show_info=${False} |
| 85 | + Execute Command tedge mqtt pub -q 1 --retain te/device/main/service/${SERVICE_NAME}/cmd/restart '{}' |
| 86 | + |
| 87 | +Supported Service Commands Should Be |
| 88 | + [Arguments] ${external_id} @{expected} |
| 89 | + Cumulocity.External Identity Should Exist ${external_id} show_info=${False} |
| 90 | + Wait Until Keyword Succeeds 30x 2s Managed Object Service Commands Should Be @{expected} |
| 91 | + |
| 92 | +Managed Object Service Commands Should Be |
| 93 | + [Arguments] @{expected} |
| 94 | + ${mo}= Cumulocity.Managed Object Should Have Fragments c8y_SupportedServiceCommands |
| 95 | + ${actual}= Evaluate sorted($mo["c8y_SupportedServiceCommands"]) |
| 96 | + ${wanted}= Evaluate sorted($expected) |
| 97 | + Should Be Equal ${actual} ${wanted} |
| 98 | + |
| 99 | +Create Service Command Operation |
| 100 | + [Arguments] ${external_id} ${fragment} |
| 101 | + Cumulocity.External Identity Should Exist ${external_id} show_info=${False} |
| 102 | + ${operation}= Cumulocity.Create Operation |
| 103 | + ... fragments={"c8y_ServiceCommand":${fragment}} |
| 104 | + ... description=Service command |
| 105 | + RETURN ${operation} |
0 commit comments