def add_vrouter(self): gsc_obj = self._global_system_config_obj if self._args.ip_fabric_subnet: ip_subnet, mask = self._args.ip_fabric_subnet.split('/') so = SubnetType(ip_subnet, int(mask)) sl = gsc_obj.get_ip_fabric_subnets() if sl is None: gsc_obj.set_ip_fabric_subnets(SubnetListType([so])) self._vnc_lib.global_system_config_update(gsc_obj) elif so not in sl.subnet: sl.subnet.append(so) gsc_obj.set_ip_fabric_subnets(sl) self._vnc_lib.global_system_config_update(gsc_obj) vrouter_obj = VirtualRouter( self._args.host_name, gsc_obj, virtual_router_ip_address=self._args.host_ip) vrouter_exists = True try: vrouter_obj = self._vnc_lib.virtual_router_read( fq_name=vrouter_obj.get_fq_name()) except NoIdError: vrouter_exists = False if self._args.sub_cluster_name: sub_cluster_obj = SubCluster(self._args.sub_cluster_name) try: sub_cluster_obj = self._vnc_lib.sub_cluster_read( fq_name=sub_cluster_obj.get_fq_name()) except NoIdError: raise RuntimeError("Sub cluster has to be provisioned first") vrouter_obj.add_sub_cluster(sub_cluster_obj) # Configure router type if self._args.router_type: vrouter_obj.set_virtual_router_type(self._args.router_type) if self._args.dpdk_enabled: vrouter_obj.set_virtual_router_dpdk_enabled(True) else: vrouter_obj.set_virtual_router_dpdk_enabled(False) # Configure sirov physical networks if self._args.sriov_physnets: vrouter_obj.set_virtual_router_sriov_physical_networks( self._args.sriov_physnets) if vrouter_exists: self.vrouter_fq_name = vrouter_obj.get_fq_name() self._vnc_lib.virtual_router_update(vrouter_obj) else: try: self.vrouter_fq_name = vrouter_obj.get_fq_name() self._vnc_lib.virtual_router_create(vrouter_obj) except RefsExistError: print("Already created!")
def test_cluster_id_automatically_assigned(self): sc = SubCluster('sc-%s' % self.id()) self.api.sub_cluster_create(sc) sc = self.api.sub_cluster_read(id=sc.uuid) self.assertIsNotNone(sc.get_sub_cluster_id()) zk_db = self._api_server._db_conn._zk_db self.assertEqual( zk_db._get_sub_cluster_from_id(sc.get_sub_cluster_id()), sc.get_fq_name_str(), )
def test_sub_cluster_id_deallocated_on_delete(self): sc = SubCluster('sc-%s' % self.id()) self.api.sub_cluster_create(sc) sc = self.api.sub_cluster_read(id=sc.uuid) self.api.sub_cluster_delete(id=sc.uuid) zk_db = self._api_server._db_conn._zk_db self.assertNotEqual( zk_db._get_sub_cluster_from_id(sc.get_sub_cluster_id()), sc.get_fq_name_str(), )
def test_manually_allocate_sub_cluster_id(self): sub_cluster_id = self._id_range.pop() sc = SubCluster('sc-%s' % self.id(), sub_cluster_id=sub_cluster_id) self.api.sub_cluster_create(sc) sc = self.api.sub_cluster_read(id=sc.uuid) self.assertEqual(sc.get_sub_cluster_id(), sub_cluster_id) zk_db = self._api_server._db_conn._zk_db self.assertEqual( zk_db._get_sub_cluster_from_id(sub_cluster_id), sc.get_fq_name_str(), )
def test_sub_cluster_id_range(self): sub_cluster_id = 1 << 32 # more than 4 bytes cluster ID if self._global_asn > 0xFFFF: sub_cluster_id = 1 << 16 # more than 2 bytes cluster ID sc = SubCluster('sc-%s' % self.id(), sub_cluster_id=sub_cluster_id) with mock.patch.object(self._api_server, '_validate_simple_type', return_value=sub_cluster_id): self.assertRaises(BadRequest, self.api.sub_cluster_create, sc) sc = SubCluster('sc-%s' % self.id(), sub_cluster_id=0) with mock.patch.object(self._api_server, '_validate_simple_type', return_value=0): self.assertRaises(BadRequest, self.api.sub_cluster_create, sc)
def test_change_global_asn_from_2_to_4_bytes(self): sc = SubCluster('sc-%s' % self.id()) self.api.sub_cluster_create(sc) sc = self.api.sub_cluster_read(id=sc.uuid) allocated_id = sc.get_sub_cluster_id() self.assertIsNotNone(allocated_id) self.assertLess(allocated_id, 1 << 16) self._gsc.set_autonomous_system(ASN_4_BYTES) self._gsc.enable_4byte_as = True self.api.global_system_config_update(self._gsc) sc = self.api.sub_cluster_read(id=sc.uuid) self.assertEqual(sc.get_sub_cluster_id(), allocated_id) self._gsc.set_autonomous_system(ASN_2_BYTES) self._gsc.enable_4byte_as = False self.api.global_system_config_update(self._gsc)
def test_ibgp_auto_mesh_sub(self): config_db.GlobalSystemConfigST.ibgp_auto_mesh = True self.assertEqual(config_db.GlobalSystemConfigST.get_ibgp_auto_mesh(), True, "ibgp_auto_mesh_toggle_test") # create subcluster sub_cluster_obj = SubCluster('test-host', sub_cluster_asn=64513) self._vnc_lib.sub_cluster_create(sub_cluster_obj) sub_cluster_obj = self._vnc_lib.sub_cluster_read( fq_name=sub_cluster_obj.get_fq_name()) # create router1 r1_name = self.id() + 'router1' router1 = self.create_bgp_router_sub( r1_name, 'contrail', asn=64513, router_type='external-control-node', sub_cluster=sub_cluster_obj) # create router2 r2_name = self.id() + 'router2' router2 = self.create_bgp_router_sub( r2_name, 'contrail', asn=64513, router_type='external-control-node', sub_cluster=sub_cluster_obj) # create router3 r3_name = self.id() + 'router3' router3 = self.create_bgp_router(r3_name, 'contrail') # create router4 r4_name = self.id() + 'router4' router4 = self.create_bgp_router(r4_name, 'contrail') self.check_bgp_peering(router3, router4, 1) self.check_bgp_peering(router1, router2, 1) self._vnc_lib.bgp_router_delete(id=router1.uuid) self._vnc_lib.bgp_router_delete(id=router2.uuid) self._vnc_lib.bgp_router_delete(id=router3.uuid) self._vnc_lib.bgp_router_delete(id=router4.uuid) self._vnc_lib.sub_cluster_delete(id=sub_cluster_obj.uuid) gevent.sleep(1)
def test_change_global_asn_from_2_to_4_bytes_with_to_high_id(self): sub_cluster_id = self._id_range.pop() self.assertGreaterEqual(sub_cluster_id, 1 << 16) sc = SubCluster('sc-%s' % self.id(), sub_cluster_id=sub_cluster_id) self.api.sub_cluster_create(sc) self._gsc.set_autonomous_system(ASN_4_BYTES) self._gsc.enable_4byte_as = True self.assertRaises(BadRequest, self.api.global_system_config_update, self._gsc) self.api.sub_cluster_delete(id=sc.uuid) self._gsc.set_autonomous_system(ASN_4_BYTES) self._gsc.enable_4byte_as = True self.api.global_system_config_update(self._gsc) sc = SubCluster('sc-%s' % self.id(), sub_cluster_id=sub_cluster_id) self.assertRaises(BadRequest, self.api.sub_cluster_create, sc) self._gsc.set_autonomous_system(ASN_2_BYTES) self._gsc.enable_4byte_as = False self.api.global_system_config_update(self._gsc) self.api.sub_cluster_create(sc)
def test_ibgp_auto_mesh_sub(self): config_db.GlobalSystemConfigST.ibgp_auto_mesh = True self.assertEqual(config_db.GlobalSystemConfigST.get_ibgp_auto_mesh(), True, "ibgp_auto_mesh_toggle_test") # create subcluster sub_cluster_obj = SubCluster('test-host', sub_cluster_asn=64513) self._vnc_lib.sub_cluster_create(sub_cluster_obj) sub_cluster_obj = self._vnc_lib.sub_cluster_read( fq_name=sub_cluster_obj.get_fq_name()) # create router1 r1_name = self.id() + 'router1' router1 = self.create_bgp_router_sub(r1_name, 'contrail', asn=64513, router_type='external-control-node', sub_cluster=sub_cluster_obj) # create router2 r2_name = self.id() + 'router2' router2 = self.create_bgp_router_sub(r2_name, 'contrail', asn=64513, router_type='external-control-node', sub_cluster=sub_cluster_obj) # create router3 r3_name = self.id() + 'router3' router3 = self.create_bgp_router(r3_name, 'contrail') # create router4 r4_name = self.id() + 'router4' router4 = self.create_bgp_router(r4_name, 'contrail') self.check_bgp_peering(router3, router4, 1) self.check_bgp_peering(router1, router2, 1) self._vnc_lib.bgp_router_delete(id=router1.uuid) self._vnc_lib.bgp_router_delete(id=router2.uuid) self._vnc_lib.bgp_router_delete(id=router3.uuid) self._vnc_lib.bgp_router_delete(id=router4.uuid) self._vnc_lib.sub_cluster_delete(id=sub_cluster_obj.uuid) gevent.sleep(1)
def test_cannot_use_allocated_sub_cluster_id(self): # automatically allocated sc1 = SubCluster('sc1-%s' % self.id()) self.api.sub_cluster_create(sc1) sc1 = self.api.sub_cluster_read(id=sc1.uuid) sc2 = SubCluster( 'sc2-%s' % self.id(), sub_cluster_id=sc1.get_sub_cluster_id()) self.assertRaises(BadRequest, self.api.sub_cluster_create, sc2) # or manually allocated sc3 = SubCluster( 'sc3-%s' % self.id(), sub_cluster_id=self._id_range.pop()) self.api.sub_cluster_create(sc3) sc4 = SubCluster( 'sc4-%s' % self.id(), sub_cluster_id=sc3.get_sub_cluster_id()) self.assertRaises(BadRequest, self.api.sub_cluster_create, sc4)
def test_update_allocated_id(self): sc = SubCluster('sc-%s' % self.id()) self.api.sub_cluster_create(sc) sc = self.api.sub_cluster_read(id=sc.uuid) allocated_id = sc.get_sub_cluster_id() self.assertIsNotNone(allocated_id) sub_cluster_id = self._id_range.pop() self.assertNotEqual(allocated_id, sub_cluster_id) sc.set_sub_cluster_id(sub_cluster_id) self.api.sub_cluster_update(sc) zk_db = self._api_server._db_conn._zk_db self.assertEqual( zk_db._get_sub_cluster_from_id(sub_cluster_id), sc.get_fq_name_str(), ) self.assertIsNone(zk_db._get_sub_cluster_from_id(allocated_id))
def test_cannot_update_asn(self): sc = SubCluster('sc-%s' % self.id()) self.api.sub_cluster_create(sc) sc.set_sub_cluster_asn(43) self.assertRaises(BadRequest, self.api.sub_cluster_update, sc)
def test_first_allocated_id_is_one(self): sc = SubCluster('sc-%s' % self.id()) self.api.sub_cluster_create(sc) sc = self.api.sub_cluster_read(id=sc.uuid) self.assertEqual(sc.get_sub_cluster_id(), 1)