diff --git a/tobiko/common/_skip.py b/tobiko/common/_skip.py index 4e6260102..be1593ad9 100644 --- a/tobiko/common/_skip.py +++ b/tobiko/common/_skip.py @@ -49,7 +49,10 @@ def skip_if_match(reason, match, predicate, *args, **kwargs): def wrapped_method(*_args, **_kwargs): return_value = predicate(*args, **kwargs) if match(return_value): - skip(reason, return_value=return_value) + if '{return_value' in reason: + skip(reason, return_value=return_value) + else: + skip(reason) return method(*_args, **_kwargs) if obj is method: diff --git a/tobiko/openstack/keystone/__init__.py b/tobiko/openstack/keystone/__init__.py index 8f3e60b18..1a55b5fe0 100644 --- a/tobiko/openstack/keystone/__init__.py +++ b/tobiko/openstack/keystone/__init__.py @@ -15,6 +15,7 @@ from __future__ import absolute_import from tobiko.openstack.keystone import _client from tobiko.openstack.keystone import _credentials +from tobiko.openstack.keystone import _services from tobiko.openstack.keystone import _session keystone_client = _client.keystone_client @@ -34,6 +35,10 @@ KeystoneCredentials = _credentials.KeystoneCredentials KeystoneCredentialsFixture = _credentials.KeystoneCredentialsFixture InvalidKeystoneCredentials = _credentials.InvalidKeystoneCredentials +has_service = _services.has_service +is_service_missing = _services.is_service_missing +skip_if_missing_service = _services.skip_if_missing_service + keystone_session = _session.keystone_session KeystoneSessionFixture = _session.KeystoneSessionFixture KeystoneSessionManager = _session.KeystoneSessionManager diff --git a/tobiko/openstack/keystone/_services.py b/tobiko/openstack/keystone/_services.py new file mode 100644 index 000000000..0705c68a4 --- /dev/null +++ b/tobiko/openstack/keystone/_services.py @@ -0,0 +1,51 @@ +# Copyright 2019 Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +from __future__ import absolute_import + +import tobiko +from tobiko.openstack.keystone import _client + + +class ServiceListFixture(tobiko.SharedFixture): + + client = None + services = None + + def setup_fixture(self): + self.services = _client.list_services() + + def has_service(self, **params): + try: + _client.find_resource(self.services, + check_found=True, + check_unique=False, + **params) + except _client.KeystoneResourceNotFound: + return False + else: + return True + + +def has_service(**params): + fixture = tobiko.setup_fixture(ServiceListFixture) + return fixture.has_service(**params) + + +def is_service_missing(**params): + return not has_service(**params) + + +def skip_if_missing_service(**params): + return tobiko.skip_if('missing service: {!r}'.format(params), + is_service_missing, **params) diff --git a/tobiko/tests/functional/openstack/test_keystone.py b/tobiko/tests/functional/openstack/test_keystone.py index 6580f7859..83421b065 100644 --- a/tobiko/tests/functional/openstack/test_keystone.py +++ b/tobiko/tests/functional/openstack/test_keystone.py @@ -160,3 +160,13 @@ class KeystoneClientAPITest(testtools.TestCase): self.assertEqual(service.id, endpoint.service_id) self.assertEqual('public', endpoint.interface) self.assertTrue(endpoint.enabled) + + @keystone.skip_if_missing_service(name='octavia') + def test_find_octavia_public_endpoint(self): + service = keystone.find_service(name='octavia') + endpoint = keystone.find_endpoint(service=service, + interface='public', + enabled=True) + self.assertEqual(service.id, endpoint.service_id) + self.assertEqual('public', endpoint.interface) + self.assertTrue(endpoint.enabled)