示例#1
0
def mark_recipe_tasks_finished(recipe,
                               result=TaskResult.pass_,
                               task_status=TaskStatus.completed,
                               finish_time=None,
                               only=False,
                               server_log=False,
                               num_tasks=None,
                               **kwargs):

    # we accept result=None to mean: don't add any results to recipetasks
    assert result is None or result in TaskResult
    finish_time = finish_time or datetime.datetime.utcnow()
    if not only:
        mark_recipe_running(recipe, **kwargs)
        mark_recipe_installation_finished(recipe)

    # Need to make sure recipe.watchdog has been persisted, since we delete it
    # below when the recipe completes and sqlalchemy will barf on deleting an
    # instance that hasn't been persisted.
    session.flush()

    if not server_log:
        recipe.log_server = recipe.recipeset.lab_controller.fqdn
        recipe.logs = [LogRecipe(path=u'recipe_path', filename=u'dummy.txt')]
    else:
        recipe.log_server = u'dummy-archive-server'
        recipe.logs = [
            LogRecipe(server=u'http://dummy-archive-server/beaker/',
                      path=u'recipe_path',
                      filename=u'dummy.txt')
        ]

    if not server_log:
        rt_log = lambda: LogRecipeTask(path=u'tasks', filename=u'dummy.txt')
    else:
        rt_log = lambda: LogRecipeTask(server=
                                       u'http://dummy-archive-server/beaker/',
                                       path=u'tasks',
                                       filename=u'dummy.txt')
    if not server_log:
        rtr_log = lambda: LogRecipeTaskResult(path=u'/',
                                              filename=u'result.txt')
    else:
        rtr_log = lambda: LogRecipeTaskResult(
            server=u'http://dummy-archive-server/beaker/',
            path=u'/',
            filename=u'result.txt')

    for recipe_task in recipe.tasks[:num_tasks]:
        if result is not None:
            rtr = RecipeTaskResult(recipetask=recipe_task, result=result)
            rtr.logs = [rtr_log()]
            recipe_task.results.append(rtr)
        recipe_task.logs = [rt_log()]
        recipe_task.finish_time = finish_time
        recipe_task._change_status(task_status)
    log.debug('Marked %s tasks in %s as %s with result %s', num_tasks or 'all',
              recipe.t_id, task_status, result)
示例#2
0
    def test_does_not_load_RecipeTaskResults(self):
        # In large jobs with many RecipeTasks and RecipeTaskResults,
        # beaker-log-delete would previously take a long time and a lot of
        # memory, because it was traversing the entire object graph down to
        # RecipeTaskResult and loading them all into memory.
        # This test is asserting that no RecipeTask or RecipeTaskResult
        # instances are loaded when beaker-log-delete runs.

        with session.begin():
            job = data_setup.create_completed_job()
            job.deleted = datetime.datetime.utcnow()
            recipe = job.recipesets[0].recipes[0]

            server = self.log_server_url + '/recipe/'
            open(os.path.join(self.recipe_logs_dir, 'recipe.log'), 'w').write('dummy')
            recipe.logs[:] = [LogRecipe(server=server, filename=u'recipe.log')]
            open(os.path.join(self.recipe_logs_dir, 'task.log'), 'w').write('dummy')
            recipe.tasks[0].logs[:] = [LogRecipeTask(server=server, filename=u'task.log')]
            open(os.path.join(self.recipe_logs_dir, 'result.log'), 'w').write('dummy')
            recipe.tasks[0].results[0].logs[:] = \
                [LogRecipeTaskResult(server=server, filename=u'result.log')]

        # RecipeTasks/RecipeTaskResults are already loaded from the data_setup
        # calls above, expunge the session so that log_delete starts from
        # a clean slate.
        session.expunge_all()

        with mock.patch.object(RecipeTask, '__new__', side_effect=AssertionError):
            with mock.patch.object(RecipeTaskResult, '__new__', side_effect=AssertionError):
                self.assertEquals(log_delete.log_delete(), 0)  # exit status

        # Check that we really deleted something, if not the test setup was faulty.
        with session.begin():
            job = Job.by_id(job.id)
            self.assertIsNotNone(job.purged)
示例#3
0
    def register_result_file(self, server, result_id, path, filename,
                             basepath):
        """
        register file and return path to store
        """
        try:
            result = RecipeTaskResult.by_id(result_id, lockmode='update')
        except NoResultFound:
            raise BX(_('Invalid result ID: %s' % result_id))
        RecipeTask.by_id(result.recipe_task_id, lockmode='update')
        Recipe.by_id(result.recipetask.recipe_id, lockmode='update')
        if result.recipetask.is_finished():
            raise BX('Cannot register file for finished task %s' %
                     result.recipetask.t_id)
        self._check_log_limit(result.recipetask)

        log_recipe = LogRecipeTaskResult.lazy_create(
            recipe_task_result_id=result.id,
            path=path,
            filename=filename,
        )
        log_recipe.server = server
        log_recipe.basepath = basepath
        result.recipetask.recipe.log_server = urlparse.urlparse(server)[1]
        return '%s' % result.filepath
示例#4
0
 def setUp(self):
     # set up a directory for our dummy job logs, with an HTTP server
     self.logs_dir = tempfile.mkdtemp(prefix='beaker-client-test-job-logs')
     self.addCleanup(shutil.rmtree, self.logs_dir, ignore_errors=True)
     self.archive_server = Process('http_server.py', args=[sys.executable,
             pkg_resources.resource_filename('bkr.inttest', 'http_server.py'),
             '--base', self.logs_dir], listen_port=19998)
     self.archive_server.start()
     self.addCleanup(self.archive_server.stop)
     self.log_server_url = u'http://localhost:19998/'
     # job for testing
     with session.begin():
         self.job = data_setup.create_completed_job()
         self.recipe = self.job.recipesets[0].recipes[0]
         os.mkdir(os.path.join(self.logs_dir, 'R'))
         open(os.path.join(self.logs_dir, 'R', 'dummy.txt'), 'w').write('recipe\n')
         self.recipe.logs[:] = [LogRecipe(server=self.log_server_url,
                 path=u'R', filename=u'dummy.txt')]
         os.mkdir(os.path.join(self.logs_dir, 'T'))
         open(os.path.join(self.logs_dir, 'T', 'dummy.txt'), 'w').write('task\n')
         self.recipe.tasks[0].logs[:] = [LogRecipeTask(server=self.log_server_url,
                 path=u'T', filename=u'dummy.txt')]
         os.mkdir(os.path.join(self.logs_dir, 'TR'))
         open(os.path.join(self.logs_dir, 'TR', 'dummy.txt'), 'w').write('result\n')
         self.recipe.tasks[0].results[0].logs[:] = [LogRecipeTaskResult(
                 server=self.log_server_url,
                 path=u'TR', filename=u'dummy.txt')]
示例#5
0
 def setUp(self):
     with session.begin():
         self.recipe = data_setup.create_recipe()
         data_setup.create_job_for_recipes([self.recipe])
         data_setup.mark_recipe_running(self.recipe)
         self.recipe.logs[:] = [
             LogRecipe(path=u'/', filename=u'console.log'),
             LogRecipe(path=u'some-dir', filename=u'some-file.txt')
         ]
         self.task = self.recipe.tasks[0]
         self.task.logs[:] = [
             LogRecipeTask(path=u'/', filename=u'TESTOUT.log'),
             LogRecipeTask(path=u'debug', filename=u'.task_beah_raw')
         ]
         self.task.pass_(u'', 0, u'Pass')
         self.result = self.recipe.tasks[0].results[0]
         self.result.logs[:] = [
             LogRecipeTaskResult(path=u'/', filename=u'test.log'),
             LogRecipeTaskResult(path=u'some-dir',
                                 filename=u'some-file.txt')
         ]
示例#6
0
    def register_result_file(self, server, result_id, path, filename, basepath):
        """
        register file and return path to store
        """
        try:
            result = RecipeTaskResult.by_id(result_id)
        except InvalidRequestError:
            raise BX(_('Invalid result ID: %s' % result_id))
        if result.recipetask.is_finished():
            raise BX('Cannot register file for finished task %s'
                    % result.recipetask.t_id)

        log_recipe = LogRecipeTaskResult.lazy_create(recipe_task_result_id=result.id,
                                                     path=path, 
                                                     filename=filename,
                                                    )
        log_recipe.server = server
        log_recipe.basepath = basepath
        result.recipetask.recipe.log_server = urlparse.urlparse(server)[1]
        return '%s' % result.filepath
示例#7
0
    def register_result_file(self, server, result_id, path, filename,
                             basepath):
        """
        register file and return path to store
        """
        try:
            result = RecipeTaskResult.by_id(result_id)
        except InvalidRequestError:
            raise BX(_('Invalid result ID: %s' % result_id))
        if result.recipetask.is_finished():
            raise BX('Cannot register file for finished task %s' %
                     result.recipetask.t_id)

        log_recipe = LogRecipeTaskResult.lazy_create(
            recipe_task_result_id=result.id,
            path=path,
            filename=filename,
        )
        log_recipe.server = server
        log_recipe.basepath = basepath
        result.recipetask.recipe.log_server = urlparse.urlparse(server)[1]
        return '%s' % result.filepath
示例#8
0
    def register_result_file(self, server, result_id, path, filename, basepath):
        """
        register file and return path to store
        """
        try:
            result = RecipeTaskResult.by_id(result_id, lockmode='update')
        except NoResultFound:
            raise BX(_('Invalid result ID: %s' % result_id))
        RecipeTask.by_id(result.recipe_task_id, lockmode='update')
        Recipe.by_id(result.recipetask.recipe_id, lockmode='update')
        if result.recipetask.is_finished():
            raise BX('Cannot register file for finished task %s'
                    % result.recipetask.t_id)
        self._check_log_limit(result.recipetask)

        log_recipe = LogRecipeTaskResult.lazy_create(recipe_task_result_id=result.id,
                                                     path=path, 
                                                     filename=filename,
                                                    )
        log_recipe.server = server
        log_recipe.basepath = basepath
        result.recipetask.recipe.log_server = urlparse.urlparse(server)[1]
        return '%s' % result.filepath