From: Daira Hopwood Date: Thu, 18 Apr 2013 18:37:03 +0000 (+0100) Subject: Configuration for MS Azure. X-Git-Url: https://git.rkrishnan.org/vdrive/frontends/wapi.txt?a=commitdiff_plain;h=3303b94ab3df9982d17989d43f009dc3e9ecc2b2;p=tahoe-lafs%2Ftahoe-lafs.git Configuration for MS Azure. Author: Itamar Turner-Trauring Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/storage/backends/cloud/msazure/msazure_container.py b/src/allmydata/storage/backends/cloud/msazure/msazure_container.py index b954c9d2..fb5c5d40 100644 --- a/src/allmydata/storage/backends/cloud/msazure/msazure_container.py +++ b/src/allmydata/storage/backends/cloud/msazure/msazure_container.py @@ -23,9 +23,6 @@ from twisted.web.http import datetimeToString from allmydata.storage.backends.cloud.cloud_common import IContainer, \ ContainerItem, ContainerListing, CommonContainerMixin -def configure_msazure_container(*args): - pass - class MSAzureStorageContainer(CommonContainerMixin): implements(IContainer) @@ -212,3 +209,13 @@ class MSAzureStorageContainer(CommonContainerMixin): need_response_body=False) d.addCallback(lambda (response, body): body) return d + + +def configure_msazure_container(storedir, config): + """ + Configure the MS Azure storage container. + """ + account_name = config.get_config("storage", "msazure.account_name") + container_name = config.get_config("storage", "msazure.container_name") + account_key = config.get_private_config("msazure_account_key") + return MSAzureStorageContainer(account_name, account_key, container_name) diff --git a/src/allmydata/test/test_client.py b/src/allmydata/test/test_client.py index d5edef86..56bfec9c 100644 --- a/src/allmydata/test/test_client.py +++ b/src/allmydata/test/test_client.py @@ -405,6 +405,66 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase): mock_OpenStackContainer.assert_called_once_with(mock_AuthenticationClient.return_value, "456", "bucket") + def test_msazure_config_required(self): + """ + account_name and container_name are all required by MS Azure + configuration. + """ + configs = ["mszure.account_name = theaccount", + "msazure.container_name = bucket"] + for i in range(len(configs)): + basedir = self.mktemp() + os.mkdir(basedir) + bad_config = configs[:] + del bad_config[i] + self._write_secret(basedir, "msazure_account_key") + fileutil.write(os.path.join(basedir, "tahoe.cfg"), + BASECONFIG + + "[storage]\n" + + "enabled = true\n" + + "backend = cloud.msazure\n" + + "\n".join(bad_config) + "\n") + self.failUnlessRaises(MissingConfigEntry, client.Client, basedir) + + def test_msazure_config_required_private_key(self): + """ + msazure_account_key secret is required by MS Azure configuration. + """ + basedir = self.mktemp() + os.mkdir(basedir) + fileutil.write(os.path.join(basedir, "tahoe.cfg"), + BASECONFIG + + "[storage]\n" + + "enabled = true\n" + + "backend = cloud.msazure\n" + + "googlestorage.account_name = theaccount\n" + + "googlestorage.container_name = bucket\n") + self.failUnlessRaises(MissingConfigEntry, client.Client, basedir) + + @mock.patch('allmydata.storage.backends.cloud.msazure.msazure_container.MSAzureStorageContainer') + def test_msazure_config(self, mock_MSAzureStorageContainer): + """ + Given good configuration, we correctly configure a good MSAzureStorageContainer. + """ + basedir = self.mktemp() + os.mkdir(basedir) + self._write_secret(basedir, "msazure_account_key", "abc") + fileutil.write(os.path.join(basedir, "tahoe.cfg"), + BASECONFIG + + "[storage]\n" + + "enabled = true\n" + + "backend = cloud.msazure\n" + + "msazure.account_name = theaccount\n" + + "msazure.container_name = bucket\n") + c = client.Client(basedir) + server = c.getServiceNamed("storage") + self.failUnless(isinstance(server.backend, CloudBackend), server.backend) + # Protect against typos with isinstance(), because mock is dangerous. + self.assertFalse(isinstance( + mock_MSAzureStorageContainer.assert_called_once_with, mock.Mock)) + mock_MSAzureStorageContainer.assert_called_once_with( + "theaccount", "abc", "bucket") + def test_expire_mutable_false_unsupported(self): basedir = "client.Basic.test_expire_mutable_false_unsupported" os.mkdir(basedir)