本文整理汇总了Python中bkr.server.model.Task类的典型用法代码示例。如果您正苦于以下问题:Python Task类的具体用法?Python Task怎么用?Python Task使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Task类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: default
def default(self, *args, **kw):
try:
using_task_id = False
if len(args) == 1:
try:
task_id = int(args[0])
using_task_id = True
except ValueError:
pass
if using_task_id:
task = Task.by_id(task_id)
else:
task = Task.by_name("/%s" % "/".join(args))
#Would rather not redirect but do_search expects task_id in URL
#This is the simplest way of dealing with it
redirect("/tasks/%s" % task.id)
except InvalidRequestError:
if using_task_id:
err_msg = u'Invalid task_id %s' % args[0]
else:
err_msg = u'Invalid task /%s' % '/'.join(args)
flash(_(err_msg))
redirect("/tasks")
return dict(task=task,
form = self.task_form,
value = dict(task_id = task.id),
options = dict(hidden=dict(task = 1)),
action = './do_search')
示例2: default
def default(self, *args, **kw):
try:
using_task_id = False
if len(args) == 1:
try:
task_id = int(args[0])
using_task_id = True
except ValueError:
pass
if using_task_id:
task = Task.by_id(task_id)
else:
task = Task.by_name("/%s" % "/".join(args))
#Would rather not redirect but do_search expects task_id in URL
#This is the simplest way of dealing with it
redirect("/tasks/%s" % task.id)
except DatabaseLookupError as e:
flash(unicode(e))
redirect("/tasks")
return dict(task=task,
form = self.task_form,
value = dict(task_id = task.id),
options = dict(hidden=dict(task = 1)),
action = './do_search')
示例3: save
def save(self, task_rpm, *args, **kw):
"""
TurboGears method to upload task rpm package
"""
rpm_path = Task.get_rpm_path(task_rpm.filename)
if not task_rpm.filename:
flash(_(u'No task RPM specified'))
redirect(url("./new"))
# we do it here, since we do not want to proceed
# any further
if len(task_rpm.filename) > 255:
flash(_(u"Task RPM name should be <= 255 characters"))
redirect(url("./new"))
if os.path.exists("%s" % rpm_path):
flash(_(u'Failed to import because we already have %s' %
task_rpm.filename ))
redirect(url("./new"))
try:
def write_data(f):
siphon(task_rpm.file, f)
task = Task.update_task(task_rpm.filename, write_data)
except Exception, err:
session.rollback()
log.exception('Failed to import %s', task_rpm.filename)
flash(_(u'Failed to import task: %s' % err))
redirect(url("./new"))
示例4: update_db
def update_db(self):
self.logger.info('Updating local Beaker database..')
for task_rpm in self.tasks_added:
self.logger.debug('Adding %s'% task_rpm)
with open(os.path.join(self.task_dir,task_rpm)) as f:
try:
session.begin()
task = self.tasks.process_taskinfo(self.tasks.read_taskinfo(f))
old_rpm = task.rpm
task.rpm = task_rpm
session.commit()
except Exception:
session.rollback()
session.close()
self.logger.critical('Error adding task %s' % task_rpm)
unlink_ignore(task_rpm)
else:
session.close()
self.logger.debug('Successfully added %s' % task.rpm)
if old_rpm:
unlink_ignore(os.path.join(self.task_dir, old_rpm))
# Update task repo
self.logger.info('Creating repodata..')
Task.update_repo()
return
示例5: _create_recipe
def _create_recipe(self, system=None):
with session.begin():
install_task = Task.by_name(u'/distribution/install')
reserve_task = Task.by_name(u'/distribution/reservesys')
lc = create_lab_controller()
rhel62_server_x86_64 = create_rhel62_server_x86_64(lab_controller=lc)
if not system:
system = create_x86_64_automated(lc)
recipe = data_setup.create_recipe(distro_tree=rhel62_server_x86_64, task_list=[install_task, reserve_task])
data_setup.create_job_for_recipes([recipe], owner=create_user(), whiteboard=u'')
data_setup.mark_recipe_complete(recipe, system=system)
self.recipe_id = recipe.id
return recipe
示例6: _create_recipe_with_user_defined_distro
def _create_recipe_with_user_defined_distro(self, **kwargs):
with session.begin():
install_task = Task.by_name(u'/distribution/check-install')
reserve_task = Task.by_name(u'/distribution/reservesys')
lc = create_lab_controller()
system = create_x86_64_automated(lc)
recipe = data_setup.create_recipe(custom_distro=True, osmajor=kwargs['osmajor'],
task_list=[install_task, reserve_task]) if \
'osmajor' in kwargs else data_setup.create_recipe(custom_distro=True, task_list=[install_task, reserve_task])
data_setup.create_job_for_recipes([recipe], owner=create_user(), whiteboard=u'')
data_setup.mark_recipe_complete(recipe, system=system)
self.recipe_id = recipe.id
return recipe
示例7: test_recipe_running_then_cancelled
def test_recipe_running_then_cancelled(self):
""" This tests the case where the recipe is running, has a valid
reservation request, but is cancelled before it's completed.
"""
with session.begin():
recipe = data_setup.create_recipe(
task_list=[Task.by_name(u'/distribution/install')] * 2,
reservesys=True)
job = data_setup.create_job_for_recipes([recipe])
job_id = job.id
data_setup.mark_recipe_running(recipe)
data_setup.mark_recipe_installation_finished(recipe)
# we want at least one task to be Completed here
# https://bugzilla.redhat.com/show_bug.cgi?id=1195558
job.recipesets[0].recipes[0].tasks[0].stop()
job.recipesets[0].recipes[0].tasks[1].start()
beakerd.update_dirty_jobs()
with session.begin():
job = Job.by_id(job_id)
self.assertEqual(job.recipesets[0].recipes[0].status,
TaskStatus.running)
job.recipesets[0].cancel()
beakerd.update_dirty_jobs()
with session.begin():
job = Job.by_id(job_id)
self.assertEqual(job.recipesets[0].recipes[0].status,
TaskStatus.cancelled)
示例8: test_recipe_running_then_watchdog_expired
def test_recipe_running_then_watchdog_expired(self):
""" This tests the case where the recipe is running, has a valid
reservation request, but the watchdog expires before it's
completed.
"""
with session.begin():
recipe = data_setup.create_recipe(
task_list=[Task.by_name(u'/distribution/install')],
reservesys=True)
job = data_setup.create_job_for_recipes([recipe])
job_id = job.id
data_setup.mark_recipe_tasks_finished(recipe,
task_status=TaskStatus.aborted)
job.recipesets[0].recipes[0].abort()
beakerd.update_dirty_jobs()
with session.begin():
job = Job.by_id(job_id)
self.assertEqual(job.recipesets[0].recipes[0].status,
TaskStatus.reserved)
job.recipesets[0].recipes[0].return_reservation()
beakerd.update_dirty_jobs()
with session.begin():
job = Job.by_id(job_id)
self.assertEqual(job.recipesets[0].recipes[0].status,
TaskStatus.aborted)
示例9: test_task_aborted_return_reservation
def test_task_aborted_return_reservation(self):
""" This tests the case where the task was aborted, then
the recipe goes to Reserved state and then finally the reservation
is returned
"""
with session.begin():
recipe = data_setup.create_recipe(
task_list=[Task.by_name(u'/distribution/install')],
reservesys=True)
job = data_setup.create_job_for_recipes([recipe])
job_id = job.id
data_setup.mark_recipe_tasks_finished(recipe, result=TaskResult.warn,
task_status=TaskStatus.aborted)
job._mark_dirty()
beakerd.update_dirty_jobs()
with session.begin():
job = Job.by_id(job_id)
self.assertEqual(job.recipesets[0].recipes[0].status,
TaskStatus.reserved)
job.recipesets[0].recipes[0].return_reservation()
beakerd.update_dirty_jobs()
with session.begin():
job = Job.by_id(job_id)
self.assertEqual(job.recipesets[0].recipes[0].status,
TaskStatus.aborted)
示例10: _disable
def _disable(self, t_id, *args, **kw):
"""
disable task
task.valid=False
remove task rpms from filesystem
"""
task = Task.by_id(t_id)
return task.disable()
示例11: test_reserved_then_job_cancelled
def test_reserved_then_job_cancelled(self):
""" This tests the case where the recipe is Reserved
but the job is cancelled
"""
recipe = data_setup.create_recipe(task_list=[Task.by_name(u"/distribution/install")], reservesys=True)
job = data_setup.create_job_for_recipes([recipe])
data_setup.mark_recipe_tasks_finished(recipe)
job.update_status()
self.assertEqual(job.recipesets[0].recipes[0].status, TaskStatus.reserved)
job.cancel()
job.update_status()
self.assertEqual(job.recipesets[0].recipes[0].status, TaskStatus.completed)
示例12: test_adding_task_with_releases_list
def test_adding_task_with_releases_list(self):
with session.begin():
OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux5')
OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux6')
rpm_path = pkg_resources.resource_filename('bkr.inttest.server',
'task-rpms/tmp-distribution-beaker-dummy_for_bz1422410-1.0-1.noarch.rpm')
out = run_client(['bkr', 'task-add', rpm_path])
self.assertIn(u'Success', out)
with session.begin():
task = Task.by_name(u'/distribution/beaker/dummy_for_bz1422410')
self.assertItemsEqual([OSMajor.by_name(u'RedHatEnterpriseLinux5')],
task.exclusive_osmajors)
示例13: test_task_aborted_return_reservation
def test_task_aborted_return_reservation(self):
""" This tests the case where the task was aborted, then
the recipe goes to Reserved state and then finally the reservation
is returned
"""
recipe = data_setup.create_recipe(task_list=[Task.by_name(u"/distribution/install")], reservesys=True)
job = data_setup.create_job_for_recipes([recipe])
data_setup.mark_recipe_tasks_finished(recipe, result=TaskResult.warn, task_status=TaskStatus.aborted)
job.update_status()
self.assertEqual(job.recipesets[0].recipes[0].status, TaskStatus.reserved)
job.recipesets[0].recipes[0].return_reservation()
job.update_status()
self.assertEqual(job.recipesets[0].recipes[0].status, TaskStatus.aborted)
示例14: test_reserved_then_watchdog_expired
def test_reserved_then_watchdog_expired(self):
""" This tests the case where the external
watchdog expires when the recipe is in Reserved state
"""
recipe = data_setup.create_recipe(task_list=[Task.by_name(u"/distribution/install")], reservesys=True)
job = data_setup.create_job_for_recipes([recipe])
data_setup.mark_recipe_tasks_finished(recipe)
job._mark_dirty()
job.update_status()
self.assertEqual(job.recipesets[0].recipes[0].status, TaskStatus.reserved)
job.recipesets[0].recipes[0].abort()
job.update_status()
self.assertEqual(job.recipesets[0].recipes[0].status, TaskStatus.completed)
示例15: expiring_reservations
def expiring_reservations(self):
"""
Get expiring reservations
"""
tasks = Task.by_name(u'/distribution/reservesys')
query = Recipe.query\
.join(Recipe.recipeset).join(RecipeSet.job).filter(Job.owner == self.user)\
.join(Recipe.watchdog).join(Watchdog.recipetask)\
.join(Recipe.resource)\
.filter(or_(RecipeTask.task == tasks, Recipe.status == TaskStatus.reserved))\
.filter(Watchdog.kill_time <= (datetime.utcnow() + timedelta(hours=self.reservation_expiry)))\
.values(Watchdog.kill_time, RecipeResource.fqdn)
return list(query)