You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2012/12/04 07:11:29 UTC

svn commit: r1416790 - in /libcloud/trunk: CHANGES libcloud/storage/drivers/cloudfiles.py libcloud/test/storage/test_cloudfiles.py

Author: tomaz
Date: Tue Dec  4 06:11:27 2012
New Revision: 1416790

URL: http://svn.apache.org/viewvc?rev=1416790&view=rev
Log:
Add ex_purge_from_cdn method to the CloudFiles driver. Part of LIBCLOUD-267.

Modified:
    libcloud/trunk/CHANGES
    libcloud/trunk/libcloud/storage/drivers/cloudfiles.py
    libcloud/trunk/libcloud/test/storage/test_cloudfiles.py

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1416790&r1=1416789&r2=1416790&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Tue Dec  4 06:11:27 2012
@@ -82,6 +82,9 @@ Changes with Apache Libcloud in developm
       containers (iterate_containers). ; LIBCLOUD-261
       [Mahendra M]
 
+    - Add ex_purge_from_cdn method to the CloudFiles driver. ; LIBCLOUD-267
+      [Tomaz Muraus]
+
   *) DNS
 
     - Update 'if type' checks in the update_record methods to behave correctly

Modified: libcloud/trunk/libcloud/storage/drivers/cloudfiles.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/storage/drivers/cloudfiles.py?rev=1416790&r1=1416789&r2=1416790&view=diff
==============================================================================
--- libcloud/trunk/libcloud/storage/drivers/cloudfiles.py (original)
+++ libcloud/trunk/libcloud/storage/drivers/cloudfiles.py Tue Dec  4 06:11:27 2012
@@ -404,6 +404,24 @@ class CloudFilesStorageDriver(StorageDri
 
         raise LibcloudError('Unexpected status code: %s' % (response.status))
 
+    def ex_purge_from_cdn(self, container, email=None):
+        """
+        Purge edge cache for all the objects inside the specified container.
+
+        @param email: Email where a notification will be sent when the job
+        completes. (optional)
+        @type email: C{str}
+        """
+        headers = {'X-Purge-Email': email} if email else {}
+
+        response = self.connection.request('/%s' % (container.name),
+                                           method='DELETE',
+                                           headers=headers,
+                                           cdn_request=True)
+
+        return response.status in [httplib.CREATED, httplib.ACCEPTED,
+                                   httplib.NO_CONTENT]
+
     def ex_get_meta_data(self):
         """
         Get meta data

Modified: libcloud/trunk/libcloud/test/storage/test_cloudfiles.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/storage/test_cloudfiles.py?rev=1416790&r1=1416789&r2=1416790&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/storage/test_cloudfiles.py (original)
+++ libcloud/trunk/libcloud/test/storage/test_cloudfiles.py Tue Dec  4 06:11:27 2012
@@ -44,6 +44,7 @@ from libcloud.storage.drivers.cloudfiles
 from libcloud.storage.drivers.dummy import DummyIterator
 
 from libcloud.test import StorageMockHttp, MockRawResponse # pylint: disable-msg=E0611
+from libcloud.test import MockHttpTestCase # pylint: disable-msg=E0611
 from libcloud.test.file_fixtures import StorageFileFixtures, OpenStackFixtures # pylint: disable-msg=E0611
 
 current_hash = None
@@ -497,6 +498,19 @@ class CloudFilesTests(unittest.TestCase)
         self.assertTrue('bytes_used' in meta_data)
         self.assertTrue('temp_url_key' in meta_data)
 
+    def test_ex_purge_from_cdn(self):
+        CloudFilesMockHttp.type = 'PURGE_SUCCESS'
+        container = Container(name='foo_bar_container', extra={},
+                              driver=self.driver)
+        self.assertTrue(self.driver.ex_purge_from_cdn(container=container))
+
+    def test_ex_purge_from_cdn_with_email(self):
+        CloudFilesMockHttp.type = 'PURGE_SUCCESS_EMAIL'
+        container = Container(name='foo_bar_container', extra={},
+                              driver=self.driver)
+        self.assertTrue(self.driver.ex_purge_from_cdn(container=container,
+                                                      email='test@test.com'))
+
     @mock.patch('os.path.getsize')
     def test_ex_multipart_upload_object_for_small_files(self, getsize_mock):
         getsize_mock.return_value = 0
@@ -663,7 +677,7 @@ class CloudFilesTests(unittest.TestCase)
             pass
 
 
-class CloudFilesMockHttp(StorageMockHttp):
+class CloudFilesMockHttp(StorageMockHttp, MockHttpTestCase):
 
     fixtures = StorageFileFixtures('cloudfiles')
     auth_fixtures = OpenStackFixtures()
@@ -833,6 +847,25 @@ class CloudFilesMockHttp(StorageMockHttp
             status_code = httplib.ACCEPTED
         return (status_code, body, headers, httplib.responses[httplib.OK])
 
+    def _v1_MossoCloudFS_foo_bar_container_PURGE_SUCCESS(
+        self, method, url, body, headers):
+
+        if method == 'DELETE':
+            # test_ex_purge_from_cdn
+            headers = self.base_headers
+            status_code = httplib.ACCEPTED
+        return (status_code, body, headers, httplib.responses[httplib.OK])
+
+    def _v1_MossoCloudFS_foo_bar_container_PURGE_SUCCESS_EMAIL(
+        self, method, url, body, headers):
+
+        if method == 'DELETE':
+            # test_ex_purge_from_cdn_with_email
+            self.assertEqual(headers['X-Purge-Email'], 'test@test.com')
+            headers = self.base_headers
+            status_code = httplib.ACCEPTED
+        return (status_code, body, headers, httplib.responses[httplib.OK])
+
     def _v1_MossoCloudFS_foo_bar_container_NOT_FOUND(
         self, method, url, body, headers):