Catch InstanceNotFound exceptions for V2 API virtual interfaces

Use the common.get_instance method to get the instance object
in the V2 API virtual interfaces extension rather than call
the compute api directly. The utility function
handes InstanceNotFound exceptions and tranlsates them to HTTPNotFound
rather than letting them propagate up causing a traceback.

Co-Authored-By: Michael Still <mikal@stillhq.com>

Change-Id: I8abee22c53195926e3d2af1da9b14cd9d3608e63
Closes-Bug: 1270804
libvirt: raises exception when attempt to resize disk down

Raises an exception when trying to resize an instance that needs to
resize the disk down.

Change-Id: Ic0a0bede744a1aacd057c5db9de3307b61c525b4
Related-Bug: #1270238
Raise exception if volume snapshot id not found instead of return

In V2 API, if show or delete a snapshot with an unknown id, exception
will be returned instead of raised. Even though correct error
will be returned to client, it's not aligned to other API layer
code, this patch modify it by raise exception instead of return.

Change-Id: I22d4565ca08e1c0ed5041ce903bf6ba918c14cfd
Closes-Bug: #1279189
Port libvirt copy_image tests to mock

Rather than using temporary files, monkey patching and only checking a
subset of utils.execute() arguments, let's use mock.

Change-Id: Ifd1d35d5f44fba16293263bc3b11c405a86aafd4
VMware: Ensure test VM is running in rescue tests

Code was calling get_info() on test VM, but not using it. There are 2
options to fix this:

1. Use it
2. Don't call get_info()

I have chosen option 1.

This change adds a test on the data returned by get_info() which
ensures that the vm just created is in state power_state.RUNNING. The
code later tests that the vm is in state power_state.SHUTDOWN, so the
additional test that it was previously running reinforces that
rescue() caused the shutdown to happen.

Change-Id: Iec58b0dd40702d3bcebf339e9ada8b90a2229d5c
Noted that tox is the preferred unit tester.

This bug and fix is not about deleting run_tests.sh.
The change to delete run_tests.sh has been abandoned.
Thus the documentation of run_tests.sh remains.

Change-Id: Ia0a883260affc56c148dbebc5e3a49acb36b067e
Closes-Bug: #1282393
Fix difference between mysql & psql of flavor-show

If you create a new flavor using a deleted flavorid,
the result of flavor-show is different between mysql and psql.

This issue is caused by the different processing for index in each db.

We need to specify the sort-type to avoid the issue.

Change-Id: Ib1029e80c1b981e1ec86d954b63f83650c9b1cc1
Closes-Bug: #1288636
Libvirt: Repair metadata injection into guests

The change to use Instance objects when spawning instances
changed the format of the 'metadata' property.  But this wasn't
taken into account in the code which actually injects metadata
into /meta.js in the guest's fs.

This patch ensures that the meta.js file injection expects the
new format.

Closes-bug: #1284733

Change-Id: I37049ac01b65d30d588578e351fcddac457f95a7
Cells: Pass instance objects to update/delete_instance_metadata

When nova-cells processes a 'run_compute_api_method' message it pulls
the instance from the local db and calls the appropriate compute api
method with a sqlalchemy model.  Since the update_instance_metadata and
delete_instance_metadata methods in the compute api require objects
these methods are added to the list of methods that will receive an
object.

Change-Id: Iaa5ba6878f0162e2fab8dd3e4b87ea8dd3d527f6
Closes-bug: #1290975
Fixes the Hyper-V agent individual disk metrics

Replaces aggregated metric values with separated values for each disk.

Change-Id: I3c264dfd52572e5c429ee606a47a5727a4a3af3c
Closes-Bug: #1290403
Raise NotImplementedError in NeutronV2 API

Remove unused code in nova.network.neutronv2 that returns an empty
list. Instead of just returning an empty list, let's be more explicit
and raise a NotImplementedError. This will be more descriptive if
someone is trying to use this part of the NeutronAPI.

Commit 45e92d4703 contains the changes to use the db layer instead of
the network rpcapi.

Change-Id: I2a9ada8186fd4165c7fceb15965055b5793e6e2c
Closes-Bug: 1258380
Add version 2.0 of conductor rpc interface

This commit adds a new major revision to the rpc interface used to
talk to the conductor service.  The old version will be retained in
Icehouse for Havana rolling upgrade capability.  1.x can be dropped
as soon as Juno development opens.

When 1.x gets dropped, we will be able to remove the following methods
from the conductor manager, as well as all other supporting code for
these methods throughout the conductor:

 - ping()
 - instance_get()
 - instance_get_all()
 - migration_get()
 - migration_get_unconfirmed_by_dest_compute()
 - migration_create()
 - migration_update()
 - aggregate_get()
 - aggregate_get_by_host()
 - aggregate_metadata_add()
 - aggregate_metadata_delete()
 - get_backdoor_port()
 - security_group_get_by_instance()
 - security_group_rule_get_by_security_group()
 - block_device_mapping_destroy()
 - instance_get_all_hung_in_rebooting()
 - instance_info_cache_update()
 - instance_type_get()
 - vol_get_usage_by_time()
 - vol_usage_update()
 - compute_stop()
 - compute_confirm_resize()
 - compute_reboot()

We can also drop backwards compatibility handling for the absence of
any parameters added to other methods during 1.x.

Note that the client side will only send 2.0 messages, but that's
fine.  We expect the nova-conductor service to get updated at the same
time as, or before anything that uses this client code.

For more information on this type of change, see:
https://wiki.openstack.org/wiki/RpcMajorVersionUpdates

Part of blueprint rpc-major-version-updates-icehouse

Change-Id: Ic443c02b1342cceb8c86c37b51af03094157bc48
Cells API calls return 501 when cells disabled

When cells is not enabled the cells API calls should return
a 501 NotImplemented rather than have the internals
eventually raise various errors which may include timeout
errors.

+DocImpact: cells API calls will now return a 501 if cells is disabled
Closes-Bug: 1288214

Change-Id: I07e69bbe11ec88cd3f07b47846f3a0a5c9e6f3dc
Merge "Cells API calls return 501 when cells disabled"
Merge "Add version 2.0 of conductor rpc interface"
Merge "Raise NotImplementedError in NeutronV2 API"
Merge "Raise exception if volume snapshot id not found instead of return"
Merge "VMware: Ensure test VM is running in rescue tests"
Merge "Libvirt: Repair metadata injection into guests"
Merge "Catch InstanceNotFound exceptions for V2 API virtual interfaces"