]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
OpenStack: add openstack.container config parameter.
authorDavid-Sarah Hopwood <david-sarah@jacaranda.org>
Tue, 12 Feb 2013 01:58:51 +0000 (01:58 +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/storage/backends/cloud/openstack/openstack_container.py
src/allmydata/test/test_client.py
src/allmydata/test/test_storage.py

index 2da588a8b3f9c0bb290b6f404527212b8eb7f510..cacd375249b0069dca02f3a9cc21d7d1285d3103 100644 (file)
@@ -26,10 +26,11 @@ def configure_openstack_container(storedir, config):
 
     auth_service_url = config.get_config("storage", "openstack.url", DEFAULT_AUTH_URLS[provider])
     username = config.get_config("storage", "openstack.username")
+    container_name = config.get_config("storage", "openstack.container")
     reauth_period = 23*60*60 #seconds
 
     auth_client = AuthenticationClient(api_key, provider, auth_service_url, username, reauth_period)
-    return OpenStackContainer(auth_client)
+    return OpenStackContainer(auth_client, container_name)
 
 
 class UnexpectedAuthenticationResponse(Exception):
@@ -144,8 +145,9 @@ class OpenStackContainer(ContainerRetryMixin, ContainerListMixin):
     I represent a real OpenStack container.
     """
 
-    def __init__(self, auth_client):
+    def __init__(self, auth_client, container_name):
         self._auth_client = auth_client
+        self._container_name = container_name
 
         #self.client = OpenStackClient(auth_client)
         #self.ServiceError = OpenStackError
index e15b212c3cbe63f9909371c8ac5c523983e39388..ab3b0f6a362e52c7100e0bb8f80017d98bcd2a91 100644 (file)
@@ -358,14 +358,17 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
                   "enabled = true\n" +
                   "backend = cloud.openstack\n" +
                   "openstack.provider = rackspace\n" +
-                  "openstack.username = alex\n")
+                  "openstack.username = alex\n" +
+                  "openstack.container = test\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)
+        container_call_args = mock_OpenStackContainer.call_args_list
+        self.failUnlessEqual(len(container_call_args), 1)
+        self.failUnlessEqual(container_call_args[0][0][1:], ("test",))
         server = c.getServiceNamed("storage")
         self.failUnless(isinstance(server.backend, CloudBackend), server.backend)
 
@@ -380,7 +383,8 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
                                     "readonly = true\n" +
                                     "backend = cloud.openstack\n" +
                                     "openstack.provider = rackspace\n" +
-                                    "openstack.username = alex\n")
+                                    "openstack.username = alex\n" +
+                                    "openstack.container = test\n")
         self.failUnlessRaises(InvalidValueError, client.Client, basedir)
 
     def test_openstack_config_no_username(self):
@@ -392,7 +396,21 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
                                     "[storage]\n" +
                                     "enabled = true\n" +
                                     "backend = cloud.openstack\n" +
-                                    "openstack.provider = rackspace\n")
+                                    "openstack.provider = rackspace\n" +
+                                    "openstack.container = test\n")
+        self.failUnlessRaises(MissingConfigEntry, client.Client, basedir)
+
+    def test_openstack_config_no_container(self):
+        basedir = "client.Basic.test_openstack_config_no_container"
+        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" +
+                                    "openstack.username = alex\n")
         self.failUnlessRaises(MissingConfigEntry, client.Client, basedir)
 
     def test_openstack_config_no_api_key(self):
@@ -404,7 +422,8 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
                                     "enabled = true\n" +
                                     "backend = cloud.openstack\n" +
                                     "openstack.provider = rackspace\n" +
-                                    "openstack.username = alex\n")
+                                    "openstack.username = alex\n" +
+                                    "openstack.container = test\n")
         self.failUnlessRaises(MissingConfigEntry, client.Client, basedir)
 
     def test_expire_mutable_false_unsupported(self):
index 724957c1f138da37752ae82c902521431821ab5a..f93c24b087140bd1b663e27fdf8a563807ab0aab 100644 (file)
@@ -405,6 +405,7 @@ class OpenStackCloudBackend(ServiceParentMixin, WorkdirMixin, unittest.TestCase)
     PROVIDER = "rackspace"
     AUTH_SERVICE_URL = "auth_service_url"
     USERNAME = "username"
+    CONTAINER = "container"
     API_KEY = "api_key"
     STORAGE_URL = "storage_url"
     CDN_MANAGEMENT_URL = "cdn_management_url"
@@ -444,6 +445,7 @@ class OpenStackCloudBackend(ServiceParentMixin, WorkdirMixin, unittest.TestCase)
             'openstack.provider': self.PROVIDER,
             'openstack.url': self.AUTH_SERVICE_URL,
             'openstack.username': self.USERNAME,
+            'openstack.container': self.CONTAINER,
         }
         from allmydata.node import _None
         class MockConfig(object):