From f7fd2fce612242b1bcf28ff18c771be1e8dba662 Mon Sep 17 00:00:00 2001 From: "Andrea Frittoli (andreaf)" Date: Fri, 2 Feb 2018 19:39:56 +0100 Subject: [PATCH] Change the list of extensions to a dict The stage-output role accepts a list of extensions to be replaced as txt so that they can be seen directly from within a web browser. Using a list means that children jobs cannot add to the parent setting, only overwrite. Adding support for dicts while preserving, at least for now, support for lists - to avoid breaking existing implementations. This reverts change 844b3333aae02d596061386b5a1a2fbc821950be. Change-Id: I5052c873f0a5da7ecaa38627e8900af86bbec2f9 Needed-By: https://review.openstack.org/539686 Needed-By: https://review.openstack.org/539708 Needed-By: https://review.openstack.org/539854 --- roles/stage-output/README.rst | 7 +++--- roles/stage-output/tasks/main.yaml | 36 +++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/roles/stage-output/README.rst b/roles/stage-output/README.rst index 9e5e848dd..3dd8d37bc 100644 --- a/roles/stage-output/README.rst +++ b/roles/stage-output/README.rst @@ -31,7 +31,7 @@ intended to be used before output fetching in a base job's post-playbook. .. zuul:rolevar:: extensions_to_txt :default: null - A list of file extensions to be replaced with .txt when staging. + A dict of file extensions to be replaced with .txt when staging. This can be useful to ensure that text files with an extension not registered in the web server may be viewed via browser when uploaded to a file server. @@ -43,8 +43,9 @@ intended to be used before output fetching in a base job's post-playbook. Example: extensions_to_txt: - - conf - - log + conf: True + log: True + txt: False zuul.conf --(staged as)--> zuul_conf.txt diff --git a/roles/stage-output/tasks/main.yaml b/roles/stage-output/tasks/main.yaml index fefc674ff..330490a7e 100644 --- a/roles/stage-output/tasks/main.yaml +++ b/roles/stage-output/tasks/main.yaml @@ -4,12 +4,38 @@ with_dict: "{{ zuul_copy_output }}" register: sources -- name: Build the replace regex - set_fact: - extensions_regex: "{{ extensions_to_txt | join('|') | default('__do_not_replace__') }}" +- name: Output a warning when input is not a dict and not empty + debug: + msg: "WARNING: extensions_to_txt is a list, values defined by parents will be overwritten" + when: + - extensions_to_txt is not mapping + - extensions_to_txt -- debug: - var: extensions_regex +- name: Build the extensions list when input is not a dict (including empty) + set_fact: + extension_list: > + {% set extensions = ['__does_not_match__'] -%} + {% if extensions_to_txt -%} + {% set extensions = extensions_to_txt -%} + {% endif -%} + {{- extensions -}} + when: extensions_to_txt is not mapping + +- name: Build the extensions list when input is a dict + set_fact: + extension_list: > + {% set extensions = [] -%} + {% for extension, extension_bool in extensions_to_txt.items() -%} + {% if extension_bool -%} + {% set _ = extensions.append(extension) -%} + {% endif -%} + {% endfor -%} + {{- extensions -}} + when: extensions_to_txt is mapping + +- name: Build the extensions regular expression + set_fact: + extensions_regex: "{{ extension_list | join('|') }}" # TODO(andreaf) We might want to enforce that item.value is a valid value # in docs, artifacts, logs. Null case already handled.