Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 1 | Patrole Style Commandments |
| 2 | ========================== |
DavidPurcell | 663aedf | 2017-01-03 10:01:14 -0500 | [diff] [blame] | 3 | |
gaozx | 6f663e0 | 2017-08-10 10:24:16 +0800 | [diff] [blame] | 4 | - Step 1: Read the OpenStack Style Commandments: `<https://docs.openstack.org/hacking/latest/>`__ |
| 5 | - Step 2: Review Tempest's Style Commandments: `<https://docs.openstack.org/tempest/latest/HACKING.html>`__ |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 6 | - Step 3: Read on |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 7 | |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 8 | Patrole Specific Commandments |
| 9 | ------------------------------ |
| 10 | |
| 11 | Patrole borrows the following commandments from Tempest; refer to |
gaozx | 6f663e0 | 2017-08-10 10:24:16 +0800 | [diff] [blame] | 12 | `Tempest's Commandments <https://docs.openstack.org/tempest/latest/HACKING.html>`__ |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 13 | for more information: |
| 14 | |
| 15 | .. note:: |
| 16 | |
| 17 | The original Tempest Commandments do not include Patrole-specific paths. |
| 18 | Patrole-specific paths replace the Tempest-specific paths within Patrole's |
| 19 | hacking checks. |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 20 | |
Felipe Monteiro | fdc4514 | 2018-07-18 20:54:20 +0100 | [diff] [blame^] | 21 | - [T102] Cannot import OpenStack python clients in |
| 22 | ``patrole_tempest_plugin/tests/api`` |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 23 | - [T105] Tests cannot use setUpClass/tearDownClass |
| 24 | - [T106] vim configuration should not be kept in source files. |
| 25 | - [T107] Check that a service tag isn't in the module path |
| 26 | - [T108] Check no hyphen at the end of rand_name() argument |
| 27 | - [T109] Cannot use testtools.skip decorator; instead use |
Felipe Monteiro | fdc4514 | 2018-07-18 20:54:20 +0100 | [diff] [blame^] | 28 | ``decorators.skip_because`` from ``tempest.lib`` |
| 29 | - [T113] Check that tests use ``data_utils.rand_uuid()`` instead of |
| 30 | ``uuid.uuid4()`` |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 31 | - [N322] Method's default argument shouldn't be mutable |
| 32 | |
| 33 | The following are Patrole's specific Commandments: |
| 34 | |
| 35 | - [P100] The ``rbac_rule_validation.action`` decorator must be applied to |
Felipe Monteiro | fdc4514 | 2018-07-18 20:54:20 +0100 | [diff] [blame^] | 36 | an RBAC test |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 37 | - [P101] RBAC test filenames must end with "_rbac.py"; for example, |
Felipe Monteiro | fdc4514 | 2018-07-18 20:54:20 +0100 | [diff] [blame^] | 38 | test_servers_rbac.py, not test_servers.py |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 39 | - [P102] RBAC test class names must end in 'RbacTest' |
Samantha Blanco | cd87077 | 2017-05-22 14:23:17 -0400 | [diff] [blame] | 40 | - [P103] ``self.client`` must not be used as a client alias; this allows for |
Felipe Monteiro | fdc4514 | 2018-07-18 20:54:20 +0100 | [diff] [blame^] | 41 | code that is more maintainable and easier to read |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 42 | |
Felipe Monteiro | 1c8620a | 2018-02-25 18:52:22 +0000 | [diff] [blame] | 43 | Role Overriding |
| 44 | --------------- |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 45 | |
Felipe Monteiro | 1c8620a | 2018-02-25 18:52:22 +0000 | [diff] [blame] | 46 | Correct role overriding is vital to correct RBAC testing within Patrole. If a |
| 47 | test does not call ``rbac_utils.override_role`` within the RBAC test, followed |
| 48 | by the API endpoint that enforces the expected policy action, then the test is |
| 49 | **not** a valid Patrole test: The API endpoint under test will be performed |
| 50 | with admin role, which is always wrong unless ``CONF.patrole.rbac_test_role`` |
| 51 | is also admin. |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 52 | |
Felipe Monteiro | 1c8620a | 2018-02-25 18:52:22 +0000 | [diff] [blame] | 53 | .. todo:: |
Felipe Monteiro | 0854ded | 2017-05-05 16:30:55 +0100 | [diff] [blame] | 54 | |
Felipe Monteiro | 1c8620a | 2018-02-25 18:52:22 +0000 | [diff] [blame] | 55 | Patrole does not have a hacking check for role overriding, but one may be |
| 56 | added in the future. |
Felipe Monteiro | 9ae705d | 2018-03-26 22:14:44 -0400 | [diff] [blame] | 57 | |
| 58 | Branchless Patrole Considerations |
| 59 | --------------------------------- |
| 60 | |
| 61 | Like Tempest, Patrole is branchless. This is to better ensure API and RBAC |
| 62 | consistency between releases because API and RBAC behavior should not change |
| 63 | between releases. This means that the stable branches are also gated by the |
| 64 | Patrole master branch, which also means that proposed commits to Patrole must |
| 65 | work against both the master and all the currently supported stable branches |
| 66 | of the projects. As such there are a few special considerations that have to |
| 67 | be accounted for when pushing new changes to Patrole. |
| 68 | |
| 69 | 1. New Tests for new features |
| 70 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 71 | |
| 72 | Patrole, like Tempest, *implicitly* tests new features because new policies |
| 73 | oftentimes accompany new features. The same `Tempest philosophy`_ regarding |
| 74 | feature flags and new features also applies to Patrole. |
| 75 | |
| 76 | .. _Tempest philosophy: https://docs.openstack.org/tempest/latest/HACKING.html#new-tests-for-new-features |
| 77 | |
| 78 | 2. New Tests for new policies |
| 79 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 80 | |
| 81 | When adding tests for new policies that were not in previous releases of the |
| 82 | projects, the new test must be properly skipped with a feature flag. This |
| 83 | involves using the ``testtools.skip(Unless|If)`` decorator above the test |
| 84 | to check if the required policy is enabled. Similarly, a feature flag must |
| 85 | be used whenever an OpenStack service covered by Patrole changes one of its |
| 86 | policies in a backwards-incompatible way. If there isn't a method of selecting |
| 87 | the new policy from the config file then there won't be a mechanism to disable |
| 88 | the test with older stable releases and the new test won't be able to merge. |
| 89 | |
| 90 | Introduction of a new feature flag requires specifying a default value for the |
| 91 | corresponding config option that is appropriate in the latest OpenStack |
| 92 | release. Because Patrole is branchless, the feature flag's default value will |
| 93 | need to be overridden to a value that is appropriate in earlier releases in |
| 94 | which the feature isn't available. In DevStack, this can be accomplished by |
| 95 | modifying Patrole's lib installation script for previous branches (because |
| 96 | DevStack is branched). |
| 97 | |
| 98 | 3. Bug fix on core project needing Patrole changes |
| 99 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 100 | |
| 101 | When trying to land a bug fix which changes a tested API you'll have to use the |
| 102 | following procedure: |
| 103 | |
| 104 | #. Propose change to the project, get a +2 on the change even with the |
| 105 | test failing Patrole side. |
| 106 | #. Propose skip to the relevant Patrole test which will only be approved |
| 107 | after the corresponding change in the project has a +2. |
| 108 | #. Land project change in master and all open stable branches |
| 109 | (if required). |
| 110 | #. Land changed test in Patrole. |
| 111 | |
| 112 | Otherwise the bug fix won't be able to land in the project. |
| 113 | |
| 114 | 4. New Tests for existing features or policies |
| 115 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 116 | |
| 117 | The same `Tempest logic`_ regarding new tests for existing features or |
| 118 | policies also applies to Patrole. |
| 119 | |
| 120 | .. _Tempest logic: https://docs.openstack.org/tempest/latest/HACKING.html#new-tests-for-existing-features |