Add an exception class for undefined default_vim option
Change-Id: Id3d4b2f27ddca95a550f0c18d0a3bdcdd32d8957 Closes-bug: #1566770
This commit is contained in:
parent
ffc88d3d01
commit
28e7112cef
|
@ -37,6 +37,12 @@ class VimInUseException(exceptions.TackerException):
|
|||
message = _("VIM %(vim_id)s is still in use by VNF")
|
||||
|
||||
|
||||
class VimDefaultNameNotDefined(exceptions.TackerException):
|
||||
message = _("Default VIM is not set. Either specify a"
|
||||
" valid VIM during the VNF creation or set default VIM"
|
||||
" in tacker.conf")
|
||||
|
||||
|
||||
class VimDefaultIdException(exceptions.TackerException):
|
||||
message = _("Default VIM name %(vim_name)s is invalid or there are "
|
||||
"multiple VIM matches found. Please specify a valid default "
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
# 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 mock
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from tacker.extensions import nfvo
|
||||
from tacker import manager
|
||||
from tacker.tests.unit import base
|
||||
from tacker.vm import vim_client
|
||||
|
||||
|
||||
class TestVIMClient(base.TestCase):
|
||||
|
||||
def test_get_vim_without_defined_default_vim(self):
|
||||
cfg.CONF.set_override(
|
||||
'default_vim', '', 'nfvo_vim', enforce_type=True)
|
||||
vimclient = vim_client.VimClient()
|
||||
service_plugins = mock.Mock()
|
||||
with mock.patch.object(manager.TackerManager, 'get_service_plugins',
|
||||
return_value=service_plugins):
|
||||
self.assertRaises(nfvo.VimDefaultNameNotDefined,
|
||||
vimclient.get_vim, None)
|
|
@ -48,10 +48,7 @@ class VimClient(object):
|
|||
'VIM id'))
|
||||
vim_name = cfg.CONF.nfvo_vim.default_vim
|
||||
if not vim_name:
|
||||
raise nfvo.VimDefaultIdException(
|
||||
message='Default VIM is not specified. Either specify a '
|
||||
'valid VIM in the VNF create or set default VIM in'
|
||||
' tacker.conf')
|
||||
raise nfvo.VimDefaultNameNotDefined()
|
||||
try:
|
||||
vim_info = nfvo_plugin.get_vim_by_name(context, vim_name)
|
||||
except Exception:
|
||||
|
|
Loading…
Reference in New Issue