From fb9065a99f1d7b50db947de2ef3ec5249a6ba3d0 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Thu, 16 May 2013 13:49:43 -0400 Subject: [PATCH] Implement method to create containers in Microsoft Azure storage backend. --- .../cloud/msazure/msazure_container.py | 12 +++++++++++ src/allmydata/test/test_storage.py | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/allmydata/storage/backends/cloud/msazure/msazure_container.py b/src/allmydata/storage/backends/cloud/msazure/msazure_container.py index 59019e17..11303d05 100644 --- a/src/allmydata/storage/backends/cloud/msazure/msazure_container.py +++ b/src/allmydata/storage/backends/cloud/msazure/msazure_container.py @@ -214,6 +214,18 @@ class MSAzureStorageContainer(CommonContainerMixin): d.addCallback(lambda (response, body): body) return d + def _create(self): + """ + Create the container. + """ + url = self._make_container_url(self.URI) + url += "?restype=container" + d = self._authorized_http_request("MS Azure PUT container", 'PUT', + url, {}, body=None, + need_response_body=False) + d.addCallback(lambda (response, body): body) + return d + def configure_msazure_container(storedir, config): """ diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 8973c5aa..2e9968cc 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -1509,6 +1509,27 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): http_response.callback((self.Response(200), None)) self.failUnless(done) + def test_create_container(self): + """ + MSAzureStorageContainer.create() send the appropriate HTTP command to + create the container (aka bucket). + """ + http_response = self.mock_http_request() + done = [] + self.container.create().addCallback(done.append) + self.failIf(done) + self.container._http_request.assert_called_once_with( + "MS Azure PUT container", "PUT", + "https://theaccount.blob.core.windows.net/thebucket?restype=container", + {"Authorization": [self.authorization], + "x-ms-version": ["2012-02-12"], + "x-ms-date": [self.date], + }, + body=None, + need_response_body=False) + http_response.callback((self.Response(200), None)) + self.failUnless(done) + class ServerMixin: def allocate(self, account, storage_index, sharenums, size, canary=None): -- 2.45.2