Skip to content

Commit

Permalink
api-server: Do not allow to configure routes with duplicate prefixes
Browse files Browse the repository at this point in the history
Change-Id: Iecf6d3a934152db548615c2b9f157e0930cac3b8
Closes-Bug: #1546887
  • Loading branch information
sbalineni committed Mar 4, 2016
1 parent 9989ce0 commit 39bde43
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/config/api-server/tests/test_logical_router.py
Expand Up @@ -348,6 +348,39 @@ def test_lr_v6_subnets(self):
self._vnc_lib.domain_delete(id=domain.uuid)
#end

def test_route_table_prefixes(self):
rt = RouteTable("rt1")
routes = RouteTableType()
route1 = RouteType(prefix="1.1.1.1/0", next_hop="10.10.10.10", next_hop_type="ip-address")
route2 = RouteType(prefix="1.1.1.1/0", next_hop="20.20.20.20", next_hop_type="ip-address")
routes.add_route(route1)
routes.add_route(route2)
rt.set_routes(routes)
try:
self._vnc_lib.route_table_create(rt)
self.assertTrue(False, 'Create succeeded unexpectedly - duplicate prefixe routes')
except cfgm_common.exceptions.BadRequest as e:
pass

routes.delete_route(route2)
route2 = RouteType(prefix="1.1.1.2/0", next_hop="20.20.20.20", next_hop_type="ip-address")
routes.add_route(route2)
rt.set_routes(routes)
try:
self._vnc_lib.route_table_create(rt)
except:
self.assertTrue(False, 'Create failed')

routes.delete_route(route2)
route2 = RouteType(prefix="1.1.1.1/0", next_hop="20.20.20.20", next_hop_type="ip-address")
routes.add_route(route2)
rt.set_routes(routes)
try:
self._vnc_lib.route_table_update(rt)
self.assertTrue(False, 'Update succeeded unexpectedly - duplicate prefixe routes')
except cfgm_common.exceptions.BadRequest as e:
pass
#end test_route_table_prefixes

#end

Expand Down
2 changes: 2 additions & 0 deletions src/config/api-server/vnc_cfg_api_server.py
Expand Up @@ -1212,6 +1212,8 @@ def __init__(self, args_str=None):
vnc_cfg_types.LogicalInterfaceServer)
self.set_resource_class('physical-interface',
vnc_cfg_types.PhysicalInterfaceServer)
self.set_resource_class('route-table',
vnc_cfg_types.RouteTableServer)

self.set_resource_class('virtual-ip', vnc_cfg_types.VirtualIpServer)
self.set_resource_class('loadbalancer-healthmonitor',
Expand Down
27 changes: 27 additions & 0 deletions src/config/api-server/vnc_cfg_types.py
Expand Up @@ -1517,6 +1517,33 @@ def _check_vlan(cls, obj_dict, db_conn):

# end class LogicalInterfaceServer

class RouteTableServer(Resource, RouteTable):

@classmethod
def pre_dbe_create(cls, tenant_name, obj_dict, db_conn):
return cls._check_prefixes(obj_dict)
# end pre_dbe_create

@classmethod
def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn, **kwargs):
return cls._check_prefixes(obj_dict)
# end pre_dbe_update

@classmethod
def _check_prefixes(cls, obj_dict):
routes = obj_dict.get('routes') or {}
in_routes = routes.get("route") or []
in_prefixes = [r.get('prefix') for r in in_routes]
in_prefixes_set = set(in_prefixes)
if len(in_prefixes) != len(in_prefixes_set):
return (False, (400, 'duplicate prefixes not '
'allowed: %s' % obj_dict.get('uuid')))

return (True, "")
# end _check_prefixes

# end class RouteTableServer

class PhysicalInterfaceServer(Resource, PhysicalInterface):

@classmethod
Expand Down

0 comments on commit 39bde43

Please sign in to comment.