Sync models with migrations

Models should be the same as the state in DB after migration
blueprint db-sync-models-with-migrations

Change-Id: Iea57866206776c14677dfa78e868143b6fb153a9
Removes duplicate options registration in registry clients

Fixes bug #1204359

Change-Id: I5b8bd9e4465d9fe70e9311474bc2b00d9afcf046
Improve test/utils.py

Introduce new class into utils.py to keep glance api tests DRYer

Partially implements blueprint glance-tests-code-duplication

Change-Id: Ic77961fcc83806fd451afa1a0d230f09926ebfd9
Refactor glance/tests/unit/v1/test_registry_client.py

Remove code duplication from module

Partially implements blueprint glance-tests-code-duplication

Change-Id: I85f5d7a45c65533ba49f2dfdefdfccfde221468b
Refactor glance/tests/unit/v2/test_registry_client.py

Remove code duplication from module

Partially implements blueprint glance-tests-code-duplication

Change-Id: Idf54d98d0982b7c64696056c87283eb92f1164b5
Call _post_downgrade_### after downgrade migration is run

Fixes bug 1195470

Tests are currently only run after a upgrade during the database migration
unit tests and never during a downgrade. This change calls an optional
_post_downgrade_### method after running the downgrade migration to allow
it to be tested as well.

Change-Id: I592424b464b91c2be9e253402986e673ce33c8d0
Add unit test for migration 012

This continues implementing unit tests for the migrations that are
currently missing them

Change-Id: I08b92532d1469ee03b976e2522e12a4540f0dae2
Code dedup in glance/tests/unit/v1/test_registry_api.py

Move duplicated fixture set-ups, requests and assertions to tests.utils.py

bp glance-tests-code-duplication

Change-Id: Ie0f13b5f5d5a242f24ac7cd6cc548ff09ebe6ba5
Remove unused import of oslo.config

Remove unused import in glance.cmd.cache*,
and make glance code tidy and pleasing.

Change-Id: Ie5d2cf5c1a52fda505a1dd4d5b01267285a10c00
Remove unused var DEFAULT_MAX_CACHE_SIZE

In file: glance/image_cache/__init__.py, DEFAULT_MAX_CACHE_SIZE
is never used after declared, remove it and make glance code
tidy and pleasing.

Change-Id: I208f1dc63e2bc95bb6be94fdc88f9bfce069f67c
Prefetcher should perform data integrity check

When prefetching into cache we should verify the image data checksum.

Fixes bug 882585.

Change-Id: I01211894d0d76d69cbf92fe726fbed56326d950d
test failure induced by reading system config file

run run_tests.sh or tox to test the glance code, it will get
following failure:
test_get_bind_addr_default_value
test_get_path_non_exist

Analysis
--------
The root cause is resided in "glance/tests/unit/api/test_cmd.py".
In TestGlanceApiCmd.setUp, the sys.argv is overrided to ['glance-api'].
Since sys.argv is "global" variable, and this test entry it run
firstly by nosetests while running tests in "glance/tests/unit"(since
nosetests search test items alphabetically), the other test entries
will inherit the sys.argv value ['glance-api']. Finally the system
config file "/etc/glance/glance-api.conf" is read in "setUp" via
oslo.config.cfg:ConfigOpts.__call__ -> _pre_setup -> find_config_files.
CONF.bind_port and CONF.bind_host is set to the value reading from
system config file: /etc/glance/glance-api.conf.

A simplied call backtrace:
TestGlanceApiCmd.setUp -->  sys.argv = ['glance-api']
 ->JSONRequestDeserializerTest.setUp
  ->glance/common/config.py:parse_args
   ->oslo.config.cfg:ConfigOpts.__call__
    ->CONF.bind_port CONF.bind_host is set

wsgi.get_bind_addr() will read the CONF.bind_port and CONF.bind_host
to return value. if system config file is not read, CONF.bind_host
is set to "0.0.0.0", CONF.bind_port is not set. wsgi.get_bind_addr()
will return the expected value. This is the reason that individual
test of test_get_bind_addr_default_value got passed, but failed while
testing all.

The failure of test_get_path_non_exist is induced by same reason.

Test case should clear up the setting in tearDown(), especially the
"global" setting, e.g. sys.argv.

Solution
--------
The solution is simple:
In class TestGlanceApiCmd, add a private variable to backup the
sys.argv in setUp(), and restore it in tearDown().

Test method
-----------
$ ./run_tests.sh

$ tox -evenv -- nosetests \
--tests=glance.tests.unit.common.test_config:TestPasteApp

tox -evenv -- nosetests
--tests=glance.tests.unit.common.test_wsgi:JSONRequestDeserializerTest

Fixes Bug #1204186

Change-Id: I2dac8e506fa794d1faa9509258936d78e2f981d8
Remove unused import

Remove unused import in tests.functional.store modules to make codes
cleaner.

Change-Id: I07a66d0ba7c0f0233d0d03310d83b33f0b92bbe9
Fix Sphinx warning

Title underline was too short.

Change-Id: I2915f9d3ad0b208286d447ef2375e51f51b7e35d
Introduced DB pooling for non blocking DB calls

The DbApi module is wrapped with the tpool wrapper if the configuration is
enabled. use_tpool is disabled (False) by default

Related to bp mysql-thread-pool

Change-Id: Ie7274ac855549b96c581c3eb0bcf79f3c74be0ed
Fix up trivial License mismatches

This makes the Hacking licensing check succeed.

Change-Id: Iba1446fa06fe466a05514d5df0e53d26dd9fc8e4
emit warning while running flake8 without virtual env

run_tests.sh -N -p

it will call the flake8 installed on your host to detect PEP8, and
the flake8 plugin "OpenStack hacking" may not installed on your
host, so this command may not detect the OpenStack Style Commandment
supplied by hacking(e.g H202).

run_tests.sh -p
it will call the flake8 from virtual env, flake8 plugin "OpenStack
hacking" installed in virtual env will be triggered.

The result from "run_tests.sh -p" should be trusted, and jenkins uses
virtual env to run flake8 too.

When "-N" is enabled, emit warning to stderr to remind user.

Bug #1215396

Change-Id: Iac6be532b7b9bb911b745712712d1be363e8ff01
Fix useless assertTrue

In glance/tests/functional/test_scrubber.py,
TestScrubber::test_scrubber_with_metadata_enc(), local var marker_uri
is always not None, so self.assertTrue(marker_uri is not None) don't
make sense. This patch init it with None.

Change-Id: Id2fcffe6ff67b6fa59247d42ab15ffb228dd622f
Merge "Fix useless assertTrue"
Avoid redefinition of test

test_add_member() is defined twice under the same
name, however checking for different things. Rename
the 2nd instance to _unauthorized to avoid overwriting
the first implementation.

The first check is actually duplicate to test_add_member_positive.
So merging the first check with test_add_member_positive.

Change-Id: Ifb029d8f34f9f4139557bb9b197492fb344a598e