Coverage for manila/share/drivers/huawei/huawei_utils.py: 89%
37 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright (c) 2015 Huawei Technologies Co., Ltd.
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.
16import copy
18from oslo_log import log
20from manila.share.drivers.huawei import constants
21from manila.share import share_types
24LOG = log.getLogger(__name__)
27def get_share_extra_specs_params(type_id):
28 """Return the parameters for creating the share."""
29 opts = None
30 if type_id is not None: 30 ↛ 36line 30 didn't jump to line 36 because the condition on line 30 was always true
31 specs = share_types.get_share_type_extra_specs(type_id)
33 opts = _get_opts_from_specs(specs)
34 LOG.debug('Get share type extra specs: %s', opts)
36 return opts
39def _get_opts_from_specs(specs):
40 opts = copy.deepcopy(constants.OPTS_CAPABILITIES)
41 opts.update(constants.OPTS_VALUE)
43 for key, value in specs.items():
45 # Get the scope, if using scope format
46 scope = None
47 key_split = key.split(':')
48 if len(key_split) not in (1, 2):
49 continue
51 if len(key_split) == 1: 51 ↛ 52line 51 didn't jump to line 52 because the condition on line 51 was never true
52 key = key_split[0]
53 else:
54 scope = key_split[0]
55 key = key_split[1]
57 if scope: 57 ↛ 59line 57 didn't jump to line 59 because the condition on line 57 was always true
58 scope = scope.lower()
59 if key: 59 ↛ 63line 59 didn't jump to line 63 because the condition on line 59 was always true
60 key = key.lower()
62 # We want both the scheduler and the driver to act on the value.
63 if ((not scope or scope == 'capabilities') and
64 key in constants.OPTS_CAPABILITIES):
65 words = value.split()
67 if not (words and len(words) == 2 and words[0] == '<is>'):
68 LOG.error("Extra specs must be specified as "
69 "capabilities:%s='<is> True'.", key)
70 else:
71 opts[key] = words[1].lower()
73 if ((scope in constants.OPTS_CAPABILITIES) and
74 (key in constants.OPTS_VALUE)):
75 if ((scope in constants.OPTS_ASSOCIATE) and 75 ↛ 43line 75 didn't jump to line 43 because the condition on line 75 was always true
76 (key in constants.OPTS_ASSOCIATE[scope])):
77 opts[key] = value
78 return opts