From: Daira Hopwood Date: Tue, 5 Feb 2013 19:42:17 +0000 (+0000) Subject: test_client.py: add OpenStack config tests. X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/%22file:/vdrive?a=commitdiff_plain;h=2abcfba57889b40f2b8ad304175295c4dbdd507a;p=tahoe-lafs%2Ftahoe-lafs.git test_client.py: add OpenStack config tests. Signed-off-by: David-Sarah Hopwood --- diff --git a/src/allmydata/test/test_client.py b/src/allmydata/test/test_client.py index 75070ad0..b0a53d0f 100644 --- a/src/allmydata/test/test_client.py +++ b/src/allmydata/test/test_client.py @@ -352,6 +352,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)