Clear the difference between service type and name

The current code mixes service type and service name based on
the context. Service type should be service type allways. The
same applies on service name. The patch clears the difference
between these two different variables.

Story: 2005820
Task: 33577

Change-Id: Ifdeaa2b854dfa2dcfda1491b522e4e67b822fc4f
This commit is contained in:
Martin Kopec 2019-06-04 15:05:46 +00:00
parent 5dda24d406
commit 3abb0ae5c5
18 changed files with 64 additions and 43 deletions

View File

@ -535,7 +535,7 @@ def config_tempest(**kwargs):
convert=kwargs.get('convert_to_raw', False))
image.create_tempest_images(conf)
has_neutron = services.is_service("network")
has_neutron = services.is_service(**{"type": "network"})
network = services.get_service("network")
network.create_tempest_networks(has_neutron, conf,
kwargs.get('network_id'))

View File

@ -28,9 +28,10 @@ class ServiceError(Exception):
class Service(object):
def __init__(self, name, service_url, token, disable_ssl_validation,
client=None):
def __init__(self, name, s_type, service_url, token,
disable_ssl_validation, client=None):
self.name = name
self.s_type = s_type
self.service_url = service_url
self.headers = {'Accept': 'application/json', 'X-Auth-Token': token}
self.disable_ssl_validation = disable_ssl_validation
@ -58,11 +59,11 @@ class Service(object):
r = http.request('GET', url, headers=self.headers)
except Exception as e:
LOG.error("Request on service '%s' with url '%s' failed",
(self.name, url))
(self.s_type, url))
raise e
if r.status >= 400:
raise ServiceError("Request on service '%s' with url '%s' failed"
" with code %d" % (self.name, url, r.status))
" with code %d" % (self.s_type, url, r.status))
return r.data
def set_extensions(self):
@ -131,21 +132,21 @@ class Service(object):
diverges from the service name. The main example is object-store
service where the <service>-feature-enabled is object-storage.
"""
return self.name
return self.s_type
def get_service_extension_key(self):
"""Return the extension key for a particular service"""
return None
def get_unversioned_service_name(self):
"""Return name of service without versions.
def get_unversioned_service_type(self):
"""Return type of service without versions.
Some services are versioned like volumev2 and volumev3, we try to
discover these services checking the supported versions, so we need
to know the unversioned service name for this.
The default value is the name of the service.
to know the unversioned service type for this.
The default value is the type of the service.
"""
return self.name
return self.s_type
def post_configuration(self, conf, is_service):
"""Do post congiruation steps.

View File

@ -63,7 +63,7 @@ class ComputeService(VersionedService):
def post_configuration(self, conf, is_service):
conf.set('compute-feature-enabled', 'attach_encrypted_volume',
str(is_service('key-manager')))
str(is_service(**{'type': 'key-manager'})))
@staticmethod
def get_service_name():

View File

@ -23,10 +23,10 @@ from config_tempest.services.base import VersionedService
class IdentityService(VersionedService):
def __init__(self, name, service_url, token, disable_ssl_validation,
client=None):
def __init__(self, name, s_type, service_url, token,
disable_ssl_validation, client=None):
super(IdentityService, self).__init__(
name, service_url, token, disable_ssl_validation, client)
name, s_type, service_url, token, disable_ssl_validation, client)
self.extensions_v3 = []
version = ''
if 'v2' in self.service_url:

View File

@ -26,9 +26,9 @@ from config_tempest.services.base import VersionedService
class ImageService(VersionedService):
def __init__(self, name, service_url, token, disable_ssl_validation,
client=None):
super(ImageService, self).__init__(name, service_url, token,
def __init__(self, name, s_type, service_url, token,
disable_ssl_validation, client=None):
super(ImageService, self).__init__(name, s_type, service_url, token,
disable_ssl_validation,
client)

View File

@ -96,7 +96,7 @@ class Services(object):
endpoint_data), s_type)
# Create the service class and add it to services list
service = s_class(s_type, url, token,
service = s_class(s_name, s_type, url, token,
self._ssl_validation,
self._clients.get_service_client(
s_type))
@ -117,7 +117,7 @@ class Services(object):
# service is not available
# quickly instantiate a class in order to set
# availability of the service
s = s_class(None, None, None, None)
s = s_class(None, None, None, None, None)
s.set_availability(self._conf, False)
def merge_exts_multiversion_service(self, service):
@ -129,11 +129,11 @@ class Services(object):
:param service: Service object
"""
versions = service.get_supported_versions()
service_name = service.get_unversioned_service_name()
service_type = service.get_unversioned_service_type()
services_lst = []
for v in versions:
if self.is_service(service_name + v):
services_lst.append(self.get_service(service_name + v))
if self.is_service(**{'type': service_type + v}):
services_lst.append(self.get_service(service_type + v))
services_lst.append(service)
service.extensions = self.merge_extensions(services_lst)
@ -196,29 +196,35 @@ class Services(object):
replace_text = port + "/identity/" + self._creds.identity_version
return url.replace("/identity", replace_text)
def get_service(self, name):
def get_service(self, s_type):
"""Finds and returns a service object
:param name: Codename of a service
:type name: string
:param s_type: Type of a service
:type s_type: string
:return: Service object
"""
for service in self._services:
if service.name == name:
if service.s_type == s_type:
return service
return None
def is_service(self, name):
def is_service(self, **kwargs):
"""Returns true if a service is available, false otherwise
:param name: Codename of a service
:type name: string
:param kwargs: Search parameters (accepts service name or type)
:rtype: boolean
"""
if name not in self.available_services.values():
if kwargs.get('name'):
if kwargs.get('name') not in self.available_services.keys():
return False
return True
if kwargs.get('type'):
if kwargs.get('type') not in self.available_services.values():
return False
return True
return False
def post_configuration(self):
for s in self._services:
s.post_configuration(self._conf, self.is_service)

View File

@ -24,7 +24,7 @@ class ShareService(VersionedService):
conf.set('share', 'min_api_microversion', m_vs['min_microversion'])
conf.set('share', 'max_api_microversion', m_vs['max_microversion'])
def get_unversioned_service_name(self):
def get_unversioned_service_type(self):
return 'share'
@staticmethod

View File

@ -52,7 +52,7 @@ class VolumeService(VersionedService):
def get_feature_name(self):
return 'volume'
def get_unversioned_service_name(self):
def get_unversioned_service_type(self):
return 'volume'
@staticmethod
@ -61,7 +61,7 @@ class VolumeService(VersionedService):
def post_configuration(self, conf, is_service):
# Verify if the cinder backup service is enabled
if not is_service("volumev3"):
if not is_service(**{"type": "volumev3"}):
C.LOG.info("No volume service found, "
"skipping backup service check")
return

View File

@ -25,6 +25,7 @@ class TestService(BaseServiceTest):
def setUp(self):
super(TestService, self).setUp()
self.Service = Service("ServiceName",
"ServiceType",
self.FAKE_URL,
self.FAKE_TOKEN,
disable_ssl_validation=False)
@ -75,6 +76,7 @@ class TestVersionedService(BaseServiceTest):
def setUp(self):
super(TestVersionedService, self).setUp()
self.Service = VersionedService("ServiceName",
"ServiceType",
self.FAKE_URL,
self.FAKE_TOKEN,
disable_ssl_validation=False)

View File

@ -35,7 +35,7 @@ class TestEc2Service(BaseConfigTempestTest):
self.Services = Services(self.clients, conf, self._get_creds(conf))
def test_set_default_tempest_options(self):
service = Ec2Service("ec2", self.FAKE_URL, self.clients, False)
service = Ec2Service("ec2", "ec2", self.FAKE_URL, self.clients, False)
service.set_default_tempest_options(self.Services._conf)
ec2_url = self.Services._conf.get("boto", "ec2_url")
self.assertEqual(ec2_url, self.FAKE_URL)
@ -55,7 +55,7 @@ class TestS3Service(BaseConfigTempestTest):
self.Services = Services(self.clients, conf, self._get_creds(conf))
def test_set_default_tempest_options(self):
service = S3Service("s3", self.FAKE_URL, self.clients, False)
service = S3Service("s3", "s3", self.FAKE_URL, self.clients, False)
service.set_default_tempest_options(self.Services._conf)
ec2_url = self.Services._conf.get("boto", "s3_url")
self.assertEqual(ec2_url, self.FAKE_URL)

View File

@ -25,6 +25,7 @@ class TestCeilometerService(BaseServiceTest):
def setUp(self):
super(TestCeilometerService, self).setUp()
self.Service = ceilometer.MeteringService("ServiceName",
"ServiceType",
self.FAKE_URL,
self.FAKE_TOKEN,
disable_ssl_validation=False)

View File

@ -24,6 +24,7 @@ class TestComputeService(BaseServiceTest):
def setUp(self):
super(TestComputeService, self).setUp()
self.Service = ComputeService("ServiceName",
"ServiceType",
self.FAKE_URL,
self.FAKE_TOKEN,
disable_ssl_validation=False)

View File

@ -25,6 +25,7 @@ class TestIdentityService(BaseServiceTest):
def setUp(self):
super(TestIdentityService, self).setUp()
self.Service = IdentityService("ServiceName",
"ServiceType",
self.FAKE_URL + 'v2.0/',
self.FAKE_TOKEN,
disable_ssl_validation=False)

View File

@ -33,6 +33,7 @@ class TestImageService(BaseServiceTest):
def setUp(self):
super(TestImageService, self).setUp()
self.Service = ImageService("ServiceName",
"ServiceType",
self.FAKE_URL,
self.FAKE_TOKEN,
disable_ssl_validation=False)

View File

@ -42,6 +42,7 @@ class TestNetworkService(BaseServiceTest):
super(TestNetworkService, self).setUp()
self.conf = TempestConf()
self.Service = NetworkService("ServiceName",
"ServiceType",
self.FAKE_URL,
self.FAKE_TOKEN,
disable_ssl_validation=False)

View File

@ -25,6 +25,7 @@ class TestObjectStorageService(BaseServiceTest):
def setUp(self):
super(TestObjectStorageService, self).setUp()
self.Service = ObjectStorageService("ServiceName",
"ServiceType",
self.FAKE_URL,
self.FAKE_TOKEN,
disable_ssl_validation=False)

View File

@ -40,7 +40,7 @@ class TestServices(BaseConfigTempestTest):
@mock.patch('config_tempest.services.services.Services.'
'get_available_services')
def _create_services_instance(self, mock_avail, mock_discover, v2=False):
mock_avail.return_value = {'my_service': 'my_service'}
mock_avail.return_value = {'my_service': 'my_type'}
conf = self._get_conf('v2', 'v3')
creds = self._get_creds(conf, v2=v2)
clients = mock.Mock()
@ -157,9 +157,9 @@ class TestServices(BaseConfigTempestTest):
def test_get_service(self):
services = self._create_services_instance()
exp_resp = mock.Mock()
exp_resp.name = 'my_service'
exp_resp.s_type = 'my_service_type'
services._services = [exp_resp]
resp = services.get_service('my_service')
resp = services.get_service('my_service_type')
self.assertEqual(resp, exp_resp)
resp = services.get_service('my')
self.assertEqual(resp, None)
@ -168,8 +168,13 @@ class TestServices(BaseConfigTempestTest):
services = self._create_services_instance()
service = mock.Mock()
service.name = 'my_service'
service.s_type = 'my_type'
services._services = [service]
resp = services.is_service('my_service')
resp = services.is_service(name='my_service')
self.assertEqual(resp, True)
resp = services.is_service('other_service')
resp = services.is_service(name='other_service')
self.assertEqual(resp, False)
resp = services.is_service(**{'type': 'my_type'})
self.assertEqual(resp, True)
resp = services.is_service(**{'type': 'other_type'})
self.assertEqual(resp, False)

View File

@ -24,6 +24,7 @@ class TestVolumeService(BaseServiceTest):
def setUp(self):
super(TestVolumeService, self).setUp()
self.Service = volume.VolumeService("ServiceName",
"ServiceType",
self.FAKE_URL,
self.FAKE_TOKEN,
disable_ssl_validation=False)