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
« 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.
16from oslo_log import log
18from manila.common import constants
19from manila.share import driver
20from manila.tests import fake_service_instance
22LOG = log.getLogger(__name__)
25class FakeShareDriver(driver.ShareDriver):
26 """Fake share driver.
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::
31 enabled_share_backends = fake
33 [fake]
34 driver_handles_share_servers = True
35 share_backend_name = fake
36 share_driver = manila.tests.fake_driver.FakeShareDriver
38 With it you basically mocked all backend driver calls but e.g. networking
39 will still be activated.
40 """
42 def __init__(self, *args, **kwargs):
43 self._setup_service_instance_manager()
44 super(FakeShareDriver, self).__init__([True, False], *args, **kwargs)
46 def _setup_service_instance_manager(self):
47 self.service_instance_manager = (
48 fake_service_instance.FakeServiceInstanceManager())
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}
56 def unmanage(self, share, share_server=None):
57 LOG.debug("Fake share driver: unmanage")
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
65 return self.configuration.driver_handles_share_servers
67 def create_snapshot(self, context, snapshot, share_server=None):
68 pass
70 def delete_snapshot(self, context, snapshot, share_server=None):
71 pass
73 def create_share(self, context, share, share_server=None):
74 return ['/fake/path', '/fake/path2']
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 }
83 def delete_share(self, context, share, share_server=None):
84 pass
86 def ensure_share(self, context, share, share_server=None):
87 pass
89 def allow_access(self, context, share, access, share_server=None):
90 pass
92 def deny_access(self, context, share, access, share_server=None):
93 pass
95 def get_share_stats(self, refresh=False):
96 return None
98 def do_setup(self, context):
99 pass
101 def setup_server(self, *args, **kwargs):
102 pass
104 def teardown_server(self, *args, **kwargs):
105 pass
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
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)
116 def create_share_group(self, context, group_id, share_server=None):
117 pass
119 def delete_share_group(self, context, group_id, share_server=None):
120 pass
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 }