def run_test(self): """ Common test path for all configs to test against :return: """ print('Basic string operations using get/put/delete') resp = archive.put(userId=self.test_user_id, bucket=self.test_bucket_id, archiveid='document_1', data=self.document_1) print(('Document 1 PUT: {}'.format(resp))) resp = archive.get(userId=self.test_user_id, bucket=self.test_bucket_id, archiveid='document_1') self.assertEqual(self.document_1, resp) self.assertTrue(archive.exists(self.test_user_id, self.test_bucket_id, 'document_1')) self.assertFalse(archive.exists(self.test_user_id, self.test_bucket_id, 'document_10')) print('Document operations') resp = archive.put_document(userId=self.test_user_id, bucket=self.test_bucket_id, archiveId='document_json', data=self.document_json) print(('Document JSON PUT Doc: {}'.format(resp))) resp = archive.get_document(userId=self.test_user_id, bucket=self.test_bucket_id, archiveId='document_json') print(('Document JSON GET Dock: {}'.format(resp))) self.assertEqual(self.document_json, resp) print('Document operations') resp = archive.put_document(userId=self.test_user_id, bucket=self.test_bucket_id, archiveId='document_json', data=self.document_1) print(('Document string PUT Doc: {}'.format(resp))) resp = archive.get_document(userId=self.test_user_id, bucket=self.test_bucket_id, archiveId='document_json') print(('Document string GET Dock: {}'.format(resp))) self.assertEqual(self.document_1, resp)
def check(configfile): """ Test the configuration in the expected anchore-engine config location or override that and use the configuration file provided as an option. To test, the system will read and write a very small data document to the driver and then delete it on completion. :param configfile: :return: """ logger.info('Using config file {}'.format(configfile)) sys_config = load_config(configfile=configfile) if sys_config: service_config = sys_config['services']['catalog'] else: service_config = None if not service_config: logger.error( 'No configuration file or content available. Cannot test archive driver configuration' ) utils.doexit(2) archive.initialize(service_config) test_user_id = 'test' test_bucket = 'anchorecliconfigtest' test_archive_id = 'cliconfigtest' test_data = 'clitesting at {}'.format( datetime.datetime.utcnow().isoformat()) logger.info( 'Checking existence of test document with user_id = {}, bucket = {} and archive_id = {}' .format(test_user_id, test_bucket, test_archive_id)) if archive.exists(test_user_id, test_bucket, test_archive_id): test_archive_id = 'cliconfigtest2' if archive.exists(test_user_id, test_bucket, test_archive_id): logger.error( 'Found existing records for archive doc to test, aborting test to avoid overwritting any existing data' ) utils.doexit(1) logger.info( 'Creating test document with user_id = {}, bucket = {} and archive_id = {}' .format(test_user_id, test_bucket, test_archive_id)) result = archive.put(test_user_id, test_bucket, test_archive_id, data=test_data) if not result: logger.warn( 'Warning: Got empty response form archive PUT operation: {}'. format(result)) logger.info('Checking document fetch') loaded = str(archive.get(test_user_id, test_bucket, test_archive_id), 'utf-8') if not loaded: logger.error( 'Failed retrieving the written document. Got: {}'.format(loaded)) utils.doexit(5) if str(loaded) != test_data: logger.error( 'Failed retrieving the written document. Got something other than expected. Expected: "{}" Got: "{}"' .format(test_data, loaded)) utils.doexit(5) logger.info('Removing test object') archive.delete(test_user_id, test_bucket, test_archive_id) if archive.exists(test_user_id, test_bucket, test_archive_id): logger.error('Found archive object after it should have been removed') utils.doexit(5) logger.info('Archive config check completed successfully')