~ubuntu-branches/ubuntu/vivid/swift/vivid-updates

« back to all changes in this revision

Viewing changes to .pc/fix-ubuntu-tests.patch/test/unit/proxy/test_server.py

  • Committer: Package Import Robot
  • Author(s): James Page, Chuck Short, James Page
  • Date: 2014-10-06 10:06:11 UTC
  • mfrom: (1.2.31)
  • Revision ID: package-import@ubuntu.com-20141006100611-wdzkkuoru7ubtlml
Tags: 2.1.0-0ubuntu1
[ Chuck Short ]
* debian/patches/fix-doc-no-network.patch: Refreshed.
* debian/control: Add python-oslosphinx as a build dependency.

[ James Page ]
* New upstream release for OpenStack Juno.
* d/copyright: Add linebreaks to fixup file-without-copyright-
  information warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
    HTTPException
60
60
from swift.common import storage_policy
61
61
from swift.common.storage_policy import StoragePolicy, \
62
 
    StoragePolicyCollection, POLICIES, POLICY, POLICY_INDEX
 
62
    StoragePolicyCollection, POLICIES
63
63
from swift.common.request_helpers import get_sys_meta_prefix
64
64
 
65
65
# mocks
268
268
                                None)
269
269
    orig_account_info = getattr(swift.proxy.controllers.Controller,
270
270
                                'account_info', None)
 
271
    orig_container_info = getattr(swift.proxy.controllers.Controller,
 
272
                                  'container_info', None)
 
273
 
271
274
    try:
272
275
        yield True
273
276
    finally:
276
279
        swift.proxy.controllers.obj.http_connect = orig_http_connect
277
280
        swift.proxy.controllers.account.http_connect = orig_http_connect
278
281
        swift.proxy.controllers.container.http_connect = orig_http_connect
 
282
        swift.proxy.controllers.Controller.container_info = orig_container_info
279
283
 
280
284
 
281
285
def set_http_connect(*args, **kwargs):
1601
1605
                self.assertEquals(res.status[:len(expected)], expected)
1602
1606
            test_status_map((200, 200, 201, 201, -1), 201)  # connect exc
1603
1607
            # connect errors
1604
 
            test_status_map((200, 200, 201, 201, Timeout()), 201)
 
1608
            test_status_map((200, 200, Timeout(), 201, 201, ), 201)
1605
1609
            test_status_map((200, 200, 201, 201, Exception()), 201)
1606
1610
            # expect errors
1607
 
            test_status_map((200, 200, 201, 201, (Timeout(), None)), 201)
1608
 
            test_status_map((200, 200, 201, 201, (Exception(), None)), 201)
 
1611
            test_status_map((200, 200, (Timeout(), None), 201, 201), 201)
 
1612
            test_status_map((200, 200, (Exception(), None), 201, 201), 201)
1609
1613
            # response errors
1610
 
            test_status_map((200, 200, 201, 201, (100, Timeout())), 201)
1611
 
            test_status_map((200, 200, 201, 201, (100, Exception())), 201)
1612
 
            test_status_map((200, 200, 201, 201, 507), 201)  # error limited
1613
 
            test_status_map((200, 200, 201, -1, -1), 503)
1614
 
            test_status_map((200, 200, 503, 503, -1), 503)
 
1614
            test_status_map((200, 200, (100, Timeout()), 201, 201), 201)
 
1615
            test_status_map((200, 200, (100, Exception()), 201, 201), 201)
 
1616
            test_status_map((200, 200, 507, 201, 201), 201)  # error limited
 
1617
            test_status_map((200, 200, -1, 201, -1), 503)
 
1618
            test_status_map((200, 200, 503, -1, 503), 503)
1615
1619
 
1616
1620
    def test_PUT_send_exceptions(self):
1617
1621
        with save_globals():
1728
1732
            req_method, req_path, req_headers = req
1729
1733
            self.assertEqual(method, req_method)
1730
1734
            # caller can ignore leading path parts
1731
 
            self.assertTrue(req_path.endswith(path))
 
1735
            self.assertTrue(req_path.endswith(path),
 
1736
                            'expected path to end with %s, it was %s' % (
 
1737
                                path, req_path))
1732
1738
            headers = headers or {}
1733
1739
            # caller can ignore some headers
1734
1740
            for k, v in headers.items():
1735
1741
                self.assertEqual(req_headers[k], v)
1736
1742
        account_request = backend_requests.pop(0)
1737
 
        check_request(account_request, method='HEAD', path='/sda/1/a')
 
1743
        check_request(account_request, method='HEAD', path='/sda/0/a')
1738
1744
        container_request = backend_requests.pop(0)
1739
 
        check_request(container_request, method='HEAD', path='/sda/1/a/c')
1740
 
        for i, (device, request) in enumerate(zip(('sda', 'sdb', 'sdc'),
1741
 
                                                  backend_requests)):
 
1745
        check_request(container_request, method='HEAD', path='/sda/0/a/c')
 
1746
        # make sure backend requests included expected container headers
 
1747
        container_headers = {}
 
1748
        for request in backend_requests:
 
1749
            req_headers = request[2]
 
1750
            device = req_headers['x-container-device']
 
1751
            host = req_headers['x-container-host']
 
1752
            container_headers[device] = host
1742
1753
            expectations = {
1743
1754
                'method': 'POST',
1744
 
                'path': '/%s/1/a/c/o' % device,
 
1755
                'path': '/0/a/c/o',
1745
1756
                'headers': {
1746
 
                    'X-Container-Host': '10.0.0.%d:100%d' % (i, i),
1747
 
                    'X-Container-Partition': '1',
 
1757
                    'X-Container-Partition': '0',
1748
1758
                    'Connection': 'close',
1749
1759
                    'User-Agent': 'proxy-server %s' % os.getpid(),
1750
1760
                    'Host': 'localhost:80',
1751
 
                    'X-Container-Device': device,
1752
1761
                    'Referer': 'POST http://localhost/v1/a/c/o',
1753
1762
                    'X-Object-Meta-Color': 'Blue',
1754
 
                    POLICY_INDEX: '1'
 
1763
                    'X-Backend-Storage-Policy-Index': '1'
1755
1764
                },
1756
1765
            }
1757
1766
            check_request(request, **expectations)
1758
1767
 
 
1768
        expected = {}
 
1769
        for i, device in enumerate(['sda', 'sdb', 'sdc']):
 
1770
            expected[device] = '10.0.0.%d:100%d' % (i, i)
 
1771
        self.assertEqual(container_headers, expected)
 
1772
 
1759
1773
        # and again with policy override
1760
1774
        self.app.memcache.store = {}
1761
1775
        backend_requests = []
1762
1776
        req = Request.blank('/v1/a/c/o', {}, method='POST',
1763
1777
                            headers={'X-Object-Meta-Color': 'Blue',
1764
 
                                     POLICY_INDEX: 0})
 
1778
                                     'X-Backend-Storage-Policy-Index': 0})
1765
1779
        with mocked_http_conn(
1766
1780
                200, 200, 202, 202, 202,
1767
1781
                headers=resp_headers, give_connect=capture_requests
1773
1787
        for request in backend_requests[2:]:
1774
1788
            expectations = {
1775
1789
                'method': 'POST',
1776
 
                'path': '/1/a/c/o',  # ignore device bit
 
1790
                'path': '/0/a/c/o',  # ignore device bit
1777
1791
                'headers': {
1778
1792
                    'X-Object-Meta-Color': 'Blue',
1779
 
                    POLICY_INDEX: '0',
 
1793
                    'X-Backend-Storage-Policy-Index': '0',
1780
1794
                }
1781
1795
            }
1782
1796
            check_request(request, **expectations)
1787
1801
        backend_requests = []
1788
1802
        req = Request.blank('/v1/a/c/o', {}, method='POST',
1789
1803
                            headers={'X-Object-Meta-Color': 'Blue',
1790
 
                                     POLICY_INDEX: 0})
 
1804
                                     'X-Backend-Storage-Policy-Index': 0})
1791
1805
        with mocked_http_conn(
1792
1806
                200, 200, 200, 200, 200, 201, 201, 201,
1793
1807
                headers=resp_headers, give_connect=capture_requests
1796
1810
            self.assertRaises(StopIteration, fake_conn.code_iter.next)
1797
1811
        self.assertEqual(resp.status_int, 202)
1798
1812
        self.assertEqual(len(backend_requests), 8)
1799
 
        policy0 = {POLICY_INDEX: '0'}
1800
 
        policy1 = {POLICY_INDEX: '1'}
 
1813
        policy0 = {'X-Backend-Storage-Policy-Index': '0'}
 
1814
        policy1 = {'X-Backend-Storage-Policy-Index': '1'}
1801
1815
        expected = [
1802
1816
            # account info
1803
 
            {'method': 'HEAD', 'path': '/1/a'},
 
1817
            {'method': 'HEAD', 'path': '/0/a'},
1804
1818
            # container info
1805
 
            {'method': 'HEAD', 'path': '/1/a/c'},
 
1819
            {'method': 'HEAD', 'path': '/0/a/c'},
1806
1820
            # x-newests
1807
 
            {'method': 'GET', 'path': '/1/a/c/o', 'headers': policy1},
1808
 
            {'method': 'GET', 'path': '/1/a/c/o', 'headers': policy1},
1809
 
            {'method': 'GET', 'path': '/1/a/c/o', 'headers': policy1},
 
1821
            {'method': 'GET', 'path': '/0/a/c/o', 'headers': policy1},
 
1822
            {'method': 'GET', 'path': '/0/a/c/o', 'headers': policy1},
 
1823
            {'method': 'GET', 'path': '/0/a/c/o', 'headers': policy1},
1810
1824
            # new writes
1811
 
            {'method': 'PUT', 'path': '/1/a/c/o', 'headers': policy0},
1812
 
            {'method': 'PUT', 'path': '/1/a/c/o', 'headers': policy0},
1813
 
            {'method': 'PUT', 'path': '/1/a/c/o', 'headers': policy0},
 
1825
            {'method': 'PUT', 'path': '/0/a/c/o', 'headers': policy0},
 
1826
            {'method': 'PUT', 'path': '/0/a/c/o', 'headers': policy0},
 
1827
            {'method': 'PUT', 'path': '/0/a/c/o', 'headers': policy0},
1814
1828
        ]
1815
1829
        for request, expectations in zip(backend_requests, expected):
1816
1830
            check_request(request, **expectations)
2150
2164
            #                acct cont obj  obj  obj
2151
2165
            resp = req.get_response(self.app)
2152
2166
            self.assertEquals(resp.status_int, 201)
2153
 
            self.app.client_timeout = 0.1
 
2167
            self.app.client_timeout = 0.05
2154
2168
            req = Request.blank('/v1/a/c/o',
2155
2169
                                environ={'REQUEST_METHOD': 'PUT',
2156
2170
                                         'wsgi.input': SlowBody()},
2369
2383
                    collected_nodes.append(node)
2370
2384
                self.assertEquals(len(collected_nodes), 9)
2371
2385
 
 
2386
                # zero error-limited primary nodes -> no handoff warnings
2372
2387
                self.app.log_handoffs = True
2373
2388
                self.app.logger = FakeLogger()
2374
 
                object_ring.max_more_nodes = 2
2375
 
                partition, nodes = object_ring.get_nodes('account',
2376
 
                                                         'container',
2377
 
                                                         'object')
2378
 
                collected_nodes = []
2379
 
                for node in self.app.iter_nodes(object_ring,
2380
 
                                                partition):
2381
 
                    collected_nodes.append(node)
2382
 
                self.assertEquals(len(collected_nodes), 5)
2383
 
                self.assertEquals(
2384
 
                    self.app.logger.log_dict['warning'],
2385
 
                    [(('Handoff requested (1)',), {}),
2386
 
                     (('Handoff requested (2)',), {})])
2387
 
 
2388
 
                self.app.log_handoffs = False
2389
 
                self.app.logger = FakeLogger()
2390
 
                object_ring.max_more_nodes = 2
2391
 
                partition, nodes = object_ring.get_nodes('account',
2392
 
                                                         'container',
2393
 
                                                         'object')
2394
 
                collected_nodes = []
2395
 
                for node in self.app.iter_nodes(object_ring,
2396
 
                                                partition):
2397
 
                    collected_nodes.append(node)
2398
 
                self.assertEquals(len(collected_nodes), 5)
 
2389
                self.app.request_node_count = lambda r: 7
 
2390
                object_ring.max_more_nodes = 20
 
2391
                partition, nodes = object_ring.get_nodes('account',
 
2392
                                                         'container',
 
2393
                                                         'object')
 
2394
                collected_nodes = []
 
2395
                for node in self.app.iter_nodes(object_ring, partition):
 
2396
                    collected_nodes.append(node)
 
2397
                self.assertEquals(len(collected_nodes), 7)
2399
2398
                self.assertEquals(self.app.logger.log_dict['warning'], [])
 
2399
                self.assertEquals(self.app.logger.get_increments(), [])
 
2400
 
 
2401
                # one error-limited primary node -> one handoff warning
 
2402
                self.app.log_handoffs = True
 
2403
                self.app.logger = FakeLogger()
 
2404
                self.app.request_node_count = lambda r: 7
 
2405
                object_ring.clear_errors()
 
2406
                object_ring._devs[0]['errors'] = 999
 
2407
                object_ring._devs[0]['last_error'] = 2 ** 63 - 1
 
2408
 
 
2409
                collected_nodes = []
 
2410
                for node in self.app.iter_nodes(object_ring, partition):
 
2411
                    collected_nodes.append(node)
 
2412
                self.assertEquals(len(collected_nodes), 7)
 
2413
                self.assertEquals(self.app.logger.log_dict['warning'], [
 
2414
                    (('Handoff requested (5)',), {})])
 
2415
                self.assertEquals(self.app.logger.get_increments(),
 
2416
                                  ['handoff_count'])
 
2417
 
 
2418
                # two error-limited primary nodes -> two handoff warnings
 
2419
                self.app.log_handoffs = True
 
2420
                self.app.logger = FakeLogger()
 
2421
                self.app.request_node_count = lambda r: 7
 
2422
                object_ring.clear_errors()
 
2423
                for i in range(2):
 
2424
                    object_ring._devs[i]['errors'] = 999
 
2425
                    object_ring._devs[i]['last_error'] = 2 ** 63 - 1
 
2426
 
 
2427
                collected_nodes = []
 
2428
                for node in self.app.iter_nodes(object_ring, partition):
 
2429
                    collected_nodes.append(node)
 
2430
                self.assertEquals(len(collected_nodes), 7)
 
2431
                self.assertEquals(self.app.logger.log_dict['warning'], [
 
2432
                    (('Handoff requested (5)',), {}),
 
2433
                    (('Handoff requested (6)',), {})])
 
2434
                self.assertEquals(self.app.logger.get_increments(),
 
2435
                                  ['handoff_count',
 
2436
                                   'handoff_count'])
 
2437
 
 
2438
                # all error-limited primary nodes -> four handoff warnings,
 
2439
                # plus a handoff-all metric
 
2440
                self.app.log_handoffs = True
 
2441
                self.app.logger = FakeLogger()
 
2442
                self.app.request_node_count = lambda r: 10
 
2443
                object_ring.set_replicas(4)  # otherwise we run out of handoffs
 
2444
                object_ring.clear_errors()
 
2445
                for i in range(4):
 
2446
                    object_ring._devs[i]['errors'] = 999
 
2447
                    object_ring._devs[i]['last_error'] = 2 ** 63 - 1
 
2448
 
 
2449
                collected_nodes = []
 
2450
                for node in self.app.iter_nodes(object_ring, partition):
 
2451
                    collected_nodes.append(node)
 
2452
                self.assertEquals(len(collected_nodes), 10)
 
2453
                self.assertEquals(self.app.logger.log_dict['warning'], [
 
2454
                    (('Handoff requested (7)',), {}),
 
2455
                    (('Handoff requested (8)',), {}),
 
2456
                    (('Handoff requested (9)',), {}),
 
2457
                    (('Handoff requested (10)',), {})])
 
2458
                self.assertEquals(self.app.logger.get_increments(),
 
2459
                                  ['handoff_count',
 
2460
                                   'handoff_count',
 
2461
                                   'handoff_count',
 
2462
                                   'handoff_count',
 
2463
                                   'handoff_all_count'])
 
2464
 
2400
2465
            finally:
2401
2466
                object_ring.max_more_nodes = 0
2402
2467
 
4042
4107
 
4043
4108
    def test_POST_converts_delete_after_to_delete_at(self):
4044
4109
        with save_globals():
 
4110
            self.app.object_post_as_copy = False
4045
4111
            controller = proxy_server.ObjectController(self.app, 'account',
4046
4112
                                                       'container', 'object')
4047
 
            set_http_connect(200, 200, 200, 200, 200, 202, 202, 202)
 
4113
            set_http_connect(200, 200, 202, 202, 202)
4048
4114
            self.app.memcache.store = {}
4049
4115
            orig_time = time.time
4050
4116
            try:
4058
4124
                self.assertEquals(res.status, '202 Fake')
4059
4125
                self.assertEquals(req.headers.get('x-delete-at'),
4060
4126
                                  str(int(t + 60)))
4061
 
 
4062
 
                self.app.object_post_as_copy = False
4063
 
                controller = proxy_server.ObjectController(self.app, 'account',
4064
 
                                                           'container',
4065
 
                                                           'object')
4066
 
                set_http_connect(200, 200, 202, 202, 202)
4067
 
                self.app.memcache.store = {}
4068
 
                req = Request.blank('/v1/a/c/o', {},
4069
 
                                    headers={'Content-Type': 'foo/bar',
4070
 
                                             'X-Delete-After': '60'})
4071
 
                self.app.update_request(req)
4072
 
                res = controller.POST(req)
4073
 
                self.assertEquals(res.status, '202 Fake')
4074
 
                self.assertEquals(req.headers.get('x-delete-at'),
4075
 
                                  str(int(t + 60)))
4076
4127
            finally:
4077
4128
                time.time = orig_time
4078
4129
 
4256
4307
                         headers=None, query_string=None):
4257
4308
            if method == "HEAD":
4258
4309
                self.assertEquals(path, '/a/c/o.jpg')
4259
 
                self.assertNotEquals(None, headers[POLICY_INDEX])
4260
 
                self.assertEquals(1, int(headers[POLICY_INDEX]))
 
4310
                self.assertNotEquals(None,
 
4311
                                     headers['X-Backend-Storage-Policy-Index'])
 
4312
                self.assertEquals(1, int(headers
 
4313
                                         ['X-Backend-Storage-Policy-Index']))
4261
4314
 
4262
4315
        def fake_container_info(account, container, req):
4263
4316
            return {'status': 200, 'sync_key': None, 'storage_policy': '1',
4355
4408
                    expected_storage_policy = 0
4356
4409
                else:
4357
4410
                    continue
4358
 
                storage_policy_index = int(headers[POLICY_INDEX])
 
4411
                storage_policy_index = \
 
4412
                    int(headers['X-Backend-Storage-Policy-Index'])
4359
4413
                self.assertEqual(
4360
4414
                    expected_storage_policy, storage_policy_index,
4361
4415
                    'Unexpected %s request for %s '
4653
4707
        self.assertEqual(
4654
4708
            seen_headers, [
4655
4709
                {'X-Container-Host': '10.0.0.0:1000',
4656
 
                 'X-Container-Partition': '1',
 
4710
                 'X-Container-Partition': '0',
4657
4711
                 'X-Container-Device': 'sda'},
4658
4712
                {'X-Container-Host': '10.0.0.1:1001',
4659
 
                 'X-Container-Partition': '1',
 
4713
                 'X-Container-Partition': '0',
4660
4714
                 'X-Container-Device': 'sdb'},
4661
4715
                {'X-Container-Host': '10.0.0.2:1002',
4662
 
                 'X-Container-Partition': '1',
 
4716
                 'X-Container-Partition': '0',
4663
4717
                 'X-Container-Device': 'sdc'}])
4664
4718
 
4665
4719
    def test_PUT_x_container_headers_with_fewer_container_replicas(self):
4675
4729
        self.assertEqual(
4676
4730
            seen_headers, [
4677
4731
                {'X-Container-Host': '10.0.0.0:1000',
4678
 
                 'X-Container-Partition': '1',
 
4732
                 'X-Container-Partition': '0',
4679
4733
                 'X-Container-Device': 'sda'},
4680
4734
                {'X-Container-Host': '10.0.0.1:1001',
4681
 
                 'X-Container-Partition': '1',
 
4735
                 'X-Container-Partition': '0',
4682
4736
                 'X-Container-Device': 'sdb'},
4683
4737
                {'X-Container-Host': None,
4684
4738
                 'X-Container-Partition': None,
4697
4751
        self.assertEqual(
4698
4752
            seen_headers, [
4699
4753
                {'X-Container-Host': '10.0.0.0:1000,10.0.0.3:1003',
4700
 
                 'X-Container-Partition': '1',
 
4754
                 'X-Container-Partition': '0',
4701
4755
                 'X-Container-Device': 'sda,sdd'},
4702
4756
                {'X-Container-Host': '10.0.0.1:1001',
4703
 
                 'X-Container-Partition': '1',
 
4757
                 'X-Container-Partition': '0',
4704
4758
                 'X-Container-Device': 'sdb'},
4705
4759
                {'X-Container-Host': '10.0.0.2:1002',
4706
 
                 'X-Container-Partition': '1',
 
4760
                 'X-Container-Partition': '0',
4707
4761
                 'X-Container-Device': 'sdc'}])
4708
4762
 
4709
4763
    def test_POST_x_container_headers_with_more_container_replicas(self):
4721
4775
        self.assertEqual(
4722
4776
            seen_headers, [
4723
4777
                {'X-Container-Host': '10.0.0.0:1000,10.0.0.3:1003',
4724
 
                 'X-Container-Partition': '1',
 
4778
                 'X-Container-Partition': '0',
4725
4779
                 'X-Container-Device': 'sda,sdd'},
4726
4780
                {'X-Container-Host': '10.0.0.1:1001',
4727
 
                 'X-Container-Partition': '1',
 
4781
                 'X-Container-Partition': '0',
4728
4782
                 'X-Container-Device': 'sdb'},
4729
4783
                {'X-Container-Host': '10.0.0.2:1002',
4730
 
                 'X-Container-Partition': '1',
 
4784
                 'X-Container-Partition': '0',
4731
4785
                 'X-Container-Device': 'sdc'}])
4732
4786
 
4733
4787
    def test_DELETE_x_container_headers_with_more_container_replicas(self):
4743
4797
 
4744
4798
        self.assertEqual(seen_headers, [
4745
4799
            {'X-Container-Host': '10.0.0.0:1000,10.0.0.3:1003',
4746
 
             'X-Container-Partition': '1',
 
4800
             'X-Container-Partition': '0',
4747
4801
             'X-Container-Device': 'sda,sdd'},
4748
4802
            {'X-Container-Host': '10.0.0.1:1001',
4749
 
             'X-Container-Partition': '1',
 
4803
             'X-Container-Partition': '0',
4750
4804
             'X-Container-Device': 'sdb'},
4751
4805
            {'X-Container-Host': '10.0.0.2:1002',
4752
 
             'X-Container-Partition': '1',
 
4806
             'X-Container-Partition': '0',
4753
4807
             'X-Container-Device': 'sdc'}
4754
4808
        ])
4755
4809
 
4758
4812
        self.app.container_ring.set_replicas(2)
4759
4813
 
4760
4814
        delete_at_timestamp = int(time.time()) + 100000
4761
 
        delete_at_container = str(
4762
 
            delete_at_timestamp /
4763
 
            self.app.expiring_objects_container_divisor *
4764
 
            self.app.expiring_objects_container_divisor)
 
4815
        delete_at_container = utils.get_expirer_container(
 
4816
            delete_at_timestamp, self.app.expiring_objects_container_divisor,
 
4817
            'a', 'c', 'o')
4765
4818
        req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
4766
4819
                            headers={'Content-Type': 'application/stuff',
4767
4820
                                     'Content-Length': '0',
4776
4829
        self.assertEqual(seen_headers, [
4777
4830
            {'X-Delete-At-Host': '10.0.0.0:1000',
4778
4831
             'X-Delete-At-Container': delete_at_container,
4779
 
             'X-Delete-At-Partition': '1',
 
4832
             'X-Delete-At-Partition': '0',
4780
4833
             'X-Delete-At-Device': 'sda'},
4781
4834
            {'X-Delete-At-Host': '10.0.0.1:1001',
4782
4835
             'X-Delete-At-Container': delete_at_container,
4783
 
             'X-Delete-At-Partition': '1',
 
4836
             'X-Delete-At-Partition': '0',
4784
4837
             'X-Delete-At-Device': 'sdb'},
4785
4838
            {'X-Delete-At-Host': None,
4786
4839
             'X-Delete-At-Container': None,
4795
4848
        self.app.expiring_objects_container_divisor = 60
4796
4849
 
4797
4850
        delete_at_timestamp = int(time.time()) + 100000
4798
 
        delete_at_container = str(
4799
 
            delete_at_timestamp /
4800
 
            self.app.expiring_objects_container_divisor *
4801
 
            self.app.expiring_objects_container_divisor)
 
4851
        delete_at_container = utils.get_expirer_container(
 
4852
            delete_at_timestamp, self.app.expiring_objects_container_divisor,
 
4853
            'a', 'c', 'o')
4802
4854
        req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
4803
4855
                            headers={'Content-Type': 'application/stuff',
4804
4856
                                     'Content-Length': 0,
4812
4864
        self.assertEqual(seen_headers, [
4813
4865
            {'X-Delete-At-Host': '10.0.0.0:1000,10.0.0.3:1003',
4814
4866
             'X-Delete-At-Container': delete_at_container,
4815
 
             'X-Delete-At-Partition': '1',
 
4867
             'X-Delete-At-Partition': '0',
4816
4868
             'X-Delete-At-Device': 'sda,sdd'},
4817
4869
            {'X-Delete-At-Host': '10.0.0.1:1001',
4818
4870
             'X-Delete-At-Container': delete_at_container,
4819
 
             'X-Delete-At-Partition': '1',
 
4871
             'X-Delete-At-Partition': '0',
4820
4872
             'X-Delete-At-Device': 'sdb'},
4821
4873
            {'X-Delete-At-Host': '10.0.0.2:1002',
4822
4874
             'X-Delete-At-Container': delete_at_container,
4823
 
             'X-Delete-At-Partition': '1',
 
4875
             'X-Delete-At-Partition': '0',
4824
4876
             'X-Delete-At-Device': 'sdc'}
4825
4877
        ])
4826
4878
 
4851
4903
        for name, index in expected.items():
4852
4904
            req = Request.blank('/a/c', headers={'Content-Length': '0',
4853
4905
                                                 'Content-Type': 'text/plain',
4854
 
                                                 POLICY: name})
 
4906
                                                 'X-Storage-Policy': name})
4855
4907
            self.assertEqual(controller._convert_policy_to_index(req), index)
4856
4908
        # default test
4857
4909
        req = Request.blank('/a/c', headers={'Content-Length': '0',
4859
4911
        self.assertEqual(controller._convert_policy_to_index(req), None)
4860
4912
        # negative test
4861
4913
        req = Request.blank('/a/c', headers={'Content-Length': '0',
4862
 
                            'Content-Type': 'text/plain', POLICY: 'nada'})
 
4914
                            'Content-Type': 'text/plain',
 
4915
                            'X-Storage-Policy': 'nada'})
4863
4916
        self.assertRaises(HTTPException, controller._convert_policy_to_index,
4864
4917
                          req)
4865
4918
        # storage policy two is deprecated
4866
4919
        req = Request.blank('/a/c', headers={'Content-Length': '0',
4867
4920
                                             'Content-Type': 'text/plain',
4868
 
                                             POLICY: 'two'})
 
4921
                                             'X-Storage-Policy': 'two'})
4869
4922
        self.assertRaises(HTTPException, controller._convert_policy_to_index,
4870
4923
                          req)
4871
4924
 
4874
4927
        req = Request.blank('/v1/a/c')
4875
4928
        with mocked_http_conn(
4876
4929
                200, 200,
4877
 
                headers={POLICY_INDEX: int(policy)},
 
4930
                headers={'X-Backend-Storage-Policy-Index': int(policy)},
4878
4931
        ) as fake_conn:
4879
4932
            resp = req.get_response(self.app)
4880
4933
            self.assertRaises(StopIteration, fake_conn.code_iter.next)
4881
4934
        self.assertEqual(resp.status_int, 200)
4882
 
        self.assertEqual(resp.headers[POLICY], policy.name)
 
4935
        self.assertEqual(resp.headers['X-Storage-Policy'], policy.name)
4883
4936
 
4884
4937
    def test_no_convert_index_to_name_when_container_not_found(self):
4885
4938
        policy = random.choice(list(POLICIES))
4886
4939
        req = Request.blank('/v1/a/c')
4887
4940
        with mocked_http_conn(
4888
4941
                200, 404, 404, 404,
4889
 
                headers={POLICY_INDEX: int(policy)}) as fake_conn:
 
4942
                headers={'X-Backend-Storage-Policy-Index':
 
4943
                         int(policy)}) as fake_conn:
4890
4944
            resp = req.get_response(self.app)
4891
4945
            self.assertRaises(StopIteration, fake_conn.code_iter.next)
4892
4946
        self.assertEqual(resp.status_int, 404)
4893
 
        self.assertEqual(resp.headers[POLICY], None)
 
4947
        self.assertEqual(resp.headers['X-Storage-Policy'], None)
4894
4948
 
4895
4949
    def test_error_convert_index_to_name(self):
4896
4950
        req = Request.blank('/v1/a/c')
4897
4951
        with mocked_http_conn(
4898
4952
                200, 200,
4899
 
                headers={POLICY_INDEX: '-1'}) as fake_conn:
 
4953
                headers={'X-Backend-Storage-Policy-Index': '-1'}) as fake_conn:
4900
4954
            resp = req.get_response(self.app)
4901
4955
            self.assertRaises(StopIteration, fake_conn.code_iter.next)
4902
4956
        self.assertEqual(resp.status_int, 200)
4903
 
        self.assertEqual(resp.headers[POLICY], None)
 
4957
        self.assertEqual(resp.headers['X-Storage-Policy'], None)
4904
4958
        error_lines = self.app.logger.get_lines_for_level('error')
4905
4959
        self.assertEqual(2, len(error_lines))
4906
4960
        for msg in error_lines:
5032
5086
                                    headers={'Content-Length': 0})
5033
5087
                if requested_policy:
5034
5088
                    expected_policy = requested_policy
5035
 
                    req.headers[POLICY] = policy.name
 
5089
                    req.headers['X-Storage-Policy'] = policy.name
5036
5090
                else:
5037
5091
                    expected_policy = POLICIES.default
5038
5092
                res = req.get_response(self.app)
5050
5104
                    len(backend_requests))
5051
5105
                for headers in backend_requests:
5052
5106
                    if not requested_policy:
5053
 
                        self.assertFalse(POLICY_INDEX in headers)
 
5107
                        self.assertFalse('X-Backend-Storage-Policy-Index' in
 
5108
                                         headers)
5054
5109
                        self.assertTrue(
5055
5110
                            'X-Backend-Storage-Policy-Default' in headers)
5056
5111
                        self.assertEqual(
5057
5112
                            int(expected_policy),
5058
5113
                            int(headers['X-Backend-Storage-Policy-Default']))
5059
5114
                    else:
5060
 
                        self.assertTrue(POLICY_INDEX in headers)
5061
 
                        self.assertEqual(int(headers[POLICY_INDEX]),
 
5115
                        self.assertTrue('X-Backend-Storage-Policy-Index' in
 
5116
                                        headers)
 
5117
                        self.assertEqual(int(headers
 
5118
                                         ['X-Backend-Storage-Policy-Index']),
5062
5119
                                         policy.idx)
5063
5120
                # make sure all mocked responses are consumed
5064
5121
                self.assertRaises(StopIteration, mock_conn.code_iter.next)
5162
5219
            self.app.max_containers_per_account = 12345
5163
5220
            controller = proxy_server.ContainerController(self.app, 'account',
5164
5221
                                                          'container')
5165
 
            self.assert_status_map(controller.PUT, (201, 201, 201), 403,
 
5222
            self.assert_status_map(controller.PUT,
 
5223
                                   (200, 200, 201, 201, 201), 201,
 
5224
                                   missing_container=True)
 
5225
 
 
5226
            controller = proxy_server.ContainerController(self.app, 'account',
 
5227
                                                          'container_new')
 
5228
 
 
5229
            self.assert_status_map(controller.PUT, (200, 404, 404, 404), 403,
5166
5230
                                   missing_container=True)
5167
5231
 
5168
5232
            self.app.max_containers_per_account = 12345
5811
5875
            200, 201, 201, 201)    # HEAD PUT PUT PUT
5812
5876
        self.assertEqual(seen_headers, [
5813
5877
            {'X-Account-Host': '10.0.0.0:1000',
5814
 
             'X-Account-Partition': '1',
 
5878
             'X-Account-Partition': '0',
5815
5879
             'X-Account-Device': 'sda'},
5816
5880
            {'X-Account-Host': '10.0.0.1:1001',
5817
 
             'X-Account-Partition': '1',
 
5881
             'X-Account-Partition': '0',
5818
5882
             'X-Account-Device': 'sdb'},
5819
5883
            {'X-Account-Host': None,
5820
5884
             'X-Account-Partition': None,
5831
5895
            200, 201, 201, 201)    # HEAD PUT PUT PUT
5832
5896
        self.assertEqual(seen_headers, [
5833
5897
            {'X-Account-Host': '10.0.0.0:1000,10.0.0.3:1003',
5834
 
             'X-Account-Partition': '1',
 
5898
             'X-Account-Partition': '0',
5835
5899
             'X-Account-Device': 'sda,sdd'},
5836
5900
            {'X-Account-Host': '10.0.0.1:1001',
5837
 
             'X-Account-Partition': '1',
 
5901
             'X-Account-Partition': '0',
5838
5902
             'X-Account-Device': 'sdb'},
5839
5903
            {'X-Account-Host': '10.0.0.2:1002',
5840
 
             'X-Account-Partition': '1',
 
5904
             'X-Account-Partition': '0',
5841
5905
             'X-Account-Device': 'sdc'}
5842
5906
        ])
5843
5907
 
5851
5915
            200, 204, 204, 204)    # HEAD DELETE DELETE DELETE
5852
5916
        self.assertEqual(seen_headers, [
5853
5917
            {'X-Account-Host': '10.0.0.0:1000',
5854
 
             'X-Account-Partition': '1',
 
5918
             'X-Account-Partition': '0',
5855
5919
             'X-Account-Device': 'sda'},
5856
5920
            {'X-Account-Host': '10.0.0.1:1001',
5857
 
             'X-Account-Partition': '1',
 
5921
             'X-Account-Partition': '0',
5858
5922
             'X-Account-Device': 'sdb'},
5859
5923
            {'X-Account-Host': None,
5860
5924
             'X-Account-Partition': None,
5871
5935
            200, 204, 204, 204)    # HEAD DELETE DELETE DELETE
5872
5936
        self.assertEqual(seen_headers, [
5873
5937
            {'X-Account-Host': '10.0.0.0:1000,10.0.0.3:1003',
5874
 
             'X-Account-Partition': '1',
 
5938
             'X-Account-Partition': '0',
5875
5939
             'X-Account-Device': 'sda,sdd'},
5876
5940
            {'X-Account-Host': '10.0.0.1:1001',
5877
 
             'X-Account-Partition': '1',
 
5941
             'X-Account-Partition': '0',
5878
5942
             'X-Account-Device': 'sdb'},
5879
5943
            {'X-Account-Host': '10.0.0.2:1002',
5880
 
             'X-Account-Partition': '1',
 
5944
             'X-Account-Partition': '0',
5881
5945
             'X-Account-Device': 'sdc'}
5882
5946
        ])
5883
5947
 
6742
6806
        self.assertEqual(si['max_object_name_length'],
6743
6807
                         constraints.MAX_OBJECT_NAME_LENGTH)
6744
6808
        self.assertTrue('strict_cors_mode' in si)
 
6809
        self.assertEqual(si['allow_account_management'], False)
 
6810
        self.assertEqual(si['account_autocreate'], False)
6745
6811
        # this next test is deliberately brittle in order to alert if
6746
6812
        # other items are added to swift info
6747
 
        self.assertEqual(len(si), 14)
 
6813
        self.assertEqual(len(si), 16)
6748
6814
 
6749
6815
        self.assertTrue('policies' in si)
6750
6816
        sorted_pols = sorted(si['policies'], key=operator.itemgetter('name'))