]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_client.py: add OpenStack config tests.
authorDavid-Sarah Hopwood <david-sarah@jacaranda.org>
Tue, 5 Feb 2013 19:42:17 +0000 (19:42 +0000)
committerDaira Hopwood <daira@jacaranda.org>
Fri, 17 Apr 2015 21:31:37 +0000 (22:31 +0100)
Signed-off-by: David-Sarah Hopwood <david-sarah@jacaranda.org>
src/allmydata/test/test_client.py

index 13cf78923e4fd34d201b0405ea26299e65bcd863..e15b212c3cbe63f9909371c8ac5c523983e39388 100644 (file)
@@ -347,6 +347,66 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
                                     "s3.bucket = test\n")
         self.failUnlessRaises(MissingConfigEntry, client.Client, basedir)
 
+    @mock.patch('allmydata.storage.backends.cloud.openstack.openstack_container.AuthenticationClient')
+    @mock.patch('allmydata.storage.backends.cloud.openstack.openstack_container.OpenStackContainer')
+    def test_openstack_config_good_defaults(self, mock_OpenStackContainer, mock_AuthenticationClient):
+        basedir = "client.Basic.test_openstack_config_good_defaults"
+        os.mkdir(basedir)
+        self._write_secret(basedir, "openstack_api_key")
+        config = (BASECONFIG +
+                  "[storage]\n" +
+                  "enabled = true\n" +
+                  "backend = cloud.openstack\n" +
+                  "openstack.provider = rackspace\n" +
+                  "openstack.username = alex\n")
+        fileutil.write(os.path.join(basedir, "tahoe.cfg"), config)
+
+        c = client.Client(basedir)
+        mock_AuthenticationClient.assert_called_with("dummy", "rackspace",
+                                                     "https://identity.api.rackspacecloud.com/v1.0",
+                                                     "alex", 23*60*60)
+        self.failUnlessEqual(len(mock_OpenStackContainer.mock_calls), 1)
+        server = c.getServiceNamed("storage")
+        self.failUnless(isinstance(server.backend, CloudBackend), server.backend)
+
+    def test_openstack_readonly_bad(self):
+        basedir = "client.Basic.test_openstack_readonly_bad"
+        os.mkdir(basedir)
+        self._write_secret(basedir, "openstack_api_key")
+        fileutil.write(os.path.join(basedir, "tahoe.cfg"),
+                                    BASECONFIG +
+                                    "[storage]\n" +
+                                    "enabled = true\n" +
+                                    "readonly = true\n" +
+                                    "backend = cloud.openstack\n" +
+                                    "openstack.provider = rackspace\n" +
+                                    "openstack.username = alex\n")
+        self.failUnlessRaises(InvalidValueError, client.Client, basedir)
+
+    def test_openstack_config_no_username(self):
+        basedir = "client.Basic.test_openstack_config_no_username"
+        os.mkdir(basedir)
+        self._write_secret(basedir, "openstack_api_key")
+        fileutil.write(os.path.join(basedir, "tahoe.cfg"),
+                                    BASECONFIG +
+                                    "[storage]\n" +
+                                    "enabled = true\n" +
+                                    "backend = cloud.openstack\n" +
+                                    "openstack.provider = rackspace\n")
+        self.failUnlessRaises(MissingConfigEntry, client.Client, basedir)
+
+    def test_openstack_config_no_api_key(self):
+        basedir = "client.Basic.test_openstack_config_no_api_key"
+        os.mkdir(basedir)
+        fileutil.write(os.path.join(basedir, "tahoe.cfg"),
+                                    BASECONFIG +
+                                    "[storage]\n" +
+                                    "enabled = true\n" +
+                                    "backend = cloud.openstack\n" +
+                                    "openstack.provider = rackspace\n" +
+                                    "openstack.username = alex\n")
+        self.failUnlessRaises(MissingConfigEntry, client.Client, basedir)
+
     def test_expire_mutable_false_unsupported(self):
         basedir = "client.Basic.test_expire_mutable_false_unsupported"
         os.mkdir(basedir)