| 1 |
# Copyright 2013, 2016 Red Hat, Inc. |
| 2 |
# All Rights Reserved. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
|
| 16 |
import json |
| 17 |
import re |
| 18 |
|
| 19 |
from config_tempest import constants as C |
| 20 |
from config_tempest.services.base import ServiceError |
| 21 |
from config_tempest.services.base import VersionedService |
| 22 |
from config_tempest import utils |
| 23 |
|
| 24 |
from tempest.lib import exceptions |
| 25 |
|
| 26 |
|
| 27 |
class VolumeService(VersionedService): |
| 28 |
def set_extensions(self): |
| 29 |
body = self.do_get(self.service_url + '/extensions') |
| 30 |
body = json.loads(body) |
| 31 |
self.extensions = list(map(lambda x: x['alias'], body['extensions'])) |
| 32 |
|
| 33 |
def set_versions(self): |
| 34 |
url_without_version = utils.get_base_url(self.service_url) |
| 35 |
body = self.do_get(url_without_version, top_level=False) |
| 36 |
self.versions_body = json.loads(body) |
| 37 |
self.versions = self.deserialize_versions(self.versions_body) |
| 38 |
|
| 39 |
def get_volume_pools(self): |
| 40 |
body = self.do_get(self.service_url + '/scheduler-stats/get_pools') |
| 41 |
body = json.loads(body) |
| 42 |
return body |
| 43 |
|
| 44 |
def set_default_tempest_options(self, conf): |
| 45 |
if 'v3' in self.service_url: |
| 46 |
m_vs = self.filter_api_microversions() |
| 47 |
conf.set('volume', 'min_microversion', m_vs['min_microversion']) |
| 48 |
conf.set('volume', 'max_microversion', m_vs['max_microversion']) |
| 49 |
|
| 50 |
try: |
| 51 |
pools = self.get_volume_pools()['pools'] |
| 52 |
except exceptions.Forbidden: |
| 53 |
C.LOG.warning("User has no permissions to list back-end storage " |
| 54 |
"pools - storage back-ends can't be discovered.") |
| 55 |
return |
| 56 |
except ServiceError: |
| 57 |
C.LOG.warning("Volume backend doesn't exist.") |
| 58 |
return |
| 59 |
if pools: |
| 60 |
backends = [ |
| 61 |
re.findall(r'(\w*)@(\w*)', pool['name'])[0][1] |
| 62 |
for pool in pools |
| 63 |
] |
| 64 |
conf.set('volume', 'backend_names', ','.join(backends)) |
| 65 |
if len(backends) > 1: |
| 66 |
conf.set('volume-feature-enabled', 'multi_backend', 'True') |
| 67 |
|
| 68 |
def get_service_extension_key(self): |
| 69 |
return 'api_extensions' |
| 70 |
|
| 71 |
@staticmethod |
| 72 |
def get_codename(): |
| 73 |
return 'cinder' |
| 74 |
|
| 75 |
def get_feature_name(self): |
| 76 |
return 'volume' |
| 77 |
|
| 78 |
def get_unversioned_service_type(self): |
| 79 |
return 'volume' |
| 80 |
|
| 81 |
@staticmethod |
| 82 |
def get_service_type(): |
| 83 |
return ['volumev3'] |
| 84 |
|
| 85 |
def post_configuration(self, conf, is_service): |
| 86 |
# Verify if the cinder backup service is enabled |
| 87 |
if not is_service(name=self.name): |
| 88 |
C.LOG.info("No volume service found, " |
| 89 |
"skipping backup service check") |
| 90 |
conf.set('volume-feature-enabled', 'backup', 'False') |
| 91 |
return |
| 92 |
try: |
| 93 |
params = {'binary': 'cinder-backup'} |
| 94 |
is_backup = self.client.list_services(**params) |
| 95 |
except exceptions.Forbidden: |
| 96 |
C.LOG.warning("User has no permissions to list services - " |
| 97 |
"cinder-backup service can't be discovered.") |
| 98 |
conf.set('volume-feature-enabled', 'backup', 'False') |
| 99 |
return |
| 100 |
|
| 101 |
if is_backup: |
| 102 |
services = is_backup['services'] |
| 103 |
backup_enabled = 'False' |
| 104 |
for service in services: |
| 105 |
if service['state'] == 'up': |
| 106 |
backup_enabled = 'True' |
| 107 |
break |
| 108 |
|
| 109 |
# post_configuration method is called with every volume (v2, |
| 110 |
# v3) service, therefore set the value with priority so that it |
| 111 |
# can't be overrided by this method called from other instance |
| 112 |
# of volume service |
| 113 |
conf.set('volume-feature-enabled', 'backup', backup_enabled, |
| 114 |
priority=True) |