def _create_recipe(self, system=None):
     with session.begin():
         install_task = Task.by_name(u'/distribution/check-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
 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
 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
 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
Beispiel #5
0
 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)
Beispiel #6
0
 def test_task_without_failed_results_should_not_expand(self):
     with session.begin():
         recipe = data_setup.create_recipe(task_list=[
             Task.by_name(u'/distribution/install'),
             Task.by_name(u'/distribution/reservesys')
         ])
         job = data_setup.create_job_for_recipes([recipe])
         data_setup.mark_recipe_tasks_finished(recipe, result=TaskResult.pass_)
         job.update_status()
     b = self.browser
     go_to_recipe_view(b, recipe)
     for task in recipe.tasks:
         b.find_element_by_xpath('//div[@id="recipe-task-details-%s" and '
                 'not(contains(@class, "in"))]' % task.id)
     _, fragment = urlparse.urldefrag(b.current_url)
     self.assertEquals(fragment, 'tasks')
 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)
Beispiel #8
0
    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')
Beispiel #9
0
    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')
Beispiel #10
0
    def default(self, *args, **kw):
        # to handle the case one of the flask methods
        # have raised a 404 but the intention isn't to redirect
        # back to cherrypy, but legitimately 404
        if cherrypy.request.method != 'GET':
            raise cherrypy.HTTPError(404)
        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")

        attributes = task.to_dict()
        attributes['can_disable'] = bool(identity.current.user
                                         and identity.current.user.is_admin())

        return dict(attributes=attributes,
                    url="/tasks/%s" % task.id,
                    form=self.task_form,
                    value=dict(task_id=task.id),
                    options=dict(hidden=dict(task=1)),
                    action='./do_search')
Beispiel #11
0
 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)
Beispiel #12
0
 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')
Beispiel #13
0
 def test_task_without_failed_results_should_not_expand(self):
     with session.begin():
         recipe = data_setup.create_recipe(task_list=[
             Task.by_name(u'/distribution/install'),
             Task.by_name(u'/distribution/reservesys')
         ])
         job = data_setup.create_job_for_recipes([recipe])
         data_setup.mark_recipe_tasks_finished(recipe, result=TaskResult.pass_)
         job.update_status()
     b = self.browser
     go_to_recipe_view(b, recipe)
     for task in recipe.tasks:
         b.find_element_by_xpath('//div[@id="recipe-task-details-%s" and '
                 'not(contains(@class, "in"))]' % task.id)
     _, fragment = urlparse.urldefrag(b.current_url)
     self.assertEquals(fragment, 'tasks')
Beispiel #14
0
 def test_first_failed_task_should_expand_when_first_loading(self):
     with session.begin():
         recipe = data_setup.create_recipe(task_list=[
             Task.by_name(u'/distribution/install'),
             Task.by_name(u'/distribution/reservesys')
         ])
         job = data_setup.create_job_for_recipes([recipe])
         data_setup.mark_recipe_tasks_finished(recipe, result=TaskResult.fail)
         job.update_status()
     b = self.browser
     go_to_recipe_view(b, recipe)
     # The in class is an indication that a task is expanded.
     b.find_element_by_css_selector('#task%s .recipe-task-details.collapse.in'
             % recipe.tasks[0].id)
     _, fragment = urlparse.urldefrag(b.current_url)
     self.assertEquals(fragment, 'task%s' % recipe.tasks[0].id)
Beispiel #15
0
 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)
Beispiel #16
0
    def _get_task_xml(self, server, task):

        # if local, directly read the database
        if server == 'local':
            try:
                self.logger.debug(
                    'Getting task XML for %s from local database' % task)
                return Task.by_name(task, True).to_xml(False)
            except Exception:
                self.logger.error(
                    'Could not get task XML for %s from local Beaker DB. Continuing.'
                    % task)
                return None

        try:
            self.logger.debug('Getting task XML for %s from %s' %
                              (task, getattr(self, server)))
            return self.proxy.tasks.to_xml(task, False)
        except (xmlrpclib.Fault, xmlrpclib.ProtocolError) as e:
            # If something goes wrong with this task, for example:
            # https://bugzilla.redhat.com/show_bug.cgi?id=915549
            # we do our best to continue anyway...
            self.logger.error(
                'Could not get task XML for %s from %s. Continuing.' %
                (task, server))
            self.logger.error('Error message: %s' % e)
            return None
Beispiel #17
0
 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)
Beispiel #18
0
 def test_first_failed_task_should_expand_when_first_loading(self):
     with session.begin():
         recipe = data_setup.create_recipe(task_list=[
             Task.by_name(u'/distribution/install'),
             Task.by_name(u'/distribution/reservesys')
         ])
         job = data_setup.create_job_for_recipes([recipe])
         data_setup.mark_recipe_tasks_finished(recipe, result=TaskResult.fail)
         job.update_status()
     b = self.browser
     go_to_recipe_view(b, recipe)
     # The in class is an indication that a task is expanded.
     b.find_element_by_css_selector('#task%s .recipe-task-details.collapse.in'
             % recipe.tasks[0].id)
     _, fragment = urlparse.urldefrag(b.current_url)
     self.assertEquals(fragment, 'task%s' % recipe.tasks[0].id)
Beispiel #19
0
 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)
Beispiel #20
0
 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)
 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)
Beispiel #22
0
 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)
 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)
 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)
Beispiel #25
0
 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)
Beispiel #26
0
 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)
 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.
     """
     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, task_status=TaskStatus.aborted)
     job.recipesets[0].recipes[0].abort()
     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)
 def test_reserves_system_when_recipe_waiting(self):
     recipe = data_setup.create_recipe(task_list=[Task.by_name(u"/distribution/utils/dummy")], reservesys=True)
     job = data_setup.create_job_for_recipes([recipe])
     # Anaconda installs the OS (Status: Installing) and reboots
     # beakerd comes along and calls update_dirty_jobs which sets the recipe to: Waiting
     data_setup.mark_recipe_waiting(recipe)
     # In the meantime however our task has finished really quickly, which
     # means the min_status is TaskStatus.completed and therefore finished
     data_setup.mark_recipe_tasks_finished(recipe, only=True)
     # beakerd hasn't come along and updated our recipe yet, so it's still
     # in waiting
     self.assertEqual(job.recipesets[0].recipes[0].status, TaskStatus.waiting)
     # Now beakerd updates it and should reserve our system
     job.update_status()
     self.assertEqual(job.recipesets[0].recipes[0].status, TaskStatus.reserved)
Beispiel #29
0
def create_recipe(distro_tree=None, task_list=None,
        task_name=u'/distribution/reservesys', num_tasks=None, whiteboard=None,
        role=None, ks_meta=None, cls=MachineRecipe, **kwargs):
    recipe = cls(ttasks=1)
    recipe.ks_meta = ks_meta
    recipe.whiteboard = whiteboard
    recipe.distro_tree = distro_tree
    recipe.role = role or u'STANDALONE'
    custom_distro = kwargs.get('custom_distro', False)

    if not custom_distro:
        if not distro_tree:
            distro_tree = create_distro_tree(**kwargs)
        recipe.distro_tree = distro_tree
        recipe.installation = recipe.distro_tree.create_installation_from_tree()
        recipe.distro_requires = lxml.etree.tostring(recipe.distro_tree.to_xml(), encoding=unicode)
    else:
        name = kwargs.get('distro_name', u'MyAwesomeLinux1.0')
        tree_url = kwargs.get('tree_url', u'ftp://dummylab.example.com/distros/MyAwesomeLinux1/')
        initrd_path = kwargs.get('initrd_path', u'pxeboot/initrd')
        kernel_path = kwargs.get('kernel_path', u'pxeboot/vmlinuz')
        arch = kwargs.get('arch', u'i386')
        variant = kwargs.get('variant', u'Server')
        osmajor = kwargs.get('osmajor', u'DansAwesomeLinux6')
        osminor = kwargs.get('osminor', u'0')
        arch = Arch.by_name(arch)
        recipe.installation = Installation(tree_url=tree_url, initrd_path=initrd_path, kernel_path=kernel_path, arch=arch,
                                           distro_name=name, osmajor=osmajor, osminor=osminor, variant=variant)

    if kwargs.get('reservesys', False):
        recipe.reservation_request = RecipeReservationRequest()
        if kwargs.get('reservesys_duration'):
            recipe.reservation_request.duration = kwargs['reservesys_duration']

    if num_tasks:
        task_list = [create_task() for i in range(0, num_tasks)]
    if not task_list: #don't specify a task_list and a task_name...
        try:
            task = Task.by_name(task_name)
        except LookupError:
            task = create_task(name=task_name)
        task_list = [task]
    for t in task_list:
        rt = RecipeTask.from_task(t)
        rt.role = u'STANDALONE'
        recipe.tasks.append(rt)
    recipe.ttasks = len(task_list)
    return recipe
Beispiel #30
0
def create_recipe(distro_tree=None, task_list=None,
        task_name=u'/distribution/reservesys', num_tasks=None, whiteboard=None,
        role=None, ks_meta=None, cls=MachineRecipe, **kwargs):
    recipe = cls(ttasks=1)
    recipe.ks_meta = ks_meta
    recipe.whiteboard = whiteboard
    recipe.distro_tree = distro_tree
    recipe.role = role or u'STANDALONE'
    custom_distro = kwargs.get('custom_distro', False)

    if not custom_distro:
        if not distro_tree:
            distro_tree = create_distro_tree(**kwargs)
        recipe.distro_tree = distro_tree
        recipe.installation = recipe.distro_tree.create_installation_from_tree()
        recipe.distro_requires = lxml.etree.tostring(recipe.distro_tree.to_xml(), encoding=unicode)
    else:
        name = kwargs.get('distro_name', u'MyAwesomeLinux1.0')
        tree_url = kwargs.get('tree_url', u'ftp://dummylab.example.com/distros/MyAwesomeLinux1/')
        initrd_path = kwargs.get('initrd_path', u'pxeboot/initrd')
        kernel_path = kwargs.get('kernel_path', u'pxeboot/vmlinuz')
        arch = kwargs.get('arch', u'i386')
        variant = kwargs.get('variant', u'Server')
        osmajor = kwargs.get('osmajor', u'DansAwesomeLinux6')
        osminor = kwargs.get('osminor', u'0')
        arch = Arch.by_name(arch)
        recipe.installation = Installation(tree_url=tree_url, initrd_path=initrd_path, kernel_path=kernel_path, arch=arch,
                                           distro_name=name, osmajor=osmajor, osminor=osminor, variant=variant)

    if kwargs.get('reservesys', False):
        recipe.reservation_request = RecipeReservationRequest()
        if kwargs.get('reservesys_duration'):
            recipe.reservation_request.duration = kwargs['reservesys_duration']

    if num_tasks:
        task_list = [create_task() for i in range(0, num_tasks)]
    if not task_list: #don't specify a task_list and a task_name...
        try:
            task = Task.by_name(task_name)
        except LookupError:
            task = create_task(name=task_name)
        task_list = [task]
    for t in task_list:
        rt = RecipeTask.from_task(t)
        rt.role = u'STANDALONE'
        recipe.tasks.append(rt)
    recipe.ttasks = len(task_list)
    return recipe
Beispiel #31
0
 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)
 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.
     """
     recipe = data_setup.create_recipe(task_list=[Task.by_name(u"/distribution/install")] * 2, reservesys=True)
     job = data_setup.create_job_for_recipes([recipe])
     data_setup.mark_recipe_running(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()
     job.update_status()
     self.assertEqual(job.recipesets[0].recipes[0].status, TaskStatus.running)
     job.recipesets[0].cancel()
     job.update_status()
     self.assertEqual(job.recipesets[0].recipes[0].status, TaskStatus.cancelled)
Beispiel #33
0
 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)
Beispiel #34
0
 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)
Beispiel #35
0
    def _get_task_xml(self, server, task):

        # if local, directly read the database
        if server == 'local':
            try:
                self.logger.debug('Getting task XML for %s from local database' % task)
                return Task.by_name(task, True).to_xml(False)
            except Exception:
                self.logger.error('Could not get task XML for %s from local Beaker DB. Continuing.' % task)
                return None

        try:
            self.logger.debug('Getting task XML for %s from %s' % (task, getattr(self, server)))
            return self.proxy.tasks.to_xml(task, False)
        except (xmlrpclib.Fault, xmlrpclib.ProtocolError) as e:
            # If something goes wrong with this task, for example:
            # https://bugzilla.redhat.com/show_bug.cgi?id=915549
            # we do our best to continue anyway...
            self.logger.error('Could not get task XML for %s from %s. Continuing.' % (task, server))
            self.logger.error('Error message: %s' % e)
            return None
Beispiel #36
0
 def test_reserved_then_watchdog_expired(self):
     """ This tests the case where the external
     watchdog expires when the recipe is in Reserved state
     """
     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)
         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].abort()
         job._update_status()
     with session.begin():
         job = Job.by_id(job_id)
         self.assertEqual(job.recipesets[0].recipes[0].status,
                          TaskStatus.completed)
Beispiel #37
0
 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')],
             reservesys=True)
         job = data_setup.create_job_for_recipes([recipe])
         job_id = job.id
         data_setup.mark_recipe_running(recipe)
         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.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)
Beispiel #38
0
 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')],
             reservesys=True)
         job = data_setup.create_job_for_recipes([recipe])
         job_id = job.id
         data_setup.mark_recipe_running(recipe)
         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.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)
Beispiel #39
0
 def test_reserved_then_job_cancelled(self):
     """ This tests the case where the recipe is Reserved
     but the job is cancelled
     """
     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)
         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.cancel()
     beakerd.update_dirty_jobs()
     with session.begin():
         job = Job.by_id(job_id)
         self.assertEqual(job.recipesets[0].recipes[0].status,
                          TaskStatus.completed)
Beispiel #40
0
 def test_reserved_then_job_cancelled(self):
     """ This tests the case where the recipe is Reserved
     but the job is cancelled
     """
     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)
         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.cancel()
     beakerd.update_dirty_jobs()
     with session.begin():
         job = Job.by_id(job_id)
         self.assertEqual(job.recipesets[0].recipes[0].status,
                          TaskStatus.completed)
Beispiel #41
0
 def to_xml(self, name, pretty, valid=True):
     """
     Returns task details as xml
     """
     return Task.by_name(name, valid).to_xml(pretty)
Beispiel #42
0
                # If fetch URL is given, the task doesn't need to exist.
                xmltasks.append(xmltask)
            elif Task.exists_by_name(xmltask.name, valid=True):
                xmltasks.append(xmltask)
            else:
                invalid_tasks.append(xmltask.name)
        if invalid_tasks and not ignore_missing_tasks:
            raise BX(_('Invalid task(s): %s') % ', '.join(invalid_tasks))
        for xmltask in xmltasks:
            if hasattr(xmltask, 'fetch'):
                recipetask = RecipeTask.from_fetch_url(
                    xmltask.fetch.url,
                    subdir=xmltask.fetch.subdir,
                    name=xmltask.name)
            else:
                recipetask = RecipeTask.from_task(Task.by_name(xmltask.name))
            recipetask.role = xmltask.role
            for xmlparam in xmltask.iter_params():
                param = RecipeTaskParam(name=xmlparam.name,
                                        value=xmlparam.value)
                recipetask.params.append(param)
            recipe.tasks.append(recipetask)
        if not recipe.tasks:
            raise BX(_('No Tasks! You can not have a recipe with no tasks!'))
        return recipe

    @expose('json')
    def update_recipe_set_response(self, recipe_set_id, response_id):
        rs = RecipeSet.by_id(recipe_set_id)
        old_response = None
        if rs.nacked is None:
Beispiel #43
0
 def to_dict(self, name, valid=None):
     """
     Returns an XML-RPC structure (dict) with details about the given task.
     """
     return Task.by_name(name, valid).to_dict()
Beispiel #44
0
        for xmltask in xmlrecipe.iter_tasks():
            if hasattr(xmltask, 'fetch'):
                # If fetch URL is given, the task doesn't need to exist.
                xmltasks.append(xmltask)
            elif Task.exists_by_name(xmltask.name, valid=True):
                xmltasks.append(xmltask)
            else:
                invalid_tasks.append(xmltask.name)
        if invalid_tasks and not ignore_missing_tasks:
            raise BX(_('Invalid task(s): %s') % ', '.join(invalid_tasks))
        for xmltask in xmltasks:
            if hasattr(xmltask, 'fetch'):
                recipetask = RecipeTask.from_fetch_url(xmltask.fetch.url,
                        subdir=xmltask.fetch.subdir, name=xmltask.name)
            else:
                recipetask = RecipeTask.from_task(Task.by_name(xmltask.name))
            recipetask.role = xmltask.role
            for xmlparam in xmltask.iter_params():
                param = RecipeTaskParam( name=xmlparam.name, 
                                        value=xmlparam.value)
                recipetask.params.append(param)
            recipe.tasks.append(recipetask)
        if not recipe.tasks:
            raise BX(_('No Tasks! You can not have a recipe with no tasks!'))
        return recipe

    @expose('json')
    def update_recipe_set_response(self,recipe_set_id,response_id):
        rs = RecipeSet.by_id(recipe_set_id)
        if rs.nacked is None:
            rs.nacked = RecipeSetResponse(response_id=response_id)
Beispiel #45
0
 def to_xml(self, name, pretty, valid=True):
     """
     Returns task details as xml
     """
     return Task.by_name(name, valid).to_xml(pretty)
Beispiel #46
0
 def to_dict(self, name, valid=None):
     """
     Returns an XML-RPC structure (dict) with details about the given task.
     """
     return Task.by_name(name, valid).to_dict()