def test_can_update_and_delete_non_default_routing_instance(self): project = Project('project-%s' % self.id()) self.api.project_create(project) vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project) self.api.virtual_network_create(vn) ri = RoutingInstance('ri-%s' % self.id(), parent_obj=vn) self.api.routing_instance_create(ri) ri.set_display_name('new-name-%s' % self.id()) self.api.routing_instance_update(ri) self.api.routing_instance_delete(id=ri.uuid)
def test_cannot_update_routing_instance_to_default(self): project = Project('project-%s' % self.id()) self.api.project_create(project) vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project) self.api.virtual_network_create(vn) ri = RoutingInstance('ri-%s' % self.id(), parent_obj=vn) self.api.routing_instance_create(ri) ri.set_routing_instance_is_default(True) msg = CANNOT_MODIFY_MSG % { 'resource_type': RoutingInstance.object_type.replace('_', ' ').title(), 'fq_name': ri.get_fq_name_str(), 'uuid': ri.uuid, } msg = r'^%s$' % msg.replace('(', r'\(').replace(')', r'\)') with self.assertRaisesRegex(RefsExistError, msg): self.api.routing_instance_update(ri)
def test_routing_instance_create(self): project = self._project_fetch_or_create(self.id()) vn = VirtualNetwork(name='vn-{}'.format(self.id()), parent_obj=project) try: uuid = self.api.virtual_network_create(vn) except RefsExistError: uuid = self.api.fq_name_to_id('virtual_network', vn.fq_name) vn.set_uuid(uuid) ri_name = 'default-routing-instance' ri_fq_name = ':'.join(vn.fq_name + [ri_name]) sci = ServiceChainInfo( service_chain_id=ri_fq_name, prefix=['20.0.0.0/24'], routing_instance=ri_name, service_chain_address='0.255.255.250', service_instance='default-domain:default-project:test_service', sc_head=True) sciv6 = ServiceChainInfo( service_chain_id=ri_fq_name, prefix=['1000::/16'], routing_instance=ri_name, service_chain_address='::0.255.255.252', service_instance='default-domain:default-project:test_service_v6', sc_head=False) static_route_entries = StaticRouteEntriesType(route=[ StaticRouteType(prefix='test', next_hop='10.100.100.100', route_target=['test-route-target'], community='') ]) default_ce_protocol = DefaultProtocolType( bgp=ProtocolBgpType(autonomous_system=42), ospf=ProtocolOspfType(area=1)) prop_map = { 'name': ri_name, 'annotations': {}, 'parent_obj': vn, 'parent_type': 'virtual-network', 'default_ce_protocol': default_ce_protocol, 'display_name': 'some_string', 'evpn_ipv6_service_chain_information': sciv6, 'evpn_service_chain_information': sci, 'ipv6_service_chain_information': sciv6, 'routing_instance_fabric_snat': False, 'routing_instance_has_pnf': False, 'routing_instance_is_default': False, 'service_chain_information': sci, 'static_route_entries': static_route_entries } obj = self.set_properties(RoutingInstance(), prop_map) self.assertSchemaObjCreateOrUpdate(obj)
def test_context_undo_fail_db_create_routing_instance(self): project = Project('project-%s' % self.id()) self.api.project_create(project) vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project) self.api.virtual_network_create(vn) mock_zk = self._api_server._db_conn._zk_db ri_name = 'ri-%s' % self.id() ri_fq_name = vn.fq_name + [ri_name] ri = RoutingInstance(ri_name, parent_obj=vn) ri.set_routing_instance_is_default(False) self.api.routing_instance_create(ri) # Make sure we have right zk path (ri_fq_name) ri_uuid, _ = mock_zk.get_fq_name_to_uuid_mapping( 'routing_instance', ri_fq_name) self.assertTrue(ri_uuid is not None) # Clean ri self.api.routing_instance_delete(id=ri_uuid) ri = RoutingInstance(ri_name, parent_obj=vn) ri.set_routing_instance_is_default(False) def stub(*args, **kwargs): return (False, (500, "Fake error")) with ExpectedException(HttpError): with test_common.flexmocks([(self._api_server._db_conn, 'dbe_create', stub)]): self.api.routing_instance_create(ri) # Check if uuid for ri got released during undo action # using same zk path parameters as above with ExpectedException(TypeError): mock_zk.get_fq_name_to_uuid_mapping('routing_instance', ri_fq_name)
def test_routing_instance_service_chain_info(self): project = Project('project-%s' % self.id()) self.api.project_create(project) vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project) self.api.virtual_network_create(vn) ri_name = 'ri-%s' % self.id() ri_fq_name = ':'.join(vn.fq_name + [ri_name]) sci = ServiceChainInfo( service_chain_id=ri_fq_name, prefix=['20.0.0.0/24'], routing_instance=ri_name, service_chain_address='0.255.255.250', service_instance='default-domain:default-project:test_service', sc_head=True) sciv6 = ServiceChainInfo( service_chain_id=ri_fq_name, prefix=['1000::/16'], routing_instance=ri_name, service_chain_address='::0.255.255.252', service_instance='default-domain:default-project:test_service_v6', sc_head=False) ri = RoutingInstance(name=ri_name, parent_obj=vn, service_chain_information=sci, ipv6_service_chain_information=sciv6, evpn_service_chain_information=sci, evpn_ipv6_service_chain_information=sciv6, routing_instance_is_default=False) uuid = self.api.routing_instance_create(ri) ri.set_uuid(uuid) ri_fq_name = vn.fq_name + [ri.name] ri = self.api.routing_instance_read(ri_fq_name) ri.set_display_name('new RI name') self.api.routing_instance_update(ri) updated_ri = self.api.routing_instance_read(id=ri.uuid) for attr in [ 'service_chain_information', 'ipv6_service_chain_information', 'evpn_service_chain_information', 'evpn_ipv6_service_chain_information' ]: self.assertEqual(getattr(ri, attr), getattr(updated_ri, attr))