handles empty dhcp_domain with hostname in metadata

Fixes bug 1064713.

Currently hostname in metadata is created by concatenating the
instance hostname with the dhcp_domain. When dhcp_domain is empty,
it results in a hostname with a trailing dot.

Change-Id: I52a50ff7f62c0a0dc900ddf707cc3dddce62bcb3
(cherry picked from commit 46b7b6392575c645a0d34739605d9165f4358d8a)
Fix issues deleting instances in RESIZED state

DB API call migration_get_by_instance_and_status requires admin
context...and it'll also raise an exception if no migration matches.

_delete() in compute/api was not using admin context, and was checking
for a false return from the DB call vs checking for an exception.

Added a test that covers both problems.

Fixes bug 1056601

Change-Id: Ib3c631dccbb2776761cf5acb8bab1d814bf3e282
(cherry picked from commit 8c9c380935b4aac40269754a291134c130bccec9)
libvirt: allows attach and detach from all domains

Previously attaching/detaching from a shutoff domain would fail.

Fixes bug 1057730

Change-Id: I876872700da125cb078746401b1b80da265880ff
(cherry picked from commit 81fa6f717d6e32a4cfc2c734e228e60b204da045)
xenapi: Refactor snapshots during resize

Currently, we use VM.snapshot for resize, which fails if we have a
volume attached to the VM, which does not support snapshots. This change
uses VDI.snapshot instead, for all VDIs that are not attached by nova.

Also needed for xenapi: detaching and reattaching volumes during
migrations and reverting of migrations.

Fixes Bug #1028092

Change-Id: I3e2973747135a9c33de194e38537620c397bb87e
(cherry picked from commit 359527501604ea720b594a2ed1b32cd29fe6adbc)
libvirt: Fix _cleanup_resize

Undefine domain and unplug vifs in _cleanup_resize if the instance was
migrated to another host.

Fixes bug 1015731

Change-Id: If6eb1ada029d462777bbd6ea113c98c3b801cf5d
(cherry picked from commit d272415fd6fe9cdbd66fdfdf9aedc8a43b87d9b5)
Consistent Rollback for instance creation failures

Fixes Bug 1065092

Adds a single QUOTA.rollback for all exceptions rather than performing
the rollback individually. Ensures that no stale "reservations" are left
in place after a failed instance creation.

Change-Id: I354726b651ae8feb6153d5865e0b14b54c73314b
Add call to trigger_instance[add/remove]_security_group_refresh quantum

The calls to trigger_instance[add/remove]_security_group_refresh were
not being called in quantumv2/api. This patch adds those calls.
Fixes bug 1057069

Change-Id: Ia76d37ebf2546a26f893dcbc8d5a05f02324ad6b
Detect and fix issues caused by vol ID migration

The migration from volume ID to UUID neglected to update the provider_location
field on the volume.  As a result the iqn and volume name no long match and
existing volumes are no longer able to be attached after an upgrade
(essex -> folsom and then nova-vol->cinder).

This patch adds a method to the volume driver that will check for the
mismatch of volume name in the iqn during service start up.  If
detected it will update the provider_location field in the database
to include the new ID.  Also it will create a symlink to the device backing
file that also has the correct naming convention.

Note: We don't disturb an connections that are currently attached.
For this case we add a check in manager.detach and do any provider_location
cleanup that's needed at that time.  This ensures that connections
persist on restarts of tgtd and reboot.

Change-Id: Ib41ebdc849ebc31a9225bdc4902209c5a23da104
Fixes: bug 1065702
Fix nova-network MAC collision logic

The exception being caught and transformed in sqlalchemy/api.py
was incorrect, causing nova-network to miss it in the MAC
collision retry loop.

This patch corrects that and adds a test of the collision logic.

Backports the fix for bug 1059366

Change-Id: I89d17eb8606a18f102e4de0dc76c77205cafbc8d
Merge "Detect and fix issues caused by vol ID migration" into stable/folsom
Merge "Fix nova-network MAC collision logic" into stable/folsom
Merge "libvirt: Fix _cleanup_resize" into stable/folsom
Merge "xenapi: Refactor snapshots during resize" into stable/folsom
Merge "libvirt: allows attach and detach from all domains" into stable/folsom
Merge "Fix issues deleting instances in RESIZED state" into stable/folsom
Merge "handles empty dhcp_domain with hostname in metadata" into stable/folsom
create_db_entry_for_new_instance did not call sgh for default

When an instance is launched create_db_entry_for_new_instance() is
called which calls self.db.instance_create(). Then,
db.security_group_ensure_default() is called which creates the
default security group entry in the nova db. Though the sgh handler was
not called. Alternatively, if any nova secgroup-* call is made the sgh
is called which creates the default security group. This patch adds
a call to ensure_default() before db.instance_create() so the sgh
is called. Fixes a case missed in  bug 1050982

Change-Id: I9649b5ef026ca18a55abfb66e87fd0e358eba6f2
Fix VM deletion from down compute node

* free network resources
* free volume resources
* delete.start and delete.stop notifications added
* Handle network deallocate in multi_host mode

Fixes bug 1067214

Co-authored-by: Vishvananda Ishaya <vishvananda@gmail.com>
Change-Id: I0d4a7dc5836d39e405824528de214f23b214849f
(cherry picked from commit 3dff43356619b4a935a5f395b066e96e8856bb4f)
Fixed instance deletion issue from Nova API.

When host Compute is down, Nova API deletes the resources associated with the
instance. However, since the instance is marked deleted first, the next query
to update the instance vm_state and task_state in DB fails. And instance
remains in state vm_state=ACTIVE, task_state=DELETING, deleted=True.

Fixes LP: #1074305

Change-Id: I0a4e64d180b4b2c5e398a21a62b29b7d59549a9f
(cherry picked from commit d00f09f2ebfa17b1b66ac080f4719f925e0777de)
 fix deletion of LVM backed instances

    The enumeration of the logical volumes was incorrect,
    thus causing the deletion of instances booted from them,
    to fail.

    Fixes bug: 1078085

Change-Id: Ib899754002cea28f310b042e5d4a7f89416e031e
Cherry-picked: 3c9e48d1119b77428346680c2a009c44ff9bf2ce