diff --git a/tests/RobotFramework/requirements/requirements.txt b/tests/RobotFramework/requirements/requirements.txt index 5ecd7d7be38..b5a3562068c 100644 --- a/tests/RobotFramework/requirements/requirements.txt +++ b/tests/RobotFramework/requirements/requirements.txt @@ -2,7 +2,7 @@ dateparser~=1.1.7 paho-mqtt~=1.6.1 python-dotenv~=0.20.0 robotframework~=6.0.0 -robotframework-c8y @ git+https://github.com/reubenmiller/robotframework-c8y.git@0.13.4 +robotframework-c8y @ git+https://github.com/reubenmiller/robotframework-c8y.git@0.15.0 robotframework-debuglibrary~=2.3.0 robotframework-jsonlibrary~=0.5 robotframework-pabot~=2.13.0 diff --git a/tests/RobotFramework/tests/cumulocity/configuration/c8y-configuration-plugin-updated.toml b/tests/RobotFramework/tests/cumulocity/configuration/c8y-configuration-plugin-updated.toml new file mode 100644 index 00000000000..dbce68b6b2e --- /dev/null +++ b/tests/RobotFramework/tests/cumulocity/configuration/c8y-configuration-plugin-updated.toml @@ -0,0 +1,6 @@ +files = [ + { path = '/etc/tedge/tedge.toml', user = 'tedge', group = 'tedge', mode = 0o444 }, + { path = '/etc/tedge/system.toml', type = 'system.toml', user = 'tedge', group = 'tedge', mode = 0o444 }, + { path = '/etc/config1.json', type = 'CONFIG1', user = 'tedge', group = 'tedge', mode = 0o444 }, + { path = '/etc/config2.json', type = 'Config@2.0.0', user = 'tedge', group = 'tedge', mode = 0o444 }, +] \ No newline at end of file diff --git a/tests/RobotFramework/tests/cumulocity/configuration/c8y-configuration-plugin.toml b/tests/RobotFramework/tests/cumulocity/configuration/c8y-configuration-plugin.toml new file mode 100644 index 00000000000..c05eed061be --- /dev/null +++ b/tests/RobotFramework/tests/cumulocity/configuration/c8y-configuration-plugin.toml @@ -0,0 +1,5 @@ +files = [ + { path = '/etc/tedge/tedge.toml', user = 'tedge', group = 'tedge', mode = 0o444 }, + { path = '/etc/tedge/system.toml', type = 'system.toml', user = 'tedge', group = 'tedge', mode = 0o444 }, + { path = '/etc/config1.json', type = 'CONFIG1', user = 'tedge', group = 'tedge', mode = 0o640 }, +] \ No newline at end of file diff --git a/tests/RobotFramework/tests/cumulocity/configuration/config1-version2.json b/tests/RobotFramework/tests/cumulocity/configuration/config1-version2.json new file mode 100644 index 00000000000..bd971750a2e --- /dev/null +++ b/tests/RobotFramework/tests/cumulocity/configuration/config1-version2.json @@ -0,0 +1 @@ +{"name":"configuration1","version":2} \ No newline at end of file diff --git a/tests/RobotFramework/tests/cumulocity/configuration/config1.json b/tests/RobotFramework/tests/cumulocity/configuration/config1.json new file mode 100644 index 00000000000..8ef932f6b83 --- /dev/null +++ b/tests/RobotFramework/tests/cumulocity/configuration/config1.json @@ -0,0 +1 @@ +{"name":"configuration1"} \ No newline at end of file diff --git a/tests/RobotFramework/tests/cumulocity/configuration/configuration_operation.robot b/tests/RobotFramework/tests/cumulocity/configuration/configuration_operation.robot new file mode 100644 index 00000000000..718b1e12ee9 --- /dev/null +++ b/tests/RobotFramework/tests/cumulocity/configuration/configuration_operation.robot @@ -0,0 +1,118 @@ +*** Settings *** +Resource ../../../resources/common.resource +Library Cumulocity +Library ThinEdgeIO + +Test Tags theme:c8y theme:configuration +Suite Setup Custom Setup +Test Teardown Get Logs +Test Setup Test Setup + +# Note: Use larger timeout (120s instead of 30s default) for operation +# assertions to allow for cases where the c8y jwt token request times out +# as the retry mechanism will wait 60 seconds before requesting a new jwt + +*** Variables *** +${DEFAULT_CONFIG} c8y-configuration-plugin + +*** Test Cases *** + +Set configuration when file exists + ${config_url}= Cumulocity.Create Inventory Binary config1 CONFIG1 file=${CURDIR}/config1-version2.json + ${operation}= Cumulocity.Set Configuration CONFIG1 url=${config_url} + ${operation}= Operation Should Be SUCCESSFUL ${operation} timeout=120 + ${target_contents}= Execute Command cat /etc/config1.json + Should Be Equal ${target_contents} {"name":"configuration1","version":2} + ${FILE_MODE_OWNERSHIP}= Execute Command stat -c '%a %U:%G' /etc/config1.json strip=${True} + # Note: File permission will not change if the file already exists + Should Be Equal ${FILE_MODE_OWNERSHIP} 644 root:root + +Set configuration when file does not exist + Execute Command rm -f /etc/config1.json + ${config_url}= Cumulocity.Create Inventory Binary config1 CONFIG1 file=${CURDIR}/config1-version2.json + ${operation}= Cumulocity.Set Configuration CONFIG1 url=${config_url} + ${operation}= Operation Should Be SUCCESSFUL ${operation} timeout=120 + ${target_contents}= Execute Command cat /etc/config1.json + Should Be Equal ${target_contents} {"name":"configuration1","version":2} + ${FILE_MODE_OWNERSHIP}= Execute Command stat -c '%a %U:%G' /etc/config1.json strip=${True} + Should Be Equal ${FILE_MODE_OWNERSHIP} 640 tedge:tedge + +Set configuration with broken url + ${operation}= Cumulocity.Set Configuration CONFIG1 url=invalid://hellö.zip + ${operation}= Operation Should Be FAILED ${operation} timeout=120 + ${target_contents}= Execute Command cat /etc/config1.json + Should Be Equal ${target_contents} {"name":"configuration1"} + +Get configuration + ${operation}= Cumulocity.Get Configuration CONFIG1 + ${operation}= Operation Should Be SUCCESSFUL ${operation} timeout=120 + ${events}= Cumulocity.Device Should Have Event/s minimum=1 maximum=1 type=CONFIG1 + ${uploaded_contents}= Cumulocity.Event Should Have An Attachment ${events[0]["id"]} + ${target_contents}= Execute Command cat /etc/config1.json + Should Be Equal ${target_contents} ${uploaded_contents.decode("utf8")} + Should Be Equal ${target_contents} {"name":"configuration1"} + +Get non existent configuration file + Execute Command rm -f /etc/config1.json + File Should Not Exist /etc/config1.json + ${operation}= Cumulocity.Get Configuration CONFIG1 + Operation Should Be FAILED ${operation} failure_reason=.*No such file or directory.* + +Get non existent configuration type + ${operation}= Cumulocity.Get Configuration unknown_config + Operation Should Be FAILED ${operation} failure_reason=.*requested config_type unknown_config is not defined in the plugin configuration file.* + +Update configuration plugin config via cloud + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG1 + ${config_url}= Cumulocity.Create Inventory Binary c8y-configuration-plugin ${DEFAULT_CONFIG} file=${CURDIR}/c8y-configuration-plugin-updated.toml + ${operation}= Cumulocity.Set Configuration ${DEFAULT_CONFIG} url=${config_url} + ${operation}= Operation Should Be SUCCESSFUL ${operation} + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG1 Config@2.0.0 + +Modify configuration plugin config via local filesystem modify inplace + [Documentation] Editing the c8y-configuration-plugin.toml locally requires the + ... c8y-configuration-plugin service to be restarted + Skip msg="Fails due to https://github.com/thin-edge/thin-edge.io/issues/1896" + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG1 + Execute Command sed -i 's/CONFIG1/CONFIG3/g' /etc/tedge/c8y/c8y-configuration-plugin.toml + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG3 + +Modify configuration plugin config via local filesystem overwrite + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG1 + ${NEW_CONFIG}= Execute Command sed 's/CONFIG1/CONFIG3/g' /etc/tedge/c8y/c8y-configuration-plugin.toml + Execute Command echo "${NEW_CONFIG}" > /etc/tedge/c8y/c8y-configuration-plugin.toml + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG3 + +Update configuration plugin config via local filesystem copy + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG1 + Transfer To Device ${CURDIR}/c8y-configuration-plugin-updated.toml /etc/tedge/c8y/ + Execute Command cp /etc/tedge/c8y/c8y-configuration-plugin-updated.toml /etc/tedge/c8y/c8y-configuration-plugin.toml + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG1 Config@2.0.0 + +Update configuration plugin config via local filesystem move (different directory) + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG1 + Transfer To Device ${CURDIR}/c8y-configuration-plugin-updated.toml /etc/ + Execute Command mv /etc/c8y-configuration-plugin-updated.toml /etc/tedge/c8y/c8y-configuration-plugin.toml + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG1 Config@2.0.0 + +Update configuration plugin config via local filesystem move (same directory) + Skip msg="Fails due to https://github.com/thin-edge/thin-edge.io/issues/1896" + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG1 + Transfer To Device ${CURDIR}/c8y-configuration-plugin-updated.toml /etc/tedge/c8y/ + Execute Command mv /etc/tedge/c8y/c8y-configuration-plugin-updated.toml /etc/tedge/c8y/c8y-configuration-plugin.toml + Cumulocity.Should Support Configurations ${DEFAULT_CONFIG} /etc/tedge/tedge.toml system.toml CONFIG1 Config@2.0.0 + +*** Keywords *** + +Test Setup + ThinEdgeIO.Transfer To Device ${CURDIR}/c8y-configuration-plugin.toml /etc/tedge/c8y/ + ThinEdgeIO.Transfer To Device ${CURDIR}/config1.json /etc/ + Execute Command chown root:root /etc/tedge/c8y/c8y-configuration-plugin.toml /etc/config1.json + ThinEdgeIO.Service Health Status Should Be Up c8y-configuration-plugin + ThinEdgeIO.Service Health Status Should Be Up tedge-agent + ThinEdgeIO.Service Health Status Should Be Up tedge-mapper-c8y + +Custom Setup + ${DEVICE_SN}= Setup + Set Suite Variable $DEVICE_SN + Device Should Exist ${DEVICE_SN}