Пример #1
0
 def test_mark_for_deletion_two_updates_with_yield(self):
     ts = '1558463777.42739'
     with FakeInternalClient([
         swob.Response(json.dumps([
             {'name': 'obj1'},
             {'name': 'obj2'},
             {'name': 'obj3'},
             {'name': u'obj4-\N{SNOWMAN}'},
             {'name': 'obj5'},
             {'name': 'obj6'},
         ])),
         swob.Response(status=202),
         swob.Response(json.dumps([
         ])),
         swob.Response(status=202),
     ]) as swift:
         self.assertEqual(list(container_deleter.mark_for_deletion(
             swift,
             'account',
             'container',
             '',
             'end',
             'pre',
             timestamp=utils.Timestamp(ts),
             yield_time=0,
         )), [(5, 'obj5'), (6, 'obj6'), (6, None)])
         self.assertEqual(swift.calls, [
             ('GET', '/v1/account/container',
              'format=json&marker=&end_marker=end&prefix=pre', {}, None),
             ('UPDATE', '/v1/.expiring_objects/' + ts.split('.')[0], '', {
                 'X-Backend-Allow-Private-Methods': 'True',
                 'X-Backend-Storage-Policy-Index': '0',
                 'X-Timestamp': ts}, mock.ANY),
             ('GET', '/v1/account/container',
              'format=json&marker=obj6&end_marker=end&prefix=pre',
              {}, None),
             ('UPDATE', '/v1/.expiring_objects/' + ts.split('.')[0], '', {
                 'X-Backend-Allow-Private-Methods': 'True',
                 'X-Backend-Storage-Policy-Index': '0',
                 'X-Timestamp': ts}, mock.ANY),
         ])
         self.assertEqual(
             json.loads(swift.calls[-3].body),
             container_deleter.make_delete_jobs(
                 'account', 'container',
                 ['obj1', 'obj2', 'obj3', u'obj4-\N{SNOWMAN}', 'obj5'],
                 utils.Timestamp(ts)
             )
         )
         self.assertEqual(
             json.loads(swift.calls[-1].body),
             container_deleter.make_delete_jobs(
                 'account', 'container', ['obj6'],
                 utils.Timestamp(ts)
             )
         )
Пример #2
0
 def test_make_delete_jobs_native_utf8(self):
     ts = '1558463777.42739'
     uacct = acct = u'acct-\U0001f334'
     ucont = cont = u'cont-\N{SNOWMAN}'
     uobj1 = obj1 = u'obj-\N{GREEK CAPITAL LETTER ALPHA}'
     uobj2 = obj2 = u'/obj-\N{GREEK CAPITAL LETTER OMEGA}'
     if six.PY2:
         acct = acct.encode('utf8')
         cont = cont.encode('utf8')
         obj1 = obj1.encode('utf8')
         obj2 = obj2.encode('utf8')
     self.assertEqual(
         container_deleter.make_delete_jobs(acct, cont, [obj1, obj2],
                                            utils.Timestamp(ts)),
         [{
             'name': u'%s-%s/%s/%s' % (ts, uacct, ucont, uobj1),
             'deleted': 0,
             'created_at': ts,
             'etag': utils.MD5_OF_EMPTY_STRING,
             'size': 0,
             'storage_policy_index': 0,
             'content_type': 'application/async-deleted'
         }, {
             'name': u'%s-%s/%s/%s' % (ts, uacct, ucont, uobj2),
             'deleted': 0,
             'created_at': ts,
             'etag': utils.MD5_OF_EMPTY_STRING,
             'size': 0,
             'storage_policy_index': 0,
             'content_type': 'application/async-deleted'
         }])
Пример #3
0
 def test_make_delete_jobs_native_utf8(self):
     ts = '1558463777.42739'
     uacct = acct = u'acct-\U0001f334'
     ucont = cont = u'cont-\N{SNOWMAN}'
     uobj1 = obj1 = u'obj-\N{GREEK CAPITAL LETTER ALPHA}'
     uobj2 = obj2 = u'/obj-\N{GREEK CAPITAL LETTER OMEGA}'
     if six.PY2:
         acct = acct.encode('utf8')
         cont = cont.encode('utf8')
         obj1 = obj1.encode('utf8')
         obj2 = obj2.encode('utf8')
     self.assertEqual(
         container_deleter.make_delete_jobs(
             acct, cont, [obj1, obj2], utils.Timestamp(ts)),
         [{'name': u'%s-%s/%s/%s' % (ts.split('.')[0], uacct, ucont, uobj1),
           'deleted': 0,
           'created_at': ts,
           'etag': utils.MD5_OF_EMPTY_STRING,
           'size': 0,
           'storage_policy_index': 0,
           'content_type': 'application/async-deleted'},
          {'name': u'%s-%s/%s/%s' % (ts.split('.')[0], uacct, ucont, uobj2),
           'deleted': 0,
           'created_at': ts,
           'etag': utils.MD5_OF_EMPTY_STRING,
           'size': 0,
           'storage_policy_index': 0,
           'content_type': 'application/async-deleted'}])
Пример #4
0
 def test_make_delete_jobs_unicode_utf8(self):
     ts = '1558463777.42739'
     acct = u'acct-\U0001f334'
     cont = u'cont-\N{SNOWMAN}'
     obj1 = u'obj-\N{GREEK CAPITAL LETTER ALPHA}'
     obj2 = u'obj-\N{GREEK CAPITAL LETTER OMEGA}'
     self.assertEqual(
         container_deleter.make_delete_jobs(acct, cont, [obj1, obj2],
                                            utils.Timestamp(ts)),
         [{
             'name': u'%s-%s/%s/%s' % (ts.split('.')[0], acct, cont, obj1),
             'deleted': 0,
             'created_at': ts,
             'etag': utils.MD5_OF_EMPTY_STRING,
             'size': 0,
             'storage_policy_index': 0,
             'content_type': 'application/async-deleted'
         }, {
             'name': u'%s-%s/%s/%s' % (ts.split('.')[0], acct, cont, obj2),
             'deleted': 0,
             'created_at': ts,
             'etag': utils.MD5_OF_EMPTY_STRING,
             'size': 0,
             'storage_policy_index': 0,
             'content_type': 'application/async-deleted'
         }])
Пример #5
0
 def test_mark_for_deletion_one_update_no_yield(self):
     ts = '1558463777.42739'
     with FakeInternalClient([
             swob.Response(
                 json.dumps([
                     {
                         'name': '/obj1'
                     },
                     {
                         'name': 'obj2'
                     },
                     {
                         'name': 'obj3'
                     },
                 ])),
             swob.Response(json.dumps([])),
             swob.Response(status=202),
     ]) as swift:
         self.assertEqual(
             container_deleter.mark_for_deletion(
                 swift,
                 'account',
                 'container',
                 '',
                 '',
                 '',
                 timestamp=utils.Timestamp(ts),
                 yield_time=None,
             ), 3)
         self.assertEqual(swift.calls, [
             ('GET', '/v1/account/container',
              'format=json&marker=&end_marker=&prefix=', {}, None),
             ('GET', '/v1/account/container',
              'format=json&marker=obj3&end_marker=&prefix=', {}, None),
             ('UPDATE', '/v1/.expiring_objects/' + ts.split('.')[0], '', {
                 'X-Backend-Allow-Private-Methods': 'True',
                 'X-Backend-Storage-Policy-Index': '0',
                 'X-Timestamp': ts
             }, mock.ANY),
         ])
         self.assertEqual(
             json.loads(swift.calls[-1].body),
             container_deleter.make_delete_jobs('account', 'container',
                                                ['/obj1', 'obj2', 'obj3'],
                                                utils.Timestamp(ts)))
Пример #6
0
 def test_make_delete_jobs(self):
     ts = '1558463777.42739'
     self.assertEqual(
         container_deleter.make_delete_jobs(
             'acct', 'cont', ['obj1', 'obj2'],
             utils.Timestamp(ts)),
         [{'name': ts.split('.')[0] + '-acct/cont/obj1',
           'deleted': 0,
           'created_at': ts,
           'etag': utils.MD5_OF_EMPTY_STRING,
           'size': 0,
           'storage_policy_index': 0,
           'content_type': 'application/async-deleted'},
          {'name': ts.split('.')[0] + '-acct/cont/obj2',
           'deleted': 0,
           'created_at': ts,
           'etag': utils.MD5_OF_EMPTY_STRING,
           'size': 0,
           'storage_policy_index': 0,
           'content_type': 'application/async-deleted'}])
Пример #7
0
 def test_make_delete_jobs(self):
     ts = '1558463777.42739'
     self.assertEqual(
         container_deleter.make_delete_jobs('acct', 'cont',
                                            ['obj1', 'obj2'],
                                            utils.Timestamp(ts)),
         [{
             'name': ts + '-acct/cont/obj1',
             'deleted': 0,
             'created_at': ts,
             'etag': utils.MD5_OF_EMPTY_STRING,
             'size': 0,
             'storage_policy_index': 0,
             'content_type': 'application/async-deleted'
         }, {
             'name': ts + '-acct/cont/obj2',
             'deleted': 0,
             'created_at': ts,
             'etag': utils.MD5_OF_EMPTY_STRING,
             'size': 0,
             'storage_policy_index': 0,
             'content_type': 'application/async-deleted'
         }])