Skip to content

Instantly share code, notes, and snippets.

@alistairncoles
Last active November 27, 2017 15:22
Show Gist options
  • Save alistairncoles/19cab1495654c9c0e02f7222c5d1ce3e to your computer and use it in GitHub Desktop.
Save alistairncoles/19cab1495654c9c0e02f7222c5d1ce3e to your computer and use it in GitHub Desktop.
test for async delete-at updates when there's no x-container-delete-at- headers
diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py
index a692a27b..42bcb586 100644
--- a/test/unit/obj/test_server.py
+++ b/test/unit/obj/test_server.py
@@ -5587,6 +5587,58 @@ class TestObjectController(unittest.TestCase):
['X-Delete-At-Container header must be specified for expiring '
'objects background PUT to work properly. Making best guess as '
'to the container name for now.'])
+ self.assertEqual(
+ given_args, [
+ 'PUT', '.expiring_objects', '0000000000', '0000000002-a/c/o',
+ '127.0.0.1:1234',
+ '3', 'sdc1', HeaderKeyDict({
+ # the .expiring_objects account is always policy-0
+ 'X-Backend-Storage-Policy-Index': 0,
+ 'x-size': '0',
+ 'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
+ 'x-content-type': 'text/plain',
+ 'x-timestamp': utils.Timestamp('1').internal,
+ 'x-trans-id': '1234',
+ 'referer': 'PUT http://localhost/v1/a/c/o'}),
+ 'sda1', policy])
+
+ def test_delete_at_update_put_with_no_info(self):
+ # Same as previous test, test_delete_at_update_put_with_info, but
+ # missing all the X-Delete-At-* headers.
+ policy = random.choice(list(POLICIES))
+ given_args = []
+
+ def fake_async_update(*args):
+ given_args.extend(args)
+
+ self.object_controller.async_update = fake_async_update
+ self.object_controller.logger = self.logger
+ req = Request.blank(
+ '/v1/a/c/o',
+ environ={'REQUEST_METHOD': 'PUT'},
+ headers={'X-Timestamp': 1,
+ 'X-Trans-Id': '1234',
+ 'X-Backend-Storage-Policy-Index': int(policy)})
+ self.object_controller.delete_at_update('PUT', 2, 'a', 'c', 'o',
+ req, 'sda1', policy)
+ self.assertEqual(
+ self.logger.get_lines_for_level('warning'),
+ ['X-Delete-At-Container header must be specified for expiring '
+ 'objects background PUT to work properly. Making best guess as '
+ 'to the container name for now.'])
+ self.assertEqual(
+ given_args, [
+ 'PUT', '.expiring_objects', '0000000000', '0000000002-a/c/o',
+ None, None, None, HeaderKeyDict({
+ # the .expiring_objects account is always policy-0
+ 'X-Backend-Storage-Policy-Index': 0,
+ 'x-size': '0',
+ 'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
+ 'x-content-type': 'text/plain',
+ 'x-timestamp': utils.Timestamp('1').internal,
+ 'x-trans-id': '1234',
+ 'referer': 'PUT http://localhost/v1/a/c/o'}),
+ 'sda1', policy])
def test_delete_at_update_delete(self):
policy = random.choice(list(POLICIES))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment