Update instance.node on evacuate

The evacuate API works like a migration from a dead node. As part of
migration, the instance.node property is updated to reflect the target
node that the instance is migrating to. This is later used when the
migration is confirmed/reverted. The problem is when an instance is
being evacuated, the node property isn't getting updated and the
instance will have the old (dead) node value set on it after it's
evacuated. This patch updates instance.node when the instance is
evacuated.

Fixes bug 1198284

Change-Id: I4901fb937160e955df7c97c37265783e844fdbef
Sync db.models.Instance* with migrations.

This patch syncs models with migrations for:
    - InstanceIdMapping
    - InstanceMetadata
    - InstanceSystemMetadata
    - InstanceTypeExtraSpecs
    - InstanceTypeProjects
    - InstanceTypes
    - InstanceGroupMember
    - InstanceGroupPolicy
    - InstanceGroupMetadata

Blueprint: db-sync-models-with-migrations

Change-Id: Ice28b9d545f60f7df381e3fcf2c86a2b8e7350d3
Unimplemented pause should not change vm state on PowerVM

The instance of PowerVM does not support pause, but
after pause the instance, the state change to PAUSED,
it's unreasonable.

Change-Id: I4fb184388c37ea8708cdacc173dc1b2dbd4d1597
Fixes: bug #1202082
Handle instance being deleted while in filter scheduler

Adds handling of InstanceNotFound when trying to update the
scheduled_at time of an instance.

Users can delete an instance at any time (and many test
cases delete very quickly), so this should be a warning
not an error

Fixes bug 1191126

Change-Id: I72b296668f60b1de71ff8c6d7bbb749023d89f12
Sync v2/v3 console_output API extensions

Synchronises changes made to the v2 version of the console_output
API extension to v3 in commit c651f4928c65407cff86a9f9efc046a0f76a9519
which fixed bug  #1194032

Partially implements blueprint nova-v3-api

Change-Id: Ie28d771d25636decb7b1f17756654be56762b35f
port disk_config API into v3 part1

This changeset only copies the v2 files into the appropriate v3
directories unchanged. The copy as-is will not be loaded by either
the v2 or v3 extension loaders. The second changeset will then
make the changes required for it to work as a v3 extension.

This is being tried in order to make reviewing of extension
porting easier as gerrit will display only what is actually
changed for v3 rather than entirely new files.

Partially implements: bp v3-api-extension-versioning

Change-Id: Ia2ef4ab8cb63878d16360378c61e5182f4593200
Port used limits extension to v3 API Part 1

This changeset only copies the v2 implementation file into the
appropriate v3 directory unchanged. The copy as-is will not be
loaded by either the v2 or v3 extension loaders. The second
changeset will then make the changes required for it to work as a
v3 extension.

This is being done in order to make reviewing of extension porting
easier as gerrit will display only what is actually changed for v3
rather than entirely new files.

Partially implements blueprint nova-v3-api

Change-Id: I34214370f53d481346eb11fec6b8fd0ddeb42918
Prompt error message when creating aggregate without aggregate name

When using API to create an availability zone via aggregate, the
prompt message will be "There was a conflict when trying to complete
your request" if the request body looks like below.
{"aggregate": {"name": "", "availability_zone": "zy1_zone53335"}}

The message is not accurate, aggregate name should not be null.

Fixes bug 1188032
Change-Id: I1fb74186886283a9b6763abb665b8ce42e4bb24c
Fix aggregate_get_by_host host filtering

aggregate_get_by_host never actually joins the _hosts relationship,
so aggregates with non-matching hosts are still included in the output.

This change adds the join and improves the tests to cover the bug.

Fixes bug 1201277.

Change-Id: I87ebfe3de193b9ae47e3a2c8350a49d9cc863fb0
Fix IPAddress and CIDR type decorators

Use load_dialect_impl() user hook instead of calling
with_variant() on a type implementation in IPAddress
and CIDR type decorators. This makes this code work
with SQLAlchemy 0.8.x versions.

Fixes bug 1200231

Change-Id: Ib0eb582f472116bda817d3e35e26888dc116ad58
Fix filtering aggregate metadata by key

Filtering by metadata key has no effect in the following two functions:

    aggregate_metadata_get_by_host
    aggregate_host_get_by_metadata_key

Rely on the explicit join instead of joinedload to load the _metadata
relationship in these functions (indicated by the contains_eager
option), so that filtering by key still applies when the metadata is
collected.

Fixes bug 1201283.

Change-Id: I3e44b5db8d67787bfa14f0e57d30a02a271a8833
Port used limits extension to v3 API Part 2

Ports the used limits extension and the corresponding unittests to
the v3 framework.

Partially implements blueprint nova-v3-api

Change-Id: I6f1aa507ffd297e56d9cfd23972bc3bb15ba181a
Remove redundant if statements in cells.state

Removed redundant if statements since checking if cell is None twice
was not intuitive.

Change-Id: I20d7ade5acd27d23ba53ef065d0e4d24218182c2
Moved tests for server._action_rebuild

Move tests to separate class as a preparation for code
deduplication.

This work continues in https://review.openstack.org/34556

bp nova-tests-code-duplication

Change-Id: I985232fa0a9b2d5b73034047b06138a8a3d7e390
Code dedup in tests for server._action_rebuild

Externed common parts to setUp():
- request body
- request object
- test image UUID
- test image URL
These parts were equal in the most part of the methods.

bp nova-tests-code-duplication

Change-Id: Ie29dd090075915a4065ee395b4e50fc178f72f3b
Make Instance object properly update *metadata

Currently, the Instance object won't notice when metadata or
system_metadata has changed and thus won't include it in updates it
makes to the database.

We could make these two dicts full-fledged objects, but that's a bit
overkill for this purpose. Stash a copy of them every time we reset
our changes so that we can detect changes in save().

Note that this includes tests to some shelve tests which are now
wrong because they modify the instance's sys_meta prematurely.
Turns out, these are the tests that pointed out the need for
this tracking :)

Related to blueprint unified-object-model
Fixes bug 1201776

Change-Id: I3df462645979742379a41060cda5bb5084fddb20
Fix Instance object handling of implied fields

The situation around info_cache and security_groups is a bit
confusing and inconsistent at the moment. Since some of the
"all" queries don't join info_cache and security_groups,
avoid assuming that they are there, either triggering an
unintentional lazy load, or a KeyError in a few cases where the
DB API returns a dict.

Also, don't ever allow us to recurse into another instance object
looking for a loaded attribute in case it fails to load from the
get query.

Related to blueprint unified-object-model

Change-Id: I40b72274cd24034b03c8e07af56e7c8d49b6b898
Fix shelve's use of system_metadata

The shelve patches needed to include a hack to make the changes
to system_metadata get saved properly. Now that it's fixed,
clean that up.

Related to blueprint unified-object-model

Change-Id: I79a2db66544e0662e48445505a818ff62f765569
Fix duplicate osapi_hide_server_address_states config option

This is causing an error in the config file tool generator.
Import the config option from the v3 API copy of this code.

Change-Id: I5a03f509c91de080d3753bf351d891d06600e84b
Add expected_errors for extension deferred_delete v3

Partially implements bp v3-api-extension-versioning

Change-Id: Ia63f6cd947c20a05e84385f2401d6b869ebeb456