Move oslotest to test only requirements

oslotest is only used for unit testing, so
it shouldn't be in requirements.txt

Change-Id: I5073fbd93712072cec8598663590e35fc2edd08d
synchronize 'stop' and power state periodic task

This change adds the synchronized decorator to the stop function and
_sync_instance_power_state to address a race condition when powering
off and updating the database for an instance. The power off and
database update should be protected so the periodic task sees a
consistent view when it checks power state from the driver and
VM state from the database in order to take action.

In the bug, a stopped instance is in the middle of being rebuilt,
and while it is in the process of being returned to the original
STOPPED state, _sync_power_states sees the combination of the
power state from the driver being 'on' and the vm_state from
the database as being STOPPED. This patch aims to ensure power
'off' and vm_state set to STOPPED happen atomically in the
stop_instance function. Thus, the read by _sync_power_states
must also be synced on the instance UUID.

Change-Id: I8aa83ab8dca35878cf792ae2d46feaa9912ffd38
Closes-Bug: #1320628
Catch image and flavor exceptions in _build_and_run_instance

If a user selects a flavor with a disk size that is smaller than
the requested image, a FlavorDiskTooSmall exception is thrown.
However, this exception is not specifically caught in
_build_and_run_instance, but is caught as generic exception,
causing a RescheduledException to be thrown. This forces the
instance to be rescheduled a few times before finally throwing
a NoValidHost exception. It causes confusion because the actual
cause of it is that the disk size is smaller than the requested
image. The following patch properly catches exceptions thrown by
_check_requested_image in _build_and_run_instance.

Change-Id: Ic8b435ba7e8721aa8ca54f29c1ad808833a7608d
Closes-Bug: #1330856
libvirt: fix typo in fakelibvirt listAllDomains()

It looks like this code isn't used in the tests at all since we replace
it with a fake in the list_instance_domains() tests ... so what's the
point of it?

We could also add tests for the function in test_fakelibvirt, but that
feels rather pointless too?

Change-Id: I8fa5301ad86e2eb117f40d26a7cfe7b9d86c873a
Fix interfaces template for two interfaces and IPv6

If you have more than one interface and IPv6 enabled, then the interfaces file
emitted would have the incorrect syntax: the `auto eth1` line would be
appended to the end of the `gateway` line of the previous stanza.

This was a result of improper whitespace control in the Jinja template which
this patch fixes.

In order to prevent regressions, this patch swaps out the existing tests with
corresponding tests that are whitespace sensitive. This is important because
it's difficult to tweak Jinja templates in a way that fixes the whitespace
for one scenario while not breaking another.

Closes-Bug: 1339888

Change-Id: Id5566ea2f93ee1a6b8bc42e83bc64a1c6a09e680
libvirt: speed up list_instances method

Switch the list_instances method to use the new
list_instance_domains method. This removes the last
user of list_instance_ids, so delete that method.

Blueprint: libvirt-domain-listing-speedup
Change-Id: I101c42799589f01a830d974e48a1fd4b9fc60371
Merge "Catch image and flavor exceptions in _build_and_run_instance"
Merge "Fix interfaces template for two interfaces and IPv6"
Merge "synchronize 'stop' and power state periodic task"
Merge "libvirt: fix typo in fakelibvirt listAllDomains()"
Merge "Move oslotest to test only requirements"
Merge "libvirt: speed up list_instances method"
Make nova-api use quotas object for reservations

This makes nova-api use the quotas object for reservations;
more work needs to be done to convert the rest.

Partial-Bug: #1131395
Change-Id: I3e4d233278966c79019235ac8836a825c46c27ea
Enable terminate for EC2 InstanceInitiatedShutdownBehavior

The EC2 API supports an instance attribute called
InstanceInitiatedShutdownBehavior (IISB) which can be set to
'stop' or 'terminate' (default: 'stop').  When the instance
initiates its own shutdown, this determines whether or not
the instance hangs around in the Shutoff state or is
terminated by the system.

In nova, this is handled by the shutdown_terminate boolean.
IISB = stop      => shutdown_terminate = False
IISB = terminate => shutdown_terminate = True

sync_instance_power_state now invokes compute_api.delete if
shutdown_terminate = True and we detect the instance power state
has gone from Running to Shutdown.

Closes-bug #1131395
Change-Id: I284ae7a84384f19131703c4ad44e0e5f5b03f5d4