Add test to ensure policy is always authorized
Add test to ensure policy is always authorized

This adds new unit tests to ensure that all API methods decorated
with @expose.expose are also calling policy.authorize() and
context.to_policy_values() within the method body.

This is done by patching sys.modules to replace the @expose decorator
with a wrapper that records a reference to the exposed method. Then,
all API modules' (chassis, node, port, etc.) sources are reloaded
within the unit test, causing the test classes own decorator to be
called, and references to every @expose'd method to be recorded in the
test class instance. The test case then iterates over that list of
function references, and inspects the python source of each one to
determine if it contains a call to the policy.authorize and
context.to_policy_values methods. An error is raised if it does not.

This approach is rather brutish, but without being able to invoke
@authorize as a decorator (*) I have not found a better way than
inspecting the source.

(*) we can't invoke @authorize as a decorator because decorators are
evaluated at module compile time, but @authorize requires run-time
context available only from the Pecan run-time magic accessor
pecan.request.context.

Co-Authored-By: Vladyslav Drok <488302dd246f7368b4b820d34501759efce48f70@mirantis.com>
Change-Id: Iebfd9183dcbd49dbef78398c07327a347a41976e

NaohiroTamura/ironic,SauloAislan/ironic,pshchelo/ironic,openstack/ironic,pshchelo/ironic,NaohiroTamura/ironic,openstack/ironic,SauloAislan/ironic