Introduce post_configuration method

The patch renames set_service_availability method to
post_configuration.
The patch also removes some service specific code by
implementing a new Service method - post_configuration.

Story: 2002787
Task: 30507

Change-Id: I1155a5b204ed4d69bf59a697185d3e3c3b4aeb79
changes/66/651866/4
Martin Kopec 4 years ago
parent b7ea055eed
commit 507940a586

@ -241,6 +241,10 @@ class ClientManager(object):
return self
elif service_name == "compute":
return self.hosts_client
elif "volume" in service_name:
return self.volume_client
elif service_name == "metering":
return self.service_client
else:
return None

@ -536,7 +536,7 @@ def config_tempest(**kwargs):
network.create_tempest_networks(has_neutron, conf,
kwargs.get('network_id'))
services.set_service_availability()
services.post_configuration()
services.set_supported_api_versions()
services.set_service_extensions()

@ -147,6 +147,14 @@ class Service(object):
"""
return self.name
def post_configuration(self, conf, is_service):
"""Do post congiruation steps.
:param conf: config_tempest.tempest_conf.TempestConf
:param is_service: config_tempest.services.services.Services.is_service
"""
return None
class VersionedService(Service):
def set_versions(self, top_level=True):

@ -14,23 +14,29 @@
# under the License.
from config_tempest import constants as C
from config_tempest.services.base import Service
from tempest.lib import exceptions
def check_ceilometer_service(conf, service_client):
"""If a metering service is available, set it to conf
class MeteringService(Service):
:type conf: TempestConf object
:type service_client: Tempest's identity.v3.services_client.ServicesClient
"""
try:
params = {'type': 'metering'}
services = service_client.list_services(**params)
except exceptions.Forbidden:
C.LOG.warning("User has no permissions to list services - "
"metering service can't be discovered.")
return
if services and len(services['services']):
metering = services['services'][0]
if 'ceilometer' in metering['name'] and metering['enabled']:
conf.set('service_available', 'ceilometer', 'True')
def post_configuration(self, conf, is_service):
try:
params = {'type': 'metering'}
services = self.client.list_services(**params)
except exceptions.Forbidden:
C.LOG.warning("User has no permissions to list services - "
"metering service can't be discovered.")
return
if services and len(services['services']):
metering = services['services'][0]
if 'ceilometer' in metering['name'] and metering['enabled']:
conf.set('service_available', 'ceilometer', 'True')
@staticmethod
def get_service_name():
return ['ceilometer']
@staticmethod
def get_codename():
return 'ceilometer'

@ -61,6 +61,10 @@ class ComputeService(VersionedService):
C.LOG.info('Can not retrieve hosts, user are not allowed')
return 1
def post_configuration(self, conf, is_service):
conf.set('compute-feature-enabled', 'attach_encrypted_volume',
str(is_service('key-manager')))
@staticmethod
def get_service_name():
return ['nova']

@ -21,9 +21,7 @@ import pyclbr
from six.moves import urllib
from config_tempest import constants as C
from config_tempest.services import ceilometer
from config_tempest.services import horizon
from config_tempest.services import volume
from tempest.lib import exceptions
import config_tempest.services
@ -221,24 +219,12 @@ class Services(object):
return False
return True
def set_service_availability(self):
# check availability of volume backup service
volume.check_volume_backup_service(self._conf,
self._clients.volume_client,
self.is_service("volumev3"))
ceilometer.check_ceilometer_service(self._conf,
self._clients.service_client)
def post_configuration(self):
for s in self._services:
s.post_configuration(self._conf, self.is_service)
horizon.configure_horizon(self._conf)
# TODO(arxcruz): This should be set in compute service, not here,
# however, it requires a refactor in the code, which is not our
# goal right now
self._conf.set('compute-feature-enabled',
'attach_encrypted_volume',
str(self.is_service('key-manager')))
def set_supported_api_versions(self):
# set supported API versions for services with more of them
for service in self._services:

@ -59,24 +59,23 @@ class VolumeService(VersionedService):
def get_service_name():
return ['cinderv2', 'cinderv3']
def check_volume_backup_service(conf, volume_client, is_volumev3):
"""Verify if the cinder backup service is enabled"""
if not is_volumev3:
C.LOG.info("No volume service found, "
"skipping backup service check")
return
try:
params = {'binary': 'cinder-backup'}
is_backup = volume_client.list_services(**params)
except exceptions.Forbidden:
C.LOG.warning("User has no permissions to list services - "
"cinder-backup service can't be discovered.")
return
if is_backup:
# We only set backup to false if the service isn't running
# otherwise we keep the default value
service = is_backup['services']
if not service or service[0]['state'] == 'down':
conf.set('volume-feature-enabled', 'backup', 'False')
def post_configuration(self, conf, is_service):
# Verify if the cinder backup service is enabled
if not is_service("volumev3"):
C.LOG.info("No volume service found, "
"skipping backup service check")
return
try:
params = {'binary': 'cinder-backup'}
is_backup = self.client.list_services(**params)
except exceptions.Forbidden:
C.LOG.warning("User has no permissions to list services - "
"cinder-backup service can't be discovered.")
return
if is_backup:
# We only set backup to false if the service isn't running
# otherwise we keep the default value
service = is_backup['services']
if not service or service[0]['state'] == 'down':
conf.set('volume-feature-enabled', 'backup', 'False')

@ -24,11 +24,16 @@ from config_tempest.tests.base import BaseServiceTest
class TestCeilometerService(BaseServiceTest):
def setUp(self):
super(TestCeilometerService, self).setUp()
self.Service = ceilometer.MeteringService("ServiceName",
self.FAKE_URL,
self.FAKE_TOKEN,
disable_ssl_validation=False)
self.conf = TempestConf()
def test_check_ceilometer_service(self):
client_service_mock = self.FakeServiceClient(services={})
ceilometer.check_ceilometer_service(self.conf, client_service_mock)
self.Service.client = client_service_mock
self.Service.post_configuration(self.conf, client_service_mock)
self._assert_conf_get_not_raises(configparser.NoSectionError,
"service_available",
@ -42,6 +47,8 @@ class TestCeilometerService(BaseServiceTest):
}
]
})
ceilometer.check_ceilometer_service(self.conf, client_service_mock)
self.Service.client = client_service_mock
self.Service.post_configuration(self.conf, client_service_mock)
self.Service.post_configuration(self.conf, client_service_mock)
self.assertEqual(self.conf.get('service_available', 'ceilometer'),
'True')

@ -37,12 +37,15 @@ class TestVolumeService(BaseServiceTest):
exp_resp = ['v2.0', 'v2.1']
self._set_get_versions(self.Service, exp_resp, self.FAKE_VERSIONS)
@mock.patch('config_tempest.services.services.Services.is_service')
@mock.patch('config_tempest.services.volume.C.LOG')
def test_check_volume_backup_service_no_volume(self, mock_logging):
volume.check_volume_backup_service(self.conf, None, False)
def test_post_configuration_no_volume(self, mock_logging, mock_is_service):
mock_is_service.return_value = False
self.Service.post_configuration(self.conf, mock_is_service)
self.assertTrue(mock_logging.info.called)
def test_check_volume_backup_service_state_down(self):
@mock.patch('config_tempest.services.services.Services.is_service')
def test_post_configuration_state_down(self, mock_is_service):
client_service_mock = self.FakeServiceClient(services={
'services': [
{
@ -50,16 +53,19 @@ class TestVolumeService(BaseServiceTest):
}
]
})
volume.check_volume_backup_service(self.conf,
client_service_mock, True)
self.Service.client = client_service_mock
mock_is_service.return_value = True
self.Service.post_configuration(self.conf, mock_is_service)
self.assertEqual(self.conf.get('volume-feature-enabled',
'backup'), 'False')
def test_check_volume_backup_service_no_service(self):
@mock.patch('config_tempest.services.services.Services.is_service')
def test_post_configuration_no_service(self, mock_is_service):
client_service_mock = self.FakeServiceClient(services={
'services': []
})
volume.check_volume_backup_service(self.conf,
client_service_mock, True)
self.Service.client = client_service_mock
mock_is_service.return_value = True
self.Service.post_configuration(self.conf, mock_is_service)
self.assertEqual(self.conf.get('volume-feature-enabled',
'backup'), 'False')

Loading…
Cancel
Save