Fix state sync logic related to the PAUSED VM state

A VM may get into the paused state not only because the user request
via API calls, but also due to (temporary) external instrumentations.
Before the virt layer can reliably report the reason, we simply ignore
the state discrepancy. In many cases, the VM state will go back to
running after the external instrumentation is done.

Fix bug 1097806.

Change-Id: I8edef45d60fa79d6ddebf7d0438042a7b3986b55
(cherry picked from commit f7fbdeb5672bae7d3bffd6fa76de1ce81fc132bf)
Fix an error in affinity filters

Fix a call to compute_api.get_all to properly exclude deleted instances.
Add tests to prohibit this error in the future.

After some thought, this can be further optimized to let the instance
query do all the filtering/matching.

Resolves bug 1107156.

Change-Id: I6d6a6ba44d38d363489853d0407ad4cc94046656
(cherry picked from commit 8bc80cab3c134d64953b4f6493cab80b5bdc1b69)
Avoid stuck task_state on snapshot image failure

Fixes bug LP 1101136

Previously if the glance interaction failed prior to an
instance being snapshot'd or backed up, the task state
remained stuck at image_snapshot/backup.

The normal task state reversion logic did not kick in,
as this is limited to the compute layer, whereas the
intial glance interaction occurs within the API layer.

Now, we avoid this problem by delaying setting the task
state until the initial image creation has completed.

Change-Id: Id498ae6b3674306743013e4fe99837da8e2031b5
Final versioning for 2012.2.3

Change-Id: Ic83a1c1617ad74b931f54f1755bc9dcecfe2c527
Bump version to 2012.2.4

Set version to 2012.2.4, but with final=False

Change-Id: I9dab1dc62e41cdb4143a3c8083e65c4b13a22eb4
populate dnsmasq lease db with valid leases

At start dnsmasq retrieves its lease db by calling the nova-dhcpbridge
script with the init action.

Previously we were returning all allocated IPs in the network and
calculating the lease exirpation time based upon instances.updated_at
or instances.created_at.

Now we are only returning entries for IPs that are allocated and leased.
Additionally we set the lease expiration time to be i
now + CONF.dhcp_lease_time

Change-Id: Ie3b4fafd38094dc01ceea592ab5229e581193512
Fixes: bug #1103260
(cherry picked from commit e12339def3d9182f5ab23869e6bdc946e8e42825)
Add a safe_minidom_parse_string function.

Adds a new utils.safe_minidom_parse_string function and
updates external API facing Nova modules to use it.
This ensures we have safe defaults on our incoming API XML parsing.

Internally safe_minidom_parse_string uses a ProtectedExpatParser
class to disable DTDs and entities from being parsed when using
minidom.

Fixes LP Bug #1100282 for Folsom.

Change-Id: I6a4051b5e66f3ce5a330b2589c42e6e9e5b9268e
Merge "Avoid stuck task_state on snapshot image failure" into stable/folsom
Enable libvirt to work with NoopFirewallDriver

Fixes bug 1050433

Change-Id: I49613c7d1e6b14411dcdc342366e163a21673f78
Merge "Add a safe_minidom_parse_string function." into stable/folsom
Merge "Enable libvirt to work with NoopFirewallDriver" into stable/folsom
Merge "Fix state sync logic related to the PAUSED VM state" into stable/folsom
Avoid vm instance shutdown when power state is NOSTATE

* nova/compute/manager.py (_sync_power_states): Log the condition
where we can retrieve the state from the hyperviser, rather than
stopping the VM.

Related grizzly commits are 95e77703 and ad101ce5

Fixes bug: 1085771
Change-Id: I5fb9fdc6bcde729c00c4931960ed0de3b8fa189d
libvirt: Fix nova-compute start when missing ip.

If nova-compute is restarted when an instance has no ip address
the libvirt/vif:_get_configuration method will throw an index
error. Check for existance of an ip before attempting to retrieve
one. Includes failing test.

Fixes bug 1131330

Change-Id: Id383544b44e64205fc3b4f850d0d11ad2ebd5da7
VNC Token Validation

Force console auth service to flush all tokens
associated with an instance when it is deleted.
This will fix a bug where the console for the
wrong instance can be connected to via the console
if the correct circumstances occur. This change also
makes a call to veriry vnc console tokens when a
user attempts to connect to a console. This ensures
the user is connecting to the correct console.

bug 1125378
Change-Id: I0d83ec6c4dbfef1af912a200ee15f8052f72da96
Handle compute node not available for live migration

This patch handles exception.ComputeServiceUnavailable by restoring
instance's vm_state and instance's task_state after live migration
failure caused by unavailable source/dest compute node.

Raises detailed HTTPBadRequest explanation for this exception.

Fixes bug 973393 and bug 1051881

Conflicts:
	nova/scheduler/driver.py
	nova/scheduler/manager.py
	nova/tests/api/openstack/compute/contrib/test_admin_actions.py
	nova/tests/scheduler/test_scheduler.py

Change-Id: If825b61fad9c4e3030f2e6c5002907255eaf3661
remove intermediate libvirt downloaded images

* nova/virt/images.py (fetch_to_raw): When converting a downloaded
image to raw, ensure we delete the original download image.
I.E. the .part file.  The regression was introduced in 7c265343.
* nova/tests/test_libvirt.py (test_fetch_raw_image): A new test
for this function which wasn't tested previously.

Conflicts:

	nova/tests/test_libvirt.py
	nova/virt/images.py

Fixes bug: 1125068
Change-Id: Ie6f2cff1a554b8500fd66f0832566ae1b317be40
(cherry picked from commit 1501a4e4f75efb63385a1dadc728c2ef245bf7de)
Ensure we add a new line when appending to rc.local

When we add content to rc.local, if the file already
exists then we need to make sure we add the content
after a new line explicitly

Fixes LP #1089668

Change-Id: I35be1496703b302f732363fa76ce832505eed599
(cherry picked from commit f393a513d7894ddb800e4dfc87da896600fb7421)
Fix double reboot issue during soft reboot

Using the ID of domain in Libvirt to recognize the hard reboot has been
implemented or not, if the ID changed, we believe the domain has been rebooted,
return True and break from soft reboot.

Fixes: bug #1046356

Change-Id: Iec2f9e8225cfe2779f84d2095667f3c0e621e935
(cherry picked from commit 6344bff494758e0d7d7d25f43a3b56d82447441e)
libvirt: Optimize test_connection and capabilities

The getCapabilities call can be very slow so it is not a good choice
for testing the libvirt connection. This patch switches to
getLibVersion and also caches the result of getCapabilities so it
doesn't need to be requested every time. Note that this means that
nova-compute will need to be restarted if the capaabilities of the
host changes. This is an acceptable risk because capabilities
changes should be very rare and nova-compute should be restarted
if libvirt is restarted or reinstalled.

This simple change lowers boot time in my devstack install from
22 seconds down to 8 seconds!

Fixes bug 1100446
(cherry picked from commit ec3d7e4cb882eff42fa8f1e5f8f52723fb909b0e)

Conflicts:
	nova/virt/libvirt/driver.py

Change-Id: I3adbb48a2859a54ed93503f26de684acbd157841