Allow skipping in case service is not available

Change-Id: I9c5ca4d54c547a23275bbc2123fcf0f5dfa22368
This commit is contained in:
Federico Ressi 2019-07-18 14:47:03 +02:00
parent 225a26de03
commit a38e1b6a34
4 changed files with 70 additions and 1 deletions

View File

@ -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:

View File

@ -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

View File

@ -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)

View File

@ -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)