Fix migration 147 downgrading with no aggregates

Add some extra bulletproofing to downgrading migration 147 where
there may have been no aggregates.

Change-Id: I6e4aabf4fff462e9ad53083621077ce0e0a80a43
Fix docstring for disk_cachemodes

The docstring for the disk_cachemodes option implied a syntax that is
incorrect for a ListOpt.  Change the example to match exactly what you
would put in the config file for it to work.

Change-Id: Ie999d2799dba6c47facdc771e1cf6081d28d6b85
Closes-Bug: #1106423
(cherry picked from commit 1df9b26b51ff3a153b93d79e25bef454e08a8e38)
Fix difference between mysql & psql of flavor-show

If you create a new flavor using a deleted flavorid,
the result of flavor-show is different between mysql and psql.

This issue is caused by the different processing for index in each db.

We need to specify the sort-type to avoid the issue.

Change-Id: Ib1029e80c1b981e1ec86d954b63f83650c9b1cc1
Closes-Bug: #1288636
(cherry picked from commit 4bbb4d88595cfd5f75528d8789be94d0ec9fbe62)
Update aggregate should not allow duplicated names

It is not allow to create 2 aggregates with the same name
but if update an existing one with a name already used
by other aggregate that check should be made.
This patch doesn't allow to change the name to an existing
one.

Change-Id: Icfe315594beaec94229e5a4a4c1bb80fc366b66e
Closes-Bug: #1288296
(cherry picked from commit 2b2decfd1b5b0d68813bc7e5b5e4349a1ab592aa)
Add context as parameter for two libvirt APIs

When finish_revert_migration is called, the caller of
finish_revert_migration already includes context as a parameter,
but finish_revert_migration did not reuse this parameter and still
re-generate the context inside finish_revert_migration, we should
add context as a new parameter for finish_revert_migration so that
the functions inside of it can reuse context when needed.

For the function _create_domain_and_network in libvirt/driver.py,
it set context as an optional parameter, but context isn't really
an optional parameter for this method. We should always pass a
context down because it might be needed somewhere inside
_create_domain_and_network().

The patch includes two parts:
1) Add context as a new parameter for finish_revert_migration
2) Set context as a required parameter for _create_domain_and_network

Closes-Bug: #1251261
(cherry picked from commit 81fc3967bca0f154d72d5de7875b646e1b6c47c8)

Conflicts:
	nova/tests/compute/test_compute_mgr.py
	nova/virt/vmwareapi/vmops.py

Change-Id: I72d131fc8dce903400e3080d51ba0fc0a1320751
Make cells 'flavorid' for resizes

Cells should use 'flavorid' (not 'id') for resizes.

bug 1241222

Change-Id: I57b997425f183f25d3ca032c7d8c35c1f49e3afc
(cherry picked from commit 034df6e875d6c0b590f3cfb802574c2f982fd534)
libvirt: Custom disk_bus setting is being lost on hard_reboot

Currently, a non-default disk_bus setting of and image will not be used,
when powering on an instance (or _hard_reboot).

hard_reboot() should use image_meta, if it exist, when constructing
the disk_info

Closes-Bug: #1255449

(cherry picked from commit 0fe3001d639df81ae4e5f77bcfc32bc1bffb014e)

Conflicts:
	nova/virt/libvirt/driver.py

Change-Id: I477f69c47515ad22165421b4d23ac865c7869873
Add declaration of 'refresh_instance_security_rules' to virt driver

The method 'refresh_instance_security_rules' was not defined
in the virt driver ComputeDriver class. In cases where the
underlying virt driver does not support security groups
an exception would be encountered indication that the driver
class does not have the specific attribute.

In addition to adding the method the patch set also catches the
exception NotImplementedError and logs a warning.

Closes-bug: #1269448
(cherry picked from commit 5a98d7b61fa6adb1557e69f2f234406be0e2739c)

Conflicts:
	nova/tests/virt/hyperv/test_hypervapi.py

Change-Id: Ia36b0dfb54a3ede86467d87f0650a0902adb6d46
Fix security group list when not defined for an instance

If an instance has an empty security group list an exception
is thrown due to iteration attempt of None.

To fix this, this patch modifies get_instance_security_group
to return an empty list instead of None.

Conflicts:
	nova/tests/api/openstack/compute/contrib/test_neutron_security_groups.py
	nova/tests/network/security_group/test_neutron_driver.py

Change-Id: I7efb3c3a58d7e20501d126c6d194479ca1d14166
Closes-Bug: #1291489
(cherry picked from commit c32986966dfd034c3d706b2e9ab2820a2c3cfc3e)
Always filter out multicast from reflection

Instances will try IPv6 neighbour discovery via multicast
even in an IPv4-only cloud and can throw errors
if they see inbound packets from their own MAC address

Closes-bug: #1229625

Change-Id: I3539e788fe07519d87ce7c3800c5d38b7bd99d3b
(cherry picked from commit 9c044d2c94812e18cf84927fbf719cd073fe6c4f)
Fixes hyper-v volume attach when host is AD member

The domain name gets added to the initiator name used by the host
if it's an Active Directory member.

Currently the method which gets the initiator name does not take
this into account when retrieving the default initiator name.

Trying to use a wrong initiator name will lead to an exception when
trying to log in to the according iSCSI target.

This patch simply appends the domain name (when the host is an AD
member) to the initiator name used to log in to iSCSI targets.

Closes-Bug: #1328870
(cherry-picked from commit 0d9419f2b36561bf50bbe0f720c8dd8ad4e96660)

Change-Id: Ifbe762c685e46081059a01043431b2c4ac5473fc
Fix incorrect root partition size and compatible volume name

When using rbd backend, it needs to resize volume size if size presents. Else
we will get wrong image size.

Rbd volume always uses uuid as the main pattern of volume name, now change to
it is necessary.

This patch also include a follow up fix of the original patch.
https://review.openstack.org/#/c/92512/

Fix bug 1219658

(cherry picked from commit 1b66a47b5f4cbcdf1a9a1ec38532474588a3fee2)

Conflicts:
	nova/virt/libvirt/imagebackend.py

Change-Id: I3dc8d639b066eac35d190b8d4687c41c9f4d5824
Fixes NoneType vcpu list returned by Libvirt driver

* libvirt dom.vcpu may return a NoneType if vcpus dont exist

Change-Id: Iee10c2559ceea636bc4896595962e3470228ad35
Closes-Bug: #1274758
(cherry picked from commit 82821b407ce7a226918758876abca46b727d9706)
Avoid re-adding iptables rules for instances that have disappeared

The remove_filters_for_instance() method fails silently if the
instance's chain is gone (i.e. it's been deleted). If this
happens while we're refreshing security group rules, we will
not notice this case and re-add stale rules for an old instance,
breaking our firewall for new instances.

This adds a quick check after we've captured the lock to see if
the associated chain exists, and bails if it doesn't.

Conflicts:
	nova/virt/firewall.py

Required changes:
- unit test was updated because in Havana, IptablesFirewallDriver has
  .instances instead of .instance_infos, and a separate .network_infos
  attribute.

Change-Id: Ic75988939f82de49735d85fe99a9eecd4baf45c9
Related-bug: #1182131
(cherry picked from commit 6aa368b99249d01f8fd7183c15d11986ad6a6fb7)
(cherry picked from commit 132d5a2064cfdc579a2e51f07e10e8eafbdf6327)
Merge "Fixes hyper-v volume attach when host is AD member" into stable/havana
Ignore 'dynamic' addr flag on bridge configuration

When setting the bridge up, if that flag is present but not
ignored, the delete command will fail and may leave the
interface and the bridge in an inconsistent state.

Closes-Bug: #1274611
Related-Bug: #1077066
Change-Id: Iff65d61d724d0de5d8173ac37f7f748aa23e5d8b
(cherry picked from commit 0d447f6edd406547e828c592823ac6624e56e91f)
VMware: Add check for datacenter with no datastore

When there is a datacenter with no datastore in it,
nova boot fails.

This patch addresses the issue by adding a check
and ignoring the empty datacenter.

closes-bug: #1302482
(cherry picked from commit 529e7d14a716fcc1264b2e8053be3c842afd2153)

Conflicts:

	nova/tests/virt/vmwareapi/test_vmops.py

Change-Id: I3c8242767f5991d4aeffab09c763a21493fc363e
Merge "Ignore 'dynamic' addr flag on bridge configuration" into stable/havana
Set is_public to False by default for volume backed snapshots

This update results in the same behavior that is already implemented
in _create_image where the meta_data for is_public is set to False.

Change-Id: Ie0720d5c847871527db7d9477ca6cb05abe7a1a5
Closes-Bug: #1255316
(cherry picked from commit 0530e02004578a36039111beddf472fcf3e48df6)
Merge "VMware: Add check for datacenter with no datastore" into stable/havana