Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion kernelci/legacy/lava/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys

from jinja2 import Environment, FileSystemLoader
from jinja2.exceptions import TemplateRuntimeError


def add_kci_raise(jinja2_env):
Expand All @@ -23,7 +24,7 @@ def add_kci_raise(jinja2_env):
"""

def template_exception(msg):
raise Exception(msg)
raise TemplateRuntimeError(msg)

jinja2_env.globals["kci_raise"] = template_exception

Expand Down
3 changes: 2 additions & 1 deletion kernelci/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import requests
import yaml
from jinja2 import ChoiceLoader, Environment, FileSystemLoader
from jinja2.exceptions import TemplateRuntimeError

from kernelci.config.base import get_system_arch

Expand Down Expand Up @@ -136,7 +137,7 @@ def _get_jinja2_functions(cls):

def kci_raise(msg):
"""Raise an exception"""
raise Exception(msg)
raise TemplateRuntimeError(msg)

def kci_yaml_dump(data):
"""Dump data to YAML"""
Expand Down
19 changes: 19 additions & 0 deletions tests/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,32 @@
import pytest
import yaml
from jinja2 import Environment, FileSystemLoader
from jinja2.exceptions import TemplateRuntimeError

import kernelci.config
import kernelci.legacy.lava
import kernelci.runtime
import kernelci.runtime.lava
from kernelci.runtime.pull_labs import compute_tuxrun_parameters


def test_kci_raise_uses_jinja_runtime_error():
"""The runtime helper raises a template-specific exception."""
kci_raise = kernelci.runtime.Runtime._get_jinja2_functions()["kci_raise"]

with pytest.raises(TemplateRuntimeError, match="invalid parameters"):
kci_raise("invalid parameters")


def test_legacy_kci_raise_uses_jinja_runtime_error():
"""The legacy LAVA helper raises a template-specific exception."""
environment = Environment()
kernelci.legacy.lava.add_kci_raise(environment)

with pytest.raises(TemplateRuntimeError, match="invalid parameters"):
environment.globals["kci_raise"]("invalid parameters")


@pytest.mark.parametrize(
"docker_image", [None, "example.com/lava/fastboot:latest"]
)
Expand Down