def needs_azure(test_item): """ Use as a decorator before test classes or methods to only run them if Azure is usable. """ test_item = _mark_test('azure', test_item) keyName = os.getenv('TOIL_AZURE_KEYNAME') if not keyName or keyName is None: return unittest.skip("Set TOIL_AZURE_KEYNAME to include this test.")( test_item) try: # noinspection PyUnresolvedReferences import azure.storage except ImportError: return unittest.skip( "Install Toil with the 'azure' extra to include this test.")( test_item) except: raise else: # check for the credentials file from toil.jobStores.azureJobStore import credential_file_path full_credential_file_path = os.path.expanduser(credential_file_path) if not os.path.exists(full_credential_file_path): # no file, check for environment variables try: from toil.jobStores.azureJobStore import _fetchAzureAccountKey _fetchAzureAccountKey(keyName) except: return unittest.skip( "Configure %s with the access key for the '%s' storage " "account." % (credential_file_path, keyName))(test_item) return test_item
def _cleanUpExternalStore(self, containerName): from toil.jobStores.azureJobStore import _fetchAzureAccountKey from azure.storage.blob import BlobService blobService = BlobService(account_key=_fetchAzureAccountKey( self.accountName), account_name=self.accountName) blobService.delete_container(containerName)
def _createExternalStore(): from toil.jobStores.azureJobStore import _fetchAzureAccountKey blobService = BlobService(account_key=_fetchAzureAccountKey(AzureJobStoreTest.accountName), account_name=AzureJobStoreTest.accountName) containerName = 'import-export-test-%s' % uuid.uuid4() blobService.create_container(containerName) return containerName
def _createExternalStore(self): from toil.jobStores.azureJobStore import _fetchAzureAccountKey from azure.storage.blob import BlobService blobService = BlobService(account_key=_fetchAzureAccountKey(self.accountName), account_name=self.accountName) containerName = 'import-export-test-%s' % uuid.uuid4() blobService.create_container(containerName) return containerName
def _getUrlForTestFile(cls, size=None): from toil.jobStores.azureJobStore import _fetchAzureAccountKey fileName = 'testfile_%s' % uuid.uuid4() containerName = cls._externalStore() url = 'wasb://%s@%s.blob.core.windows.net/%s' % (containerName, cls.accountName, fileName) if size is None: return url blobService = BlobService(account_key=_fetchAzureAccountKey(cls.accountName), account_name=cls.accountName) content = os.urandom(size) blobService.put_block_blob_from_text(containerName, fileName, content) return url, hashlib.md5(content).hexdigest()
def _prepareTestFile(self, containerName, size=None): from toil.jobStores.azureJobStore import _fetchAzureAccountKey from azure.storage.blob import BlobService fileName = 'testfile_%s' % uuid.uuid4() url = 'wasb://%s@%s.blob.core.windows.net/%s' % (containerName, self.accountName, fileName) if size is None: return url blobService = BlobService(account_key=_fetchAzureAccountKey(self.accountName), account_name=self.accountName) content = os.urandom(size) blobService.put_block_blob_from_text(containerName, fileName, content) return url, hashlib.md5(content).hexdigest()
def _cleanUpExternalStore(self, containerName): from toil.jobStores.azureJobStore import _fetchAzureAccountKey from azure.storage.blob import BlobService blobService = BlobService(account_key=_fetchAzureAccountKey(self.accountName), account_name=self.accountName) blobService.delete_container(containerName)