def test_bgp_router_update_with_invalid_4_byte_asn(self): gsc = self.api.global_system_config_read(GlobalSystemConfig().fq_name) # Enable 4 byte ASN flag in GSC gsc.enable_4byte_as = True self.api.global_system_config_update(gsc) rt_inst_obj = self.api.routing_instance_read(fq_name=[ 'default-domain', 'default-project', 'ip-fabric', '__default__' ]) bgp_router_params = BgpRouterParams(router_type='control-node', autonomous_system=64512, local_autonomous_system=64500) bgp_router_obj = BgpRouter(name='bgprouter1', parent_obj=rt_inst_obj, bgp_router_parameters=bgp_router_params) bgp_router_uuid = self.api.bgp_router_create(bgp_router_obj) # Read back the bgp_router object bgp_router_obj = self.api.bgp_router_read(id=bgp_router_uuid) # update asn numbers to invalid 4 byte value new_bgp_router_params = BgpRouterParams( router_type='control-node', autonomous_system=0x1FFFFFFFFF, local_autonomous_system=0x1FFFFFFFFF) bgp_router_obj.set_bgp_router_parameters(new_bgp_router_params) self.assertRaises(BadRequest, self.api.bgp_router_update, bgp_router_obj) # Now delete the bgp router object and disable 4 byte ASN flag self.api.bgp_router_delete(id=bgp_router_uuid) gsc.enable_4byte_as = False self.api.global_system_config_update(gsc)
def test_bgp_router_update_with_invalid_2_byte_asn(self): rt_inst_obj = self.api.routing_instance_read(fq_name=[ 'default-domain', 'default-project', 'ip-fabric', '__default__' ]) bgp_router_params = BgpRouterParams(router_type='control-node', autonomous_system=64512, local_autonomous_system=64500) bgp_router_obj = BgpRouter(name='bgprouter1', parent_obj=rt_inst_obj, bgp_router_parameters=bgp_router_params) bgp_router_uuid = self.api.bgp_router_create(bgp_router_obj) # Read back the bgp_router object bgp_router_obj = self.api.bgp_router_read(id=bgp_router_uuid) # update asn numbers to invalid 2 byte value new_bgp_router_params = BgpRouterParams( router_type='control-node', autonomous_system=0x1FFFF, local_autonomous_system=0x1FFFF) bgp_router_obj.set_bgp_router_parameters(new_bgp_router_params) self.assertRaises(BadRequest, self.api.bgp_router_update, bgp_router_obj) # Delete the bgp router self.api.bgp_router_delete(id=bgp_router_uuid)
def create_bgp_router(self, name, vendor, asn=None): ip_fabric_ri = self._vnc_lib.routing_instance_read( fq_name=['default-domain', 'default-project', 'ip-fabric', '__default__']) router = BgpRouter(name, parent_obj=ip_fabric_ri) params = BgpRouterParams() params.vendor = 'contrail' params.autonomous_system = asn router.set_bgp_router_parameters(params) self._vnc_lib.bgp_router_create(router) return router
def create_bgp_router(self, name, vendor, asn=None): ip_fabric_ri = self._vnc_lib.routing_instance_read( fq_name=['default-domain', 'default-project', 'ip-fabric', '__default__']) router = BgpRouter(name, parent_obj=ip_fabric_ri) params = BgpRouterParams() params.vendor = 'contrail' params.autonomous_system = asn router.set_bgp_router_parameters(params) self._vnc_lib.bgp_router_create(router) return router
def test_control_node_zone(self): gsc = self.api.global_system_config_read(GlobalSystemConfig().fq_name) cnz = [] for i in range(2): cnz_name = "cnz-" + str(i) cnz.append(ControlNodeZone(name=cnz_name, parent_obj=gsc)) self.api.control_node_zone_create(cnz[i]) rt_inst_obj = self.api.routing_instance_read(fq_name=[ 'default-domain', 'default-project', 'ip-fabric', '__default__' ]) bgp_router_params = BgpRouterParams(router_type='control-node') # create bgp_rotuer with two control-node-zones bgp_router_obj = BgpRouter(name='bgprouter', parent_obj=rt_inst_obj, bgp_router_parameters=bgp_router_params) bgp_router_obj.add_control_node_zone(cnz[0]) bgp_router_obj.add_control_node_zone(cnz[1]) try: self.api.bgp_router_create(bgp_router_obj) except BadRequest: pass # update bgp_router with two control-node-zones bgp_router_obj = BgpRouter(name='bgprouter', parent_obj=rt_inst_obj, bgp_router_parameters=bgp_router_params) bgp_router_uuid = self.api.bgp_router_create(bgp_router_obj) bgp_router_obj.add_control_node_zone(cnz[0]) bgp_router_obj.add_control_node_zone(cnz[1]) try: self.api.bgp_router_update(bgp_router_obj) except BadRequest: self.api.bgp_router_delete(id=bgp_router_uuid) # update bgp_router with same control-node-zone bgp_router_obj = BgpRouter(name='bgprouter', parent_obj=rt_inst_obj, bgp_router_parameters=bgp_router_params) bgp_router_obj.add_control_node_zone(cnz[0]) bgp_router_uuid = self.api.bgp_router_create(bgp_router_obj) bgp_router_obj = self.api.bgp_router_read(id=bgp_router_uuid) bgp_router_obj.add_control_node_zone(cnz[0]) self.api.bgp_router_update(bgp_router_obj) # update bgp_router with new control-node-zone bgp_router_obj.add_control_node_zone(cnz[1]) try: self.api.bgp_router_update(bgp_router_obj) except BadRequest: self.api.bgp_router_delete(id=bgp_router_uuid) for i in range(2): self.api.control_node_zone_delete(fq_name=cnz[i].fq_name)
def test_bgp_router_create_with_invalid_2_byte_local_asn(self): rt_inst_obj = self.api.routing_instance_read(fq_name=[ 'default-domain', 'default-project', 'ip-fabric', '__default__' ]) bgp_router_params = BgpRouterParams(router_type='control-node', autonomous_system=64512, local_autonomous_system=700000) bgp_router_obj = BgpRouter(name='bgprouter1', parent_obj=rt_inst_obj, bgp_router_parameters=bgp_router_params) self.assertRaises(BadRequest, self.api.bgp_router_create, bgp_router_obj)
def test_bgp_router_update_with_hold_time(self): # Create gbp router object rt_inst_obj = self.api.routing_instance_read(fq_name=[ 'default-domain', 'default-project', 'ip-fabric', '__default__' ]) bgp_router_params = BgpRouterParams(router_type='control-node') bgp_router_obj = BgpRouter(name='bgprouter', parent_obj=rt_inst_obj, bgp_router_parameters=bgp_router_params) bgp_router_uuid = self.api.bgp_router_create(bgp_router_obj) for test in self.hold_time_test_cases: # Update hold time with valid and invalid values bgp_router_params = BgpRouterParams(router_type='control-node', hold_time=test['hold_time']) bgp_router_obj.set_bgp_router_parameters(bgp_router_params) if test['should_pass']: self.api.bgp_router_update(bgp_router_obj) else: self.assertRaises(BadRequest, self.api.bgp_router_update, bgp_router_obj) # Finally, delete the bgp router object self.api.bgp_router_delete(id=bgp_router_uuid)
def test_bgp_router_create_with_hold_time(self): rt_inst_obj = self.api.routing_instance_read(fq_name=[ 'default-domain', 'default-project', 'ip-fabric', '__default__' ]) for test in self.hold_time_test_cases: bgp_router_params = BgpRouterParams(router_type='control-node', hold_time=test['hold_time']) bgp_router_obj = BgpRouter(name='bgprouter', parent_obj=rt_inst_obj, bgp_router_parameters=bgp_router_params) if test['should_pass']: # Create gbp router object with proper hold time bgp_router_uuid = self.api.bgp_router_create(bgp_router_obj) self.api.bgp_router_delete(id=bgp_router_uuid) else: # Try to create gbp router object with improper hold time # and expect error self.assertRaises(BadRequest, self.api.bgp_router_create, bgp_router_obj)
def create_router(self, name, mgmt_ip, vendor='juniper', product='mx', ignore_pr=False, role=None, cluster_id=0, ignore_bgp=False, fabric=None): bgp_router, pr = None, None if not ignore_bgp: bgp_router = BgpRouter(name, display_name=name + "-bgp", parent_obj=self._get_ip_fabric_ri_obj()) params = BgpRouterParams() params.address = mgmt_ip params.identifier = mgmt_ip params.address_families = AddressFamilies( ['route-target', 'inet-vpn', 'e-vpn', 'inet6-vpn']) params.autonomous_system = randint(0, 64512) params.cluster_id = cluster_id bgp_router.set_bgp_router_parameters(params) self._vnc_lib.bgp_router_create(bgp_router) gevent.sleep(1) if not ignore_pr: pr = PhysicalRouter(name, display_name=name) pr.physical_router_management_ip = mgmt_ip pr.physical_router_vendor_name = vendor pr.physical_router_product_name = product pr.physical_router_vnc_managed = True if role: pr.physical_router_role = role uc = UserCredentials('user', 'pw') pr.set_physical_router_user_credentials(uc) pr.set_fabric(fabric) if not ignore_bgp: pr.set_bgp_router(bgp_router) self._vnc_lib.physical_router_create(pr) gevent.sleep(1) return bgp_router, pr
def test_bgp_router_create_with_invalid_4_byte_asn(self): gsc = self.api.global_system_config_read(GlobalSystemConfig().fq_name) # Enable 4 byte ASN flag in GSC gsc.enable_4byte_as = True self.api.global_system_config_update(gsc) rt_inst_obj = self.api.routing_instance_read(fq_name=[ 'default-domain', 'default-project', 'ip-fabric', '__default__' ]) bgp_router_params = BgpRouterParams(router_type='control-node', autonomous_system=0x1FFFFFFFF, local_autonomous_system=700000) bgp_router_obj = BgpRouter(name='bgprouter1', parent_obj=rt_inst_obj, bgp_router_parameters=bgp_router_params) self.assertRaises(BadRequest, self.api.bgp_router_create, bgp_router_obj) # Now disable 4 byte ASN flag gsc.enable_4byte_as = False self.api.global_system_config_update(gsc)
def create_router(self, name, mgmt_ip, vendor='juniper', product='mx', ignore_pr=False, role=None, cluster_id=0, ignore_bgp=False, fabric=None): bgp_router, pr = None, None if not ignore_bgp: bgp_router = BgpRouter(name, display_name=name+"-bgp", parent_obj=self._get_ip_fabric_ri_obj()) params = BgpRouterParams() params.address = mgmt_ip params.identifier = mgmt_ip params.address_families = AddressFamilies(['route-target', 'inet-vpn', 'e-vpn', 'inet6-vpn']) params.autonomous_system = randint(0, 64512) params.cluster_id = cluster_id bgp_router.set_bgp_router_parameters(params) self._vnc_lib.bgp_router_create(bgp_router) gevent.sleep(1) if not ignore_pr: pr = PhysicalRouter(name, display_name=name) pr.physical_router_management_ip = mgmt_ip pr.physical_router_vendor_name = vendor pr.physical_router_product_name = product pr.physical_router_vnc_managed = True if role: pr.physical_router_role = role uc = UserCredentials('user', 'pw') pr.set_physical_router_user_credentials(uc) pr.set_fabric(fabric) if not ignore_bgp: pr.set_bgp_router(bgp_router) self._vnc_lib.physical_router_create(pr) gevent.sleep(1) return bgp_router, pr