diff --git a/roles/htmlify-logs/library/htmlify.py b/roles/htmlify-logs/library/htmlify.py index 2b02f0c3a..90629c7f8 100644 --- a/roles/htmlify-logs/library/htmlify.py +++ b/roles/htmlify-logs/library/htmlify.py @@ -14,6 +14,11 @@ # under the License. import cgi +html_escape = getattr(cgi, 'escape', None) +if not html_escape: + import html + html_escape = html.escape + import argparse import gzip import sys @@ -95,7 +100,7 @@ def run(inpath, outpath): for i, line in enumerate(infile): i = i + 1 - line = cgi.escape(line.rstrip('\n')) + line = html_escape(line.rstrip('\n')) outfile.write('' % (i, i, i)) outfile.write(line.rstrip('\n')) outfile.write("\n") diff --git a/roles/htmlify-logs/library/test-fixtures/reference/job-output.txt b/roles/htmlify-logs/library/test-fixtures/reference-cgi/job-output.txt similarity index 100% rename from roles/htmlify-logs/library/test-fixtures/reference/job-output.txt rename to roles/htmlify-logs/library/test-fixtures/reference-cgi/job-output.txt diff --git a/roles/htmlify-logs/library/test-fixtures/reference-html/job-output.txt b/roles/htmlify-logs/library/test-fixtures/reference-html/job-output.txt new file mode 100644 index 000000000..3f3d4e995 --- /dev/null +++ b/roles/htmlify-logs/library/test-fixtures/reference-html/job-output.txt @@ -0,0 +1,112 @@ + +
+ + + ++2018-08-01 00:43:51.328884 | Job console starting... +2018-08-01 00:44:01.742989 | PRE-RUN START: [trusted : opendev.org/openstack/project-config/playbooks/base/pre.yaml@master] +2018-08-01 00:44:04.693529 | +2018-08-01 00:44:04.693765 | PLAY [localhost] +2018-08-01 00:44:04.736664 | +2018-08-01 00:44:04.736863 | TASK [emit-job-header : Setup log path fact] +2018-08-01 00:44:04.804077 | localhost | ok +2018-08-01 00:44:04.870027 | +2018-08-01 00:44:04.870264 | TASK [set-zuul-log-path-fact : Set log path for a change] +2018-08-01 00:44:04.942854 | localhost | skipping: Conditional result was False +2018-08-01 00:44:04.970178 | +2018-08-01 00:44:04.970405 | TASK [set-zuul-log-path-fact : Set log path for a ref update] +2018-08-01 00:44:05.067095 | localhost | ok +2018-08-01 00:44:05.094186 | +2018-08-01 00:44:05.094430 | TASK [set-zuul-log-path-fact : Set log path for a periodic job] +2018-08-01 00:44:05.152841 | localhost | skipping: Conditional result was False +2018-08-01 00:44:05.188754 | +2018-08-01 00:44:05.189030 | TASK [emit-job-header : Print job information] +2018-08-01 00:44:05.317656 | # Job Information +2018-08-01 00:44:05.318162 | Ansible Version: 2.5.7 +2018-08-01 00:44:05.318269 | Job: trigger-readthedocs-webhook +2018-08-01 00:44:05.318371 | Pipeline: post +2018-08-01 00:44:05.318469 | Executor: ze09.openstack.org +2018-08-01 00:44:05.318567 | Triggered by: https://opendev.org/x/gerrit-dash-creator/commit/ee5167a518de07c325f326df212c92e5c1e786a9 +2018-08-01 00:44:05.318663 | Log URL (when completed): http://logs.openstack.org/ee/ee5167a518de07c325f326df212c92e5c1e786a9/post/trigger-readthedocs-webhook/f677f03 +2018-08-01 00:44:05.349043 | +2018-08-01 00:44:05.349250 | PLAY [all] +2018-08-01 00:44:05.385083 | +2018-08-01 00:44:05.385308 | TASK [Gather network facts] +2018-08-01 00:44:07.104842 | ubuntu-xenial | ok +2018-08-01 00:44:07.167964 | +2018-08-01 00:44:07.168193 | TASK [add-build-sshkey : Check to see if ssh key was already created for this build] +2018-08-01 00:44:07.760495 | ubuntu-xenial -> localhost | ok +2018-08-01 00:44:07.799900 | +2018-08-01 00:44:07.800163 | TASK [add-build-sshkey : Create Temp SSH key] +2018-08-01 00:44:08.445211 | ubuntu-xenial -> localhost | Generating public/private rsa key pair. +2018-08-01 00:44:08.445859 | ubuntu-xenial -> localhost | Your identification has been saved in /var/lib/zuul/builds/f677f0312811438a8db3fa38953649c7/work/f677f0312811438a8db3fa38953649c7_id_rsa. +2018-08-01 00:44:08.445989 | ubuntu-xenial -> localhost | Your public key has been saved in /var/lib/zuul/builds/f677f0312811438a8db3fa38953649c7/work/f677f0312811438a8db3fa38953649c7_id_rsa.pub. +2018-08-01 00:44:08.446099 | ubuntu-xenial -> localhost | The key fingerprint is: +2018-08-01 00:44:08.446205 | ubuntu-xenial -> localhost | SHA256:ZNugwiDo1mjkhNQt/GnNoH3XQgo+uU/jA8NtHUKCPiY zuul@ze09 +2018-08-01 00:44:08.446320 | ubuntu-xenial -> localhost | The key's randomart image is: +2018-08-01 00:44:08.446424 | ubuntu-xenial -> localhost | +---[RSA 1024]----+ +2018-08-01 00:44:08.446527 | ubuntu-xenial -> localhost | | .o o | +2018-08-01 00:44:08.446630 | ubuntu-xenial -> localhost | |+ = = . . | +2018-08-01 00:44:08.446732 | ubuntu-xenial -> localhost | |+oo * X * . | +2018-08-01 00:44:08.446834 | ubuntu-xenial -> localhost | |=EoB O X B . | +2018-08-01 00:44:08.446936 | ubuntu-xenial -> localhost | | *o.* * S + | +2018-08-01 00:44:08.447037 | ubuntu-xenial -> localhost | |o * = . | +2018-08-01 00:44:08.447138 | ubuntu-xenial -> localhost | | B . | +2018-08-01 00:44:08.447239 | ubuntu-xenial -> localhost | | + | +2018-08-01 00:44:08.447339 | ubuntu-xenial -> localhost | | . | +2018-08-01 00:44:08.447440 | ubuntu-xenial -> localhost | +----[SHA256]-----+ +2018-08-01 00:44:08.447643 | ubuntu-xenial -> localhost | ok: Runtime: 0:00:00.022230 +here is a line with some <escapes> ++ + + diff --git a/roles/htmlify-logs/library/test_htmlify.py b/roles/htmlify-logs/library/test_htmlify.py index 16aef34cf..d58a53399 100644 --- a/roles/htmlify-logs/library/test_htmlify.py +++ b/roles/htmlify-logs/library/test_htmlify.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import cgi import gzip import os @@ -30,7 +31,10 @@ class TestHTMLify(testtools.TestCase): def _test_file(self, fn, ref_fn): in_path = os.path.join(FIXTURE_DIR, 'in', fn) - ref_path = os.path.join(FIXTURE_DIR, 'reference', ref_fn) + if getattr(cgi, 'escape', None): + ref_path = os.path.join(FIXTURE_DIR, 'reference-cgi', ref_fn) + else: + ref_path = os.path.join(FIXTURE_DIR, 'reference-html', ref_fn) out_root = self.useFixture(fixtures.TempDir()).path out_path = os.path.join(out_root, fn) run(in_path, out_path) diff --git a/tox.ini b/tox.ini index 1bbbd9dc1..acda17e30 100644 --- a/tox.ini +++ b/tox.ini @@ -2,6 +2,7 @@ minversion = 1.6 skipsdist = True envlist = linters +ignore_basepython_conflict = True [testenv] basepython = python3