Change devstack to OS_PROJECT_NAME and avoid mocking oslo.policy internals

To pass the tests in gate, this commit has 2 separate changes

1) OS_TENANT_NAME is no longer used in the latest devstack, it causes all
datasource driver fail, as well as jenkins gate failure.

This fix changes devstack to use OS_PROJECT_NAME

2) Previously, we tested oslo.policy by mocking out one of the internals
of oslo.policy, just like Neutron.  Besides being improper, the newest
release of oslo.policy broke that test, which is what is blocking
the tip of master currently.

This fix shamelessly copies the fix out of Neutron, mocking out
at the layer of HTTPCheck.

Change-Id: I2a4eae714946ce98a060a43dd501b9b3619aa68e
Closes-Bug: #1505057
Closes-bug: #1505750
This commit is contained in:
Yingxin Cheng 2015-10-12 14:58:03 +08:00 committed by Tim Hinrichs
parent 6a2c8eb9fa
commit 6474767b17
2 changed files with 11 additions and 12 deletions

View File

@ -20,8 +20,6 @@ import os.path
import mock
from oslo_config import cfg
from oslo_policy import policy as oslo_policy
import six
import six.moves.urllib.request as urlrequest
from congress.common import config
from congress.common import policy
@ -105,21 +103,22 @@ class PolicyTestCase(base.TestCase):
result = policy.enforce(self.context, action, self.target)
self.assertEqual(result, True)
@mock.patch.object(urlrequest, 'urlopen',
return_value=six.moves.StringIO("True"))
def test_enforce_http_true(self, mock_urlopen):
@mock.patch.object(oslo_policy._checks.HttpCheck, '__call__',
return_value=True)
def test_enforce_http_true(self, mock_httpcheck):
action = "example:get_http"
target = {}
result = policy.enforce(self.context, action, target)
self.assertEqual(result, True)
self.assertTrue(result)
@mock.patch.object(urlrequest, 'urlopen',
return_value=six.moves.StringIO("False"))
def test_enforce_http_false(self, mock_urlopen):
@mock.patch.object(oslo_policy._checks.HttpCheck, '__call__',
return_value=False)
def test_enforce_http_false(self, mock_httpcheck):
action = "example:get_http"
target = {}
self.assertRaises(exception.PolicyNotAuthorized, policy.enforce,
self.context, action, target)
self.assertRaises(exception.PolicyNotAuthorized,
policy.enforce, self.context,
action, target)
def test_templatized_enforcement(self):
target_mine = {'project_id': 'fake'}

View File

@ -157,7 +157,7 @@ function _configure_service {
openstack congress datasource create $2 "$2" \
--config poll_time=10 \
--config username=$OS_USERNAME \
--config tenant_name=$OS_TENANT_NAME \
--config tenant_name=$OS_PROJECT_NAME \
--config password=$OS_PASSWORD \
--config auth_url=http://$SERVICE_HOST:5000/v2.0
fi