def post_collection(self, helper, collection_id, document_data, buffer_mode_param=None, empty_collection=False): """ Ingest the collection after checking preconditions """ buffer_mode = ConfigdocsHelper.get_buffer_mode(buffer_mode_param) if helper.is_buffer_valid_for_bucket(collection_id, buffer_mode): buffer_revision = helper.add_collection(collection_id, document_data) if not (empty_collection or helper.is_collection_in_buffer( collection_id)): # raise an error if adding the collection resulted in no new # revision (meaning it was unchanged) and we're not explicitly # clearing the collection raise ApiError( title=('Collection {} not added to Shipyard ' 'buffer'.format(collection_id)), description='Collection created no new revision', status=falcon.HTTP_400, error_list=[{ 'message': ('The collection {} added no new revision, and has ' 'been rejected as invalid input. This likely ' 'means that the collection already exists and ' 'was reloaded with the same contents'.format( collection_id)) }], retry=False, ) else: return helper.get_deckhand_validation_status(buffer_revision) else: raise ApiError( title='Invalid collection specified for buffer', description='Buffermode : {}'.format(buffer_mode.value), status=falcon.HTTP_409, error_list=[{ 'message': ('Buffer is either not empty or the ' 'collection already exists in buffer. ' 'Setting a different buffermode may ' 'provide the desired functionality') }], retry=False, )
def post_collection(self, helper, collection_id, document_data, buffer_mode_param=None): """ Ingest the collection after checking preconditions """ buffer_mode = ConfigdocsHelper.get_buffer_mode(buffer_mode_param) if helper.is_buffer_valid_for_bucket(collection_id, buffer_mode): buffer_revision = helper.add_collection(collection_id, document_data) if helper.is_collection_in_buffer(collection_id): return helper.get_deckhand_validation_status(buffer_revision) else: raise ApiError( title=('Collection {} not added to Shipyard ' 'buffer'.format(collection_id)), description='Collection empty or resulted in no revision', status=falcon.HTTP_400, error_list=[{ 'message': ('Empty collections are not supported. After ' 'processing, the collection {} added no new ' 'revision, and has been rejected as invalid ' 'input'.format(collection_id)) }], retry=False, ) else: raise ApiError( title='Invalid collection specified for buffer', description='Buffermode : {}'.format(buffer_mode.value), status=falcon.HTTP_409, error_list=[{ 'message': ('Buffer is either not empty or the ' 'collection already exists in buffer. ' 'Setting a different buffermode may ' 'provide the desired functionality') }], retry=False, )
def test_get_buffer_mode(): """ ensures that strings passed to get_buffer_mode are properly handled """ # None cases assert ConfigdocsHelper.get_buffer_mode('') == BufferMode.REJECTONCONTENTS assert ConfigdocsHelper.get_buffer_mode( None) == BufferMode.REJECTONCONTENTS # valid cases assert ConfigdocsHelper.get_buffer_mode( 'rejectoncontents') == BufferMode.REJECTONCONTENTS assert ConfigdocsHelper.get_buffer_mode('append') == BufferMode.APPEND assert ConfigdocsHelper.get_buffer_mode('replace') == BufferMode.REPLACE # case insensitive assert ConfigdocsHelper.get_buffer_mode( 'ReJEcTOnConTenTs') == BufferMode.REJECTONCONTENTS # bad value assert ConfigdocsHelper.get_buffer_mode('hippopotomus') is None
def post_collection(self, helper, collection_id, document_data, buffer_mode_param=None, empty_collection=False): """Ingest the collection after checking preconditions""" extra_messages = {'warning': [], 'info': []} validation_status = None buffer_mode = ConfigdocsHelper.get_buffer_mode(buffer_mode_param) # Validate that a deployment version document was provided, unless we # were told to skip this check ver_validation_cfg = CONF.validations.deployment_version_create.lower() if empty_collection or ver_validation_cfg == 'skip': LOG.debug('Skipping deployment version document validation') else: if not self._validate_deployment_version(helper, document_data): title = 'Deployment version document missing from collection' error_msg = ('Expected document to be present with schema: {} ' 'and name: {}').format( DEPLOYMENT_DATA_DOC['schema'], DEPLOYMENT_DATA_DOC['name']) if ver_validation_cfg in ['info', 'warning']: extra_messages[ver_validation_cfg].append('{}. {}'.format( title, error_msg)) else: # Error raise ApiError( title=title, description=('Collection rejected due to missing ' 'deployment data document'), status=falcon.HTTP_400, error_list=[{ 'message': error_msg }], retry=False, ) if helper.is_buffer_valid_for_bucket(collection_id, buffer_mode): buffer_revision = helper.add_collection(collection_id, document_data) if not (empty_collection or helper.is_collection_in_buffer(collection_id)): # raise an error if adding the collection resulted in no new # revision (meaning it was unchanged) and we're not explicitly # clearing the collection raise ApiError( title=('Collection {} not added to Shipyard ' 'buffer'.format(collection_id)), description='Collection created no new revision', status=falcon.HTTP_400, error_list=[{ 'message': ('The collection {} added no new revision, and has ' 'been rejected as invalid input. This likely ' 'means that the collection already exists and ' 'was reloaded with the same contents'.format( collection_id)) }], retry=False, ) else: validation_status = helper.get_deckhand_validation_status( buffer_revision) else: raise ApiError( title='Invalid collection specified for buffer', description='Buffermode : {}'.format(buffer_mode.value), status=falcon.HTTP_409, error_list=[{ 'message': ('Buffer is either not empty or the ' 'collection already exists in buffer. ' 'Setting a different buffermode may ' 'provide the desired functionality') }], retry=False, ) for level, messages in extra_messages.items(): if len(messages): add_messages_to_validation_status(validation_status, messages, level) return validation_status