From c7fab344ae9350730889c36ddaadefd43e6857bb Mon Sep 17 00:00:00 2001 From: Horia Delicoti Date: Tue, 7 Feb 2017 23:33:08 +0100 Subject: [PATCH 1/5] r/resinos.robot: Adding keyword that sends commands to the device. Signed-off-by: Horia Delicoti --- resources/resinos.robot | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/resources/resinos.robot b/resources/resinos.robot index d7aa183..2c6a6fb 100644 --- a/resources/resinos.robot +++ b/resources/resinos.robot @@ -86,6 +86,13 @@ Check if service "${service}" is running using socket "${socket}" Should Contain ${result.stdout} active Process ${result} +Run command "${command}" on device using socket "${socket}" + ${result} = Run Process echo "send root\nsend ${command}" > minicom_script.sh shell=yes cwd=/tmp/enable_getty_service + Process ${result} + Run Process minicom -D ${socket} -S /tmp/enable_getty_service/minicom_script.sh -C /tmp/enable_getty_service/minicom_output.txt shell=yes cwd=/tmp timeout=1s + File Should Not Be Empty /tmp/enable_getty_service/minicom_output.txt + Process ${result} + Check that backup files are not found in the "${image}" ${LOOPDEVICE} = Set up loop device for "${image}" ${random} = Evaluate random.randint(0, sys.maxint) modules=random, sys From 925e1805cc4fb41f7dd146cdd60a00ff49555380 Mon Sep 17 00:00:00 2001 From: Horia Delicoti Date: Tue, 7 Feb 2017 23:35:30 +0100 Subject: [PATCH 2/5] libraries: Adding python script that checks the correct update strategy. * Adding template files to be compared to when controlling the update strategy. Signed-off-by: Horia Delicoti --- libraries/FileComparator.py | 46 +++++++++++++++++++++++++ libraries/template_delete-then-download | 21 +++++++++++ libraries/template_download-then-kill | 17 +++++++++ libraries/template_hand-over | 13 +++++++ libraries/template_kill-then-download | 17 +++++++++ 5 files changed, 114 insertions(+) create mode 100755 libraries/FileComparator.py create mode 100644 libraries/template_delete-then-download create mode 100644 libraries/template_download-then-kill create mode 100644 libraries/template_hand-over create mode 100644 libraries/template_kill-then-download diff --git a/libraries/FileComparator.py b/libraries/FileComparator.py new file mode 100755 index 0000000..2f6aaa9 --- /dev/null +++ b/libraries/FileComparator.py @@ -0,0 +1,46 @@ + +# ################################################################################################## +# +# Script that searches for a template inside a system log file +# NOTE: Templates need to have the "old_app_name" and "new_app_name" groups defined in template file +# +# ################################################################################################## + +import sys +import logging +import re + +if __name__ == '__main__': + + logging.basicConfig(level=logging.DEBUG) + + if len(sys.argv) < 2: + logging.error("Expected 2 arguments - the two files that are to be read.") + logging.error("Usage: python %s " % sys.argv[0]) + sys.exit(100) + + template_file = sys.argv[1] + file_to_compare = sys.argv[2] + + with open(template_file, "r") as fd: + lines = fd.readlines() + template = "".join([x.rstrip("\n") for x in lines]) + + pattern = re.compile(template, re.IGNORECASE) + + with open(file_to_compare, "r") as fd: + to_compare = fd.read() + + matches = pattern.search(to_compare, re.IGNORECASE) + if matches is None: + logging.info("Files are different!") + sys.exit(1) + + new_app_name = matches.group("new_app_name") + old_app_name = matches.group("old_app_name") + + if new_app_name == old_app_name: + logging.info("Old app was reinstalled") + sys.exit(2) + + logging.info("Pattern found in %s" % file_to_compare) diff --git a/libraries/template_delete-then-download b/libraries/template_delete-then-download new file mode 100644 index 0000000..2538808 --- /dev/null +++ b/libraries/template_delete-then-download @@ -0,0 +1,21 @@ +Killing application '(?P.+)'\n +(.*\n)* +Application exited '(?P=old_app_name)'\n +(.*\n)* +Killed application '(?P=old_app_name)'\n +(.*\n)* +Deleting image for application '(?P=old_app_name)'\n +(.*\n)* +Deleted image for application '(?P=old_app_name)'\n +(.*\n)* +Downloading application '(?P.+)'\n +(.*\n)* +Downloaded application '(?P=new_app_name)'\n +(.*\n)* +Installing application '(?P=new_app_name)'\n +(.*\n)* +Installed application '(?P=new_app_name)'\n +(.*\n)* +Starting application '(?P=new_app_name)'\n +(.*\n)* +Started application '(?P=new_app_name)' diff --git a/libraries/template_download-then-kill b/libraries/template_download-then-kill new file mode 100644 index 0000000..95a2b00 --- /dev/null +++ b/libraries/template_download-then-kill @@ -0,0 +1,17 @@ +Downloading application '(?P.+)'\n +(.*\n)* +Downloaded application '(?P=new_app_name)'\n +(.*\n)* +Killing application '(?P.+)'\n +(.*\n)* +Application exited '(?P=old_app_name)'\n +(.*\n)* +Killed application '(?P=old_app_name)'\n +(.*\n)* +Installing application '(?P=new_app_name)'\n +(.*\n)* +Installed application '(?P=new_app_name)'\n +(.*\n)* +Starting application '(?P=new_app_name)'\n +(.*\n)* +Started application '(?P=new_app_name)' diff --git a/libraries/template_hand-over b/libraries/template_hand-over new file mode 100644 index 0000000..05fea46 --- /dev/null +++ b/libraries/template_hand-over @@ -0,0 +1,13 @@ +Downloading application '(?P.+)'\n +(.*\n)* +Downloaded application '(?P=new_app_name)'\n +(.*\n)* +Installing application '(?P=new_app_name)'\n +(.*\n)* +Installed application '(?P=new_app_name)'\n +(.*\n)* +Starting application '(?P=new_app_name)'\n +(.*\n)* +Started application '(?P=new_app_name)'\n +(.*\n)* +Killing application '(?P.+)' diff --git a/libraries/template_kill-then-download b/libraries/template_kill-then-download new file mode 100644 index 0000000..3d1bae5 --- /dev/null +++ b/libraries/template_kill-then-download @@ -0,0 +1,17 @@ +Killing application '(?P.+)'\n +(.*\n)* +Application exited '(?P=old_app_name)'\n +(.*\n)* +Killed application '(?P=old_app_name)'\n +(.*\n)* +Downloading application '(?P.+)'\n +(.*\n)* +Downloaded application '(?P=new_app_name)'\n +(.*\n)* +Installing application '(?P=new_app_name)'\n +(.*\n)* +Installed application '(?P=new_app_name)'\n +(.*\n)* +Starting application '(?P=new_app_name)'\n +(.*\n)* +Started application '(?P=new_app_name)' From a5ab332af3d78370ce0b72e36e097f96c1d86a71 Mon Sep 17 00:00:00 2001 From: Horia Delicoti Date: Tue, 7 Feb 2017 23:39:30 +0100 Subject: [PATCH 3/5] r/resincli.robot: Adding keyword to test the update strategy of Resin Supervisor. * Adding keyword for git to force push to application. Signed-off-by: Horia Delicoti --- resources/resincli.robot | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/resources/resincli.robot b/resources/resincli.robot index 7431c2c..607b783 100644 --- a/resources/resincli.robot +++ b/resources/resincli.robot @@ -54,6 +54,13 @@ Git push "${directory}" to application "${application_name}" ${result} = Run Process git push resin HEAD:refs/heads/master shell=yes cwd=${directory} Process ${result} +Git push force "${directory}" to application "${application_name}" + Set Environment Variable RESINUSER ${RESINUSER} + ${result} = Run Process git remote add resin $RESINUSER@git.${RESINRC_RESIN_URL}:$RESINUSER/${application_name}.git shell=yes cwd=${directory} + Process ${result} + ${result} = Run Process git push resin HEAD:refs/heads/master -f shell=yes cwd=${directory} + Process ${result} + Configure "${image}" with "${application_name}" File Should Exist ${image} msg="Provided images file does not exist" ${result_register} = Run Process resin device register ${application_name} | cut -d ' ' -f 4 shell=yes @@ -142,14 +149,37 @@ Check enabling supervisor delta on "${application_name}" Remove ENV variable "RESIN_SUPERVISOR_DELTA" from application "${application_name}" [Teardown] Run Keyword Remove Directory /tmp/${random} recursive=True +Test update strategy "${update_strategy}" to application "${application_name}" + Add ENV variable "RESIN_SUPERVISOR_UPDATE_STRATEGY" with value "${update_strategy}" to application "${application_name}" + Check if ENV variable "RESIN_SUPERVISOR_UPDATE_STRATEGY" with value "${update_strategy}" exists in application "${application_name}" + ${random} = Evaluate random.randint(0, sys.maxint) modules=random, sys + Git clone "${application_repo}" "/tmp/${random}" + Git checkout "${application_commit}" "/tmp/${random}" + Add console output "Update strategy: ${update_strategy}" to "/tmp/${random}" + ${last_commit} = Get the last git commit from "/tmp/${random}" + Git checkout "${last_commit}" "/tmp/${random}" + Run Keyword If '${update_strategy}' == 'hand-over' Run command "killall python" on device using socket "unix\#/tmp/console.sock" + Run Keyword If '${update_strategy}' == 'hand-over' Add ENV variable "RESIN_SUPERVISOR_HANDOVER_TIMEOUT" with value "600" to application "${application_name}" + Run Keyword If '${update_strategy}' == 'hand-over' Check if ENV variable "RESIN_SUPERVISOR_HANDOVER_TIMEOUT" with value "600" exists in application "${application_name}" + Git push force "/tmp/${random}" to application "${application_name}" + Wait Until Keyword Succeeds 30x 10s Device "${device_uuid}" log should contain "Update strategy: ${update_strategy}" + ${result} = Run Keyword If '${update_strategy}' == 'hand-over' Run Process resin logs ${device_uuid} | grep -B30 "Killing application" -s | tail -30 | grep -A30 "Updating config" | awk -F '\\)\ ' '{print $2'} > test_file_${update_strategy} shell=yes cwd=/tmp + ... ELSE Run Process resin logs ${device_uuid} | grep -B30 "Started application" -s | tail -30 | grep -A30 "Updating" | awk -F '\\)\ ' '{print $2'} > test_file_${update_strategy} shell=yes cwd=/tmp + Process ${result} + ${result} = Run Process python /autohat/libraries/FileComparator.py /autohat/libraries/template_${update_strategy} /tmp/test_file_${update_strategy} shell=yes + Process ${result} + [Teardown] Run Keywords Remove Directory /tmp/${random} recursive=True + ... AND Remove ENV variable "RESIN_SUPERVISOR_UPDATE_STRATEGY" from application "${application_name}" + ... AND Run Keyword If '${update_strategy}' == 'hand-over' Remove ENV variable "RESIN_SUPERVISOR_HANDOVER_TIMEOUT" from application "${application_name}" + Add console output "${message}" to "${directory}" ${result} = Run Process git config --global user.email "%{email}" shell=yes cwd=${directory} Process ${result} - ${result} = Run Process sed -i '6i echo \"${message}\"' start.sh shell=yes cwd=${directory} + ${result} = Run Process sed -ie 's/Hello World!/${message}/g' start.sh shell=yes cwd=${directory} Process ${result} ${result} = Run Process git add . shell=yes cwd=${directory} Process ${result} - ${result} = Run Process git commit -m "Console message added" shell=yes cwd=${directory} + ${result} = Run Process git commit -m "Console message added: ${message}" shell=yes cwd=${directory} Process ${result} Get the last git commit from "${directory}" From fd667efa09029aabfcb162e782936166dcbc0249 Mon Sep 17 00:00:00 2001 From: Horia Delicoti Date: Tue, 7 Feb 2017 23:42:58 +0100 Subject: [PATCH 4/5] qemu.robot: Adding test case that checks the update strategies. Signed-off-by: Horia Delicoti --- qemu.robot | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qemu.robot b/qemu.robot index 2cc8854..60ffc87 100644 --- a/qemu.robot +++ b/qemu.robot @@ -49,6 +49,11 @@ Git pushing to application Git push "/tmp/${application_name}" to application "${application_name}" Checking if device is running the pushed application (Tries for 300 s) Wait Until Keyword Succeeds 30x 10s Device "${device_uuid}" log should contain "Hello" +Checking update strategies + Test update strategy "kill-then-download" to application "${application_name}" + Test update strategy "download-then-kill" to application "${application_name}" + Test update strategy "delete-then-download" to application "${application_name}" + Test update strategy "hand-over" to application "${application_name}" Providing a device to the application with delta already enabled Run "${image}" on "${application_name}" with delta already enabled Checking if kernel module loading works From b42daebbe138c331824d040aa295e0cd0fe8cfa5 Mon Sep 17 00:00:00 2001 From: Horia Delicoti Date: Tue, 7 Feb 2017 23:46:39 +0100 Subject: [PATCH 5/5] CHANGELOG.md: Adding entry for test case that checks the update strategies of Resin Supervisor. [Connects to #38] Signed-off-by: Horia Delicoti --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 828abaa..7b49034 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Change log ----------- +* Add test case that checks the update strategies of Resin Supervisor [Horia] * Test case that provides a device to the application that already has delta enabled [Horia] * Fixing keyword that fails if duplicate names are found in resin keys. Also, adding disclaimer as warning [Horia] * Changing resin-cli version to v.5.2.4 [Horia]