def test_create_segment_allocation_ranges_same_overlap_fails(self): """Assert same segments with overlapping ids are disallowed.""" sa_range_dict = self._make_segment_allocation_range_dict() sa_range_request = {"segment_allocation_range": sa_range_dict} # create initial segment with range 10-15 sa_range_dict["first_id"] = 10 sa_range_dict["last_id"] = 15 sa_ranges_api.create_segment_allocation_range(self.context, sa_range_request) invalid_ranges = [ (10, 15), # same range (5, 10), # collides at start (15, 20), # collides at end (8, 12), # overlaps from start (12, 17), # overlaps from end (9, 16), # superset (11, 14), # subset ] for first_id, last_id in invalid_ranges: sa_range_dict["first_id"] = first_id sa_range_dict["last_id"] = last_id self.assertRaises( q_exc.InvalidSegmentAllocationRange, sa_ranges_api.create_segment_allocation_range, self.context, sa_range_request, )
def test_create_segment_allocation_ranges_same_overlap_fails(self): """Assert same segments with overlapping ids are disallowed.""" sa_range_dict = self._make_segment_allocation_range_dict() sa_range_request = {"segment_allocation_range": sa_range_dict} # create initial segment with range 10-15 sa_range_dict['first_id'] = 10 sa_range_dict['last_id'] = 15 sa_ranges_api.create_segment_allocation_range(self.context, sa_range_request) invalid_ranges = [ (10, 15), # same range (5, 10), # collides at start (15, 20), # collides at end (8, 12), # overlaps from start (12, 17), # overlaps from end (9, 16), # superset (11, 14) # subset ] for first_id, last_id in invalid_ranges: sa_range_dict['first_id'] = first_id sa_range_dict['last_id'] = last_id self.assertRaises(quark_exceptions.InvalidSegmentAllocationRange, sa_ranges_api.create_segment_allocation_range, self.context, sa_range_request)
def test_create_segment_allocation_ranges(self): """Assert segments with same type/id are allowed.""" sa_range_dict = self._make_segment_allocation_range_dict() sa_range_request = {"segment_allocation_range": sa_range_dict} valid_ranges = [ (10, 15), (5, 9), (16, 20), ] for first_id, last_id in valid_ranges: sa_range_dict['first_id'] = first_id sa_range_dict['last_id'] = last_id sa_range = sa_ranges_api.create_segment_allocation_range( self.context, sa_range_request) # Find all ranges added in the db sa_range_models = db_api.segment_allocation_range_find( self.context, id=sa_range['id'], scope=db_api.ALL) # Assert we actually added the range to the db with correct # values and returned the correct response. self.assertEqual(len(sa_range_models), 1) self.assertEqual(self._sa_range_to_dict(sa_range_models[0]), sa_range)
def test_create_segment_allocation_ranges_diff_overlap_allowed(self): """Assert different segments with overlapping ids are allowed.""" sa_range_dict = self._make_segment_allocation_range_dict() sa_range_request = {"segment_allocation_range": sa_range_dict} segment_ids = [ 'segment1', 'segment2', 'segment3' ] for segment_id in segment_ids: sa_range_dict['first_id'] = 1 sa_range_dict['last_id'] = 5 sa_range_dict['segment_id'] = segment_id sa_range = sa_ranges_api.create_segment_allocation_range( self.context, sa_range_request) # Find all ranges added in the db sa_range_models = db_api.segment_allocation_range_find( self.context, id=sa_range['id'], scope=db_api.ALL) # Assert we actually added the range to the db with correct # values and returned the correct response. self.assertEqual(len(sa_range_models), 1) self.assertEqual(self._sa_range_to_dict(sa_range_models[0]), sa_range)
def test_create_segment_allocation_range_creates_allocations(self): """Assert created segments populate the allocation table.""" sa_range_dict = self._make_segment_allocation_range_dict() sa_range_request = {"segment_allocation_range": sa_range_dict} sa_range = sa_ranges_api.create_segment_allocation_range(self.context, sa_range_request) allocs = db_api.segment_allocation_find(self.context, segment_allocation_range_id=sa_range["id"]).all() self.assertEqual(len(allocs), sa_range["size"])
def test_create_segment_allocation_range_creates_allocations(self): """Assert created segments populate the allocation table.""" sa_range_dict = self._make_segment_allocation_range_dict() sa_range_request = {"segment_allocation_range": sa_range_dict} sa_range = sa_ranges_api.create_segment_allocation_range( self.context, sa_range_request) allocs = db_api.segment_allocation_find( self.context, segment_allocation_range_id=sa_range['id']).all() self.assertEqual(len(allocs), sa_range['size'])
def test_create_segment_allocation_range(self): """Assert a range is created.""" # Create a segment allocation range sa_range_dict = self._make_segment_allocation_range_dict() sa_range_request = {"segment_allocation_range": sa_range_dict} sa_range = sa_ranges_api.create_segment_allocation_range(self.context, sa_range_request) # Find all ranges added in the db sa_range_models = db_api.segment_allocation_range_find(self.context, scope=db_api.ALL) # ensure non-admins can fetch them as well sa_range_models = db_api.segment_allocation_range_find(self.old_context, scope=db_api.ALL) # Assert we actually added the range to the db with correct # values and returned the correct response. self.assertEqual(len(sa_range_models), 1) self.assertEqual(self._sa_range_to_dict(sa_range_models[0]), sa_range)
def test_create_segment_allocation_range(self): """Assert a range is created.""" # Create a segment allocation range sa_range_dict = self._make_segment_allocation_range_dict() sa_range_request = {"segment_allocation_range": sa_range_dict} sa_range = sa_ranges_api.create_segment_allocation_range( self.context, sa_range_request) # Find all ranges added in the db sa_range_models = db_api.segment_allocation_range_find( self.context, scope=db_api.ALL) # ensure non-admins can fetch them as well sa_range_models = db_api.segment_allocation_range_find( self.old_context, scope=db_api.ALL) # Assert we actually added the range to the db with correct # values and returned the correct response. self.assertEqual(len(sa_range_models), 1) self.assertEqual(self._sa_range_to_dict(sa_range_models[0]), sa_range)
def test_create_segment_allocation_ranges_diff_overlap_allowed(self): """Assert different segments with overlapping ids are allowed.""" sa_range_dict = self._make_segment_allocation_range_dict() sa_range_request = {"segment_allocation_range": sa_range_dict} segment_ids = ['segment1', 'segment2', 'segment3'] for segment_id in segment_ids: sa_range_dict['first_id'] = 1 sa_range_dict['last_id'] = 5 sa_range_dict['segment_id'] = segment_id sa_range = sa_ranges_api.create_segment_allocation_range( self.context, sa_range_request) # Find all ranges added in the db sa_range_models = db_api.segment_allocation_range_find( self.context, id=sa_range['id'], scope=db_api.ALL) # Assert we actually added the range to the db with correct # values and returned the correct response. self.assertEqual(len(sa_range_models), 1) self.assertEqual(self._sa_range_to_dict(sa_range_models[0]), sa_range)
def create_segment_allocation_range(self, context, sa_range): self._fix_missing_tenant_id( context, sa_range["segment_allocation_range"]) return segment_allocation_ranges.create_segment_allocation_range( context, sa_range)
def create_segment_allocation_range(self, context, sa_range): self._fix_missing_tenant_id(context, sa_range, "segment_allocation_range") return segment_allocation_ranges.create_segment_allocation_range( context, sa_range)