aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Casagrande <milo.casagrande@linaro.org>2015-01-19 16:42:58 +0100
committerMilo Casagrande <milo.casagrande@linaro.org>2015-01-19 16:42:58 +0100
commitdedc04c79a6721cc7cbebaf9a917a28867fd1d7c (patch)
treeb26e1a0c5ced25ce2521d321ff69a067833dbf8e
parent71bfbd5e2506b15c4c8c31dd2f267a35c00a2760 (diff)
Make send api accepts the lab name.
* Make it possible to trigger the boot report email only for a single lab. * Fix docs. Change-Id: I3d0ae770d87a6977c7e98ee0904f09afb1f7d6d4
-rw-r--r--app/handlers/common.py1
-rw-r--r--app/taskqueue/tasks.py33
-rw-r--r--app/utils/report.py29
-rw-r--r--doc/collection-send.rst18
-rw-r--r--doc/schema-send.rst4
5 files changed, 76 insertions, 9 deletions
diff --git a/app/handlers/common.py b/app/handlers/common.py
index eea4fbf..dbb2462 100644
--- a/app/handlers/common.py
+++ b/app/handlers/common.py
@@ -319,6 +319,7 @@ SEND_VALID_KEYS = {
models.DELAY_KEY,
models.JOB_KEY,
models.KERNEL_KEY,
+ models.LAB_NAME_KEY,
models.REPORT_SEND_TO_KEY,
models.SEND_BOOT_REPORT_KEY,
models.SEND_BUILD_REPORT_KEY
diff --git a/app/taskqueue/tasks.py b/app/taskqueue/tasks.py
index c5f5cfb..8b47b42 100644
--- a/app/taskqueue/tasks.py
+++ b/app/taskqueue/tasks.py
@@ -120,12 +120,24 @@ def defconfig_bisect(doc_id, db_options, fields=None):
@taskc.app.task(name="schedule-boot-report")
def schedule_boot_report(json_obj, db_options, mail_options, countdown):
+ """Schedule a second task to send the boot report.
+
+ :param json_obj: The json data as sent in the request.
+ :type json_obj: dict
+ :param db_options: The options necessary to connect to the database.
+ :type db_options: dict
+ :param mail_options: The options necessary to connect to the SMTP server.
+ :type mail_options: dict
+ :param countdown: The delay in seconds to send the email.
+ :type countdown: int
+ """
j_get = json_obj.get
to_addrs = []
if bool(j_get(models.SEND_BOOT_REPORT_KEY, False)):
job = j_get(models.JOB_KEY)
kernel = j_get(models.KERNEL_KEY)
+ lab_name = j_get(models.LAB_NAME_KEY, None)
boot_emails = j_get(models.BOOT_REPORT_SEND_TO_KEY, None)
generic_emails = j_get(models.REPORT_SEND_TO_KEY, None)
@@ -144,7 +156,7 @@ def schedule_boot_report(json_obj, db_options, mail_options, countdown):
if to_addrs:
send_boot_report.apply_async(
- [job, kernel, to_addrs, db_options, mail_options],
+ [job, kernel, lab_name, to_addrs, db_options, mail_options],
countdown=countdown)
else:
utils.LOG.warn(
@@ -153,11 +165,26 @@ def schedule_boot_report(json_obj, db_options, mail_options, countdown):
@taskc.app.task(name="send-boot-report")
-def send_boot_report(job, kernel, to_addrs, db_options, mail_options):
+def send_boot_report(job, kernel, lab_name, to_addrs, db_options, mail_options):
+ """Create the boot report email and send it.
+
+ :param job: The job name.
+ :type job: str
+ :param kernel: The kernel name.
+ :type kernel: str
+ :param lab_name: The name of the lab.
+ :type lab_name: str
+ :param to_addrs: List of recipients.
+ :type to_addrs: list
+ :param db_options: The options necessary to connect to the database.
+ :type db_options: dict
+ :param mail_options: The options necessary to connect to the SMTP server.
+ :type mail_options: dict
+ """
utils.LOG.info("Preparing boot report email for '%s-%s'", job, kernel)
body, subject = utils.report.create_boot_report(
- job, kernel, db_options=db_options)
+ job, kernel, lab_name, db_options=db_options)
if all([body is not None, subject is not None]):
utils.LOG.info("Sending boot report email for '%s-%s'", job, kernel)
diff --git a/app/utils/report.py b/app/utils/report.py
index 0800fcd..2b2d673 100644
--- a/app/utils/report.py
+++ b/app/utils/report.py
@@ -92,13 +92,18 @@ def save_report(job, kernel, r_type, status, errors, db_options):
# pylint: disable=too-many-locals
-def create_boot_report(job, kernel, db_options):
+def create_boot_report(job, kernel, lab_name, db_options):
"""Create the boot report email to be sent.
+ If lab_name is not None, it will trigger a boot report only for that
+ specified lab.
+
:param job: The name of the job.
:type job: str
:param kernel: The name of the kernel.
:type kernel: str
+ :param lab_name: The name of the lab.
+ :type lab_name: str
:param db_options: The mongodb database connection parameters.
:type db_options: dict
:return A tuple with the email body and subject as strings or None.
@@ -112,6 +117,8 @@ def create_boot_report(job, kernel, db_options):
models.JOB_KEY: job,
models.KERNEL_KEY: kernel,
}
+ if lab_name is not None:
+ spec[models.LAB_NAME_KEY] = lab_name
_, total_count = utils.db.find_and_count(
database[models.BOOT_COLLECTION],
@@ -141,7 +148,7 @@ def create_boot_report(job, kernel, db_options):
fail_results = [x for x in fail_results.clone()]
conflict_data = None
- if fail_count != total_count:
+ if all([fail_count != total_count, lab_name is None]):
spec[models.STATUS_KEY] = models.PASS_STATUS
for key, val in unique_data.iteritems():
spec[key] = {"$in": val}
@@ -178,10 +185,12 @@ def create_boot_report(job, kernel, db_options):
conflict_data, _ = _parse_results(conflicts)
email_body, subject = _create_boot_email(
- job, kernel, failed_data, fail_count, total_count, conflict_data)
+ job, kernel, lab_name, failed_data, fail_count, total_count,
+ conflict_data)
elif fail_count == 0 and total_count > 0:
email_body, subject = _create_boot_email(
- job, kernel, failed_data, fail_count, total_count, conflict_data)
+ job, kernel, lab_name, failed_data, fail_count, total_count,
+ conflict_data)
elif fail_count == 0 and total_count == 0:
utils.LOG.warn(
"Nothing found for '%s-%s': no email report sent", job, kernel)
@@ -303,13 +312,16 @@ def _search_conflicts(failed, passed):
# pylint: disable=too-many-arguments
def _create_boot_email(
- job, kernel, failed_data, fail_count, total_count, conflict_data):
+ job, kernel, lab_name, failed_data, fail_count, total_count,
+ conflict_data):
"""Parse the results and create the email text body to send.
:param job: The name of the job.
:type job: str
:param kernel: The name of the kernel.
:type kernel: str
+ :param lab_name: The name of the lab.
+ :type lab_name: str
:param failed_data: The parsed failed results.
:type reduce: dict
:param fail_count: The total number of failed results.
@@ -326,16 +338,21 @@ def _create_boot_email(
"passed": total_count - fail_count,
"failed": fail_count,
"kernel": kernel,
+ "lab_name": lab_name,
"base_url": DEFAULT_BASE_URL,
"build_url": DEFAULT_BUILD_URL,
"boot_url": DEFAULT_BOOT_URL
}
+ # We use io and strings must be unicode.
email_body = u""
subject = (
u"%(job)s boot: %(total_results)d boots: "
- "%(passed)d passed, %(failed)d failed (%(kernel)s)" % args
+ "%(passed)d passed, %(failed)d failed (%(kernel)s)"
)
+ if lab_name is not None:
+ subject = " ".join([subject, u"- %(lab_name)s"])
+ subject = subject % args
with io.StringIO() as m_string:
m_string.write(
diff --git a/doc/collection-send.rst b/doc/collection-send.rst
index 6a456c7..23fe5e6 100644
--- a/doc/collection-send.rst
+++ b/doc/collection-send.rst
@@ -29,6 +29,7 @@ POST
:reqjson string job: The name of the job.
:reqjson string kernel: The name of the kernel.
+ :reqjson string lab_name: The name of the lab.
:reqjson boolean boot_report: If the boot report should be created and sent. Default to 0 (false).
:reqjson boolean build_report: If the build report should be created and sent. Default to 0 (false).
:reqjson send_to: A string or an array of strings of email addresses where to send the reports.
@@ -66,6 +67,23 @@ POST
"delay": 14400
}
+ .. sourcecode:: http
+
+ POST /send HTTP/1.1
+ Host: api.kernelci.org
+ Content-Type: application/json
+ Accept: */*
+ Authorization: token
+
+ {
+ "job": "next",
+ "kernel": "next-20150113",
+ "lab_name": "lab",
+ "boot_report": 1,
+ "send_to": ["email@example.net"],
+ "delay": 30
+ }
+
DELETE
******
diff --git a/doc/schema-send.rst b/doc/schema-send.rst
index 9f0a009..221a204 100644
--- a/doc/schema-send.rst
+++ b/doc/schema-send.rst
@@ -26,6 +26,10 @@ data sent to the server.
"type": "string",
"description": "The kernel name associated with the object"
},
+ "lab_name": {
+ "type": "string",
+ "description": "The name of the lab to trigger the report for"
+ },
"boot_report": {
"type": "boolean",
"description": "Whether the boot report should be created and sent",