blob: db1f6909c75998fab629c4bd37878d7bbc24ee3f [file] [log] [blame]
Felipe Monteiroeb197db2018-06-10 12:21:49 -04001Patrole Coding Guide
2====================
DavidPurcell663aedf2017-01-03 10:01:14 -05003
gaozx6f663e02017-08-10 10:24:16 +08004- 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 Monteiro0854ded2017-05-05 16:30:55 +01006- Step 3: Read on
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +01007
Felipe Monteiro0854ded2017-05-05 16:30:55 +01008Patrole Specific Commandments
9------------------------------
10
11Patrole borrows the following commandments from Tempest; refer to
gaozx6f663e02017-08-10 10:24:16 +080012`Tempest's Commandments <https://docs.openstack.org/tempest/latest/HACKING.html>`__
Felipe Monteiro0854ded2017-05-05 16:30:55 +010013for 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.
20..
21
22- [T102] Cannot import OpenStack python clients in patrole_tempest_plugin/tests/api
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
28 decorators.skip_because from tempest.lib
29- [T113] Check that tests use data_utils.rand_uuid() instead of uuid.uuid4()
30- [N322] Method's default argument shouldn't be mutable
31
32The following are Patrole's specific Commandments:
33
34- [P100] The ``rbac_rule_validation.action`` decorator must be applied to
Samantha Blancob6a9c212017-08-09 17:43:08 -040035 an RBAC test
Felipe Monteiro0854ded2017-05-05 16:30:55 +010036- [P101] RBAC test filenames must end with "_rbac.py"; for example,
37 test_servers_rbac.py, not test_servers.py
38- [P102] RBAC test class names must end in 'RbacTest'
Samantha Blancocd870772017-05-22 14:23:17 -040039- [P103] ``self.client`` must not be used as a client alias; this allows for
40 code that is more maintainable and easier to read
Felipe Monteiro0854ded2017-05-05 16:30:55 +010041
Felipe Monteiro1c8620a2018-02-25 18:52:22 +000042Role Overriding
43---------------
Felipe Monteiro0854ded2017-05-05 16:30:55 +010044
Felipe Monteiro1c8620a2018-02-25 18:52:22 +000045Correct role overriding is vital to correct RBAC testing within Patrole. If a
46test does not call ``rbac_utils.override_role`` within the RBAC test, followed
47by the API endpoint that enforces the expected policy action, then the test is
48**not** a valid Patrole test: The API endpoint under test will be performed
49with admin role, which is always wrong unless ``CONF.patrole.rbac_test_role``
50is also admin.
Felipe Monteiro0854ded2017-05-05 16:30:55 +010051
Felipe Monteiro1c8620a2018-02-25 18:52:22 +000052.. todo::
Felipe Monteiro0854ded2017-05-05 16:30:55 +010053
Felipe Monteiro1c8620a2018-02-25 18:52:22 +000054 Patrole does not have a hacking check for role overriding, but one may be
55 added in the future.
Felipe Monteiro9ae705d2018-03-26 22:14:44 -040056
57Branchless Patrole Considerations
58---------------------------------
59
60Like Tempest, Patrole is branchless. This is to better ensure API and RBAC
61consistency between releases because API and RBAC behavior should not change
62between releases. This means that the stable branches are also gated by the
63Patrole master branch, which also means that proposed commits to Patrole must
64work against both the master and all the currently supported stable branches
65of the projects. As such there are a few special considerations that have to
66be accounted for when pushing new changes to Patrole.
67
681. New Tests for new features
69^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70
71Patrole, like Tempest, *implicitly* tests new features because new policies
72oftentimes accompany new features. The same `Tempest philosophy`_ regarding
73feature flags and new features also applies to Patrole.
74
75.. _Tempest philosophy: https://docs.openstack.org/tempest/latest/HACKING.html#new-tests-for-new-features
76
772. New Tests for new policies
78^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79
80When adding tests for new policies that were not in previous releases of the
81projects, the new test must be properly skipped with a feature flag. This
82involves using the ``testtools.skip(Unless|If)`` decorator above the test
83to check if the required policy is enabled. Similarly, a feature flag must
84be used whenever an OpenStack service covered by Patrole changes one of its
85policies in a backwards-incompatible way. If there isn't a method of selecting
86the new policy from the config file then there won't be a mechanism to disable
87the test with older stable releases and the new test won't be able to merge.
88
89Introduction of a new feature flag requires specifying a default value for the
90corresponding config option that is appropriate in the latest OpenStack
91release. Because Patrole is branchless, the feature flag's default value will
92need to be overridden to a value that is appropriate in earlier releases in
93which the feature isn't available. In DevStack, this can be accomplished by
94modifying Patrole's lib installation script for previous branches (because
95DevStack is branched).
96
973. Bug fix on core project needing Patrole changes
98^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99
100When trying to land a bug fix which changes a tested API you'll have to use the
101following procedure:
102
103 #. Propose change to the project, get a +2 on the change even with the
104 test failing Patrole side.
105 #. Propose skip to the relevant Patrole test which will only be approved
106 after the corresponding change in the project has a +2.
107 #. Land project change in master and all open stable branches
108 (if required).
109 #. Land changed test in Patrole.
110
111Otherwise the bug fix won't be able to land in the project.
112
1134. New Tests for existing features or policies
114^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115
116The same `Tempest logic`_ regarding new tests for existing features or
117policies also applies to Patrole.
118
119.. _Tempest logic: https://docs.openstack.org/tempest/latest/HACKING.html#new-tests-for-existing-features