From 18e0a906c58adcc808024b018d47bfa0fc32f949 Mon Sep 17 00:00:00 2001 From: Luis Araujo <luis.araujo@collabora.co.uk> Date: Thu, 13 Dec 2018 18:57:00 +0800 Subject: [PATCH] Add changes to render the new git-repos directive The new install:git-repos directive in the test case YAML files will allow to clone the tests scripts in order to integrate the test cases into LAVA. This commit adapts the renderer to properly generate test case pages with this new directive. Signed-off-by: Luis Araujo <luis.araujo@collabora.co.uk> --- atc_renderer/parser.py | 5 +++- atc_renderer/renderer.py | 41 ++++++++++++++++++++------- atc_renderer/templates/macros.html | 10 +++++++ atc_renderer/templates/test_case.html | 3 +- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/atc_renderer/parser.py b/atc_renderer/parser.py index 3597ca8..d11a6e3 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 04bacf6..72ec8d5 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 c52198d..24fd3dd 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 95384ec..e94d22e 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 %} -- GitLab