Futureproof keystone unit tests against new occ

We have a version of OCC coming out that fixes how keystoneclient is
constructed. The fix is good - however, it breaks a couple of places
where we're mocking to the old behavior. This will all go away once
we're done with keystoneclient-ectomy, so for now just put in a version
detection switch.

Change-Id: I9d4908ef12d40868dc207b130e3244577b9870e9
This commit is contained in:
Monty Taylor 2017-04-18 11:30:59 -05:00
parent 3b8ef1b88a
commit b459c8de5c
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 26 additions and 3 deletions

View File

@ -17,6 +17,7 @@ import collections
import time
import uuid
from distutils import version as du_version
import fixtures
import mock
import os
@ -416,6 +417,16 @@ class RequestsMockTestCase(BaseTestCase):
self.adapter = self.useFixture(rm_fixture.Fixture())
self.calls = []
self._uri_registry.clear()
# occ > 1.26.0 fixes keystoneclient construction. Unfortunately, it
# breaks our mocking of what keystoneclient does here. Since we're
# close to just getting rid of ksc anyway, just put in a version match
occ_version = du_version.StrictVersion(occ.__version__)
if occ_version > du_version.StrictVersion('1.26.0'):
versioned_endpoint = 'https://identity.example.com/v2.0'
else:
versioned_endpoint = 'https://identity.example.com/'
self.__do_register_uris([
dict(method='GET', uri='https://identity.example.com/',
text=open(self.discovery_json, 'r').read()),
@ -423,7 +434,7 @@ class RequestsMockTestCase(BaseTestCase):
text=open(os.path.join(
self.fixtures_directory, 'catalog-v2.json'), 'r').read()
),
dict(method='GET', uri='https://identity.example.com/',
dict(method='GET', uri=versioned_endpoint,
text=open(self.discovery_json, 'r').read()),
dict(method='GET', uri='https://identity.example.com/',
text=open(self.discovery_json, 'r').read())

View File

@ -12,10 +12,12 @@
from keystoneauth1 import plugin as ksa_plugin
from distutils import version as du_version
import mock
import munch
import testtools
import os_client_config as occ
from os_client_config import cloud_config
import shade
from shade import exc
@ -1143,8 +1145,18 @@ class TestShadeOperator(base.TestCase):
session_mock = mock.Mock()
get_session_mock.return_value = session_mock
self.op_cloud.get_session_endpoint('identity')
session_mock.get_endpoint.assert_called_with(
interface=ksa_plugin.AUTH_INTERFACE)
# occ > 1.26.0 fixes keystoneclient construction. Unfortunately, it
# breaks our mocking of what keystoneclient does here. Since we're
# close to just getting rid of ksc anyway, just put in a version match
occ_version = du_version.StrictVersion(occ.__version__)
if occ_version > du_version.StrictVersion('1.26.0'):
kwargs = dict(
interface='public', region_name='RegionOne',
service_name=None, service_type='identity')
else:
kwargs = dict(interface=ksa_plugin.AUTH_INTERFACE)
session_mock.get_endpoint.assert_called_with(**kwargs)
@mock.patch.object(cloud_config.CloudConfig, 'get_session')
def test_has_service_no(self, get_session_mock):