def update_recipeset_status(id): """ Updates the status of a recipe set. The request must be :mimetype:`application/json`. Currently the only allowed value for status is 'Cancelled', which has the effect of cancelling all recipes in the recipe set that have not finished yet. :param id: ID of the recipe set. :jsonparam string status: The new status. Must be 'Cancelled'. :jsonparam string msg: A message describing the reason for updating the status. """ recipeset = _get_rs_by_id(id) if not recipeset.can_cancel(identity.current.user): raise Forbidden403('Cannot update recipe set status') data = read_json_request(request) if 'status' not in data: raise BadRequest400('Missing status') status = TaskStatus.from_string(data['status']) msg = data.get('msg', None) or None if status != TaskStatus.cancelled: raise BadRequest400('Status must be "Cancelled"') with convert_internal_errors(): recipeset.record_activity(user=identity.current.user, service=u'HTTP', field=u'Status', action=u'Cancelled') recipeset.cancel(msg=msg) return '', 204
def test_update_status_can_be_roundtripped_40214(self): complete_job_xml = pkg_resources.resource_string( 'bkr.inttest', 'job_40214.xml') xmljob = XmlJob(xmltramp.parse(complete_job_xml)) data_setup.create_tasks(xmljob) session.flush() # Import the job xml job = self.controller.process_xmljob(xmljob, self.user) session.flush() # Mark job waiting data_setup.mark_job_waiting(job) session.flush() # watchdog's should exist self.assertNotEqual(len(watchdogs_for_job(job)), 0) # Play back the original jobs results and status data_setup.playback_job_results(job, xmljob) session.flush() # Verify that the original status and results match self.assertEquals(TaskStatus.from_string(xmljob.wrappedEl('status')), job.status) self.assertEquals(TaskResult.from_string(xmljob.wrappedEl('result')), job.result) for i, recipeset in enumerate(xmljob.iter_recipeSets()): for j, recipe in enumerate(recipeset.iter_recipes()): self.assertEquals( TaskStatus.from_string(recipe.wrappedEl('status')), job.recipesets[i].recipes[j].status) self.assertEquals( TaskResult.from_string(recipe.wrappedEl('result')), job.recipesets[i].recipes[j].result) for k, task in enumerate(recipe.iter_tasks()): self.assertEquals( TaskStatus.from_string(task.status), job.recipesets[i].recipes[j].tasks[k].status) self.assertEquals( TaskResult.from_string(task.result), job.recipesets[i].recipes[j].tasks[k].result) # No watchdog's should exist when the job is complete self.assertEquals(len(watchdogs_for_job(job)), 0)
def test_update_status_can_be_roundtripped_40214(self): complete_job_xml = pkg_resources.resource_string('bkr.inttest', 'job_40214.xml') xmljob = XmlJob(xmltramp.parse(complete_job_xml)) data_setup.create_tasks(xmljob) session.flush() # Import the job xml job = self.controller.process_xmljob(xmljob, self.user) session.flush() # Mark job waiting data_setup.mark_job_waiting(job) session.flush() # watchdog's should exist self.assertNotEqual(len(watchdogs_for_job(job)), 0) # Play back the original jobs results and status data_setup.playback_job_results(job, xmljob) session.flush() # Verify that the original status and results match self.assertEquals(TaskStatus.from_string(xmljob.wrappedEl('status')), job.status) self.assertEquals(TaskResult.from_string(xmljob.wrappedEl('result')), job.result) for i, recipeset in enumerate(xmljob.iter_recipeSets()): for j, recipe in enumerate(recipeset.iter_recipes()): self.assertEquals(TaskStatus.from_string(recipe.wrappedEl('status')), job.recipesets[i].recipes[j].status) self.assertEquals(TaskResult.from_string(recipe.wrappedEl('result')), job.recipesets[i].recipes[j].result) for k, task in enumerate(recipe.iter_tasks()): self.assertEquals(TaskStatus.from_string(task.status), job.recipesets[i].recipes[j].tasks[k].status) self.assertEquals(TaskResult.from_string(task.result), job.recipesets[i].recipes[j].tasks[k].result) # No watchdog's should exist when the job is complete self.assertEquals(len(watchdogs_for_job(job)), 0)
def test_update_status_can_be_roundtripped_40214(self): complete_job_xml = pkg_resources.resource_string("bkr.inttest", "job_40214.xml") xmljob = lxml.etree.fromstring(complete_job_xml) data_setup.create_tasks(xmljob) session.flush() # Import the job xml job = self.controller.process_xmljob(xmljob, self.user) session.flush() # Mark job waiting data_setup.mark_job_waiting(job) session.flush() # watchdog's should exist self.assertNotEqual(len(watchdogs_for_job(job)), 0) # Play back the original jobs results and status data_setup.playback_job_results(job, xmljob) session.flush() # Verify that the original status and results match self.assertEquals(TaskStatus.from_string(xmljob.get("status")), job.status) self.assertEquals(TaskResult.from_string(xmljob.get("result")), job.result) for i, recipeset in enumerate(xmljob.xpath("recipeSet")): for j, recipe in enumerate(recipeset.xpath("recipes")): self.assertEquals(TaskStatus.from_string(recipe.get("status")), job.recipesets[i].recipes[j].status) self.assertEquals(TaskResult.from_string(recipe.get("result")), job.recipesets[i].recipes[j].result) for k, task in enumerate(recipe.xpath("task")): self.assertEquals( TaskStatus.from_string(task.get("status")), job.recipesets[i].recipes[j].tasks[k].status ) self.assertEquals( TaskResult.from_string(task.get("result")), job.recipesets[i].recipes[j].tasks[k].result ) # No watchdog's should exist when the job is complete self.assertEquals(len(watchdogs_for_job(job)), 0)