diff --git a/atc_renderer/parser.py b/atc_renderer/parser.py index 3597ca8681c5a34cbf2b9f205e6e84f043b605a8..d11a6e31a952761373b89e50ab2299dc4d3081ca 100644 --- a/atc_renderer/parser.py +++ b/atc_renderer/parser.py @@ -51,7 +51,10 @@ test_case_format = { 'post-conditions': (False, []) }), 'install': (False, { - 'deps': (True, []) + # git-repos should be mandatory. + # TODO: Set to True once all test cases use git-repos + 'git-repos' : (False, []), + 'deps': (False, []) }), 'run': (True, { 'steps': (True, []) diff --git a/atc_renderer/renderer.py b/atc_renderer/renderer.py index 04bacf62637cc22ce94a1502ec2853a4df29b374..72ec8d5ade0475b41a0cf8edc465917ae82117ae 100644 --- a/atc_renderer/renderer.py +++ b/atc_renderer/renderer.py @@ -81,6 +81,15 @@ def priority_color(priority): (priority == 'high' and 'warning') or \ (priority == 'critical' and 'danger') or 'light' +def get_git_repo_dir(git_repo=None): + # TODO: Remove this `if` once all test cases use git-repos. + if git_repo: + try: + return os.path.splitext(os.path.split(git_repo)[1])[0] + except IndexError: + print("Incorrect git-repos repository path:", git_repo) + exit(1) + def get_template_values(testcase_data): template_values = {} is_automated = False @@ -122,6 +131,27 @@ def get_template_values(testcase_data): template_values.update({ 'run_steps' : parse_list(steps, automated_run=is_automated) }) + # If the test is automated, it should always have 'install:git-repos' + install = testcase_data.get('install') + if is_automated and install: + git_repos = install.get('git-repos', []) + git_repo_url = None + for gr in git_repos: + git_repo_url = gr.get('url') + if not git_repo_url: + print("Error: missing mandatory field install:git-repos:url for " \ + "automated tests") + exit(1) + + template_values.update({ 'git_repo_url' : git_repo_url }) + template_values.update({ 'git_repo_dir' : get_git_repo_dir(git_repo_url) }) + + deps = install.get('deps') + if deps: + # A install.deps directive will always add a preconditions section + # to install the required packages using the macro to install packages. + template_values.update({ 'packages_list' : ' '.join(deps) }) + # No mandatory fields for nm in ['notes', 'format', 'maintainer', 'resources', 'pre-conditions', 'post-conditions']: @@ -132,17 +162,6 @@ def get_template_values(testcase_data): 'post-conditions'] else value }) - install = testcase_data.get('install') - if install: - deps = install.get('deps') - if not deps: - print("Error: missing mandatory field deps for install") - exit(1) - template_values.update({ 'install_steps' : deps }) - # A install.deps directive will always add a preconditions section - # to install the required packages using the macro to install packages. - template_values.update({ 'packages_list' : ' '.join(deps) }) - # Macros variables ostree_preconditions = metadata.get('macro_ostree_preconditions') if ostree_preconditions: diff --git a/atc_renderer/templates/macros.html b/atc_renderer/templates/macros.html index c52198d3849ec915997504d2bf481f187a0b66df..24fd3ddb1fdd2dc3401c4cf5b6a9368c08c40feb 100644 --- a/atc_renderer/templates/macros.html +++ b/atc_renderer/templates/macros.html @@ -1,3 +1,13 @@ +{% macro git_repo(git_repo_url, git_repo_dir) %} + <li class="mb-sm-2">Clone the tests repository from another computer <i>(Note that the branch being tested may change depending on the release, please make sure to clone the correct branch for the release in question)</i>:</li> + <p><kbd>$ git clone {{ git_repo_url }}</kbd></p> + <li class="mb-sm-2">Copy the test directory {{ git_repo_dir }} to the device:</li> + <p><kbd>$ DUT_IP=<device-ip></kbd></p> + <p><kbd>$ scp -r {{ git_repo_dir }} user@$DUT_IP:</kbd></p> + <li class="mb-sm-2">Log into the target:</li> + <p><kbd>$ ssh user@$DUT_IP</kbd></p> +{% endmacro %} + {% macro ostree_preconditions(pkgname) %} <li class="mb-sm-2">From a PC, download and unpack the test data tarball from the gitlab test repository:</li> <p><kbd>$ wget https://gitlab.apertis.org/tests/{{ pkgname }}/-/archive/master/{{ pkgname }}.tar.gz</kbd></p> diff --git a/atc_renderer/templates/test_case.html b/atc_renderer/templates/test_case.html index 95384ec4e8b7c5e9aeb525b46ab6c50d1cac5f90..e94d22ed3c8005ba9e8e9d16f0e1b9c2f7fde4c8 100644 --- a/atc_renderer/templates/test_case.html +++ b/atc_renderer/templates/test_case.html @@ -36,12 +36,13 @@ </ul> {% endif %} - {% if pre_conditions or pkgname or packages_list or libname %} + {% if pre_conditions or pkgname or packages_list or libname or git_repo_url %} <hr /> <h4>Pre Conditions</h4> <ol> {% if pkgname %}{{ macros.ostree_preconditions(pkgname) }}{% endif %} {% if packages_list %}{{ macros.install_packages(packages_list) }}{% endif %} + {% if git_repo_url and not pkgname %}{{ macros.git_repo(git_repo_url, git_repo_dir) }}{% endif %} {% if libname %}{{ macros.modules_preconditions(libname) }}{% endif %} {% for comment, command, output, _, link in pre_conditions %} {% if comment %}<li class="mb-sm-2">{{ comment|e }}</li>{% endif %}