Downgrade MySQL to the same state it used to be

virtual_interfaces_instance_uuid_fkey exists as a KEY, not a UNIQUE KEY in
MySQL which causes trouble when downgrading.

Don't re-create the virtual_interfaces_instance_uuid_fkey on downgrade as it
wasn't upgraded properly and therefore still exists. This forces the downgrade
to look exactly like it was before the upgrade.

Fixes bug 1207344

Change-Id: Id1700e1cbba669df2dd8e5c5a842b859577aa32c
Remove the indexes on downgrade to work with MySQL

Fixes MySQL downgrade on migration 203.
Add tests to check the indexes.

Fixes bug 1207174

Change-Id: If50fb49e1c76c2a7512141dae5f1a5818dc1b699
Fix migration downgrade 146 with mysql

Add availability zones back in individually to work with MySQL downgrades
on migration 146.

Fixes bug 1207956

Change-Id: I48b3ce27b92f231e280ee5af7a3e1b8ce6c4b018
xenapi: refactor - extract get_virtual_size

This change extracts a function get_virtual_size. This is needed,
because we would like to support tar.gz files, in which case the image's
virtual size will be determined by looking at the tar.gz stream. The
first tarinfo will tell us the size.

related to blueprint xenapi-supported-image-import-export

Change-Id: If34bb8849ad2dacf471f1bec5e72a37ddda79464
Remove unsafe XML parsing

Move to using xmlutils for XML parsing. Fixes missing patch
for the V3 API in commit 0ef2c55d804e0dab58cb5419a0cafd6a805315c7
and fixes bug 1210529

Change-Id: I6dc6111844277565d075a4ff5a08fdee5bc99344
Fix instance_group_delete() DB API method

Table 'instance_groups' has two columns that can be used to
unambigously identify the specific row:
  - 'id' (Integer, primary_key=True, autoincrement=True)
  - 'uuid' (String)

The former is used internally to bind related instances by FKs
(InstanceGroupMember, InstanceGroupPolicy and InstanceGroupMetadata),
and the latter is accepted by public methods of DB API. This must
be a miss in DB schema design, because 'uuid' could be used for both
use cases.

instance_group_delete() deletes the instance group (and all related
instances) given its UUID value. When related entities are deleted
they are filtered by the FK value - the 'group_id' column, however,
the 'group_uuid' value is passed.

Such DELETE statement is executed successfully (though WHERE clause never
evaluates to True, so the query is logically incorrect) on MySQL and SQLite,
which are often too 'soft' when checking data types of passed values.

This patch fixes the instance_group_delete() method and renames the 'group_uuid'
argument of _instance_group_model_get_query() to 'group_id', because this one
is actually always called with id value rather than with uuid.

Closes-Bug: #1211307

Change-Id: Ic8bcb4b218f570f26420904aeb74eb14567235fb
Fix ReservationTestCase on PostgreSQL

setUp() of ReservationTestCase calls quota_reserve() passing
timeutils.utcnow() as a value of 'until_refresh' argument.
until_refresh column is actually of type int rather than
datetime or varchar, so these tests fail on PostgreSQL.

Blueprint: db-api-tests-on-all-backends

Change-Id: Ib57579db2080f44bd41b91e83b0eee6f77f51840
Allow swap_volume to be called by Cinder

This allows Cinder to call swap_volume as part of a volume migration.
Cinder creates the new volume and calls Nova to perform the swap. When
Nova finishes, it calls Cinder to complete the migration, where it
updates the volume metadata so that the volume ID remains unchanged.
Thus, if Cinder detects that the migration was initiated by Cinder, it
will return the original volume ID to keep using. Otherwise, it will
return the new volume's ID for Nova to use, which is what it had done
before.

Change-Id: If352f2e11701148a5aeccaf7fd6379528fa8be31
Remove "N309 Python 3.x incompatible construct"

This check was implemented as H231 in Hacking 0.6 or newer
(I0bd89fa05d88de34ca62ce59f427468ede226126),
so the duplicate implementation can be removed.

Change-Id: I003d8611621adc53f1afcfd77691f345397670b0
Fix exception handling in V3 API coverage extension

Commit 616098dcd36b20e01d38898b8942003df664e6ac fixed the exception
handling in the V2 version of the coverage extension so backtrace
information is not lost when an exception is reraised. This applies
the same fix to the V3 version

Change-Id: I29ec1492c2def9c60c8ff471683914ae2943966e
Refactor integrated tests to support V2 and V3 API testing Part 2

This changeset moves the APISampleTestBase class out into its own
file so the V3 versions of the tests can cleanly import it separate
from the V2 code.

Partially implements v3-api-unittests
Partially implements v3-api-specification

Change-Id: If0994934edb2ab19004353f9a4089ce525ed31dd
Port integrated tests for V3 API

Ports most of the integrated tests to the V3 API. The
test api samples test will be ported to the V3 API in a later
changeset

Partially implements blueprint v3-api-unittests

Change-Id: I00a93471d95760e6c97534808c5a93522710b20d
Adds infra for v3 API sample creation

Adds the required infrastructure for the v3 API sample creation.
- v3 API samples and the test cases are in their own v3 directory
- API samples from "core" are now put in their own (per plugin)
  directory rather than in the root directory
- Testcases to create api samples are now placed in individual
  files rather than one giant one. I think it makes it clearer what
  testcases we do have and avoids merge conflict pain

Adds API samples for basic servers interaction

Fix for bug in servers.py where if no extension was loaded which
extends create xml deserialization an exception would occur (fixed
here because it causes the api sample tests ported to fail).

Partially implements blueprint v3-api-unittests

Change-Id: I653af49dcc499c18f14b6e1764711a9922354069
Handle InstanceInvalidState of soft_delete

Since commit 99c51e34230394cadf0b82e364ea10c38e193979, instance
is not able to be soft_deleted if instance has never been active.
But there are circumstances when instance fails on initial build.
Thus if we set reclaim_instance_interval in nova.conf, we cannot
delete such instances in any way.

This patch fixes this by handling InstanceInvalidState exception
when try to soft_delete instance. The delete() function is called
for instance which has never been active.

Bug 1202158

Change-Id: I7d0d9414d7436e56b6a3e5861ee3c2f02473df2b
Stub out entry points in LookupTorrentURLTestCase

Torrent URL lookup functions are registered via entry-points.

If the tests run in an environment where the production lookup function is
present, it will use that; not what we want for tests.

Instead, we should stubout entry-points so we have a mock URL lookup function.

Fixes bug 1211396

Change-Id: Ibc2b34bfdcecaad4c53fb00e925a8b21965d8577
Set VM back to its original state if cold migration failed

If migration of a VM in the STOPPED state failed due to
NoValidHost, the VM was erroneously set to ACTIVE.

The fix sets the VM back to its original state instead.

Fix bug 1204905

Change-Id: I67ccac9ff4104fbd63c545b9f9399206a7febae7
Fix instance metadata access in xenapi

In preparation for objects, use the helper method in utils to get instance
metadata.

Related to blueprint unified-object-model

Change-Id: I552369937854ec195d1f9abb1835b4e6afef7a70
Updates tools/config/README

The sample command line lacks the arguments required for executing
the script. Added the command line used in check_uptodate.sh

Fixes bug #1204204

Change-Id: I475491872577632c472695a3b1089caaf1f27d7c
Add new compute method for building an instance

The run_instance method on the compute manager handles rescheduling of a
failed build by casting back to the scheduler.  In order to maintain
backwards compatibility while modifying the build process to go through
the conductor a new method is being added to co-ordinate building an
instance.

This is one part of a series of patches to build up the
build_and_run_instance method.

The conductor will be switched over to calling this method once it
reaches a level of consistency with the current run_instance method.

Part of bp query-scheduler

Change-Id: I879805efa4a0a045082c02b10926e1278136b72c
nova.conf configurable gzip compression level

Currently only used by XenAPI.

Sets GZIP environment variable before spawning tar -cz to force the
compression level. Defaults to none, which means the GZIP environment
variable is not set and the default (usually -6) is used.

Implements: blueprint image-compression-mode

Change-Id: I02e136b7215a4f2cefc259f40bde9c1b205737ed