Merge "Use TEST-NET-1 for unit tests, not 127.0.0.1"
This commit is contained in:
commit
dc48fed4ed
@ -44,9 +44,11 @@ name = 'heat'
|
||||
class Collector(object):
|
||||
def __init__(self,
|
||||
keystoneclient=keystoneclient,
|
||||
heatclient=heatclient):
|
||||
heatclient=heatclient,
|
||||
discover_class=None):
|
||||
self.keystoneclient = keystoneclient
|
||||
self.heatclient = heatclient
|
||||
self.discover_class = discover_class
|
||||
|
||||
def collect(self):
|
||||
if CONF.heat.auth_url is None:
|
||||
@ -74,7 +76,8 @@ class Collector(object):
|
||||
user_id=CONF.heat.user_id,
|
||||
password=CONF.heat.password,
|
||||
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(
|
||||
service_type='orchestration', endpoint_type='publicURL')
|
||||
logger.debug('Fetching metadata from %s' % endpoint)
|
||||
|
@ -41,7 +41,7 @@ class Keystone(object):
|
||||
in subsequent invocations of os-collect-config.
|
||||
'''
|
||||
def __init__(self, auth_url, user_id, password, project_id,
|
||||
keystoneclient=None):
|
||||
keystoneclient=None, discover_class=None):
|
||||
'''Initialize Keystone wrapper.
|
||||
|
||||
@param string auth_url auth_url for keystoneclient
|
||||
@ -49,15 +49,18 @@ class Keystone(object):
|
||||
@param string project_id project_id for keystoneclient
|
||||
@param object keystoneclient optional keystoneclient implementation.
|
||||
Uses keystoneclient.v3 if unspecified.
|
||||
@param object discover_class optional keystoneclient.discover.Discover
|
||||
class.
|
||||
'''
|
||||
self.keystoneclient = keystoneclient or ks_keystoneclient
|
||||
self.discover_class = discover_class or ks_discover.Discover
|
||||
self.user_id = user_id
|
||||
self.password = password
|
||||
self.project_id = project_id
|
||||
self._client = None
|
||||
try:
|
||||
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')
|
||||
if v3_auth_url:
|
||||
self.auth_url = v3_auth_url
|
||||
|
@ -154,7 +154,7 @@ class FakeReqSession(object):
|
||||
class FakeRequests(object):
|
||||
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._expected_netloc = expected_netloc
|
||||
|
||||
@ -200,7 +200,7 @@ class TestCfnBase(testtools.TestCase):
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
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.addCleanup(self.hint_file.close)
|
||||
collect.setup_conf()
|
||||
|
@ -22,8 +22,6 @@ import tempfile
|
||||
|
||||
import extras
|
||||
import fixtures
|
||||
from keystoneclient import discover as ks_discover
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
import testtools
|
||||
from testtools import matchers
|
||||
@ -74,12 +72,14 @@ class TestCollect(testtools.TestCase):
|
||||
'cfn': {'requests_impl': test_cfn.FakeRequests(self)},
|
||||
'heat': {
|
||||
'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},
|
||||
'zaqar': {
|
||||
'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,
|
||||
@ -111,7 +111,7 @@ class TestCollect(testtools.TestCase):
|
||||
'--config-file',
|
||||
'/dev/null',
|
||||
'--cfn-metadata-url',
|
||||
'http://127.0.0.1:8000/v1/',
|
||||
'http://192.0.2.1:8000/v1/',
|
||||
'--cfn-stack-name',
|
||||
'foo',
|
||||
'--cfn-path',
|
||||
@ -129,7 +129,7 @@ class TestCollect(testtools.TestCase):
|
||||
'--heat-project-id',
|
||||
'9f6b09df-4d7f-4a33-8ec3-9924d8f46f10',
|
||||
'--heat-auth-url',
|
||||
'http://127.0.0.1:5000/v3',
|
||||
'http://192.0.2.1:5000/v3',
|
||||
'--heat-stack-id',
|
||||
'a/c482680f-7238-403d-8f76-36acf0c8e0aa',
|
||||
'--heat-resource-name',
|
||||
@ -225,7 +225,7 @@ class TestCollect(testtools.TestCase):
|
||||
'--config-file',
|
||||
'/dev/null',
|
||||
'--cfn-metadata-url',
|
||||
'http://127.0.0.1:8000/v1/',
|
||||
'http://192.0.2.1:8000/v1/',
|
||||
'--cfn-stack-name',
|
||||
'foo',
|
||||
'--cfn-path',
|
||||
@ -275,7 +275,7 @@ class TestCollect(testtools.TestCase):
|
||||
'--config-file', '/dev/null',
|
||||
'--print',
|
||||
'--cfn-metadata-url',
|
||||
'http://127.0.0.1:8000/v1/',
|
||||
'http://192.0.2.1:8000/v1/',
|
||||
'--cfn-stack-name',
|
||||
'foo',
|
||||
'--cfn-path',
|
||||
@ -343,44 +343,42 @@ class TestCollectAll(testtools.TestCase):
|
||||
|
||||
cfg.CONF.cachedir = self.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.path = ['foo.Metadata']
|
||||
cfg.CONF.cfn.access_key_id = '0123456789ABCDEF'
|
||||
cfg.CONF.cfn.secret_access_key = 'FEDCBA9876543210'
|
||||
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.password = 'FEDCBA9876543210'
|
||||
cfg.CONF.heat.project_id = '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10'
|
||||
cfg.CONF.heat.stack_id = 'a/c482680f-7238-403d-8f76-36acf0c8e0aa'
|
||||
cfg.CONF.heat.resource_name = 'server'
|
||||
cfg.CONF.local.path = [_setup_local_metadata(self)]
|
||||
cfg.CONF.request.metadata_url = 'http://127.0.0.1:8000/my_metadata/'
|
||||
cfg.CONF.zaqar.auth_url = 'http://127.0.0.1:5000/v3'
|
||||
cfg.CONF.request.metadata_url = 'http://192.0.2.1:8000/my_metadata/'
|
||||
cfg.CONF.zaqar.auth_url = 'http://192.0.2.1:5000/v3'
|
||||
cfg.CONF.zaqar.user_id = '0123456789ABCDEF'
|
||||
cfg.CONF.zaqar.password = 'FEDCBA9876543210'
|
||||
cfg.CONF.zaqar.project_id = '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10'
|
||||
cfg.CONF.zaqar.queue_id = '4f3f46d3-09f1-42a7-8c13-f91a5457192c'
|
||||
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@mock.patch.object(ks_discover.Discover, 'url_for')
|
||||
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
|
||||
def _call_collect_all(self, store, collector_kwargs_map=None,
|
||||
collectors=None):
|
||||
if collector_kwargs_map is None:
|
||||
collector_kwargs_map = {
|
||||
'ec2': {'requests_impl': test_ec2.FakeRequests},
|
||||
'cfn': {'requests_impl': test_cfn.FakeRequests(self)},
|
||||
'heat': {
|
||||
'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},
|
||||
'zaqar': {
|
||||
'keystoneclient': test_zaqar.FakeKeystoneClient(self),
|
||||
'zaqarclient': test_zaqar.FakeZaqarClient(self)
|
||||
'zaqarclient': test_zaqar.FakeZaqarClient(self),
|
||||
'discover_class': test_heat.FakeKeystoneDiscover
|
||||
},
|
||||
}
|
||||
if collectors is None:
|
||||
@ -413,12 +411,14 @@ class TestCollectAll(testtools.TestCase):
|
||||
'requests_impl': test_cfn.FakeRequestsSoftwareConfig(self)},
|
||||
'heat': {
|
||||
'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},
|
||||
'zaqar': {
|
||||
'keystoneclient': test_zaqar.FakeKeystoneClient(self),
|
||||
'zaqarclient': test_zaqar.FakeZaqarClient(self)
|
||||
'zaqarclient': test_zaqar.FakeZaqarClient(self),
|
||||
'discover_class': test_heat.FakeKeystoneDiscover
|
||||
},
|
||||
}
|
||||
expected_changed = set((
|
||||
@ -456,12 +456,14 @@ class TestCollectAll(testtools.TestCase):
|
||||
'requests_impl': test_cfn.FakeRequestsSoftwareConfig(self)},
|
||||
'heat': {
|
||||
'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},
|
||||
'zaqar': {
|
||||
'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(
|
||||
@ -493,7 +495,8 @@ class TestCollectAll(testtools.TestCase):
|
||||
'cfn': {'requests_impl': test_cfn.FakeRequests(self)}
|
||||
}
|
||||
(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.assertThat(content, matchers.IsInstance(dict))
|
||||
self.assertNotIn('ec2', content)
|
||||
|
@ -13,9 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import fixtures
|
||||
from keystoneclient import discover as ks_discover
|
||||
from keystoneclient import exceptions as ks_exc
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
import testtools
|
||||
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):
|
||||
|
||||
def __init__(self, testcase, configs=None):
|
||||
@ -84,7 +91,7 @@ class FakeKeystoneClient(object):
|
||||
def url_for(self, service_type, endpoint_type):
|
||||
self._test.assertEqual('orchestration', service_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):
|
||||
return 'this is an auth_ref'
|
||||
@ -103,7 +110,7 @@ class FakeHeatClient(object):
|
||||
|
||||
def Client(self, version, endpoint, token):
|
||||
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)
|
||||
return self
|
||||
|
||||
@ -125,7 +132,7 @@ class TestHeatBase(testtools.TestCase):
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
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.password = 'FEDCBA9876543210'
|
||||
cfg.CONF.heat.project_id = '9f6b09df-4d7f-4a33-8ec3-9924d8f46f10'
|
||||
@ -134,13 +141,10 @@ class TestHeatBase(testtools.TestCase):
|
||||
|
||||
|
||||
class TestHeat(TestHeatBase):
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@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
|
||||
def test_collect_heat(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.assertEqual('heat', heat_md[0][0])
|
||||
heat_md = heat_md[0][1]
|
||||
@ -153,16 +157,13 @@ class TestHeat(TestHeatBase):
|
||||
# level setting for urllib3.connectionpool.
|
||||
self.assertTrue(
|
||||
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__')
|
||||
@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
|
||||
def test_collect_heat_fail(self):
|
||||
heat_collect = heat.Collector(
|
||||
keystoneclient=FakeFailKeystoneClient(self),
|
||||
heatclient=FakeHeatClient(self))
|
||||
heatclient=FakeHeatClient(self),
|
||||
discover_class=FakeKeystoneDiscover)
|
||||
self.assertRaises(exc.HeatMetadataNotAvailable, heat_collect.collect)
|
||||
self.assertIn('Forbidden', self.log.output)
|
||||
|
||||
@ -204,14 +205,11 @@ class TestHeat(TestHeatBase):
|
||||
|
||||
|
||||
class TestHeatSoftwareConfig(TestHeatBase):
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@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
|
||||
def test_collect_heat(self):
|
||||
heat_md = heat.Collector(
|
||||
keystoneclient=FakeKeystoneClient(self),
|
||||
heatclient=FakeHeatClientSoftwareConfig(self)).collect()
|
||||
heatclient=FakeHeatClientSoftwareConfig(self),
|
||||
discover_class=FakeKeystoneDiscover).collect()
|
||||
self.assertThat(heat_md, matchers.IsInstance(list))
|
||||
self.assertEqual(2, len(heat_md))
|
||||
self.assertEqual('heat', heat_md[0][0])
|
||||
|
@ -15,9 +15,7 @@
|
||||
import tempfile
|
||||
|
||||
import fixtures
|
||||
from keystoneclient import discover as ks_discover
|
||||
from keystoneclient import exceptions as ks_exc
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
import testtools
|
||||
|
||||
@ -26,21 +24,22 @@ from os_collect_config import keystone
|
||||
from os_collect_config.tests import test_heat
|
||||
|
||||
|
||||
class FakeKeystoneClient(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
class FakeKeystoneDiscoverNone(test_heat.FakeKeystoneDiscover):
|
||||
|
||||
def Client(self, *args, **kwargs):
|
||||
return self
|
||||
|
||||
@property
|
||||
def service_catalog(self):
|
||||
return {}
|
||||
def url_for(self, version):
|
||||
return None
|
||||
|
||||
|
||||
class FakeFailGetAuthRef(FakeKeystoneClient):
|
||||
def get_auth_ref(self):
|
||||
raise ks_exc.AuthorizationFailed('Should not be called')
|
||||
class FakeKeystoneDiscoverError(test_heat.FakeKeystoneDiscover):
|
||||
|
||||
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):
|
||||
@ -52,51 +51,38 @@ class KeystoneTest(testtools.TestCase):
|
||||
self.cachedir = tempfile.mkdtemp()
|
||||
cfg.CONF.set_override('cache_dir', self.cachedir, group='keystone')
|
||||
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@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()
|
||||
def test_discover_fail(self):
|
||||
ks = keystone.Keystone(
|
||||
'http://server.test:5000/v2.0', 'auser', 'apassword', 'aproject',
|
||||
test_heat.FakeKeystoneClient(self))
|
||||
self.assertEqual(ks.auth_url, 'http://server.test:5000/v3')
|
||||
'http://192.0.2.1:5000/v2.0', 'auser', 'apassword', 'aproject',
|
||||
test_heat.FakeKeystoneClient(self),
|
||||
FakeKeystoneDiscoverError)
|
||||
self.assertEqual(ks.auth_url, 'http://192.0.2.1:5000/v3')
|
||||
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@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
|
||||
def test_discover_v3_unsupported(self):
|
||||
ks = keystone.Keystone(
|
||||
'http://server.test:5000/v2.0', 'auser', 'apassword', 'aproject',
|
||||
test_heat.FakeKeystoneClient(self))
|
||||
self.assertEqual(ks.auth_url, 'http://server.test:5000/v2.0')
|
||||
mock___init__.assert_called_with(auth_url='http://server.test:5000/')
|
||||
'http://192.0.2.1:5000/v2.0', 'auser', 'apassword', 'aproject',
|
||||
test_heat.FakeKeystoneClient(self),
|
||||
FakeKeystoneDiscoverNone)
|
||||
self.assertEqual(ks.auth_url, 'http://192.0.2.1:5000/v2.0')
|
||||
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@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/'
|
||||
def test_cache_is_created(self):
|
||||
ks = keystone.Keystone(
|
||||
'http://server.test:5000/', 'auser', 'apassword', 'aproject',
|
||||
test_heat.FakeKeystoneClient(self))
|
||||
'http://192.0.2.1:5000/', 'auser', 'apassword', 'aproject',
|
||||
test_heat.FakeKeystoneClient(self),
|
||||
test_heat.FakeKeystoneDiscover)
|
||||
self.assertIsNotNone(ks.cache)
|
||||
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@mock.patch.object(ks_discover.Discover, 'url_for')
|
||||
def _make_ks(self, client, mock_url_for, mock___init__):
|
||||
def _make_ks(self, client):
|
||||
class Configs(object):
|
||||
auth_url = 'http://server.test:5000/'
|
||||
auth_url = 'http://192.0.2.1:5000/'
|
||||
user_id = 'auser'
|
||||
password = 'apassword'
|
||||
project_id = 'aproject'
|
||||
|
||||
mock___init__.return_value = None
|
||||
mock_url_for.return_value = Configs.auth_url
|
||||
return keystone.Keystone(
|
||||
'http://server.test:5000/', 'auser', 'apassword', 'aproject',
|
||||
client(self, Configs))
|
||||
'http://192.0.2.1:5000/', 'auser', 'apassword', 'aproject',
|
||||
client(self, Configs),
|
||||
FakeKeystoneDiscoverBase)
|
||||
|
||||
def test_cache_auth_ref(self):
|
||||
ks = self._make_ks(test_heat.FakeKeystoneClient)
|
||||
@ -113,13 +99,3 @@ class KeystoneTest(testtools.TestCase):
|
||||
self.assertTrue(False, 'auth_ref should have failed.')
|
||||
except ks_exc.AuthorizationFailure:
|
||||
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)
|
||||
|
@ -148,7 +148,7 @@ class TestRequestBase(testtools.TestCase):
|
||||
super(TestRequestBase, self).setUp()
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
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):
|
||||
|
@ -31,7 +31,7 @@ class FakeKeystoneClient(test_heat.FakeKeystoneClient):
|
||||
def url_for(self, service_type, endpoint_type):
|
||||
self._test.assertEqual('messaging', service_type)
|
||||
self._test.assertEqual('publicURL', endpoint_type)
|
||||
return 'http://127.0.0.1:8888/'
|
||||
return 'http://192.0.2.1:8888/'
|
||||
|
||||
|
||||
class FakeZaqarClient(object):
|
||||
@ -41,7 +41,7 @@ class FakeZaqarClient(object):
|
||||
|
||||
def Client(self, endpoint, conf, 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
|
||||
|
||||
def queue(self, queue_id):
|
||||
@ -64,7 +64,7 @@ class FakeZaqarClientSoftwareConfig(object):
|
||||
|
||||
def Client(self, endpoint, conf, 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
|
||||
|
||||
def queue(self, queue_id):
|
||||
@ -87,7 +87,7 @@ class TestZaqar(testtools.TestCase):
|
||||
self.log = self.useFixture(fixtures.FakeLogger())
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
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.password = 'FEDCBA9876543210'
|
||||
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
|
||||
zaqar_md = zaqar.Collector(
|
||||
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.assertEqual('zaqar', zaqar_md[0][0])
|
||||
zaqar_md = zaqar_md[0][1]
|
||||
@ -116,7 +117,8 @@ class TestZaqar(testtools.TestCase):
|
||||
mock_url_for.return_value = cfg.CONF.zaqar.auth_url
|
||||
zaqar_md = zaqar.Collector(
|
||||
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.assertEqual('zaqar', zaqar_md[0][0])
|
||||
self.assertEqual(2, len(zaqar_md))
|
||||
@ -135,7 +137,8 @@ class TestZaqar(testtools.TestCase):
|
||||
zaqar_collect = zaqar.Collector(
|
||||
keystoneclient=test_heat.FakeFailKeystoneClient(
|
||||
self, cfg.CONF.zaqar),
|
||||
zaqarclient=FakeZaqarClient(self))
|
||||
zaqarclient=FakeZaqarClient(self),
|
||||
discover_class=test_heat.FakeKeystoneDiscover)
|
||||
self.assertRaises(exc.ZaqarMetadataNotAvailable, zaqar_collect.collect)
|
||||
self.assertIn('Forbidden', self.log.output)
|
||||
|
||||
|
@ -43,9 +43,11 @@ name = 'zaqar'
|
||||
class Collector(object):
|
||||
def __init__(self,
|
||||
keystoneclient=keystoneclient,
|
||||
zaqarclient=zaqarclient):
|
||||
zaqarclient=zaqarclient,
|
||||
discover_class=None):
|
||||
self.keystoneclient = keystoneclient
|
||||
self.zaqarclient = zaqarclient
|
||||
self.discover_class = discover_class
|
||||
|
||||
def collect(self):
|
||||
if CONF.zaqar.auth_url is None:
|
||||
@ -70,7 +72,8 @@ class Collector(object):
|
||||
user_id=CONF.zaqar.user_id,
|
||||
password=CONF.zaqar.password,
|
||||
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(
|
||||
service_type='messaging', endpoint_type='publicURL')
|
||||
logger.debug('Fetching metadata from %s' % endpoint)
|
||||
|
Loading…
Reference in New Issue
Block a user