From patchwork Fri Jul 6 01:26:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael-Doyle Hudson X-Patchwork-Id: 9878 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 0B1FC23F2A for ; Fri, 6 Jul 2012 01:26:16 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id AFDA0A1809A for ; Fri, 6 Jul 2012 01:26:15 +0000 (UTC) Received: by ggnf1 with SMTP id f1so8726303ggn.11 for ; Thu, 05 Jul 2012 18:26:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=e6ZMVytzU5GyRQGiEN/kDeWo6fQlK7qIl+DwDgLRfoY=; b=Ttuxf+0SL2aTy4ilHZO9nBUiPI5vJeLWA/i1J9f3joMEKxQVe3qhOrzJ6bClG6cC7j uFsn3Sv6Y3NT4TtYGLqdRwQ6WLwzxQMMbYpdysRIvx5v1td5KfHBkSAR1CU+dPGiiHu1 K/+Ituu65rBCK03To9w8QuZNJ96XFydWtG34NdWMJPij4VI89OWzbGwFRZhyppEiLHa6 BfFvbNNODIMt+ejro5kA2npMEEeYby1EhEDf95SNJ1OKEZUSNPHM1YETcLif+7QNUu4g HC6iPWXrhYJGpMitC/t1kMn9cpPri47FZIQLgimJqkPT5ZV72HKS4y1VXqBPMHKX2FfM 5S+w== Received: by 10.50.87.227 with SMTP id bb3mr1177324igb.57.1341537974897; Thu, 05 Jul 2012 18:26:14 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.24.148 with SMTP id v20csp2949ibb; Thu, 5 Jul 2012 18:26:13 -0700 (PDT) Received: by 10.180.100.2 with SMTP id eu2mr3592470wib.10.1341537973134; Thu, 05 Jul 2012 18:26:13 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id bc6si3866972wib.6.2012.07.05.18.26.12 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 Jul 2012 18:26:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1SmxJE-00036Y-JL for ; Fri, 06 Jul 2012 01:26:12 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 85E2AE012B for ; Fri, 6 Jul 2012 01:26:12 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-scheduler X-Launchpad-Branch: ~linaro-validation/lava-scheduler/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 195 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-scheduler/trunk] Rev 195: make health job creation a bit more like regular job creation Message-Id: <20120706012612.21293.67222.launchpad@ackee.canonical.com> Date: Fri, 06 Jul 2012 01:26:12 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15544"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: d9b99b8cd1784343ffcd67d2c42e44065a9ac70e X-Gm-Message-State: ALoCoQlVa12ht3zGJMa0LPwIG1kELcXvLdtildyPtew7xYQjVGxmjJazwPZcbiHlKAPZVwDVbxt2 Merge authors: Michael Hudson-Doyle (mwhudson) Related merge proposals: https://code.launchpad.net/~mwhudson/lava-scheduler/health-job-creation-tweaks/+merge/112689 proposed by: Michael Hudson-Doyle (mwhudson) review: Approve - Andy Doan (doanac) ------------------------------------------------------------ revno: 195 [merge] committer: Michael Hudson-Doyle branch nick: trunk timestamp: Fri 2012-07-06 13:25:15 +1200 message: make health job creation a bit more like regular job creation modified: lava_scheduler_app/models.py lava_scheduler_daemon/dbjobsource.py --- lp:lava-scheduler https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk You are subscribed to branch lp:lava-scheduler. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription === modified file 'lava_scheduler_app/models.py' --- lava_scheduler_app/models.py 2012-06-22 05:06:06 +0000 +++ lava_scheduler_app/models.py 2012-06-29 03:26:14 +0000 @@ -321,7 +321,7 @@ return ("lava.scheduler.job.detail", [self.pk]) @classmethod - def from_json_and_user(cls, json_data, user): + def from_json_and_user(cls, json_data, user, health_check=False): job_data = simplejson.loads(json_data) validate_job_data(job_data) if 'target' in job_data: @@ -350,10 +350,12 @@ raise ValueError( "%r is not a valid email address." % address) + if job_data.get('health_check', False) and not health_check: + raise ValueError( + "cannot submit a job with health_check: true via the api.") + job_name = job_data.get('job_name', '') - is_check = job_data.get('health_check', False) - submitter = user group = None is_public = True @@ -383,7 +385,7 @@ job = TestJob( definition=json_data, submitter=submitter, requested_device=target, requested_device_type=device_type, - description=job_name, health_check=is_check, user=user, + description=job_name, health_check=health_check, user=user, group=group, is_public=is_public) job.save() for tag in tags: === modified file 'lava_scheduler_daemon/dbjobsource.py' --- lava_scheduler_daemon/dbjobsource.py 2012-06-22 05:07:18 +0000 +++ lava_scheduler_daemon/dbjobsource.py 2012-06-29 03:14:32 +0000 @@ -1,5 +1,4 @@ import datetime -import json import logging import urlparse @@ -14,11 +13,17 @@ from linaro_django_xmlrpc.models import AuthToken +import simplejson + from twisted.internet.threads import deferToThread from zope.interface import implements -from lava_scheduler_app.models import Device, DeviceStateTransition, TestJob +from lava_scheduler_app.models import ( + Device, + DeviceStateTransition, + JSONDataError, + TestJob) from lava_scheduler_daemon.jobsource import IJobSource @@ -89,7 +94,7 @@ return self.deferForDB(self.getBoardList_impl) def _get_json_data(self, job): - json_data = json.loads(job.definition) + json_data = simplejson.loads(job.definition) json_data['target'] = job.actual_device.hostname for action in json_data['actions']: if not action['command'].startswith('submit_results'): @@ -103,23 +108,31 @@ parsed = list(parsed) parsed[1] = netloc params['server'] = urlparse.urlunsplit(parsed) + json_data['health_check'] = job.health_check return json_data def _getHealthCheckJobForBoard(self, device): job_json = device.device_type.health_check_job if not job_json: + # This should never happen, it's a logic error. self.logger.error( "no job_json in getHealthCheckJobForBoard for %r", device) + device.put_into_maintenance_mode( + None, "no job_json in getHealthCheckJobForBoard") return None else: user = User.objects.get(username='lava-health') - job_data = json.loads(job_json) - job_name = job_data.get('job_name') - job = TestJob( - definition=job_json, submitter=user, description=job_name, - health_check=True, owner=user, is_public=True) - job.save() - return job + job_data = simplejson.loads(job_json) + job_data['target'] = device.hostname + job_json = simplejson.dumps(job_data) + try: + return TestJob.from_json_and_user(job_json, user, True) + except (JSONDataError, ValueError) as e: + self.logger.exception( + "TestJob.from_json_and_user failed in _getHealthCheckJobForBoard") + device.put_into_maintenance_mode( + None, "TestJob.from_json_and_user failed for health job: %s" % e) + return None def _getJobFromQueue(self, device): jobs_for_device = TestJob.objects.all().filter( @@ -197,6 +210,9 @@ transaction.commit() return json_data else: + # _getHealthCheckJobForBoard can offline the board, so commit + # in this branch too. + transaction.commit() return None def getJobForBoard(self, board_name):