From 7d867dd7edb429436f532531009e3809cf2648c5 Mon Sep 17 00:00:00 2001 From: gong yong sheng Date: Fri, 13 Nov 2015 10:21:49 +0800 Subject: [PATCH] Fix ServiceTypeNotFound and MGMTDriverNotSpecified These two exception classes are not coding correctly. and It seems our unit test does not cover them. So this patch adds two unit negative tests. Change-Id: Ia02fac7bc644d849fb3409c72cd279957e44a3e7 Cloese-bug: 1515838 --- tacker/db/vm/vm_db.py | 2 +- tacker/extensions/vnfm.py | 10 +++++++--- tacker/tests/unit/vm/test_plugin.py | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/tacker/db/vm/vm_db.py b/tacker/db/vm/vm_db.py index 55ee9f55e..7ea8050b1 100644 --- a/tacker/db/vm/vm_db.py +++ b/tacker/db/vm/vm_db.py @@ -395,7 +395,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin): raise vnfm.MGMTDriverNotSpecified() if (not attributes.is_attr_set(service_types)): LOG.debug(_('service types unspecified')) - raise vnfm.SeviceTypesNotSpecified() + raise vnfm.ServiceTypesNotSpecified() with context.session.begin(subtransactions=True): template_id = str(uuid.uuid4()) diff --git a/tacker/extensions/vnfm.py b/tacker/extensions/vnfm.py index a2e25b2c7..6fc1b0bbc 100644 --- a/tacker/extensions/vnfm.py +++ b/tacker/extensions/vnfm.py @@ -30,11 +30,15 @@ LOG = logging.getLogger(__name__) class InfraDriverNotSpecified(exceptions.InvalidInput): - message = _('infra driver is not speicfied') + message = _('infra driver is not specified') + + +class MGMTDriverNotSpecified(exceptions.InvalidInput): + message = _('mgmt driver is not specified') class ServiceTypesNotSpecified(exceptions.InvalidInput): - message = _('service types are not speicfied') + message = _('service types are not specified') class DeviceTemplateInUse(exceptions.InUse): @@ -69,7 +73,7 @@ class DeviceTemplateNotFound(exceptions.NotFound): message = _('device template %(device_tempalte_id)s could not be found') -class SeviceTypeNotFound(exceptions.NotFound): +class ServiceTypeNotFound(exceptions.NotFound): message = _('service type %(service_type_id)s could not be found') diff --git a/tacker/tests/unit/vm/test_plugin.py b/tacker/tests/unit/vm/test_plugin.py index 36288a61b..d7d27fd86 100644 --- a/tacker/tests/unit/vm/test_plugin.py +++ b/tacker/tests/unit/vm/test_plugin.py @@ -18,6 +18,7 @@ import uuid from tacker import context from tacker.db.vm import vm_db +from tacker.extensions import vnfm from tacker.tests.unit.db import base as db_base from tacker.tests.unit.db import utils from tacker.vm import plugin @@ -116,6 +117,20 @@ class TestVNFMPlugin(db_base.SqlTestCase): device_template= mock.ANY) + def test_create_vnfd_no_service_types(self): + vnfd_obj = utils.get_dummy_vnfd_obj() + vnfd_obj['vnfd'].pop('service_types') + self.assertRaises(vnfm.ServiceTypesNotSpecified, + self.vnfm_plugin.create_vnfd, + self.context, vnfd_obj) + + def test_create_vnfd_no_mgmt_driver(self): + vnfd_obj = utils.get_dummy_vnfd_obj() + vnfd_obj['vnfd'].pop('mgmt_driver') + self.assertRaises(vnfm.MGMTDriverNotSpecified, + self.vnfm_plugin.create_vnfd, + self.context, vnfd_obj) + def test_create_vnf(self): self._insert_dummy_device_template() vnf_obj = utils.get_dummy_vnf_obj()