Service type validations should be done at specific driver
The API should not restrict the allowed service types. Each driver should validate and throw error for service types that are not supported by the driver Change-Id: Ibf43193dd7c69c6b6477642ac2720073f5884f02 Closes-bug: #1403394
This commit is contained in:
@@ -61,10 +61,6 @@ class PortNotFound(nexc.NotFound):
|
||||
message = _("Port %(port_id)s could not be found")
|
||||
|
||||
|
||||
# Service chain API supported Values
|
||||
sc_supported_type = [constants.LOADBALANCER, constants.FIREWALL]
|
||||
|
||||
|
||||
def _validate_str_list(data, valid_values=None):
|
||||
if not isinstance(data, list):
|
||||
msg = _("'%s' is not a list") % data
|
||||
@@ -104,7 +100,7 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||
'validate': {'type:string': None},
|
||||
'required_by_policy': True, 'is_visible': True},
|
||||
'service_type': {'allow_post': True, 'allow_put': False,
|
||||
'validate': {'type:values': sc_supported_type},
|
||||
'validate': {'type:string': None},
|
||||
'required': True, 'is_visible': True},
|
||||
'config': {'allow_post': True, 'allow_put': False,
|
||||
'validate': {'type:string': None},
|
||||
|
||||
@@ -25,5 +25,15 @@ class ServiceChainException(exceptions.NeutronException):
|
||||
pass
|
||||
|
||||
|
||||
class ServiceChainBadRequest(exceptions.BadRequest, ServiceChainException):
|
||||
"""Base for servicechain driver bad request exceptions returned to user."""
|
||||
pass
|
||||
|
||||
|
||||
class ServiceChainDeploymentError(ServiceChainException):
|
||||
message = _("Deployment not configured properly. See logs for details.")
|
||||
message = _("Deployment not configured properly. See logs for details.")
|
||||
|
||||
|
||||
class InvalidServiceTypeForReferenceDriver(ServiceChainBadRequest):
|
||||
message = _("The reference service chain driver only supports the services"
|
||||
" Loadbalancer and Firewall services in a Service Chain Spec")
|
||||
|
||||
@@ -27,6 +27,9 @@ from gbp.neutron.services.servicechain.common import exceptions as exc
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# Service chain API supported Values
|
||||
sc_supported_type = [pconst.LOADBALANCER, pconst.FIREWALL]
|
||||
|
||||
|
||||
class ServiceChainInstanceStack(model_base.BASEV2):
|
||||
"""ServiceChainInstance stacks owned by the servicechain driver."""
|
||||
@@ -46,7 +49,8 @@ class SimpleChainDriver(object):
|
||||
|
||||
@log.log
|
||||
def create_servicechain_node_precommit(self, context):
|
||||
pass
|
||||
if context.current['service_type'] not in sc_supported_type:
|
||||
raise exc.InvalidServiceTypeForReferenceDriver()
|
||||
|
||||
@log.log
|
||||
def create_servicechain_node_postcommit(self, context):
|
||||
|
||||
@@ -15,6 +15,7 @@ import contextlib
|
||||
import mock
|
||||
from neutron.openstack.common import jsonutils
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.plugins.common import constants
|
||||
import webob
|
||||
|
||||
from gbp.neutron.services.servicechain import config
|
||||
@@ -36,6 +37,20 @@ class SimpleChainDriverTestCase(
|
||||
|
||||
class TestServiceChainInstance(SimpleChainDriverTestCase):
|
||||
|
||||
def test_invalid_service_type_rejected(self):
|
||||
res = self.create_servicechain_node(
|
||||
service_type="test", config='{}',
|
||||
expected_res_status=webob.exc.HTTPBadRequest.code)
|
||||
self.assertEqual('InvalidServiceTypeForReferenceDriver',
|
||||
res['NeutronError']['type'])
|
||||
|
||||
def test_chain_node_create_success(self):
|
||||
res = self.create_servicechain_node(
|
||||
service_type=constants.FIREWALL, config='{}',
|
||||
expected_res_status=webob.exc.HTTPCreated.code)
|
||||
self.assertEqual(constants.FIREWALL,
|
||||
res['servicechain_node']['service_type'])
|
||||
|
||||
def test_chain_spec_update(self):
|
||||
template1 = '{"key1":"value1"}'
|
||||
scn = self.create_servicechain_node(config=template1)
|
||||
|
||||
Reference in New Issue
Block a user