diff --git a/tacker/extensions/nfvo.py b/tacker/extensions/nfvo.py index 8e606e8cc..557d65098 100644 --- a/tacker/extensions/nfvo.py +++ b/tacker/extensions/nfvo.py @@ -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 " diff --git a/tacker/tests/unit/vm/test_vim_client.py b/tacker/tests/unit/vm/test_vim_client.py new file mode 100644 index 000000000..eca68e7da --- /dev/null +++ b/tacker/tests/unit/vm/test_vim_client.py @@ -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) diff --git a/tacker/vm/vim_client.py b/tacker/vm/vim_client.py index a350dbabc..81c460ac1 100644 --- a/tacker/vm/vim_client.py +++ b/tacker/vm/vim_client.py @@ -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: