Coverage for manila/tests/fake_driver.py: 76%

56 statements  

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

1# Copyright 2012 OpenStack Foundation 

2# Copyright 2014 Mirantis Inc. 

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 

16from oslo_log import log 

17 

18from manila.common import constants 

19from manila.share import driver 

20from manila.tests import fake_service_instance 

21 

22LOG = log.getLogger(__name__) 

23 

24 

25class FakeShareDriver(driver.ShareDriver): 

26 """Fake share driver. 

27 

28 This fake driver can be also used as a test driver within a real 

29 running manila-share instance. To activate it use this in manila.conf:: 

30 

31 enabled_share_backends = fake 

32 

33 [fake] 

34 driver_handles_share_servers = True 

35 share_backend_name = fake 

36 share_driver = manila.tests.fake_driver.FakeShareDriver 

37 

38 With it you basically mocked all backend driver calls but e.g. networking 

39 will still be activated. 

40 """ 

41 

42 def __init__(self, *args, **kwargs): 

43 self._setup_service_instance_manager() 

44 super(FakeShareDriver, self).__init__([True, False], *args, **kwargs) 

45 

46 def _setup_service_instance_manager(self): 

47 self.service_instance_manager = ( 

48 fake_service_instance.FakeServiceInstanceManager()) 

49 

50 def manage_existing(self, share, driver_options, share_server=None): 

51 LOG.debug("Fake share driver: manage") 

52 LOG.debug("Fake share driver: driver options: %s", 

53 str(driver_options)) 

54 return {'size': 1} 

55 

56 def unmanage(self, share, share_server=None): 

57 LOG.debug("Fake share driver: unmanage") 

58 

59 @property 

60 def driver_handles_share_servers(self): 

61 if not isinstance(self.configuration.safe_get( 

62 'driver_handles_share_servers'), bool): 

63 return True 

64 

65 return self.configuration.driver_handles_share_servers 

66 

67 def create_snapshot(self, context, snapshot, share_server=None): 

68 pass 

69 

70 def delete_snapshot(self, context, snapshot, share_server=None): 

71 pass 

72 

73 def create_share(self, context, share, share_server=None): 

74 return ['/fake/path', '/fake/path2'] 

75 

76 def create_share_from_snapshot(self, context, share, snapshot, 

77 share_server=None, parent_share=None): 

78 return { 

79 'export_locations': ['/fake/path', '/fake/path2'], 

80 'status': constants.STATUS_AVAILABLE, 

81 } 

82 

83 def delete_share(self, context, share, share_server=None): 

84 pass 

85 

86 def ensure_share(self, context, share, share_server=None): 

87 pass 

88 

89 def allow_access(self, context, share, access, share_server=None): 

90 pass 

91 

92 def deny_access(self, context, share, access, share_server=None): 

93 pass 

94 

95 def get_share_stats(self, refresh=False): 

96 return None 

97 

98 def do_setup(self, context): 

99 pass 

100 

101 def setup_server(self, *args, **kwargs): 

102 pass 

103 

104 def teardown_server(self, *args, **kwargs): 

105 pass 

106 

107 def get_network_allocations_number(self): 

108 # NOTE(vponomaryov): Simulate drivers that use share servers and 

109 # do not use 'service_instance' module. 

110 return 2 

111 

112 def _verify_share_server_handling(self, driver_handles_share_servers): 

113 return super(FakeShareDriver, self)._verify_share_server_handling( 

114 driver_handles_share_servers) 

115 

116 def create_share_group(self, context, group_id, share_server=None): 

117 pass 

118 

119 def delete_share_group(self, context, group_id, share_server=None): 

120 pass 

121 

122 def get_share_status(self, share, share_server=None): 

123 return { 

124 'export_locations': ['/fake/path', '/fake/path2'], 

125 'status': constants.STATUS_AVAILABLE, 

126 }