Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case to test the different update strategies. #67

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
46 changes: 46 additions & 0 deletions libraries/FileComparator.py
Original file line number Diff line number Diff line change
@@ -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 <template_file> <input_file>" % 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question - The Logs from supervisor are not guaranteed to be in a order and there could be duplicates as well. I am not sure if re.search() takes this into account.

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)
21 changes: 21 additions & 0 deletions libraries/template_delete-then-download
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Killing application '(?P<old_app_name>.+)'\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<new_app_name>.+)'\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)'
17 changes: 17 additions & 0 deletions libraries/template_download-then-kill
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Downloading application '(?P<new_app_name>.+)'\n
(.*\n)*
Downloaded application '(?P=new_app_name)'\n
(.*\n)*
Killing application '(?P<old_app_name>.+)'\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)'
13 changes: 13 additions & 0 deletions libraries/template_hand-over
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Downloading application '(?P<new_app_name>.+)'\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<old_app_name>.+)'
17 changes: 17 additions & 0 deletions libraries/template_kill-then-download
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Killing application '(?P<old_app_name>.+)'\n
(.*\n)*
Application exited '(?P=old_app_name)'\n
(.*\n)*
Killed application '(?P=old_app_name)'\n
(.*\n)*
Downloading application '(?P<new_app_name>.+)'\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)'
5 changes: 5 additions & 0 deletions qemu.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 32 additions & 2 deletions resources/resincli.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
7 changes: 7 additions & 0 deletions resources/resinos.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down