Coverage for manila/tests/cmd/test_share.py: 100%
34 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 2015 Mirantis Inc.
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 sys
17from unittest import mock
19import ddt
21from manila.cmd import share as manila_share
22from manila import test
24CONF = manila_share.CONF
27@ddt.ddt
28class ManilaCmdShareTestCase(test.TestCase):
30 @ddt.data(None, [], ['foo', ], ['foo', 'bar', ])
31 def test_main(self, backends):
32 self.mock_object(manila_share.log, 'setup')
33 self.mock_object(manila_share.log, 'register_options')
34 self.mock_object(manila_share.utils, 'monkey_patch')
35 self.mock_object(manila_share.service, 'process_launcher')
36 self.mock_object(manila_share.service.Service, 'create')
37 self.launcher = manila_share.service.process_launcher.return_value
38 self.mock_object(self.launcher, 'launch_service')
39 self.mock_object(self.launcher, 'wait')
40 self.server = manila_share.service.Service.create.return_value
41 fake_host = 'fake.host'
42 CONF.set_override('enabled_share_backends', backends)
43 CONF.set_override('host', fake_host)
44 sys.argv = ['manila-share']
46 manila_share.main()
48 manila_share.log.setup.assert_called_once_with(CONF, "manila")
49 manila_share.log.register_options.assert_called_once_with(CONF)
50 manila_share.utils.monkey_patch.assert_called_once_with()
51 manila_share.service.process_launcher.assert_called_once_with()
52 self.launcher.wait.assert_called_once_with()
54 if backends:
55 manila_share.service.Service.create.assert_has_calls([
56 mock.call(
57 host=fake_host + '@' + backend,
58 service_name=backend,
59 binary='manila-share',
60 coordination=True,
61 ) for backend in backends
62 ])
63 self.launcher.launch_service.assert_has_calls([
64 mock.call(self.server) for backend in backends])
65 else:
66 manila_share.service.Service.create.assert_called_once_with(
67 binary='manila-share')
68 self.launcher.launch_service.assert_called_once_with(self.server)