Coverage for manila/share/configuration.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# 

2# Copyright (c) 2012 Rackspace Hosting 

3# Copyright (c) 2013 NetApp 

4# All Rights Reserved. 

5# 

6# Licensed under the Apache License, Version 2.0 (the "License"); you may 

7# not use this file except in compliance with the License. You may obtain 

8# a copy of the License at 

9# 

10# http://www.apache.org/licenses/LICENSE-2.0 

11# 

12# Unless required by applicable law or agreed to in writing, software 

13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

15# License for the specific language governing permissions and limitations 

16# under the License. 

17 

18""" 

19Configuration support for all drivers. 

20 

21This module allows support for setting configurations either from default 

22or from a particular CONF group, to be able to set multiple configurations 

23for a given set of values. 

24 

25For instance, two generic configurations can be set by naming them in groups as 

26 

27 [generic1] 

28 share_backend_name=generic-backend-1 

29 ... 

30 

31 [generic2] 

32 share_backend_name=generic-backend-2 

33 ... 

34 

35And the configuration group name will be passed in so that all calls to 

36configuration.volume_group within that instance will be mapped to the proper 

37named group. 

38 

39This class also ensures the implementation's configuration is grafted into the 

40option group. This is due to the way cfg works. All cfg options must be defined 

41and registered in the group in which they are used. 

42""" 

43 

44from oslo_config import cfg 

45 

46CONF = cfg.CONF 

47 

48 

49class Configuration(object): 

50 

51 def __init__(self, share_opts, config_group=None): 

52 """Graft config values into config group. 

53 

54 This takes care of grafting the implementation's config values 

55 into the config group. 

56 """ 

57 self.config_group = config_group 

58 

59 # set the local conf so that __call__'s know what to use 

60 if self.config_group: 

61 self._ensure_config_values(share_opts) 

62 self.local_conf = CONF._get(self.config_group) 

63 else: 

64 self.local_conf = CONF 

65 

66 def _ensure_config_values(self, share_opts): 

67 CONF.register_opts(share_opts, 

68 group=self.config_group) 

69 

70 def append_config_values(self, share_opts): 

71 self._ensure_config_values(share_opts) 

72 

73 def safe_get(self, value): 

74 try: 

75 return self.__getattr__(value) 

76 except cfg.NoSuchOptError: 

77 return None 

78 

79 def __getattr__(self, value): 

80 return getattr(self.local_conf, value)