Bypass the database if limit=0 for server-list requests

Not all database engines handle fetching 0 rows the same and there isn't
really a point in going to the database to return nothing, so bypass the
DB query if limit=0.

The Nova API is explicitly checking if limit >= 0 so we can't make any
changes there since they would be backwards incompatible, i.e. to start
enforcing limit > 0.

Closes-Bug: #1296929

Change-Id: Ib3d0318bec972af5f1f25202101e76066f930f34
xenapi: add a test for _get_partitions

Currently vm_utils._get_partitions is not covered by any unit tests.
This patch adds a unit test for that code.

Change-Id: I3ff612ca88250ad3d4d3e19aa12d299e12e442ed
Make compute manager use network api method return values

Calls to network api methods add_fixed_ip_to_instance() and
remove_fixed_ip_from_instance() return updated nw_info models
so there is no need to make separate calls to get this info.

This change refactors the affected code to avoid such extra
calls. Related methods in the neutron api are updated to return
the same information as their nova-network api counterparts.

Change-Id: I39dcf257ed5c101b13c2243266eed265c64e3c98
Closes-Bug: #1284345
Refactor unit tests for image service CRUD

Refactors the image service unit tests of the create() method to be unit
tests and not functional tests. There is no need to test whether an
image ID that is specified in the payload to the glance image service is
preserved; the unit and functional tests in the glanceclient package do
that, and besides, all this was testing was the behavior of the fake
glance client, which is pointless. There was also a test that created an
image and then tested the show method would raise InstanceNotFound if
not passing in the same instance name that was just created. This test
was removed, as ImageNotFound is already thoroughly tested in the show()
unit tests.

Missing in the existing unit tests was a test of failure conditions
resulting in error codes returned from the glanceclient.create() call,
and this patch adds a unit test that stresses the failure paths.

These new unit tests use mocks and assert that all code paths in the
create(), update() and delete() methods are fully tested.

Change-Id: I6d903979290b7d027c8dc66d2da712e1e1961a00
Related-bug: #1293938
Make quota rollback checks more robust in conductor tests

The existing cold migrate tests in conductor were mocking out the quota
object's rollback method but not actually validating that the quota
object is constructed properly or that the quota.QUOTAS.rollback static
method was called with the correct project_id and user_id given the
context and instance being used.  This patches makes the tests more
robust by not just making sure a method is called but that it's called
correctly.

Related-Bug: #1296502

Change-Id: Ib367d728b6bd50998db32d235f41212d0f94a8f7
Move _get_locations to module level plus tests

Moves the nova.image.glance.GlanceImageService._get_locations object
method into module level scope (the self argument was unused) and
adds full unit tests for the nova.image.glance._get_location() function.

Change-Id: Ib386330b70abe1e0353f1fafa3e68bc3e7a2d1b1
Partial-bug: #1293938
Allow -1 as the length of "get console output" API

Current "get console output" API does not allow -1 as the length and
returns a BadRequest response if receiving it. The other APIs(quota)
considers -1 as an unlimited value.
This patch allows -1 as the length for API consistency.

DocImpact

Change-Id: Idf88a238d1b0e545ebab5be872269b1b1030cc56
Related-Bug: #1295426
Revert "Fix network-api direct database hits in metadata server"

This reverts commit 79ab96e34ba5b8dd3e4e542dd3a7f65624b13367.

This commit broke the Nova metadata API when using neutron.

Change-Id: I6855b03f00492fdf51e18c0dcb0a73590a71b374
Closes-bug: #1307582
Don't explode if we fail to unplug VIFs after a failed boot

Libvirt currently attempts to unplug VIFs after destroying an
instance, which can fail if the instance was never built
properly in the first place. This patch makes it ignore errors
when trying to tear down VIFs during that cleanup. Failure
in this case would block the deletion of the instance (which
should never happen) and any real failures aren't something
we could do anything about.

Closes-bug: #1306718

Change-Id: I84a4433c3959b8f14e0259be0aa51da1654006c8
Merge "Revert "Fix network-api direct database hits in metadata server""
Merge "Make quota rollback checks more robust in conductor tests"
Merge "Bypass the database if limit=0 for server-list requests"
Merge "Don't explode if we fail to unplug VIFs after a failed boot"
Merge "Refactor unit tests for image service CRUD"
Merge "Move _get_locations to module level plus tests"
Merge "Make compute manager use network api method return values"
Merge "xenapi: add a test for _get_partitions"
Merge "Allow -1 as the length of "get console output" API"