def test_xn_declare_then_delete_xs(self): # xn needs an xs first exchange_space = ExchangeSpace(name="bozo") esid = self.ems.create_exchange_space(exchange_space, self.org_id) exchange_name = ExchangeName(name='shnoz', xn_type="XN_PROCESS") enid = self.ems.declare_exchange_name(exchange_name, esid) # delete the XS self.ems.delete_exchange_space(esid) # no longer should have assoc from XS to XN xnlist, _ = self.rr.find_subjects(RT.ExchangeSpace, PRED.hasExchangeName, enid, id_only=True) self.assertEquals(len(xnlist), 0) # cleanup: delete the XN (assoc already removed, so we reach into the implementation here) # @TODO: reaching into ex manager for transport is clunky self.rr.delete(enid) xs = exchange.ExchangeSpace( self.container.ex_manager, self.container.ex_manager._priviledged_transport, exchange_space.name) xn = exchange.ExchangeName( self.container.ex_manager, self.container.ex_manager._priviledged_transport, exchange_name.name, xs) self.container.ex_manager.delete_xn(xn, use_ems=False)
def undeclare_exchange_name(self, canonical_name='', exchange_space_id=''): """Remove an exhange nane resource @param canonical_name str @param exchange_space_id str @retval success bool @throws NotFound object with specified id does not exist """ # @TODO: currently we are using the exchange_name's id as the canonical name # and exchange_space_id is unused? exchange_name = self.container.resource_registry.read(canonical_name) if not exchange_name: raise NotFound("Exchange Name with id %s does not exist" % canonical_name) exchange_name_id = exchange_name._id # yes, this should be same, but let's make it look cleaner # get associated XS first exchange_space_list, assoc_list = self.container.resource_registry.find_subjects( RT.ExchangeSpace, PRED.hasExchangeName, exchange_name_id) if not len(exchange_space_list) == 1: raise NotFound( "Associated Exchange Space to Exchange Name %s does not exist" % exchange_name_id) exchange_space = exchange_space_list[0] # remove association between itself and XS _, assocs = self.container.resource_registry.find_subjects( RT.ExchangeSpace, PRED.hasExchangeName, exchange_name_id, id_only=True) for assoc in assocs: self.container.resource_registry.delete_association(assoc._id) # remove XN self.container.resource_registry.delete(exchange_name_id) # call container API xs = exchange.ExchangeSpace( self.container.ex_manager, self.container.ex_manager._priviledged_transport, exchange_space.name) xn = exchange.ExchangeName( self.container.ex_manager, self.container.ex_manager._priviledged_transport, exchange_name.name, xs) # type doesn't matter here self.container.ex_manager.delete_xn(xn, use_ems=False)