Ejemplo n.º 1
0
 def default(self, id):
     try:
         kickstart = RenderedKickstart.by_id(id)
     except NoResultFound:
         raise cherrypy.NotFound(id)
     if kickstart.url:
         redirect(kickstart.url)
     return kickstart.kickstart.encode('utf8')
Ejemplo n.º 2
0
def get_kickstart(id):
    """
    Flask endpoint for serving up generated kickstarts.
    """
    try:
        kickstart = RenderedKickstart.by_id(id)
    except NoResultFound:
        abort(404)
    return redirect(kickstart.url) if kickstart.url else Response(
        kickstart.kickstart.encode('utf8'), mimetype='text/plain')
Ejemplo n.º 3
0
 def test_rendered_kickstart_is_deleted(self):
     with session.begin():
         self.job_to_delete.to_delete = datetime.datetime.utcnow()
         recipe = self.job_to_delete.recipesets[0].recipes[0]
         ks = RenderedKickstart(kickstart=u'This is not a real kickstart.')
         recipe.rendered_kickstart = ks
     log_delete.log_delete()
     with session.begin():
         self.assertEqual(Recipe.by_id(recipe.id).rendered_kickstart, None)
         self.assertRaises(NoResultFound, RenderedKickstart.by_id, ks.id)
Ejemplo n.º 4
0
 def test_rendered_kickstart_is_deleted(self):
     with session.begin():
         self.job_to_delete.deleted = datetime.datetime.utcnow()
         recipe = self.job_to_delete.recipesets[0].recipes[0]
         ks = RenderedKickstart(kickstart=u'This is not a real kickstart.')
         recipe.installation.rendered_kickstart = ks
         session.flush()
         ks_id = ks.id
     run_command('log_delete.py', 'beaker-log-delete')
     with session.begin():
         session.expire_all()
         self.assertEqual(recipe.installation.rendered_kickstart, None)
         self.assertEqual(RenderedKickstart.query.filter_by(id=ks_id).count(), 0)
Ejemplo n.º 5
0
def generate_kickstart(install_options, distro_tree, system, user,
        recipe=None, ks_appends=None, kickstart=None, installation=None):
    if recipe:
        lab_controller = recipe.recipeset.lab_controller
    elif system:
        lab_controller = system.lab_controller
    else:
        raise ValueError("Must specify either a system or a recipe")

    recipe_whiteboard = job_whiteboard = ''
    if recipe:
        if recipe.whiteboard:
            recipe_whiteboard = recipe.whiteboard
        if recipe.recipeset.job.whiteboard:
            job_whiteboard = recipe.recipeset.job.whiteboard

    installation = installation if installation is not None else recipe.installation
    # User-supplied templates don't get access to our model objects, in case
    # they do something foolish/naughty.
    restricted_context = {
        'kernel_options_post': install_options.kernel_options_post_str,
        'recipe_whiteboard': recipe_whiteboard,
        'job_whiteboard': job_whiteboard,
        'distro_tree': RestrictedDistroTree(installation.osmajor, installation.osminor,
                                            installation.distro_name, installation.variant,
                                            installation.arch.arch, installation.tree_url, distro_tree),
        'distro': RestrictedDistro(installation.osmajor, installation.osminor,
                                   installation.distro_name),
        'lab_controller': RestrictedLabController(lab_controller),
        'recipe': RestrictedRecipe(recipe) if recipe else None,
        'ks_appends': ks_appends or [],
    }

    restricted_context.update(install_options.ks_meta)

    # System templates and snippets have access to more useful stuff.
    context = dict(restricted_context)
    context.update({
        'system': system,
        'lab_controller': lab_controller,
        'user': user,
        'recipe': recipe,
        'config': config,
    })
    if distro_tree:
        context.update({
            'distro_tree': distro_tree,
            'distro': distro_tree.distro,
        })
    else:
        # But user-defined distros only get access to our "Restricted" model objects
        context.update({
            'distro_tree': RestrictedDistroTree(installation.osmajor, installation.osminor,
                                                installation.distro_name, installation.variant,
                                                installation.arch.arch, installation.tree_url),
            'distro': RestrictedDistro(installation.osmajor, installation.osminor,
                                       installation.distro_name),
        })

    snippet_locations = []
    if system:
        snippet_locations.append(
             'snippets/per_system/%%s/%s' % system.fqdn)
    snippet_locations.extend([
        'snippets/per_lab/%%s/%s' % lab_controller.fqdn,
        'snippets/per_osversion/%%s/%s.%s' % (installation.osmajor, installation.osminor),
        'snippets/per_osmajor/%%s/%s' % installation.osmajor,
        'snippets/%s',
    ])

    def snippet(name):
        template = None
        candidates = [location % name for location in snippet_locations]
        for candidate in candidates:
            try:
                template = template_env.get_template(candidate)
                break
            except jinja2.TemplateNotFound:
                continue
        if template:
            retval = template.render(context)
            if retval and not retval.endswith('\n'):
                retval += '\n'
            return retval
        else:
            return u'# no snippet data for %s\n' % name
    restricted_context['snippet'] = snippet
    context['snippet'] = snippet

    with TemplateRenderingEnvironment():
        if kickstart:
            template = template_env.from_string(
                    "{% snippet 'install_method' %}\n" + kickstart)
            result = template.render(restricted_context)
        else:
            template = kickstart_template(installation.osmajor)
            result = template.render(context)

    rendered_kickstart = RenderedKickstart(kickstart=result)
    session.add(rendered_kickstart)
    session.flush() # so that it has an id
    return rendered_kickstart