diff options
| author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2015-05-13 13:21:33 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-05-14 18:04:10 +0100 |
| commit | 80ca4f00f82cd2f58fe5cda38c8cc5a719c887b6 (patch) | |
| tree | f2d5a130213c37b8aed1fb07fecf46eb9e5e1a13 /bitbake/lib/toaster/contrib/tts/launcher.py | |
| parent | 23f5b009e0ebf59cfcc9ae90a1084468fc88e42f (diff) | |
| download | poky-80ca4f00f82cd2f58fe5cda38c8cc5a719c887b6.tar.gz | |
bitbake: toaster/contrib: adding TTS squashed patch
In order to move the Toaster Test System in Toaster itself,
we create a contrib directory.
The TTS is added as a squashed patch with no history.
It contains code contributed by Ke Zou <ke.zou@windriver.com>.
(Bitbake rev: 7d24fea2b5dcaac6add738b6fb4700d698824286)
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/contrib/tts/launcher.py')
| -rwxr-xr-x | bitbake/lib/toaster/contrib/tts/launcher.py | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/contrib/tts/launcher.py b/bitbake/lib/toaster/contrib/tts/launcher.py new file mode 100755 index 0000000000..5b63bc1de6 --- /dev/null +++ b/bitbake/lib/toaster/contrib/tts/launcher.py | |||
| @@ -0,0 +1,100 @@ | |||
| 1 | #!/usr/bin/python | ||
| 2 | |||
| 3 | # ex:ts=4:sw=4:sts=4:et | ||
| 4 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 5 | # | ||
| 6 | # Copyright (C) 2015 Alexandru Damian for Intel Corp. | ||
| 7 | # | ||
| 8 | # This program is free software; you can redistribute it and/or modify | ||
| 9 | # it under the terms of the GNU General Public License version 2 as | ||
| 10 | # published by the Free Software Foundation. | ||
| 11 | # | ||
| 12 | # This program is distributed in the hope that it will be useful, | ||
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | # GNU General Public License for more details. | ||
| 16 | # | ||
| 17 | # You should have received a copy of the GNU General Public License along | ||
| 18 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | |||
| 21 | # Program to run the next task listed from the backlog.txt; designed to be | ||
| 22 | # run from crontab. | ||
| 23 | |||
| 24 | from __future__ import print_function | ||
| 25 | import sys, os, config, shellutils | ||
| 26 | from shellutils import ShellCmdException | ||
| 27 | |||
| 28 | # Import smtplib for the actual sending function | ||
| 29 | import smtplib | ||
| 30 | |||
| 31 | # Import the email modules we'll need | ||
| 32 | from email.mime.text import MIMEText | ||
| 33 | |||
| 34 | DEBUG=True | ||
| 35 | |||
| 36 | def _take_lockfile(): | ||
| 37 | return shellutils.lockfile(shellutils.mk_lock_filename()) | ||
| 38 | |||
| 39 | |||
| 40 | def read_next_task_by_state(task_state, task_name = None): | ||
| 41 | if not os.path.exists(os.path.join(os.path.dirname(__file__), config.BACKLOGFILE)): | ||
| 42 | return None | ||
| 43 | os.rename(config.BACKLOGFILE, config.BACKLOGFILE + ".tmp") | ||
| 44 | task = None | ||
| 45 | with open(config.BACKLOGFILE + ".tmp", "r") as f_in: | ||
| 46 | with open(config.BACKLOGFILE, "w") as f_out: | ||
| 47 | for line in f_in.readlines(): | ||
| 48 | if task is None: | ||
| 49 | fields = line.strip().split("|", 2) | ||
| 50 | if fields[1] == task_state: | ||
| 51 | if task_name is None or task_name == fields[0]: | ||
| 52 | task = fields[0] | ||
| 53 | print("Updating %s %s to %s" % (task, task_state, config.TASKS.next_task(task_state))) | ||
| 54 | line = "%s|%s\n" % (task, config.TASKS.next_task(task_state)) | ||
| 55 | f_out.write(line) | ||
| 56 | os.remove(config.BACKLOGFILE + ".tmp") | ||
| 57 | return task | ||
| 58 | |||
| 59 | def send_report(task_name, plaintext, errtext = None): | ||
| 60 | if errtext is None: | ||
| 61 | msg = MIMEText(plaintext) | ||
| 62 | else: | ||
| 63 | if plaintext is None: | ||
| 64 | plaintext="" | ||
| 65 | msg = MIMEText("--STDOUT dump--\n\n%s\n\n--STDERR dump--\n\n%s" % (plaintext, errtext)) | ||
| 66 | |||
| 67 | msg['Subject'] = "[review-request] %s - smoke test results" % task_name | ||
| 68 | msg['From'] = config.OWN_EMAIL_ADDRESS | ||
| 69 | msg['To'] = config.REPORT_EMAIL_ADDRESS | ||
| 70 | |||
| 71 | s = smtplib.SMTP("localhost") | ||
| 72 | s.sendmail(config.OWN_EMAIL_ADDRESS, [config.REPORT_EMAIL_ADDRESS], msg.as_string()) | ||
| 73 | s.quit() | ||
| 74 | |||
| 75 | if __name__ == "__main__": | ||
| 76 | # we don't do anything if we have another instance of us running | ||
| 77 | lf = _take_lockfile() | ||
| 78 | |||
| 79 | if lf is None: | ||
| 80 | if DEBUG: | ||
| 81 | print("Concurrent script in progress, exiting") | ||
| 82 | sys.exit(1) | ||
| 83 | |||
| 84 | next_task = read_next_task_by_state(config.TASKS.PENDING) | ||
| 85 | if next_task is not None: | ||
| 86 | print("Next task is", next_task) | ||
| 87 | errtext = None | ||
| 88 | out = None | ||
| 89 | try: | ||
| 90 | out = shellutils.run_shell_cmd("./runner.py %s" % next_task) | ||
| 91 | pass | ||
| 92 | except ShellCmdException as e: | ||
| 93 | print("Failed while running the test runner: %s", e) | ||
| 94 | errtext = e.__str__() | ||
| 95 | send_report(next_task, out, errtext) | ||
| 96 | read_next_task_by_state(config.TASKS.INPROGRESS, next_task) | ||
| 97 | else: | ||
| 98 | print("No task") | ||
| 99 | |||
| 100 | shellutils.unlockfile(lf) | ||
