def _create_store_azure(type, params): from simplekv.net.azurestore import AzureBlockBlobStore from ._hstores import HAzureBlockBlobStore conn_string = params.get('connection_string', _build_azure_url(**params)) if params['create_if_missing'] and params.get('use_sas', False): raise Exception( 'create_if_missing is incompatible with the use of SAS tokens.') if type == 'azure': return AzureBlockBlobStore( conn_string=conn_string, container=params['container'], public=False, create_if_missing=params['create_if_missing'], checksum=params.get('checksum', True), max_connections=params.get('max_connections', 2), socket_timeout=params.get('socket_timeout', (20, 100)), max_block_size=params.get('max_block_size', (4194304)), max_single_put_size=params.get('max_single_put_size', (67108864)), ) else: return HAzureBlockBlobStore( conn_string=conn_string, container=params['container'], public=False, create_if_missing=params['create_if_missing'], checksum=params.get('checksum', True), max_connections=params.get('max_connections', 2), socket_timeout=params.get('socket_timeout', (20, 100)), max_block_size=params.get('max_block_size', (4194304)), max_single_put_size=params.get('max_single_put_size', (67108864)), )
def _create_store_azure(type, params): from simplekv.net.azurestore import AzureBlockBlobStore from ._hstores import HAzureBlockBlobStore conn_string = params.get('connection_string', _build_azure_url(**params)) if params['create_if_missing'] and params.get('use_sas', False): raise Exception('create_if_missing is incompatible with the use of SAS tokens.') if type == 'azure': return AzureBlockBlobStore( conn_string=conn_string, container=params['container'], public=False, create_if_missing=params['create_if_missing'], checksum=params.get('checksum', True), ) else: return HAzureBlockBlobStore( conn_string=conn_string, container=params['container'], public=False, create_if_missing=params['create_if_missing'], checksum=params.get('checksum', True), )
def store(self): container = str(uuid()) conn_string = create_azure_conn_string(load_azure_credentials()) yield AzureBlockBlobStore(conn_string=conn_string, container=container, public=False) _delete_container(conn_string, container)
def test_missing_container(self): container = uuid() conn_string = create_azure_conn_string(load_azure_credentials()) store = AzureBlockBlobStore(conn_string=conn_string, container=container, create_if_missing=False) with pytest.raises(IOError) as exc: store.iter_keys() assert u"The specified container does not exist." in str(exc.value)
def store(self): from azure.storage.blob import BlockBlobService container = uuid() conn_string = create_azure_conn_string(load_azure_credentials()) s = BlockBlobService(connection_string=conn_string) yield AzureBlockBlobStore(conn_string=conn_string, container=container, public=False) s.delete_container(container)
def test_azure_setgetstate(): container = str(uuid()) conn_string = create_azure_conn_string(load_azure_credentials()) store = AzureBlockBlobStore(conn_string=conn_string, container=container) store.put(u'key1', b'value1') buf = pickle.dumps(store, protocol=2) store = pickle.loads(buf) assert store.get(u'key1') == b'value1' _delete_container(conn_string, container)
def store(self): container = str(uuid()) conn_string = get_azure_conn_string() yield AzureBlockBlobStore( conn_string=conn_string, container=container, public=False, checksum=True, ) _delete_container(conn_string, container)
def test_azure_setgetstate(): from azure.storage.blob import BlockBlobService container = uuid() conn_string = create_azure_conn_string(load_azure_credentials()) s = BlockBlobService(connection_string=conn_string) store = AzureBlockBlobStore(conn_string=conn_string, container=container) store.put(u'key1', b'value1') buf = pickle.dumps(store, protocol=2) store = pickle.loads(buf) assert store.get(u'key1') == b'value1' s.delete_container(container)
def test_wrong_credentials(self): from azure.storage.retry import ExponentialRetry container = uuid() conn_string = \ 'DefaultEndpointsProtocol=https;AccountName={};AccountKey={}'.\ format("testaccount", "wrongsecret") store = AzureBlockBlobStore(conn_string=conn_string, container=container, create_if_missing=False) store.block_blob_service.retry = ExponentialRetry(max_attempts=0).retry with pytest.raises(IOError) as exc: store.put(u"key", b"data") assert u"Incorrect padding" in str(exc.value)
def test_wrong_endpoint(self): from azure.storage.retry import ExponentialRetry container = uuid() conn_string = create_azure_conn_string(load_azure_credentials()) conn_string += \ ";BlobEndpoint=https://hopenostorethere.blob.core.windows.net;" store = AzureBlockBlobStore(conn_string=conn_string, container=container, create_if_missing=False) store.block_blob_service.retry = ExponentialRetry(max_attempts=0).retry with pytest.raises(IOError) as exc: store.put(u"key", b"data") assert u"Failed to establish a new connection" in str(exc.value)
def test_azure_store_attributes(): abbs = AzureBlockBlobStore('CONN_STR', 'CONTAINER', max_connections=42, checksum=True) assert abbs.conn_string == 'CONN_STR' assert abbs.container == 'CONTAINER' assert abbs.public is False assert abbs.create_if_missing is True assert abbs.max_connections == 42 assert abbs.checksum is True abbs2 = pickle.loads(pickle.dumps(abbs)) assert abbs2.conn_string == 'CONN_STR' assert abbs2.container == 'CONTAINER' assert abbs2.public is False assert abbs2.create_if_missing is True assert abbs2.max_connections == 42 assert abbs2.checksum is True
def test_wrong_endpoint(self): container = str(uuid()) conn_string = create_azure_conn_string(load_azure_credentials()) conn_string += \ ";BlobEndpoint=https://hopenostorethere.blob.core.windows.net;" store = AzureBlockBlobStore(conn_string=conn_string, container=container, create_if_missing=False) if hasattr(store, 'block_blob_service'): from azure.storage.common.retry import ExponentialRetry store.block_blob_service.retry = ExponentialRetry( max_attempts=0).retry else: store.blob_container_client._config.retry_policy.total_retries = 0 with pytest.raises(IOError) as exc: store.put(u"key", b"data") assert u"connect" in str(exc.value)
def test_azure_special_args(): # For azure-storage-blob 12, # test that the special arguments `max_block_size` and # `max_single_put_size` propagate to the constructed ContainerClient conn_string = get_azure_conn_string() MBS = 983645 MSP = 756235 abbs = AzureBlockBlobStore( conn_string=conn_string, container='container-unused', max_block_size=MBS, max_single_put_size=MSP, create_if_missing=False ) if hasattr(abbs, "blob_container_client"): cfg = abbs.blob_container_client._config assert cfg.max_single_put_size == MSP assert cfg.max_block_size == MBS
def test_wrong_endpoint(self): container = str(uuid()) conn_string = get_azure_conn_string() conn_settings = dict([s.split("=", 1) for s in conn_string.split(";") if s]) conn_settings['BlobEndpoint'] = 'https://host-does-not-exist/' conn_string = ';'.join('{}={}'.format(key, value) for key, value in conn_settings.items()) store = AzureBlockBlobStore(conn_string=conn_string, container=container, create_if_missing=False) if hasattr(store, 'block_blob_service'): from azure.storage.common.retry import ExponentialRetry store.block_blob_service.retry = ExponentialRetry( max_attempts=0 ).retry else: store.blob_container_client._config.retry_policy.total_retries = 0 with pytest.raises(IOError) as exc: store.put(u"key", b"data") assert u"connect" in str(exc.value)