Merge "Use TEST-NET-1 for unit tests, not 127.0.0.1"

This commit is contained in:
Jenkins 2016-10-25 12:43:45 +00:00 committed by Gerrit Code Review
commit dc48fed4ed
9 changed files with 110 additions and 121 deletions

View File

@ -44,9 +44,11 @@ name = 'heat'
class Collector(object): class Collector(object):
def __init__(self, def __init__(self,
keystoneclient=keystoneclient, keystoneclient=keystoneclient,
heatclient=heatclient): heatclient=heatclient,
discover_class=None):
self.keystoneclient = keystoneclient self.keystoneclient = keystoneclient
self.heatclient = heatclient self.heatclient = heatclient
self.discover_class = discover_class
def collect(self): def collect(self):
if CONF.heat.auth_url is None: if CONF.heat.auth_url is None:
@ -74,7 +76,8 @@ class Collector(object):
user_id=CONF.heat.user_id, user_id=CONF.heat.user_id,
password=CONF.heat.password, password=CONF.heat.password,
project_id=CONF.heat.project_id, project_id=CONF.heat.project_id,
keystoneclient=self.keystoneclient).client keystoneclient=self.keystoneclient,
discover_class=self.discover_class).client
endpoint = ks.service_catalog.url_for( endpoint = ks.service_catalog.url_for(
service_type='orchestration', endpoint_type='publicURL') service_type='orchestration', endpoint_type='publicURL')
logger.debug('Fetching metadata from %s' % endpoint) logger.debug('Fetching metadata from %s' % endpoint)

View File

@ -41,7 +41,7 @@ class Keystone(object):
in subsequent invocations of os-collect-config. in subsequent invocations of os-collect-config.
''' '''
def __init__(self, auth_url, user_id, password, project_id, def __init__(self, auth_url, user_id, password, project_id,
keystoneclient=None): keystoneclient=None, discover_class=None):
'''Initialize Keystone wrapper. '''Initialize Keystone wrapper.
@param string auth_url auth_url for keystoneclient @param string auth_url auth_url for keystoneclient
@ -49,15 +49,18 @@ class Keystone(object):
@param string project_id project_id for keystoneclient @param string project_id project_id for keystoneclient
@param object keystoneclient optional keystoneclient implementation. @param object keystoneclient optional keystoneclient implementation.
Uses keystoneclient.v3 if unspecified. Uses keystoneclient.v3 if unspecified.
@param object discover_class optional keystoneclient.discover.Discover
class.
''' '''
self.keystoneclient = keystoneclient or ks_keystoneclient self.keystoneclient = keystoneclient or ks_keystoneclient
self.discover_class = discover_class or ks_discover.Discover
self.user_id = user_id self.user_id = user_id
self.password = password self.password = password
self.project_id = project_id self.project_id = project_id
self._client = None self._client = None
try: try:
auth_url_noneversion = auth_url.replace('/v2.0', '/') auth_url_noneversion = auth_url.replace('/v2.0', '/')
discover = ks_discover.Discover(auth_url=auth_url_noneversion) discover = self.discover_class(auth_url=auth_url_noneversion)
v3_auth_url = discover.url_for('3.0') v3_auth_url = discover.url_for('3.0')
if v3_auth_url: if v3_auth_url:
self.auth_url = v3_auth_url self.auth_url = v3_auth_url

View File

@ -154,7 +154,7 @@ class FakeReqSession(object):
class FakeRequests(object): class FakeRequests(object):
exceptions = requests.exceptions exceptions = requests.exceptions
def __init__(self, testcase, expected_netloc='127.0.0.1:8000'): def __init__(self, testcase, expected_netloc='192.0.2.1:8000'):
self._test = testcase self._test = testcase
self._expected_netloc = expected_netloc self._expected_netloc = expected_netloc
@ -200,7 +200,7 @@ class TestCfnBase(testtools.TestCase):
self.log = self.useFixture(fixtures.FakeLogger()) self.log = self.useFixture(fixtures.FakeLogger())
self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.NestedTempfile())
self.hint_file = tempfile.NamedTemporaryFile() self.hint_file = tempfile.NamedTemporaryFile()
self.hint_file.write(u'http://127.0.0.1:8000'.encode('utf-8')) self.hint_file.write(u'http://192.0.2.1:8000'.encode('utf-8'))
self.hint_file.flush() self.hint_file.flush()
self.addCleanup(self.hint_file.close) self.addCleanup(self.hint_file.close)
collect.setup_conf() collect.setup_conf()

View File

@ -22,8 +22,6 @@ import tempfile
import extras import extras
import fixtures import fixtures
from keystoneclient import discover as ks_discover
import mock
from oslo_config import cfg from oslo_config import cfg
import testtools import testtools
from testtools import matchers from testtools import matchers
@ -74,12 +72,14 @@ class TestCollect(testtools.TestCase):
'cfn': {'requests_impl': test_cfn.FakeRequests(self)}, 'cfn': {'requests_impl': test_cfn.FakeRequests(self)},
'heat': { 'heat': {
'keystoneclient': test_heat.FakeKeystoneClient(self), 'keystoneclient': test_heat.FakeKeystoneClient(self),
'heatclient': test_heat.FakeHeatClient(self) 'heatclient': test_heat.FakeHeatClient(self),
'discover_class': test_heat.FakeKeystoneDiscover
}, },
'request': {'requests_impl': test_request.FakeRequests}, 'request': {'requests_impl': test_request.FakeRequests},
'zaqar': { 'zaqar': {
'keystoneclient': test_zaqar.FakeKeystoneClient(self), 'keystoneclient': test_zaqar.FakeKeystoneClient(self),
'zaqarclient': test_zaqar.FakeZaqarClient(self) 'zaqarclient': test_zaqar.FakeZaqarClient(self),
'discover_class': test_heat.FakeKeystoneDiscover
}, },
} }
return collect.__main__(args=fake_args, return collect.__main__(args=fake_args,
@ -111,7 +111,7 @@ class TestCollect(testtools.TestCase):
'--config-file', '--config-file',
'/dev/null', '/dev/null',
'--cfn-metadata-url', '--cfn-metadata-url',
'http://127.0.0.1:8000/v1/', 'http://192.0.2.1:8000/v1/',
'--cfn-stack-name', '--cfn-stack-name',
'foo', 'foo',
'--cfn-path', '--cfn-path',
@ -129,7 +129,7 @@ class TestCollect(testtools.TestCase):
'--heat-project-id', '--heat-project-id',
'9f6b09df-4d7f-4a33-8ec3-9924d8f46f10', '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10',
'--heat-auth-url', '--heat-auth-url',
'http://127.0.0.1:5000/v3', 'http://192.0.2.1:5000/v3',
'--heat-stack-id', '--heat-stack-id',
'a/c482680f-7238-403d-8f76-36acf0c8e0aa', 'a/c482680f-7238-403d-8f76-36acf0c8e0aa',
'--heat-resource-name', '--heat-resource-name',
@ -225,7 +225,7 @@ class TestCollect(testtools.TestCase):
'--config-file', '--config-file',
'/dev/null', '/dev/null',
'--cfn-metadata-url', '--cfn-metadata-url',
'http://127.0.0.1:8000/v1/', 'http://192.0.2.1:8000/v1/',
'--cfn-stack-name', '--cfn-stack-name',
'foo', 'foo',
'--cfn-path', '--cfn-path',
@ -275,7 +275,7 @@ class TestCollect(testtools.TestCase):
'--config-file', '/dev/null', '--config-file', '/dev/null',
'--print', '--print',
'--cfn-metadata-url', '--cfn-metadata-url',
'http://127.0.0.1:8000/v1/', 'http://192.0.2.1:8000/v1/',
'--cfn-stack-name', '--cfn-stack-name',
'foo', 'foo',
'--cfn-path', '--cfn-path',
@ -343,44 +343,42 @@ class TestCollectAll(testtools.TestCase):
cfg.CONF.cachedir = self.cache_dir.path cfg.CONF.cachedir = self.cache_dir.path
cfg.CONF.backup_cachedir = self.backup_cache_dir.path cfg.CONF.backup_cachedir = self.backup_cache_dir.path
cfg.CONF.cfn.metadata_url = 'http://127.0.0.1:8000/v1/' cfg.CONF.cfn.metadata_url = 'http://192.0.2.1:8000/v1/'
cfg.CONF.cfn.stack_name = 'foo' cfg.CONF.cfn.stack_name = 'foo'
cfg.CONF.cfn.path = ['foo.Metadata'] cfg.CONF.cfn.path = ['foo.Metadata']
cfg.CONF.cfn.access_key_id = '0123456789ABCDEF' cfg.CONF.cfn.access_key_id = '0123456789ABCDEF'
cfg.CONF.cfn.secret_access_key = 'FEDCBA9876543210' cfg.CONF.cfn.secret_access_key = 'FEDCBA9876543210'
cfg.CONF.heat_local.path = [_setup_heat_local_metadata(self)] cfg.CONF.heat_local.path = [_setup_heat_local_metadata(self)]
cfg.CONF.heat.auth_url = 'http://127.0.0.1:5000/v3' cfg.CONF.heat.auth_url = 'http://192.0.2.1:5000/v3'
cfg.CONF.heat.user_id = '0123456789ABCDEF' cfg.CONF.heat.user_id = '0123456789ABCDEF'
cfg.CONF.heat.password = 'FEDCBA9876543210' cfg.CONF.heat.password = 'FEDCBA9876543210'
cfg.CONF.heat.project_id = '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10' cfg.CONF.heat.project_id = '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10'
cfg.CONF.heat.stack_id = 'a/c482680f-7238-403d-8f76-36acf0c8e0aa' cfg.CONF.heat.stack_id = 'a/c482680f-7238-403d-8f76-36acf0c8e0aa'
cfg.CONF.heat.resource_name = 'server' cfg.CONF.heat.resource_name = 'server'
cfg.CONF.local.path = [_setup_local_metadata(self)] cfg.CONF.local.path = [_setup_local_metadata(self)]
cfg.CONF.request.metadata_url = 'http://127.0.0.1:8000/my_metadata/' cfg.CONF.request.metadata_url = 'http://192.0.2.1:8000/my_metadata/'
cfg.CONF.zaqar.auth_url = 'http://127.0.0.1:5000/v3' cfg.CONF.zaqar.auth_url = 'http://192.0.2.1:5000/v3'
cfg.CONF.zaqar.user_id = '0123456789ABCDEF' cfg.CONF.zaqar.user_id = '0123456789ABCDEF'
cfg.CONF.zaqar.password = 'FEDCBA9876543210' cfg.CONF.zaqar.password = 'FEDCBA9876543210'
cfg.CONF.zaqar.project_id = '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10' cfg.CONF.zaqar.project_id = '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10'
cfg.CONF.zaqar.queue_id = '4f3f46d3-09f1-42a7-8c13-f91a5457192c' cfg.CONF.zaqar.queue_id = '4f3f46d3-09f1-42a7-8c13-f91a5457192c'
@mock.patch.object(ks_discover.Discover, '__init__') def _call_collect_all(self, store, collector_kwargs_map=None,
@mock.patch.object(ks_discover.Discover, 'url_for') collectors=None):
def _call_collect_all(self, mock_url_for, mock___init__, store,
collector_kwargs_map=None, collectors=None):
mock___init__.return_value = None
mock_url_for.return_value = cfg.CONF.heat.auth_url
if collector_kwargs_map is None: if collector_kwargs_map is None:
collector_kwargs_map = { collector_kwargs_map = {
'ec2': {'requests_impl': test_ec2.FakeRequests}, 'ec2': {'requests_impl': test_ec2.FakeRequests},
'cfn': {'requests_impl': test_cfn.FakeRequests(self)}, 'cfn': {'requests_impl': test_cfn.FakeRequests(self)},
'heat': { 'heat': {
'keystoneclient': test_heat.FakeKeystoneClient(self), 'keystoneclient': test_heat.FakeKeystoneClient(self),
'heatclient': test_heat.FakeHeatClient(self) 'heatclient': test_heat.FakeHeatClient(self),
'discover_class': test_heat.FakeKeystoneDiscover
}, },
'request': {'requests_impl': test_request.FakeRequests}, 'request': {'requests_impl': test_request.FakeRequests},
'zaqar': { 'zaqar': {
'keystoneclient': test_zaqar.FakeKeystoneClient(self), 'keystoneclient': test_zaqar.FakeKeystoneClient(self),
'zaqarclient': test_zaqar.FakeZaqarClient(self) 'zaqarclient': test_zaqar.FakeZaqarClient(self),
'discover_class': test_heat.FakeKeystoneDiscover
}, },
} }
if collectors is None: if collectors is None:
@ -413,12 +411,14 @@ class TestCollectAll(testtools.TestCase):
'requests_impl': test_cfn.FakeRequestsSoftwareConfig(self)}, 'requests_impl': test_cfn.FakeRequestsSoftwareConfig(self)},
'heat': { 'heat': {
'keystoneclient': test_heat.FakeKeystoneClient(self), 'keystoneclient': test_heat.FakeKeystoneClient(self),
'heatclient': test_heat.FakeHeatClient(self) 'heatclient': test_heat.FakeHeatClient(self),
'discover_class': test_heat.FakeKeystoneDiscover
}, },
'request': {'requests_impl': test_request.FakeRequests}, 'request': {'requests_impl': test_request.FakeRequests},
'zaqar': { 'zaqar': {
'keystoneclient': test_zaqar.FakeKeystoneClient(self), 'keystoneclient': test_zaqar.FakeKeystoneClient(self),
'zaqarclient': test_zaqar.FakeZaqarClient(self) 'zaqarclient': test_zaqar.FakeZaqarClient(self),
'discover_class': test_heat.FakeKeystoneDiscover
}, },
} }
expected_changed = set(( expected_changed = set((
@ -456,12 +456,14 @@ class TestCollectAll(testtools.TestCase):
'requests_impl': test_cfn.FakeRequestsSoftwareConfig(self)}, 'requests_impl': test_cfn.FakeRequestsSoftwareConfig(self)},
'heat': { 'heat': {
'keystoneclient': test_heat.FakeKeystoneClient(self), 'keystoneclient': test_heat.FakeKeystoneClient(self),
'heatclient': test_heat.FakeHeatClient(self) 'heatclient': test_heat.FakeHeatClient(self),
'discover_class': test_heat.FakeKeystoneDiscover
}, },
'request': {'requests_impl': test_request.FakeRequests}, 'request': {'requests_impl': test_request.FakeRequests},
'zaqar': { 'zaqar': {
'keystoneclient': test_zaqar.FakeKeystoneClient(self), 'keystoneclient': test_zaqar.FakeKeystoneClient(self),
'zaqarclient': test_zaqar.FakeZaqarClient(self) 'zaqarclient': test_zaqar.FakeZaqarClient(self),
'discover_class': test_heat.FakeKeystoneDiscover
}, },
} }
(changed_keys, paths) = self._call_collect_all( (changed_keys, paths) = self._call_collect_all(
@ -493,7 +495,8 @@ class TestCollectAll(testtools.TestCase):
'cfn': {'requests_impl': test_cfn.FakeRequests(self)} 'cfn': {'requests_impl': test_cfn.FakeRequests(self)}
} }
(changed_keys, content) = self._call_collect_all( (changed_keys, content) = self._call_collect_all(
store=False, collector_kwargs_map=collector_kwargs_map) store=False, collector_kwargs_map=collector_kwargs_map,
collectors=['ec2', 'cfn'])
self.assertEqual(set(), changed_keys) self.assertEqual(set(), changed_keys)
self.assertThat(content, matchers.IsInstance(dict)) self.assertThat(content, matchers.IsInstance(dict))
self.assertNotIn('ec2', content) self.assertNotIn('ec2', content)

View File

@ -13,9 +13,7 @@
# limitations under the License. # limitations under the License.
import fixtures import fixtures
from keystoneclient import discover as ks_discover
from keystoneclient import exceptions as ks_exc from keystoneclient import exceptions as ks_exc
import mock
from oslo_config import cfg from oslo_config import cfg
import testtools import testtools
from testtools import matchers from testtools import matchers
@ -64,6 +62,15 @@ SOFTWARE_CONFIG_IMPOSTER_DATA = {
} }
class FakeKeystoneDiscover(object):
def __init__(self, auth_url):
pass
def url_for(self, version):
return 'http://192.0.2.1:5000/v3'
class FakeKeystoneClient(object): class FakeKeystoneClient(object):
def __init__(self, testcase, configs=None): def __init__(self, testcase, configs=None):
@ -84,7 +91,7 @@ class FakeKeystoneClient(object):
def url_for(self, service_type, endpoint_type): def url_for(self, service_type, endpoint_type):
self._test.assertEqual('orchestration', service_type) self._test.assertEqual('orchestration', service_type)
self._test.assertEqual('publicURL', endpoint_type) self._test.assertEqual('publicURL', endpoint_type)
return 'http://127.0.0.1:8004/v1' return 'http://192.0.2.1:8004/v1'
def get_auth_ref(self): def get_auth_ref(self):
return 'this is an auth_ref' return 'this is an auth_ref'
@ -103,7 +110,7 @@ class FakeHeatClient(object):
def Client(self, version, endpoint, token): def Client(self, version, endpoint, token):
self._test.assertEqual('1', version) self._test.assertEqual('1', version)
self._test.assertEqual('http://127.0.0.1:8004/v1', endpoint) self._test.assertEqual('http://192.0.2.1:8004/v1', endpoint)
self._test.assertEqual('atoken', token) self._test.assertEqual('atoken', token)
return self return self
@ -125,7 +132,7 @@ class TestHeatBase(testtools.TestCase):
self.log = self.useFixture(fixtures.FakeLogger()) self.log = self.useFixture(fixtures.FakeLogger())
self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.NestedTempfile())
collect.setup_conf() collect.setup_conf()
cfg.CONF.heat.auth_url = 'http://127.0.0.1:5000/v3' cfg.CONF.heat.auth_url = 'http://192.0.2.1:5000/v3'
cfg.CONF.heat.user_id = '0123456789ABCDEF' cfg.CONF.heat.user_id = '0123456789ABCDEF'
cfg.CONF.heat.password = 'FEDCBA9876543210' cfg.CONF.heat.password = 'FEDCBA9876543210'
cfg.CONF.heat.project_id = '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10' cfg.CONF.heat.project_id = '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10'
@ -134,13 +141,10 @@ class TestHeatBase(testtools.TestCase):
class TestHeat(TestHeatBase): class TestHeat(TestHeatBase):
@mock.patch.object(ks_discover.Discover, '__init__') def test_collect_heat(self):
@mock.patch.object(ks_discover.Discover, 'url_for')
def test_collect_heat(self, mock_url_for, mock___init__):
mock___init__.return_value = None
mock_url_for.return_value = cfg.CONF.heat.auth_url
heat_md = heat.Collector(keystoneclient=FakeKeystoneClient(self), heat_md = heat.Collector(keystoneclient=FakeKeystoneClient(self),
heatclient=FakeHeatClient(self)).collect() heatclient=FakeHeatClient(self),
discover_class=FakeKeystoneDiscover).collect()
self.assertThat(heat_md, matchers.IsInstance(list)) self.assertThat(heat_md, matchers.IsInstance(list))
self.assertEqual('heat', heat_md[0][0]) self.assertEqual('heat', heat_md[0][0])
heat_md = heat_md[0][1] heat_md = heat_md[0][1]
@ -153,16 +157,13 @@ class TestHeat(TestHeatBase):
# level setting for urllib3.connectionpool. # level setting for urllib3.connectionpool.
self.assertTrue( self.assertTrue(
self.log.output == '' or self.log.output == '' or
self.log.output == 'Starting new HTTP connection (1): 127.0.0.1\n') self.log.output == 'Starting new HTTP connection (1): 192.0.2.1\n')
@mock.patch.object(ks_discover.Discover, '__init__') def test_collect_heat_fail(self):
@mock.patch.object(ks_discover.Discover, 'url_for')
def test_collect_heat_fail(self, mock_url_for, mock___init__):
mock___init__.return_value = None
mock_url_for.return_value = cfg.CONF.heat.auth_url
heat_collect = heat.Collector( heat_collect = heat.Collector(
keystoneclient=FakeFailKeystoneClient(self), keystoneclient=FakeFailKeystoneClient(self),
heatclient=FakeHeatClient(self)) heatclient=FakeHeatClient(self),
discover_class=FakeKeystoneDiscover)
self.assertRaises(exc.HeatMetadataNotAvailable, heat_collect.collect) self.assertRaises(exc.HeatMetadataNotAvailable, heat_collect.collect)
self.assertIn('Forbidden', self.log.output) self.assertIn('Forbidden', self.log.output)
@ -204,14 +205,11 @@ class TestHeat(TestHeatBase):
class TestHeatSoftwareConfig(TestHeatBase): class TestHeatSoftwareConfig(TestHeatBase):
@mock.patch.object(ks_discover.Discover, '__init__') def test_collect_heat(self):
@mock.patch.object(ks_discover.Discover, 'url_for')
def test_collect_heat(self, mock_url_for, mock___init__):
mock___init__.return_value = None
mock_url_for.return_value = cfg.CONF.heat.auth_url
heat_md = heat.Collector( heat_md = heat.Collector(
keystoneclient=FakeKeystoneClient(self), keystoneclient=FakeKeystoneClient(self),
heatclient=FakeHeatClientSoftwareConfig(self)).collect() heatclient=FakeHeatClientSoftwareConfig(self),
discover_class=FakeKeystoneDiscover).collect()
self.assertThat(heat_md, matchers.IsInstance(list)) self.assertThat(heat_md, matchers.IsInstance(list))
self.assertEqual(2, len(heat_md)) self.assertEqual(2, len(heat_md))
self.assertEqual('heat', heat_md[0][0]) self.assertEqual('heat', heat_md[0][0])

View File

@ -15,9 +15,7 @@
import tempfile import tempfile
import fixtures import fixtures
from keystoneclient import discover as ks_discover
from keystoneclient import exceptions as ks_exc from keystoneclient import exceptions as ks_exc
import mock
from oslo_config import cfg from oslo_config import cfg
import testtools import testtools
@ -26,21 +24,22 @@ from os_collect_config import keystone
from os_collect_config.tests import test_heat from os_collect_config.tests import test_heat
class FakeKeystoneClient(object): class FakeKeystoneDiscoverNone(test_heat.FakeKeystoneDiscover):
def __init__(self, *args, **kwargs):
pass
def Client(self, *args, **kwargs): def url_for(self, version):
return self return None
@property
def service_catalog(self):
return {}
class FakeFailGetAuthRef(FakeKeystoneClient): class FakeKeystoneDiscoverError(test_heat.FakeKeystoneDiscover):
def get_auth_ref(self):
raise ks_exc.AuthorizationFailed('Should not be called') def url_for(self, version):
raise ks_exc.DiscoveryFailure()
class FakeKeystoneDiscoverBase(test_heat.FakeKeystoneDiscover):
def url_for(self, version):
return 'http://192.0.2.1:5000/'
class KeystoneTest(testtools.TestCase): class KeystoneTest(testtools.TestCase):
@ -52,51 +51,38 @@ class KeystoneTest(testtools.TestCase):
self.cachedir = tempfile.mkdtemp() self.cachedir = tempfile.mkdtemp()
cfg.CONF.set_override('cache_dir', self.cachedir, group='keystone') cfg.CONF.set_override('cache_dir', self.cachedir, group='keystone')
@mock.patch.object(ks_discover.Discover, '__init__') def test_discover_fail(self):
@mock.patch.object(ks_discover.Discover, 'url_for')
def test_discover_fail(self, mock_url_for, mock___init__):
mock___init__.return_value = None
mock_url_for.side_effect = ks_exc.DiscoveryFailure()
ks = keystone.Keystone( ks = keystone.Keystone(
'http://server.test:5000/v2.0', 'auser', 'apassword', 'aproject', 'http://192.0.2.1:5000/v2.0', 'auser', 'apassword', 'aproject',
test_heat.FakeKeystoneClient(self)) test_heat.FakeKeystoneClient(self),
self.assertEqual(ks.auth_url, 'http://server.test:5000/v3') FakeKeystoneDiscoverError)
self.assertEqual(ks.auth_url, 'http://192.0.2.1:5000/v3')
@mock.patch.object(ks_discover.Discover, '__init__') def test_discover_v3_unsupported(self):
@mock.patch.object(ks_discover.Discover, 'url_for')
def test_discover_v3_unsupported(self, mock_url_for, mock___init__):
mock___init__.return_value = None
mock_url_for.return_value = None
ks = keystone.Keystone( ks = keystone.Keystone(
'http://server.test:5000/v2.0', 'auser', 'apassword', 'aproject', 'http://192.0.2.1:5000/v2.0', 'auser', 'apassword', 'aproject',
test_heat.FakeKeystoneClient(self)) test_heat.FakeKeystoneClient(self),
self.assertEqual(ks.auth_url, 'http://server.test:5000/v2.0') FakeKeystoneDiscoverNone)
mock___init__.assert_called_with(auth_url='http://server.test:5000/') self.assertEqual(ks.auth_url, 'http://192.0.2.1:5000/v2.0')
@mock.patch.object(ks_discover.Discover, '__init__') def test_cache_is_created(self):
@mock.patch.object(ks_discover.Discover, 'url_for')
def test_cache_is_created(self, mock_url_for, mock___init__):
mock___init__.return_value = None
mock_url_for.return_value = 'http://server.test:5000/'
ks = keystone.Keystone( ks = keystone.Keystone(
'http://server.test:5000/', 'auser', 'apassword', 'aproject', 'http://192.0.2.1:5000/', 'auser', 'apassword', 'aproject',
test_heat.FakeKeystoneClient(self)) test_heat.FakeKeystoneClient(self),
test_heat.FakeKeystoneDiscover)
self.assertIsNotNone(ks.cache) self.assertIsNotNone(ks.cache)
@mock.patch.object(ks_discover.Discover, '__init__') def _make_ks(self, client):
@mock.patch.object(ks_discover.Discover, 'url_for')
def _make_ks(self, client, mock_url_for, mock___init__):
class Configs(object): class Configs(object):
auth_url = 'http://server.test:5000/' auth_url = 'http://192.0.2.1:5000/'
user_id = 'auser' user_id = 'auser'
password = 'apassword' password = 'apassword'
project_id = 'aproject' project_id = 'aproject'
mock___init__.return_value = None
mock_url_for.return_value = Configs.auth_url
return keystone.Keystone( return keystone.Keystone(
'http://server.test:5000/', 'auser', 'apassword', 'aproject', 'http://192.0.2.1:5000/', 'auser', 'apassword', 'aproject',
client(self, Configs)) client(self, Configs),
FakeKeystoneDiscoverBase)
def test_cache_auth_ref(self): def test_cache_auth_ref(self):
ks = self._make_ks(test_heat.FakeKeystoneClient) ks = self._make_ks(test_heat.FakeKeystoneClient)
@ -113,13 +99,3 @@ class KeystoneTest(testtools.TestCase):
self.assertTrue(False, 'auth_ref should have failed.') self.assertTrue(False, 'auth_ref should have failed.')
except ks_exc.AuthorizationFailure: except ks_exc.AuthorizationFailure:
pass pass
def test_service_catalog(self):
ks = self._make_ks(FakeKeystoneClient)
service_catalog = ks.service_catalog
ks2 = self._make_ks(FakeKeystoneClient)
service_catalog2 = ks2.service_catalog
self.assertEqual(service_catalog, service_catalog2)
ks2.invalidate_auth_ref()
service_catalog3 = ks.service_catalog
self.assertEqual(service_catalog, service_catalog3)

View File

@ -148,7 +148,7 @@ class TestRequestBase(testtools.TestCase):
super(TestRequestBase, self).setUp() super(TestRequestBase, self).setUp()
self.log = self.useFixture(fixtures.FakeLogger()) self.log = self.useFixture(fixtures.FakeLogger())
collect.setup_conf() collect.setup_conf()
cfg.CONF.request.metadata_url = 'http://127.0.0.1:8000/my_metadata' cfg.CONF.request.metadata_url = 'http://192.0.2.1:8000/my_metadata'
class TestRequest(TestRequestBase): class TestRequest(TestRequestBase):

View File

@ -31,7 +31,7 @@ class FakeKeystoneClient(test_heat.FakeKeystoneClient):
def url_for(self, service_type, endpoint_type): def url_for(self, service_type, endpoint_type):
self._test.assertEqual('messaging', service_type) self._test.assertEqual('messaging', service_type)
self._test.assertEqual('publicURL', endpoint_type) self._test.assertEqual('publicURL', endpoint_type)
return 'http://127.0.0.1:8888/' return 'http://192.0.2.1:8888/'
class FakeZaqarClient(object): class FakeZaqarClient(object):
@ -41,7 +41,7 @@ class FakeZaqarClient(object):
def Client(self, endpoint, conf, version): def Client(self, endpoint, conf, version):
self._test.assertEqual(1.1, version) self._test.assertEqual(1.1, version)
self._test.assertEqual('http://127.0.0.1:8888/', endpoint) self._test.assertEqual('http://192.0.2.1:8888/', endpoint)
return self return self
def queue(self, queue_id): def queue(self, queue_id):
@ -64,7 +64,7 @@ class FakeZaqarClientSoftwareConfig(object):
def Client(self, endpoint, conf, version): def Client(self, endpoint, conf, version):
self._test.assertEqual(1.1, version) self._test.assertEqual(1.1, version)
self._test.assertEqual('http://127.0.0.1:8888/', endpoint) self._test.assertEqual('http://192.0.2.1:8888/', endpoint)
return self return self
def queue(self, queue_id): def queue(self, queue_id):
@ -87,7 +87,7 @@ class TestZaqar(testtools.TestCase):
self.log = self.useFixture(fixtures.FakeLogger()) self.log = self.useFixture(fixtures.FakeLogger())
self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.NestedTempfile())
collect.setup_conf() collect.setup_conf()
cfg.CONF.zaqar.auth_url = 'http://127.0.0.1:5000/v3' cfg.CONF.zaqar.auth_url = 'http://192.0.2.1:5000/v3'
cfg.CONF.zaqar.user_id = '0123456789ABCDEF' cfg.CONF.zaqar.user_id = '0123456789ABCDEF'
cfg.CONF.zaqar.password = 'FEDCBA9876543210' cfg.CONF.zaqar.password = 'FEDCBA9876543210'
cfg.CONF.zaqar.project_id = '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10' cfg.CONF.zaqar.project_id = '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10'
@ -100,7 +100,8 @@ class TestZaqar(testtools.TestCase):
mock_url_for.return_value = cfg.CONF.zaqar.auth_url mock_url_for.return_value = cfg.CONF.zaqar.auth_url
zaqar_md = zaqar.Collector( zaqar_md = zaqar.Collector(
keystoneclient=FakeKeystoneClient(self, cfg.CONF.zaqar), keystoneclient=FakeKeystoneClient(self, cfg.CONF.zaqar),
zaqarclient=FakeZaqarClient(self)).collect() zaqarclient=FakeZaqarClient(self),
discover_class=test_heat.FakeKeystoneDiscover).collect()
self.assertThat(zaqar_md, matchers.IsInstance(list)) self.assertThat(zaqar_md, matchers.IsInstance(list))
self.assertEqual('zaqar', zaqar_md[0][0]) self.assertEqual('zaqar', zaqar_md[0][0])
zaqar_md = zaqar_md[0][1] zaqar_md = zaqar_md[0][1]
@ -116,7 +117,8 @@ class TestZaqar(testtools.TestCase):
mock_url_for.return_value = cfg.CONF.zaqar.auth_url mock_url_for.return_value = cfg.CONF.zaqar.auth_url
zaqar_md = zaqar.Collector( zaqar_md = zaqar.Collector(
keystoneclient=FakeKeystoneClient(self, cfg.CONF.zaqar), keystoneclient=FakeKeystoneClient(self, cfg.CONF.zaqar),
zaqarclient=FakeZaqarClientSoftwareConfig(self)).collect() zaqarclient=FakeZaqarClientSoftwareConfig(self),
discover_class=test_heat.FakeKeystoneDiscover).collect()
self.assertThat(zaqar_md, matchers.IsInstance(list)) self.assertThat(zaqar_md, matchers.IsInstance(list))
self.assertEqual('zaqar', zaqar_md[0][0]) self.assertEqual('zaqar', zaqar_md[0][0])
self.assertEqual(2, len(zaqar_md)) self.assertEqual(2, len(zaqar_md))
@ -135,7 +137,8 @@ class TestZaqar(testtools.TestCase):
zaqar_collect = zaqar.Collector( zaqar_collect = zaqar.Collector(
keystoneclient=test_heat.FakeFailKeystoneClient( keystoneclient=test_heat.FakeFailKeystoneClient(
self, cfg.CONF.zaqar), self, cfg.CONF.zaqar),
zaqarclient=FakeZaqarClient(self)) zaqarclient=FakeZaqarClient(self),
discover_class=test_heat.FakeKeystoneDiscover)
self.assertRaises(exc.ZaqarMetadataNotAvailable, zaqar_collect.collect) self.assertRaises(exc.ZaqarMetadataNotAvailable, zaqar_collect.collect)
self.assertIn('Forbidden', self.log.output) self.assertIn('Forbidden', self.log.output)

View File

@ -43,9 +43,11 @@ name = 'zaqar'
class Collector(object): class Collector(object):
def __init__(self, def __init__(self,
keystoneclient=keystoneclient, keystoneclient=keystoneclient,
zaqarclient=zaqarclient): zaqarclient=zaqarclient,
discover_class=None):
self.keystoneclient = keystoneclient self.keystoneclient = keystoneclient
self.zaqarclient = zaqarclient self.zaqarclient = zaqarclient
self.discover_class = discover_class
def collect(self): def collect(self):
if CONF.zaqar.auth_url is None: if CONF.zaqar.auth_url is None:
@ -70,7 +72,8 @@ class Collector(object):
user_id=CONF.zaqar.user_id, user_id=CONF.zaqar.user_id,
password=CONF.zaqar.password, password=CONF.zaqar.password,
project_id=CONF.zaqar.project_id, project_id=CONF.zaqar.project_id,
keystoneclient=self.keystoneclient).client keystoneclient=self.keystoneclient,
discover_class=self.discover_class).client
endpoint = ks.service_catalog.url_for( endpoint = ks.service_catalog.url_for(
service_type='messaging', endpoint_type='publicURL') service_type='messaging', endpoint_type='publicURL')
logger.debug('Fetching metadata from %s' % endpoint) logger.debug('Fetching metadata from %s' % endpoint)