From patchwork Wed Feb 1 03:08: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: 6482 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 6F11523F8D for ; Wed, 1 Feb 2012 03:08:13 +0000 (UTC) Received: from mail-bk0-f52.google.com (mail-bk0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id 3CAE7A184B1 for ; Wed, 1 Feb 2012 03:08:13 +0000 (UTC) Received: by bkar19 with SMTP id r19so878129bka.11 for ; Tue, 31 Jan 2012 19:08:13 -0800 (PST) Received: by 10.204.200.197 with SMTP id ex5mr11596408bkb.128.1328065692930; Tue, 31 Jan 2012 19:08:12 -0800 (PST) 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.204.130.220 with SMTP id u28cs199678bks; Tue, 31 Jan 2012 19:08:12 -0800 (PST) Received: by 10.180.93.194 with SMTP id cw2mr21718644wib.0.1328065692477; Tue, 31 Jan 2012 19:08:12 -0800 (PST) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id u55si16874826wec.76.2012.01.31.19.08.12 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 31 Jan 2012 19:08:12 -0800 (PST) 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 1RsQYO-0000Nn-9N for ; Wed, 01 Feb 2012 03:08:12 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 39456E0025 for ; Wed, 1 Feb 2012 03:08: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: 123 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-scheduler/trunk] Rev 123: reject unknown jobs at submit time Message-Id: <20120201030812.15931.32163.launchpad@ackee.canonical.com> Date: Wed, 01 Feb 2012 03:08: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="14734"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: a31d6ba950df244fc3d15f84de364dee0368ab2c Merge authors: Michael Hudson-Doyle (mwhudson) Related merge proposals: https://code.launchpad.net/~mwhudson/lava-scheduler/reject-unknown-tags-bug-921250/+merge/90801 proposed by: Michael Hudson-Doyle (mwhudson) review: Approve - Zygmunt Krynicki (zkrynicki) ------------------------------------------------------------ revno: 123 [merge] committer: Michael Hudson-Doyle branch nick: trunk timestamp: Wed 2012-02-01 16:06:38 +1300 message: reject unknown jobs at submit time modified: lava_scheduler_app/models.py lava_scheduler_app/tests.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-01-20 01:15:16 +0000 +++ lava_scheduler_app/models.py 2012-01-30 22:26:03 +0000 @@ -219,12 +219,18 @@ raise JSONDataError( "Neither 'target' nor 'device_type' found in job data.") job_name = job_data.get('job_name', '') + tags = [] + for tag_name in job_data.get('device_tags', []): + try: + tags.append(Tag.objects.get(name=tag_name)) + except Tag.DoesNotExist: + raise JSONDataError("tag %r does not exist" % tag_name) job = TestJob( definition=json_data, submitter=user, requested_device=target, requested_device_type=device_type, description=job_name) job.save() - for tag_name in job_data.get('device_tags', []): - job.tags.add(Tag.objects.get_or_create(name=tag_name)[0]) + for tag in tags: + job.tags.add(tag) return job def can_cancel(self, user): === modified file 'lava_scheduler_app/tests.py' --- lava_scheduler_app/tests.py 2012-01-24 01:43:43 +0000 +++ lava_scheduler_app/tests.py 2012-01-30 22:26:03 +0000 @@ -11,7 +11,12 @@ from linaro_django_xmlrpc.models import AuthToken -from lava_scheduler_app.models import Device, DeviceType, Tag, TestJob +from lava_scheduler_app.models import ( + Device, + DeviceType, + JSONDataError, + Tag, + TestJob) from lava_scheduler_daemon.dbjobsource import DatabaseJobSource @@ -59,6 +64,9 @@ name = self.getUniqueString('name') return DeviceType.objects.get_or_create(name=name)[0] + def ensure_tag(self, name): + return Tag.objects.get_or_create(name=name)[0] + def make_device(self, device_type=None, hostname=None): if device_type is None: device_type = self.ensure_device_type() @@ -141,8 +149,16 @@ self.factory.make_user()) self.assertEqual(set(job.tags.all()), set([])) + def test_from_json_and_user_errors_on_unknown_tags(self): + self.factory.ensure_device_type(name='panda') + self.assertRaises( + JSONDataError, TestJob.from_json_and_user, + json.dumps({'device_type':'panda', 'device_tags':['unknown']}), + self.factory.make_user()) + def test_from_json_and_user_sets_tag_from_device_tags(self): self.factory.ensure_device_type(name='panda') + self.factory.ensure_tag('tag') job = TestJob.from_json_and_user( json.dumps({'device_type':'panda', 'device_tags':['tag']}), self.factory.make_user()) @@ -151,6 +167,8 @@ def test_from_json_and_user_sets_multiple_tag_from_device_tags(self): self.factory.ensure_device_type(name='panda') + self.factory.ensure_tag('tag1') + self.factory.ensure_tag('tag2') job = TestJob.from_json_and_user( json.dumps({'device_type':'panda', 'device_tags':['tag1', 'tag2']}), self.factory.make_user()) @@ -159,6 +177,7 @@ def test_from_json_and_user_reuses_tag_objects(self): self.factory.ensure_device_type(name='panda') + self.factory.ensure_tag('tag') job1 = TestJob.from_json_and_user( json.dumps({'device_type':'panda', 'device_tags':['tag']}), self.factory.make_user())