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
Sync db.models.Security* and db.models.Volume*.

This patch syncs models with migrations.

Change-Id: I2e4a4cf28376d933be47bc496933e6964e19a56e
Clarify flavorid vs instance_type_id in db

And add comment about future direction.

Partially implements bp flavor-instance-type-dedup

Change-Id: Ia6c1bad5c3cc35e772c32803c27a50a7728045e5
Sync 10 DB models and migrations.

This patch syncs models with migrations for:
- BlockDeviceMapping
- IscsiTarget
- FixedIp
- FloatingIp
- KeyPair
- Migration
- Network
- ProviderFirewallRule
- Reservation
- S3Image

Blueprint: db-sync-models-with-migrations

Change-Id: I8e16375fe48744513167272e956cdbfdbfd8af23
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
Remove project_id from alternate image link path

Removes the project id from the alternate link path
generated for the v3 API os-images extension.

Also fixes issue with os.path.join being used to generate
urls which will break on Windows.

Partially implements blueprint nova-v3-api

Change-Id: Icc34359cc935920e2d4780849d9310c4961c8f74
Missed message -> msg_fmt conversion

We recently changed NovaException's to define `msg_fmt` instead of `message`
on the class. Looks like this exception was missed for some reason.

Fixes bug 1202255

Change-Id: If828bf42fa077665d1d92e08758fbddd342ab626
Fix inconsistency between Nova-Net and Neutron

The neutron client raises NeutronClientException (status_code 404)
that is not unknown for nova, and is translated in 500 computeFault.
Catching this exception in nova/nova/network/neutronv2/api.py and
raising more generic exception as exception.NotFound solves the problem.

Added also an unitary test to test neutronv2 api

bug #1160309
bug #1200175

Change-Id: Ib2f1a0d49a12114b28f0cd5ce0bb7119f864d1a6
Fix DB access when refreshing the network cache.

When calling ComputeManager.attach_interface(), the following happens:

1) self.network_api.allocate_port_for_instance() is called from within
   ComputeManager.attach_interface();
2) refresh_cache() is called, since it decorates allocate_port_for_instance();
3) refresh_cache calls update_instance_cache_with_nw_info(), with
   "conductor_api=None" since 'conductor_api' cannot be found in the kwargs;
4) update_instance_cache_with_nw_info() calls
   api.db.instance_info_cache_update();
5) Since the call to the database should be made through the conductor, a
   DBNotAllowed exception is raised, which prevents the cache from being updated.

This patch fixes the call to allocate_port_for_instance (step 1) so that
'conductor_api' can be found in the kwargs (step 3).

When using ComputeManager.detach_interface, the exact same problem arises (with
deallocate_port_for_instance instead of allocate_port_for_instance).

This is a first step towards fixing bug #1197192.

Change-Id: I647795907b22790759d3be74afcaf70b712cb338
Sync gettextutils from oslo

Bring in some needed extra code for handling Nova translations

Partially implements bp user-locale-api

Change-Id: Id66010eacb24c86e32f5455c5d869f9f037cff23
Add indexes to sqlite

Migration `133_folsom.py` do not create indexes for sqlite.
Added missed indexes with tests.

Fixes bug 1191838

Change-Id: I018e29ba46f2017241c13742169896625944194e
Use timeutils.utcnow() throughout the code

timeutils.utcnow() should be used instead of direct calls to
datetime.datetime.utcnow() to make it easy to override its return
value in tests.

Add a hacking rule to prevent regressions.

Fixes bug 1200141.

Change-Id: I170dbd7c9093bd627e2a0d5984b7ad1bf105c8d5
Move _validate_int_value controller func to utils

This patch moves the _validate_int_value private method of the servers API
controller (intorduced in change
I18ac285d5b3c8200d7706c7d577809b15d6ab9e8) to utils, in order to make it
usable by code outside of the controller class. This method is very
general - it checks weather an input is a valid integer.

It also changes what exceptions it raises from HTTPBadRequest to
InvalidInput - all in the spirit of being more reusable.

Finally, it adds tests and fixes a small string formatting bug that was
uncovered by adding them.

Change-Id: I65f2b6474d572ed601d20dca9dda9936d306a219
blueprint: improve-block-device-handling
Make admin API state resets use Instance.save()

This removes the 'update_state' compute API method in favor of having
the admin API use the Instance object's save() method.

This also removes the non-unity cells test for resetting state.  Cells
behavior is tested via tests on Instance.save().

Related to blueprint compute-api-objects

Change-Id: I28d1ca9d711679cc55375774e879870f457a5b0b
Make shelve pass old-world instance object to conductor

The conductor interface for notify_usage_exists() doesn't yet
work with a new-world object, so convert it with the compatibility
function before passing it from shelve().

Related to blueprint unified-object-model

Change-Id: I6c2c2dc6dedf521ed7b0c566411d6f0035038b7c
Make InfoCache.network_info be the network model

Instead of storing the DB version of network_info (which is a JSON
version of network.model.NetworkInfo) on the object, go ahead and turn
it into its native object as well.  This means that all uses of the
object don't need to worry about hydrating network_info themselves.

This adjusts all uses in the code understand the old and new ways of
life.

There's also a small issue with the get_by_instance_uuid() method that
would cause a traceback when no entry was found.  This method is not
being used yet anywhere, but this is fixed to raise a NotFound.

Related to blueprint unified-object-model

Change-Id: I882311c8a9f9df927c5650946e6398eeb33e74d0
Convert network API to use InfoCache object

This converts the db.info_cache_update() call in network/api to use
objects.  The save() method has been extended to support what we need
for cells.

Converting to the object allows us to ditch the conductor_api kwarg on
some methods.

Related to blueprint unified-object-model

Change-Id: I1722c03d20511d67acc0a8947de1d4273dc78597
Unit-ify compute_api delete tests

This makes the delete and soft_delete tests unit-like in nature,
and moves them to test_compute_api, as has been done recently
for others that we're moving to objects.

Related to blueprint compute-api-objects

Change-Id: I5e024871e5159f08cbba05fa261a9a2d08e4b8e5
Merge "Sync db.models.Instance* with migrations."