Guard against oversize flavor rxtx_factor float

We now check that rxtx_factor provided is not greater than
the Float type to be stored in the db. While the check is not
100% accurate due to float approximation it will be very
close to the max allowable. A 400 error is returned if the
provided value is too big.

Closes-Bug: 1259213
Change-Id: I72c52fa46d75275c45e72b6f5a36106d5abf8220
Co-authored-by: Takashi Natsume <natsume.takashi@lab.ntt.co.jp>
Replace detail for explanation msgs on webob exceptions.

When using detail=msg, a default msg is set and returned.
To let the user know the real cause of the error explanation arg
shall be set with the appropiate error message.

[For example]
$nova --os-compute-api-version 3 service-disable --reason 'A...' host srv
"The server could not comply with the request since it is either malformed
or otherwise incorrect."

By setting the explanation we get:
$nova --os-compute-api-version 3 service-disable --reason 'A...' host srv
ERROR: Disabled reason contains invalid characters or is too long

Change-Id: I380916b110cd021aefcbedd2f943155329860fe7
Fix the sample and unittest params of v3 scheduler-hints

The API samples of scheduler-hints contains "hypervisor" and "near"
attributes, but the attributes do not exist in the scheduler-hints
parameter of "create a server" API. This patch changes them to the
existing "same_host" attribute.
This patch also changes the attributes of some unit tests of the v3
scheduler-hints by the same attribute.

This nonexistent attributes are found during bp/nova-api-validation-fw
works. The implementation needs this change because it will deny the
unexpected attributes, which are not defined with API schema, in API
parameters.

DocImpact
Closes-Bug: #1278279

Change-Id: I8542f44b325ba909fdff8b569146c0015b150291
Fix InstanceNotFound error in _delete_instance_files

Currently the cleanup_running_deleted_instances peroidic task
failed with InstanceNotFound exception, this is because the
db query is not including the deleted instance while
_delete_instance_files() in libvirt driver.

Closes-bug: #1280140

Change-Id: Ie65ff255ad3c582a71db93b07304a21d4976a193
VMware: fix instance lookup against vSphere

Modifies the logic to search the vsphere vm for a given
instance. The change now makes use of the config.extraConfig
property to search for the instance.

Change-Id: Id11f44b9792f196ad627879d082ad829869efcdf
Closes-Bug: #1257038
Use image from the api in run_instance, if present

When booting an instance, the API layer already fetches the image
from glance and passes it to the compute manager. Right now, that
info is ignored and the compute node has fetches the image metadata
again from glance if booting from an image. This is a problem when
booting from a volume, because most of the properties that the volume
keeps when it has been created from an image won't be considered.

With this patch, the image metadata passed to run_instance from the API
will be used if present instead of asking glance again.

Change-Id: I4680d9d309d7a09f64d52ef0fb105282ace79e5f
Closes-Bug: 1281973
Catch HostBinaryNotFound exception when updating a service

When updating a service with a wrong host or binary name,
HostBinaryNotFound exception is raised. However this exception
isn't caught and the ServiceNotFound exception which won't happen
here is caught instead.
This patch fixes this bug.

Change-Id: I64b138bad74c39d087addcd766b890c4076a2ce8
Closes-Bug: #1273139
libvirt: setting a correct driver name for iscsi volumes

Setting LibvirtISCSIVolumeDriver class to be identified
as a block device to determine the correct driver name.

Change-Id: Idfb89d051ccadab1d4c4b05b817b085e094ff992
Closes-Bug: #1273496
libvirt: remove explicit /dev/random rng default

libvirt (or rather qemu) will default to /dev/random if no rng device
path is specified i.e.

  <rng model='virtio'>
    <backend model='random'/>
  </rng>

It's preferable for us to not duplicate this default to allow for a
future where libvirt or the hypervisor needs to make more intelligent
decisions about the default device to use.

Also, improve the unit tests to catch this issue.

Change-Id: Ia0f922f7de575496972b4dfa9d56aa22205f1758
Clean up _make_*_list in object models to use base.obj_make_list

There are a lot of places where _make_foo_list()s are implemented.
Actually base.obj_make_list() can be used to make the list.

The patch is to clean up the redundancies and make the code clean.

Also, in order to make _from_db_objects()s the same format, we add
'context' into the parameter list in instance fault object.

Related to blueprint icehouse-objects.

Change-Id: I1a68b6e9dc402d4e30a06f94b068233e2afa713f
Rewrite InstanceActionEvent object testcase using mock

This is a refactor change of rewriting InstanceActionEvent testcase
using mock for several follow-up changes to instance action objects.

Please Note 'test_finish' case against InstanceActionEvent object's
'finish' method has to be removed, as the action event object model
doesn't hold 'instance_uuid' information for now.

This is a part of: blueprint make-instance-action-use-objects

Change-Id: I0f4284995cd7afb4c5d1940a54996183be4eef8f
Remove trailing comma from sample JSON

The etc/nova/cells.json sample configuration file contains a trailing
comma on some elements. This is a syntax error, this change corrects the
problem.

Change-Id: I7a8200e8b7704e4377ce597d6beba91b42286469
Closes-bug: #1283718
Remove blank space after print

Check nova code, remove blank space after print.

Change-Id: I0d7f1ebe6e83189a51bf714a2f03afd8a91d515c
libvirt: image property variable already defined

A variable image_meta_prop with properties from a glance image
is already defined and can be used.

Change-Id: I5a3bab2d944c60ed744bbfc79fb9d5ad195c0d69
Add a caching scheduler driver

This adds a new scheduler driver, CachingScheduler

It currently subclasses the filter scheduler and only adds caching of
calls to host_manager.get_all_host_states.

It relies on there being a small number of schedulers, ideally one,
calls to consume_from_instance within the filter scheduler to update the
current cached list of hosts, and a low rate of deletes.

It introduces the new config value:
scheduler_driver_task_period

The periodic task it controls is used by the caching scheduler to fetch
an updated copy of host_manager.get_all_host_states.

If your value for service_down_time is much smaller than
scheduler_driver_task_period, there will be issues with hosts appearing
to be dead, just because the list of hosts is being cached. Correct
configuration of those two values can avoid this issue.

DocImpact
Part of blueprint caching-scheduler
Change-Id: I2eb873ce8024a576e597205e2d52b5d5e8aee97a
Update server_diagnostics to use instance object

Update the server_diagnostics API to get an instance object and then pass it
through the system down to the virt driver.

Converting the get_diagnostics() call in the compute manager also updates one of
the driver.get_info() calls to take an instance object.  Most had already been
converted.  There was one other stray case in the compute manager where it was
still taking an instance primitive, so this patch hits that one too to finish
the conversion of get_info() while we're at it.

Part of blueprint virt-objects

Change-Id: I20b324039c20f5b1fde4d55df2d679b7fb094573
update deallocate_for_instance to take instance obj

Update the deallocate_for_instance() method of the nova.network rpc API
to take a full instance object instead of just an instance UUID and some
other instance data.  This patch is just the mechanics of getting the
API changed.  The next patch will make use of getting the full instance
object to eliminate a db query in nova-network.

Part of blueprint nova-network-objects

Change-Id: I9be88206ecc64a92d2826a9ac43e4d2d384f29ff
Remove unused method inject_file()

Remove the unused method, inject_file(), from the compute.api and
compute.rpcapi.  mark it deprecated on the manager side to be removed on the
next major iteration of the compute rpc interface.

Related to blueprint virt-objects

Change-Id: I53339e39604f90cf7ecf159da78c4e8e9283bf87
Update pre_live_migration to take instance object

Update the pre_live_migration method in the compute api, compute manager,
and virt driver to take an instance object.  The update to the compute manager
call also happens to finish the conversion of
ensure_filtering_rules_for_instance in the virt driver API, as well.

Part of blueprint virt-objects

Change-Id: I2ddb1d72dbbd11e153f75171b3a4dc4f87ca3972
Merge "Rewrite InstanceActionEvent object testcase using mock"