Coverage for manila/share/drivers/netapp/dataontap/protocols/base.py: 100%

38 statements  

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

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

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

3# a copy of the License at 

4# 

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

6# 

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

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

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

10# License for the specific language governing permissions and limitations 

11# under the License. 

12""" 

13Abstract base class for NetApp NAS protocol helper classes. 

14""" 

15 

16import abc 

17 

18from manila.common import constants 

19from manila import utils 

20 

21 

22def access_rules_synchronized(f): 

23 """Decorator for synchronizing share access rule modification methods.""" 

24 

25 def wrapped_func(self, *args, **kwargs): 

26 

27 # The first argument is always a share, which has an ID 

28 key = "share-access-%s" % args[0]['id'] 

29 

30 @utils.synchronized(key) 

31 def source_func(self, *args, **kwargs): 

32 return f(self, *args, **kwargs) 

33 

34 return source_func(self, *args, **kwargs) 

35 

36 return wrapped_func 

37 

38 

39class NetAppBaseHelper(metaclass=abc.ABCMeta): 

40 """Interface for protocol-specific NAS drivers.""" 

41 

42 def __init__(self): 

43 self._client = None 

44 

45 def set_client(self, client): 

46 self._client = client 

47 

48 def _is_readonly(self, access_level): 

49 """Returns whether an access rule specifies read-only access.""" 

50 return access_level == constants.ACCESS_LEVEL_RO 

51 

52 @staticmethod 

53 def _get_share_export_location(share): 

54 """Returns the export location of the share. 

55 

56 The share may contain only the list of export location, depending on 

57 the entity provided by the manager. 

58 """ 

59 export_location = share.get('export_location') 

60 if not export_location: 

61 export_location_list = share.get('export_locations') 

62 if (isinstance(export_location_list, list) and 

63 len(export_location_list) > 0): 

64 export_location = export_location_list[0]['path'] 

65 

66 return export_location 

67 

68 @abc.abstractmethod 

69 def create_share(self, share, share_name, 

70 clear_current_export_policy=True, 

71 ensure_share_already_exists=False, replica=False, 

72 is_flexgroup=False): 

73 """Creates NAS share.""" 

74 

75 @abc.abstractmethod 

76 def delete_share(self, share, share_name): 

77 """Deletes NAS share.""" 

78 

79 @abc.abstractmethod 

80 def update_access(self, share, share_name, rules): 

81 """Replaces the list of access rules known to the backend storage.""" 

82 

83 @abc.abstractmethod 

84 def get_target(self, share): 

85 """Returns host where the share located.""" 

86 

87 @abc.abstractmethod 

88 def get_share_name_for_share(self, share): 

89 """Returns the flexvol name that hosts a share.""" 

90 

91 @abc.abstractmethod 

92 def cleanup_demoted_replica(self, share, share_name): 

93 """Do some cleanup regarding the former active replica"""