swift/test/unit/common
Samuel Merritt 1c88d2cb81 Fix up get_account_info and get_container_info
get_account_info used to work like this:

  * make an account HEAD request

  * ignore the response

  * get the account info by digging around in the request environment,
    where it had been deposited by elves or something

Not actually elves, but the proxy's GETorHEAD_base method would take
the HEAD response and cache it in the response environment, which was
the same object as the request environment, thus enabling
get_account_info to find it.

This was extraordinarily brittle. If a WSGI middleware were to
shallow-copy the request environment, then any middlewares to its left
could not use get_account_info, as the left middleware's request
environment would no longer be identical to the response environment
down in GETorHEAD_base.

Now, get_account_info works like this:

  * make an account HEAD request.

  * if the account info is in the request environment, return it. This
    is an optimization to avoid a double-set in memcached.

  * else, compute the account info from the response headers, store it
    in caches, and return it.

This is much easier to think about; get_account_info can get and cache
account info all on its own; the cache check and cache set are right
next to each other.

All the above is true for get_container_info as well.

get_info() is still around, but it's just a shim. It was trying to
unify get_account_info and get_container_info to exploit the
commonalities, but the number of times that "if container:" showed up
in get_info and its helpers really indicated that something was
wrong. I'd rather have two functions with some duplication than one
function with no duplication but a bunch of "if container:" branches.

Other things of note:

  * a HEAD request to a deleted account returns 410, but
    get_account_info would return 404 since the 410 came from the
    account controller *after* GETorHEAD_base ran. Now
    get_account_info returns 410 as well.

  * cache validity period (recheck_account_existence and
    recheck_container_existence) is now communicated to
    get_account_info via an X-Backend header. This way,
    get_account_info doesn't need a reference to the
    swift.proxy.server.Application object.

  * both logged swift_source values are now correct for
    get_container_info calls; before, on a cold cache,
    get_container_info would call get_account_info but not pass along
    swift_source, resulting in get_account_info logging "GET_INFO" as
    the source. Amusingly, there was a unit test asserting this bogus
    behavior.

  * callers that modify the return value of get_account_info or of
    get_container_info don't modify what's stored in swift.infocache.

  * get_account_info on an account that *can* be autocreated but has
    not been will return a 200, same as a HEAD request. The old
    behavior was a 404 from get_account_info but a 200 from
    HEAD. Callers can tell the difference by looking at
    info['account_really_exists'] if they need to know the difference
    (there is one call site that needs to know, in container
    PUT). Note: this is for all accounts when the proxy's
    "account_autocreate" setting is on.

Change-Id: I5167714025ec7237f7e6dd4759c2c6eb959b3fca
2016-05-13 10:40:56 -07:00
..
middleware Fix up get_account_info and get_container_info 2016-05-13 10:40:56 -07:00
ring change default ports for servers 2016-04-29 14:47:38 -04:00
__init__.py Initial commit of Swift code 2010-07-12 17:03:45 -05:00
corrupted_example.db Real files for bad databases. 2011-08-02 18:21:25 +00:00
malformed_example.db Real files for bad databases. 2011-08-02 18:21:25 +00:00
test_base_storage_server.py pep8 fix: assertEquals -> assertEqual 2015-10-11 12:57:25 +02:00
test_bufferedhttp.py remove remaining simplejson uses, prefer standard library import 2015-11-16 12:34:24 -08:00
test_constraints.py Refactor server side copy as middleware 2016-05-11 14:55:51 -04:00
test_container_sync_realms.py Fix unit tests failing in some cases 2014-10-09 22:04:53 +05:30
test_daemon.py pep8 fix: assertEquals -> assertEqual 2015-10-11 12:57:25 +02:00
test_db.py Require account/container metadata be UTF-8 2016-02-29 10:27:29 +00:00
test_db_replicator.py change default ports for servers 2016-04-29 14:47:38 -04:00
test_direct_client.py change default ports for servers 2016-04-29 14:47:38 -04:00
test_exceptions.py Remove swiftclient dep on direct_client 2013-12-24 03:11:43 -08:00
test_header_key_dict.py Move HeaderKeyDict to avoid an inline import 2016-03-07 12:26:48 -08:00
test_internal_client.py Check marker params in SimpleClient full listing requests 2016-03-23 23:14:06 +00:00
test_manager.py Replace assertEqual(None, *) with assertIsNone in tests 2016-02-16 23:49:06 +08:00
test_memcached.py Make _get_addr() method a function in utils. 2016-01-12 21:09:48 -08:00
test_request_helpers.py Fix proxy-server's support for chunked transferring in GET object 2016-03-02 22:56:13 +09:00
test_splice.py pep8 fix: assertEquals -> assertEqual 2015-10-11 12:57:25 +02:00
test_storage_policy.py Use smaller quorum size in proxy for even numbers of replicas 2016-04-27 16:59:00 -05:00
test_swob.py Refactor server side copy as middleware 2016-05-11 14:55:51 -04:00
test_utils.py Merge "Allow fallocate_reserve to be a percentage" 2016-05-12 08:18:39 +00:00
test_wsgi.py Make info caching work across subrequests 2016-05-13 10:36:49 -07:00