| 1 |
# Copyright 2018 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 |
|
| 18 |
from config_tempest import constants as C |
| 19 |
from config_tempest.services.base import VersionedService |
| 20 |
from config_tempest import utils |
| 21 |
|
| 22 |
from tempest.lib import exceptions |
| 23 |
|
| 24 |
|
| 25 |
class ShareService(VersionedService): |
| 26 |
|
| 27 |
def set_versions(self): |
| 28 |
url_without_version = utils.get_base_url(self.service_url) |
| 29 |
body = self.do_get(url_without_version, top_level=False) |
| 30 |
self.versions_body = json.loads(body) |
| 31 |
self.versions = self.deserialize_versions(self.versions_body) |
| 32 |
|
| 33 |
def get_share_pools(self, detail=False): |
| 34 |
url = self.service_url + '/scheduler-stats/pools' |
| 35 |
if detail: |
| 36 |
url += '/detail' |
| 37 |
body = self.do_get(url) |
| 38 |
body = json.loads(body) |
| 39 |
return body |
| 40 |
|
| 41 |
def set_default_tempest_options(self, conf): |
| 42 |
if 'v2' in self.service_url: |
| 43 |
m_vs = self.filter_api_microversions() |
| 44 |
conf.set('share', 'min_api_microversion', m_vs['min_microversion']) |
| 45 |
conf.set('share', 'max_api_microversion', m_vs['max_microversion']) |
| 46 |
|
| 47 |
try: |
| 48 |
pools = self.get_share_pools(detail=True)['pools'] |
| 49 |
except exceptions.Forbidden: |
| 50 |
C.LOG.warning("User has no permissions to list back-end storage " |
| 51 |
"pools - storage back-ends can't be discovered.") |
| 52 |
return |
| 53 |
if pools: |
| 54 |
backends = set() |
| 55 |
enable_protocols = set() |
| 56 |
dhss = set() |
| 57 |
capability_snapshot_support = set() |
| 58 |
capability_create_share_from_snapshot_support = set() |
| 59 |
capability_thin_provisioning = set() |
| 60 |
for pool in pools: |
| 61 |
backends.add(pool['backend']) |
| 62 |
pool_capabilities = pool['capabilities'] |
| 63 |
protocol = pool_capabilities['storage_protocol'].lower() |
| 64 |
enable_protocols.update(protocol.split('_')) |
| 65 |
dhss.add(pool_capabilities['driver_handles_share_servers']) |
| 66 |
capability_snapshot_support.add( |
| 67 |
pool_capabilities['snapshot_support']) |
| 68 |
capability_create_share_from_snapshot_support.add( |
| 69 |
pool_capabilities['create_share_from_snapshot_support']) |
| 70 |
thin_provisioning = pool_capabilities.get('thin_provisioning') |
| 71 |
thin_provisioning = ([thin_provisioning] |
| 72 |
if not isinstance(thin_provisioning, list) |
| 73 |
else thin_provisioning) |
| 74 |
capability_thin_provisioning.add(any(thin_provisioning)) |
| 75 |
|
| 76 |
conf.set('share', 'backend_names', ','.join(backends)) |
| 77 |
conf.set('share', 'enable_protocols', ','.join(enable_protocols)) |
| 78 |
|
| 79 |
# NOTE(gouthamr): manila tests can be run with |
| 80 |
# driver_handles_share_servers set to either True or False, |
| 81 |
# not both at the same time. Lets err on the side of caution and |
| 82 |
# set this to True if any DHSS=True backend is present. |
| 83 |
conf.set('share', 'multitenancy_enabled', str(any(dhss))) |
| 84 |
|
| 85 |
# Optional capabilities/features: |
| 86 |
conf.set('share', 'run_snapshot_tests', |
| 87 |
str(any(capability_snapshot_support))) |
| 88 |
conf.set('share', 'capability_snapshot_support', |
| 89 |
str(any(capability_snapshot_support))) |
| 90 |
conf.set('share', 'capability_create_share_from_snapshot_support', |
| 91 |
str(any(capability_create_share_from_snapshot_support))) |
| 92 |
conf.set('share', 'capability_thin_provisioned', |
| 93 |
str(any(capability_thin_provisioning))) |
| 94 |
|
| 95 |
if len(backends) > 1: |
| 96 |
conf.set('share', 'multi_backend', 'True') |
| 97 |
|
| 98 |
def get_unversioned_service_type(self): |
| 99 |
return 'share' |
| 100 |
|
| 101 |
@staticmethod |
| 102 |
def get_codename(): |
| 103 |
return 'manila' |
| 104 |
|
| 105 |
def get_feature_name(self): |
| 106 |
return 'share' |
| 107 |
|
| 108 |
@staticmethod |
| 109 |
def get_service_type(): |
| 110 |
return ['share', 'sharev2'] |