]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Configuration for MS Azure.
authorDaira Hopwood <david-sarah@jacaranda.org>
Thu, 18 Apr 2013 18:37:03 +0000 (19:37 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Fri, 17 Apr 2015 21:31:39 +0000 (22:31 +0100)
Author: Itamar Turner-Trauring <itamar@futurefoundries.com>
Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>
src/allmydata/storage/backends/cloud/msazure/msazure_container.py
src/allmydata/test/test_client.py

index b954c9d25cd7c4b2bf95806e61de5a7b4f8bb7e1..fb5c5d40e3d8c9ac3224bf033a35c0d5e71bf409 100644 (file)
@@ -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)
index 9bcf0b97453bb7e058e055b7f0c6242e6d2f6b1f..dd5d182ec5f1c1f1601ae01ff288a96924215253 100644 (file)
@@ -498,6 +498,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)