Reviewed: https://review.openstack.org/582995 Committed: https://git.openstack.org/cgit/openstack/glance/commit/?id=3e47cbea340c067cefd2ab1e029dc1fca4f5e954 Submitter: Zuul Branch: master
commit 3e47cbea340c067cefd2ab1e029dc1fca4f5e954 Author: Lance Bragstad <[email protected]> Date: Mon Jul 16 16:18:03 2018 +0000 Use glance.context.RequestContext in tests There were some recent changes to oslo.policy that include specific type checks of the ``creds`` parameter passed to the ``enforce()`` method: https://review.openstack.org/#/c/578995/ The above change allows consuming projects to pass instances of oslo_context.context.RequestContext to the policy enforcer, as opposed to building a dictionary instance from scratch multiple different ways across projects. The glance unit tests were failing with the new version of oslo.policy (1.38.0) because they were passing in a Mock instance which failed the new, more strict, type check. This commit converts the setUp class of the tests to use an instance of glance.context.RequestContext, which subclasses RequestContext from oslo.context. It also sets the user_id and project_id attributes of the context object to override authorization checks. This should allow glance to pass with newer versions of oslo.policy. Change-Id: I0a69bc9565d57fd6ad8484abc5fce0e8dd45f9f2 Closes-Bug: 1781976 ** Changed in: glance Status: New => Fix Released -- You received this bug notification because you are a member of Yahoo! Engineering Team, which is subscribed to Glance. https://bugs.launchpad.net/bugs/1781976 Title: Issues with oslo.policy 1.38.0 Status in Glance: Fix Released Bug description: There was recently a few changes to oslo.policy that allow for more flexibility when enforcing policy [0]. These changes were included in the 1.38.0 release of oslo.policy, which is cause glance unit tests to fail when updating the requirements for oslo.policy [1] I was able to recreate this locally by: 1.) running glance unit tests 2.) installing oslo.policy 1.38.0 ($ .tox/py27/bin/pip install oslo.policy===1.38.0) 3.) Rerunning unit tests with the new version of oslo.policy The following is a trace from a failing unit test in glance: File "/opt/stack/glance/.tox/py27/local/lib/python2.7/site-packages/taskflow/engines/action_engine/engine.py", line 247, in run for _state in self.run_iter(timeout=timeout): File "/opt/stack/glance/.tox/py27/local/lib/python2.7/site-packages/taskflow/engines/action_engine/engine.py", line 328, in run_iter self._change_state(states.FAILURE) File "/opt/stack/glance/.tox/py27/local/lib/python2.7/site-packages/oslo_utils/excutils.py", line 220, in __exit__ self.force_reraise() File "/opt/stack/glance/.tox/py27/local/lib/python2.7/site-packages/oslo_utils/excutils.py", line 196, in force_reraise six.reraise(self.type_, self.value, self.tb) File "/opt/stack/glance/.tox/py27/local/lib/python2.7/site-packages/taskflow/engines/action_engine/engine.py", line 300, in run_iter failure.Failure.reraise_if_any(memory.failures) File "/opt/stack/glance/.tox/py27/local/lib/python2.7/site-packages/taskflow/types/failure.py", line 339, in reraise_if_any failures[0].reraise() File "/opt/stack/glance/.tox/py27/local/lib/python2.7/site-packages/taskflow/types/failure.py", line 346, in reraise six.reraise(*self._exc_info) File "/opt/stack/glance/.tox/py27/local/lib/python2.7/site-packages/taskflow/engines/action_engine/executor.py", line 72, in _revert_task result = task.revert(**arguments) File "glance/async/flows/base_import.py", line 82, in revert image.delete() File "glance/domain/proxy.py", line 186, in delete self.base.delete() File "glance/domain/proxy.py", line 186, in delete self.base.delete() File "glance/api/policy.py", line 171, in delete self.policy.enforce(self.context, 'delete_image', dict(self.target)) File "glance/api/policy.py", line 68, in enforce action=action) File "/opt/stack/glance/.tox/py27/local/lib/python2.7/site-packages/oslo_policy/policy.py", line 835, in enforce raise InvalidContextObject(msg) oslo_policy.policy.InvalidContextObject: Invalid context object: Expected type oslo_context.context.RequestContext, dict, or the output of oslo_context.context.RequestContext.to_policy_values but got <class 'mock.mock.MagicMock'> instead. [0] https://review.openstack.org/#/c/578995/ [1] https://review.openstack.org/#/c/582418/ To manage notifications about this bug go to: https://bugs.launchpad.net/glance/+bug/1781976/+subscriptions -- Mailing list: https://launchpad.net/~yahoo-eng-team Post to : [email protected] Unsubscribe : https://launchpad.net/~yahoo-eng-team More help : https://help.launchpad.net/ListHelp

