diff --git a/doc/source/admin/index.rst b/doc/source/admin/index.rst deleted file mode 100644 index d8a2cfc..0000000 --- a/doc/source/admin/index.rst +++ /dev/null @@ -1,5 +0,0 @@ -==================== -Administrators guide -==================== - -Administrators guide of whereto. diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst index 4149c93..1afe858 100644 --- a/doc/source/cli/index.rst +++ b/doc/source/cli/index.rst @@ -2,4 +2,5 @@ Command line interface reference ================================ -CLI reference of whereto. +.. autoprogram:: whereto.app:argument_parser + :prog: whereto diff --git a/doc/source/conf.py b/doc/source/conf.py index c2a3784..5513c17 100755 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -22,7 +22,7 @@ sys.path.insert(0, os.path.abspath('../..')) # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ 'sphinx.ext.autodoc', - 'openstackdocstheme', + 'sphinxcontrib.autoprogram', #'sphinx.ext.intersphinx', ] @@ -40,11 +40,6 @@ master_doc = 'index' project = u'whereto' copyright = u'2017, OpenStack Developers' -# openstackdocstheme options -repository_name = 'openstack/whereto' -bug_project = 'whereto' -bug_tag = '' - # If true, '()' will be appended to :func: etc. cross-reference text. add_function_parentheses = True @@ -62,7 +57,7 @@ pygments_style = 'sphinx' # html_theme_path = ["."] # html_theme = '_theme' # html_static_path = ['static'] -html_theme = 'openstackdocs' +html_theme = 'nature' # Output file base name for HTML help builder. htmlhelp_basename = '%sdoc' % project diff --git a/doc/source/configuration/index.rst b/doc/source/configuration/index.rst deleted file mode 100644 index c929a7c..0000000 --- a/doc/source/configuration/index.rst +++ /dev/null @@ -1,5 +0,0 @@ -============= -Configuration -============= - -Configuration of whereto. diff --git a/doc/source/contributor/contributing.rst b/doc/source/contributor/contributing.rst deleted file mode 100644 index 2aa0707..0000000 --- a/doc/source/contributor/contributing.rst +++ /dev/null @@ -1,4 +0,0 @@ -============ -Contributing -============ -.. include:: ../../../CONTRIBUTING.rst diff --git a/doc/source/contributor/index.rst b/doc/source/contributor/index.rst index 036e449..e7efc80 100644 --- a/doc/source/contributor/index.rst +++ b/doc/source/contributor/index.rst @@ -2,8 +2,4 @@ Contributor Documentation =========================== -.. toctree:: - :maxdepth: 2 - - contributing - +.. include:: ../../../CONTRIBUTING.rst diff --git a/doc/source/index.rst b/doc/source/index.rst index e6b4eca..9a2a74f 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -3,24 +3,24 @@ You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. -======================================= -Welcome to the documentation of whereto -======================================= +======================================== + whereto: Testing Apache Redirect Rules +======================================== -Contents: +whereto is an app for testing redirect rules like what may appear in a +.htaccess file for Apache. It provides a way to test those rules in CI +jobs. + +:Source: http://git.openstack.org/cgit/openstack/whereto +:Bugs: http://bugs.launchpad.net/whereto .. toctree:: :maxdepth: 2 - readme install/index - library/index contributor/index - configuration/index cli/index user/index - admin/index - reference/index Indices and tables ================== diff --git a/doc/source/install/common_configure.rst b/doc/source/install/common_configure.rst deleted file mode 100644 index 629189c..0000000 --- a/doc/source/install/common_configure.rst +++ /dev/null @@ -1,10 +0,0 @@ -2. Edit the ``/etc/whereto/whereto.conf`` file and complete the following - actions: - - * In the ``[database]`` section, configure database access: - - .. code-block:: ini - - [database] - ... - connection = mysql+pymysql://whereto:WHERETO_DBPASS@controller/whereto diff --git a/doc/source/install/common_prerequisites.rst b/doc/source/install/common_prerequisites.rst deleted file mode 100644 index ff520f7..0000000 --- a/doc/source/install/common_prerequisites.rst +++ /dev/null @@ -1,75 +0,0 @@ -Prerequisites -------------- - -Before you install and configure the whereto service, -you must create a database, service credentials, and API endpoints. - -#. To create the database, complete these steps: - - * Use the database access client to connect to the database - server as the ``root`` user: - - .. code-block:: console - - $ mysql -u root -p - - * Create the ``whereto`` database: - - .. code-block:: none - - CREATE DATABASE whereto; - - * Grant proper access to the ``whereto`` database: - - .. code-block:: none - - GRANT ALL PRIVILEGES ON whereto.* TO 'whereto'@'localhost' \ - IDENTIFIED BY 'WHERETO_DBPASS'; - GRANT ALL PRIVILEGES ON whereto.* TO 'whereto'@'%' \ - IDENTIFIED BY 'WHERETO_DBPASS'; - - Replace ``WHERETO_DBPASS`` with a suitable password. - - * Exit the database access client. - - .. code-block:: none - - exit; - -#. Source the ``admin`` credentials to gain access to - admin-only CLI commands: - - .. code-block:: console - - $ . admin-openrc - -#. To create the service credentials, complete these steps: - - * Create the ``whereto`` user: - - .. code-block:: console - - $ openstack user create --domain default --password-prompt whereto - - * Add the ``admin`` role to the ``whereto`` user: - - .. code-block:: console - - $ openstack role add --project service --user whereto admin - - * Create the whereto service entities: - - .. code-block:: console - - $ openstack service create --name whereto --description "whereto" whereto - -#. Create the whereto service API endpoints: - - .. code-block:: console - - $ openstack endpoint create --region RegionOne \ - whereto public http://controller:XXXX/vY/%\(tenant_id\)s - $ openstack endpoint create --region RegionOne \ - whereto internal http://controller:XXXX/vY/%\(tenant_id\)s - $ openstack endpoint create --region RegionOne \ - whereto admin http://controller:XXXX/vY/%\(tenant_id\)s diff --git a/doc/source/install/get_started.rst b/doc/source/install/get_started.rst deleted file mode 100644 index 299061e..0000000 --- a/doc/source/install/get_started.rst +++ /dev/null @@ -1,9 +0,0 @@ -======================== -whereto service overview -======================== -The whereto service provides... - -The whereto service consists of the following components: - -``whereto-api`` service - Accepts and responds to end user compute API calls... diff --git a/doc/source/install/index.rst b/doc/source/install/index.rst index c237418..537e7cd 100644 --- a/doc/source/install/index.rst +++ b/doc/source/install/index.rst @@ -1,17 +1,9 @@ -================================== -whereto service installation guide -================================== +============================ + whereto installation guide +============================ -.. toctree:: - :maxdepth: 2 +The whereto package should be installed via ``pip``: - get_started.rst - install.rst - verify.rst - next-steps.rst +.. code-block:: console -The whereto service (whereto) provides... - -This chapter assumes a working setup of OpenStack following the -`OpenStack Installation Tutorial -`_. + $ pip install whereto diff --git a/doc/source/install/install-obs.rst b/doc/source/install/install-obs.rst deleted file mode 100644 index e16a713..0000000 --- a/doc/source/install/install-obs.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. _install-obs: - - -Install and configure for openSUSE and SUSE Linux Enterprise -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -This section describes how to install and configure the whereto service -for openSUSE Leap 42.1 and SUSE Linux Enterprise Server 12 SP1. - -.. include:: common_prerequisites.rst - -Install and configure components --------------------------------- - -#. Install the packages: - - .. code-block:: console - - # zypper --quiet --non-interactive install - -.. include:: common_configure.rst - - -Finalize installation ---------------------- - -Start the whereto services and configure them to start when -the system boots: - -.. code-block:: console - - # systemctl enable openstack-whereto-api.service - - # systemctl start openstack-whereto-api.service diff --git a/doc/source/install/install-rdo.rst b/doc/source/install/install-rdo.rst deleted file mode 100644 index 01cd5e9..0000000 --- a/doc/source/install/install-rdo.rst +++ /dev/null @@ -1,33 +0,0 @@ -.. _install-rdo: - -Install and configure for Red Hat Enterprise Linux and CentOS -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -This section describes how to install and configure the whereto service -for Red Hat Enterprise Linux 7 and CentOS 7. - -.. include:: common_prerequisites.rst - -Install and configure components --------------------------------- - -#. Install the packages: - - .. code-block:: console - - # yum install - -.. include:: common_configure.rst - -Finalize installation ---------------------- - -Start the whereto services and configure them to start when -the system boots: - -.. code-block:: console - - # systemctl enable openstack-whereto-api.service - - # systemctl start openstack-whereto-api.service diff --git a/doc/source/install/install-ubuntu.rst b/doc/source/install/install-ubuntu.rst deleted file mode 100644 index 842fa43..0000000 --- a/doc/source/install/install-ubuntu.rst +++ /dev/null @@ -1,31 +0,0 @@ -.. _install-ubuntu: - -Install and configure for Ubuntu -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -This section describes how to install and configure the whereto -service for Ubuntu 14.04 (LTS). - -.. include:: common_prerequisites.rst - -Install and configure components --------------------------------- - -#. Install the packages: - - .. code-block:: console - - # apt-get update - - # apt-get install - -.. include:: common_configure.rst - -Finalize installation ---------------------- - -Restart the whereto services: - -.. code-block:: console - - # service openstack-whereto-api restart diff --git a/doc/source/install/install.rst b/doc/source/install/install.rst deleted file mode 100644 index 01ff796..0000000 --- a/doc/source/install/install.rst +++ /dev/null @@ -1,20 +0,0 @@ -.. _install: - -Install and configure -~~~~~~~~~~~~~~~~~~~~~ - -This section describes how to install and configure the -whereto service, code-named whereto, on the controller node. - -This section assumes that you already have a working OpenStack -environment with at least the following components installed: -.. (add the appropriate services here and further notes) - -Note that installation and configuration vary by distribution. - -.. toctree:: - :maxdepth: 2 - - install-obs.rst - install-rdo.rst - install-ubuntu.rst diff --git a/doc/source/install/next-steps.rst b/doc/source/install/next-steps.rst deleted file mode 100644 index cb2748b..0000000 --- a/doc/source/install/next-steps.rst +++ /dev/null @@ -1,9 +0,0 @@ -.. _next-steps: - -Next steps -~~~~~~~~~~ - -Your OpenStack environment now includes the whereto service. - -To add additional services, see -https://docs.openstack.org/project-install-guide/ocata/. diff --git a/doc/source/install/verify.rst b/doc/source/install/verify.rst deleted file mode 100644 index a14a6e0..0000000 --- a/doc/source/install/verify.rst +++ /dev/null @@ -1,24 +0,0 @@ -.. _verify: - -Verify operation -~~~~~~~~~~~~~~~~ - -Verify operation of the whereto service. - -.. note:: - - Perform these commands on the controller node. - -#. Source the ``admin`` project credentials to gain access to - admin-only CLI commands: - - .. code-block:: console - - $ . admin-openrc - -#. List service components to verify successful launch and registration - of each process: - - .. code-block:: console - - $ openstack whereto service list diff --git a/doc/source/library/index.rst b/doc/source/library/index.rst deleted file mode 100644 index d102d01..0000000 --- a/doc/source/library/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -======== -Usage -======== - -To use whereto in a project:: - - import whereto diff --git a/doc/source/readme.rst b/doc/source/readme.rst deleted file mode 100644 index a6210d3..0000000 --- a/doc/source/readme.rst +++ /dev/null @@ -1 +0,0 @@ -.. include:: ../../README.rst diff --git a/doc/source/reference/index.rst b/doc/source/reference/index.rst deleted file mode 100644 index a97c53c..0000000 --- a/doc/source/reference/index.rst +++ /dev/null @@ -1,5 +0,0 @@ -========== -References -========== - -References of whereto. diff --git a/doc/source/user/index.rst b/doc/source/user/index.rst index 86f2c40..9b2fb9c 100644 --- a/doc/source/user/index.rst +++ b/doc/source/user/index.rst @@ -2,4 +2,47 @@ Users guide =========== -Users guide of whereto. +To test a set of redirects, ``whereto`` needs the input ``.htaccess`` +file and another input file with test data. + +The ``.htaccess`` file should contain ``Redirect`` and +``RedirectMatch`` directives. Blank lines and lines starting with +``#`` are ignored. For example, this input includes 6 rules: + +.. code-block:: text + + # Redirect old top-level HTML pages to the version under most recent + # full release. + redirectmatch 301 ^/$ /pike/ + redirectmatch 301 ^/index.html$ /pike/ + redirectmatch 301 ^/openstack-projects.html$ /pike/projects.html + redirectmatch 301 ^/language-bindings.html$ /pike/language-bindings.html + + # Redirect docs.openstack.org index.html subpage pointers to main page + redirect 301 /install/ /pike/install/ + redirect 301 /basic-install/ /pike/install/ + +The test data file should include one test per line, including 3 +parts: the input path, the expected HTTP response code, and the +expected output path. For example: + +.. code-block:: text + + / 301 /pike/ + / 301 /pike + /install/ 301 /pike/install/ + /no/rule 301 /should/fail + +The output from ``whereto`` includes a report of any tests that do not +match, including if no rules match and if multiple rules match. For +example: + +.. code-block:: console + + $ whereto -q --ignore-untested .htaccess test.txt + + Test on line 2 did not produce expected result: / 301 /pike + [7] redirectmatch 301 ^/$ /pike/ + No rule matched test on line 4: /no/rule 301 /should/fail + + 2 failures diff --git a/test-requirements.txt b/test-requirements.txt index f559c0e..f5aaf0d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -13,3 +13,5 @@ testtools>=1.4.0 # MIT openstackdocstheme>=1.11.0 # Apache-2.0 # releasenotes reno>=1.8.0 # Apache-2.0 + +sphinxcontrib.autoprogram diff --git a/tox.ini b/tox.ini index 731fbfa..d9736ea 100644 --- a/tox.ini +++ b/tox.ini @@ -24,7 +24,8 @@ commands = {posargs} commands = python setup.py test --coverage --testr-args='{posargs}' [testenv:docs] -commands = python setup.py build_sphinx +basepython = python3 +commands = python3 setup.py build_sphinx [testenv:releasenotes] commands = diff --git a/whereto/app.py b/whereto/app.py index 5157c88..4c46964 100644 --- a/whereto/app.py +++ b/whereto/app.py @@ -55,37 +55,41 @@ def process_tests(ruleset, tests): return (mismatches, untested) +# This is constructed outside of the main() function to support +# sphinxcontrib.autoprogram in the doc build. +argument_parser = argparse.ArgumentParser() +group = argument_parser.add_mutually_exclusive_group() +group.add_argument( + '--ignore-untested', + action='store_false', + dest='error_untested', + default=True, + help='ignore untested rules', +) +group.add_argument( + '--error-untested', + action='store_true', + dest='error_untested', + help='error if there are untested rules', +) +argument_parser.add_argument( + '-q', '--quiet', + action='store_true', + default=False, + help='run quietly', +) +argument_parser.add_argument( + 'htaccess_file', + help='file with rewrite rules', +) +argument_parser.add_argument( + 'test_file', + help='file with test data', +) + + def main(): - arg_parser = argparse.ArgumentParser() - group = arg_parser.add_mutually_exclusive_group() - group.add_argument( - '--ignore-untested', - action='store_false', - dest='error_untested', - default=True, - help='ignore untested rules', - ) - group.add_argument( - '--error-untested', - action='store_true', - dest='error_untested', - help='error if there are untested rules', - ) - arg_parser.add_argument( - '-q', '--quiet', - action='store_true', - default=False, - help='run quietly', - ) - arg_parser.add_argument( - 'htaccess_file', - help='file with rewrite rules', - ) - arg_parser.add_argument( - 'test_file', - help='file with test data', - ) - args = arg_parser.parse_args() + args = argument_parser.parse_args() ruleset = rules.RuleSet() with io.open(args.htaccess_file, 'r', encoding='utf-8') as f: