RM8741
Route create was allowing routes to be created without doing sanity checking on gateway, cidr or subnet_id. This patch adds that and three relevant tests.
This commit is contained in:
@@ -50,6 +50,11 @@ def get_routes(context):
|
||||
def create_route(context, route):
|
||||
LOG.info("create_route for tenant %s" % context.tenant_id)
|
||||
route = route["route"]
|
||||
for key in ["gateway", "cidr", "subnet_id"]:
|
||||
if key not in route:
|
||||
raise exceptions.BadRequest(resource="routes",
|
||||
msg="%s is required" % key)
|
||||
|
||||
subnet_id = route["subnet_id"]
|
||||
with context.session.begin():
|
||||
subnet = db_api.subnet_find(context, id=subnet_id, scope=db_api.ONE)
|
||||
|
@@ -135,6 +135,38 @@ class TestQuarkCreateRoutes(test_quark_plugin.TestQuarkPlugin):
|
||||
self.plugin.create_route(self.context,
|
||||
dict(route=create_route))
|
||||
|
||||
def test_create_route_no_gateway_raises(self):
|
||||
subnet = dict(id=2, ip_policy=[], cidr="192.168.0.0/24")
|
||||
create_route = dict(id=1, cidr="192.168.0.0/24",
|
||||
subnet_id=subnet["id"])
|
||||
with self._stubs(create_route=create_route, find_routes=[],
|
||||
subnet=subnet):
|
||||
with self.assertRaises(
|
||||
exceptions.BadRequest):
|
||||
self.plugin.create_route(self.context,
|
||||
dict(route=create_route))
|
||||
|
||||
def test_create_route_no_cidr_raises(self):
|
||||
subnet = dict(id=2, ip_policy=[], cidr="192.168.0.0/24")
|
||||
create_route = dict(id=1, gateway="192.168.0.1",
|
||||
subnet_id=subnet["id"])
|
||||
with self._stubs(create_route=create_route, find_routes=[],
|
||||
subnet=subnet):
|
||||
with self.assertRaises(
|
||||
exceptions.BadRequest):
|
||||
self.plugin.create_route(self.context,
|
||||
dict(route=create_route))
|
||||
|
||||
def test_create_route_no_subnet_raises(self):
|
||||
subnet = dict(id=2, ip_policy=[], cidr="192.168.0.0/24")
|
||||
create_route = dict(id=1, cidr="192.168.0.0/24", gateway="192.168.0.1")
|
||||
with self._stubs(create_route=create_route, find_routes=[],
|
||||
subnet=subnet):
|
||||
with self.assertRaises(
|
||||
exceptions.BadRequest):
|
||||
self.plugin.create_route(self.context,
|
||||
dict(route=create_route))
|
||||
|
||||
|
||||
class TestQuarkDeleteRoutes(test_quark_plugin.TestQuarkPlugin):
|
||||
@contextlib.contextmanager
|
||||
|
Reference in New Issue
Block a user