c8ff803531
Each config option has limitation for type and value. If we use method CONF.set_override without parameter enforce_type=True, we may pass wrong type to config option. This commit makes sure calling method CONF.set_override with enforce_type=True. Change-Id: I700dcd21941c6399c51e11bef2282e1e4565e85a Closes-Bug: #1517839
68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
# Copyright 2015 Mirantis Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import sys
|
|
|
|
import ddt
|
|
import mock
|
|
|
|
from manila.cmd import share as manila_share
|
|
from manila import test
|
|
|
|
CONF = manila_share.CONF
|
|
|
|
|
|
@ddt.ddt
|
|
class ManilaCmdShareTestCase(test.TestCase):
|
|
|
|
@ddt.data(None, [], ['foo', ], ['foo', 'bar', ])
|
|
def test_main(self, backends):
|
|
self.mock_object(manila_share.log, 'setup')
|
|
self.mock_object(manila_share.log, 'register_options')
|
|
self.mock_object(manila_share.utils, 'monkey_patch')
|
|
self.mock_object(manila_share.service, 'process_launcher')
|
|
self.mock_object(manila_share.service.Service, 'create')
|
|
self.launcher = manila_share.service.process_launcher.return_value
|
|
self.mock_object(self.launcher, 'launch_service')
|
|
self.mock_object(self.launcher, 'wait')
|
|
self.server = manila_share.service.Service.create.return_value
|
|
fake_host = 'fake_host'
|
|
CONF.set_override('enabled_share_backends', backends,
|
|
enforce_type=True)
|
|
CONF.set_override('host', fake_host, enforce_type=True)
|
|
sys.argv = ['manila-share']
|
|
|
|
manila_share.main()
|
|
|
|
manila_share.log.setup.assert_called_once_with(CONF, "manila")
|
|
manila_share.log.register_options.assert_called_once_with(CONF)
|
|
manila_share.utils.monkey_patch.assert_called_once_with()
|
|
manila_share.service.process_launcher.assert_called_once_with()
|
|
self.launcher.wait.assert_called_once_with()
|
|
|
|
if backends:
|
|
manila_share.service.Service.create.assert_has_calls([
|
|
mock.call(
|
|
host=fake_host + '@' + backend,
|
|
service_name=backend,
|
|
binary='manila-share') for backend in backends
|
|
])
|
|
self.launcher.launch_service.assert_has_calls([
|
|
mock.call(self.server) for backend in backends])
|
|
else:
|
|
manila_share.service.Service.create.assert_called_once_with(
|
|
binary='manila-share')
|
|
self.launcher.launch_service.assert_called_once_with(self.server)
|