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:
parent
3b8ef1b88a
commit
b459c8de5c
@ -17,6 +17,7 @@ import collections
|
|||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from distutils import version as du_version
|
||||||
import fixtures
|
import fixtures
|
||||||
import mock
|
import mock
|
||||||
import os
|
import os
|
||||||
@ -416,6 +417,16 @@ class RequestsMockTestCase(BaseTestCase):
|
|||||||
self.adapter = self.useFixture(rm_fixture.Fixture())
|
self.adapter = self.useFixture(rm_fixture.Fixture())
|
||||||
self.calls = []
|
self.calls = []
|
||||||
self._uri_registry.clear()
|
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([
|
self.__do_register_uris([
|
||||||
dict(method='GET', uri='https://identity.example.com/',
|
dict(method='GET', uri='https://identity.example.com/',
|
||||||
text=open(self.discovery_json, 'r').read()),
|
text=open(self.discovery_json, 'r').read()),
|
||||||
@ -423,7 +434,7 @@ class RequestsMockTestCase(BaseTestCase):
|
|||||||
text=open(os.path.join(
|
text=open(os.path.join(
|
||||||
self.fixtures_directory, 'catalog-v2.json'), 'r').read()
|
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()),
|
text=open(self.discovery_json, 'r').read()),
|
||||||
dict(method='GET', uri='https://identity.example.com/',
|
dict(method='GET', uri='https://identity.example.com/',
|
||||||
text=open(self.discovery_json, 'r').read())
|
text=open(self.discovery_json, 'r').read())
|
||||||
|
@ -12,10 +12,12 @@
|
|||||||
|
|
||||||
from keystoneauth1 import plugin as ksa_plugin
|
from keystoneauth1 import plugin as ksa_plugin
|
||||||
|
|
||||||
|
from distutils import version as du_version
|
||||||
import mock
|
import mock
|
||||||
import munch
|
import munch
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
|
import os_client_config as occ
|
||||||
from os_client_config import cloud_config
|
from os_client_config import cloud_config
|
||||||
import shade
|
import shade
|
||||||
from shade import exc
|
from shade import exc
|
||||||
@ -1143,8 +1145,18 @@ class TestShadeOperator(base.TestCase):
|
|||||||
session_mock = mock.Mock()
|
session_mock = mock.Mock()
|
||||||
get_session_mock.return_value = session_mock
|
get_session_mock.return_value = session_mock
|
||||||
self.op_cloud.get_session_endpoint('identity')
|
self.op_cloud.get_session_endpoint('identity')
|
||||||
session_mock.get_endpoint.assert_called_with(
|
# occ > 1.26.0 fixes keystoneclient construction. Unfortunately, it
|
||||||
interface=ksa_plugin.AUTH_INTERFACE)
|
# 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')
|
@mock.patch.object(cloud_config.CloudConfig, 'get_session')
|
||||||
def test_has_service_no(self, get_session_mock):
|
def test_has_service_no(self, get_session_mock):
|
||||||
|
Loading…
Reference in New Issue
Block a user