Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
 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()
Ejemplo n.º 7
0
    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()
Ejemplo n.º 8
0
    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()
Ejemplo n.º 9
0
 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)