From 7d9497a373f1ddba0c78a77435f05ebcf47ee926 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 18 Aug 2017 09:37:21 -0500 Subject: [PATCH] Generate api-ref redirects for service type aliases We track official service type names and their historical aliases. As api-ref is organized by service-type, it stands to reason that if a service-type changes (or has changed) that a link might exist to the old value. Use the service types authority data to generate a set of redirects for all aliases of a service to the official service type location. Change-Id: I96a5502ca6cd3e78f996ad9b60101c907e2150cd --- test-requirements.txt | 3 +++ tools/www-generator.py | 22 ++++++++++++++++++---- www/{static => }/.htaccess | 6 ++++++ 3 files changed, 27 insertions(+), 4 deletions(-) rename www/{static => }/.htaccess (94%) diff --git a/test-requirements.txt b/test-requirements.txt index 915f5d165..474e96944 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -14,5 +14,8 @@ openstackdocstheme>=1.16.0 # Apache-2.0 nwdiag sphinxcontrib-nwdiag +requests +os-service-types + # For translations Babel>=2.3.4,!=2.4.0 # BSD diff --git a/tools/www-generator.py b/tools/www-generator.py index 8661c338b..19845024e 100755 --- a/tools/www-generator.py +++ b/tools/www-generator.py @@ -20,6 +20,8 @@ import sys import lxml.html from lxml import etree import jinja2 +import os_service_types +import requests def initialize_logging(debug, verbose): @@ -67,8 +69,16 @@ def main(): logger.error("initialising template environment failed: %s" % e) return 1 + try: + service_types = os_service_types.ServiceTypes( + session=requests.Session(), only_remote=True) + except Exception as e: + logger.error("initialising service types data failed: %s" % e) + return 1 + for templateFile in environment.list_templates(): - if not templateFile.endswith('.html'): + if not (templateFile.endswith('.html') + or templateFile.endswith('.htaccess')): continue logger.info("generating %s" % templateFile) @@ -80,10 +90,14 @@ def main(): (templateFile, e)) continue + try: - output = lxml.html.tostring( - lxml.html.fromstring(template.render()), - pretty_print=True) + if templateFile.endswith('.html'): + output = lxml.html.tostring( + lxml.html.fromstring(template.render()), + pretty_print=True) + else: + output = template.render(REVERSE=service_types.reverse) except Exception as e: logger.error("rendering template %s failed: %s" % (templateFile, e)) diff --git a/www/static/.htaccess b/www/.htaccess similarity index 94% rename from www/static/.htaccess rename to www/.htaccess index 7c57dc247..3a0d33be8 100644 --- a/www/static/.htaccess +++ b/www/.htaccess @@ -60,3 +60,9 @@ redirect 301 /api-ref-share-v2.html /api-ref/shared-file-system/index.html redirect 301 /api-ref-share-v1.html /api-ref/shared-file-system/index.html # Redirect Telemetry (ceilometer only) API redirect 301 /api-ref-telemetry-v2.html https://docs.openstack.org/ceilometer/latest/webapi/v2.html + +# Redirect service-type aliases to service-type api-ref locations +{% for alias, service_type in REVERSE.items() -%} +redirectmatch 301 /api-ref/{{ alias }}/(.*) /api-ref/{{ service_type }}/$1 +{% endfor %} +