Fix logic in os_nova_host_aggregate module (#23191)

* Fix logic in os_nova_host_aggregate module

Fix logic around adding availability zone to metadata and comparing existing host list to parameter host list. 

Previously, when no availability zone was defined, an empty availability zone was being appended to metadata. This was causing 'empty named availability zone' errors when running the module against an already existing host aggregate with no availability zone. This was fixed by only appending availability zone to metadata if it is not an empty parameter.

Also added set() casting when comparing existing and new host lists. Previously, if existing host list was not in the same order as the host list in the .yml parameter file the module would consider this a change even if the two lists had the same entries.

* Update os_nova_host_aggregate.py
This commit is contained in:
Elachance 2017-08-17 12:30:38 -07:00 committed by ansibot
parent ce2c14757d
commit 7b8b444602

View file

@ -88,10 +88,12 @@ from distutils.version import StrictVersion
def _needs_update(module, aggregate):
new_metadata = (module.params['metadata'] or {})
new_metadata['availability_zone'] = module.params['availability_zone']
if module.params['availability_zone'] is not None:
new_metadata['availability_zone'] = module.params['availability_zone']
if ((module.params['name'] != aggregate.name) or
(module.params['hosts'] is not None and module.params['hosts'] != aggregate.hosts) or
(module.params['hosts'] is not None and set(module.params['hosts']) != set(aggregate.hosts)) or
(module.params['availability_zone'] is not None and module.params['availability_zone'] != aggregate.availability_zone) or
(module.params['metadata'] is not None and new_metadata != aggregate.metadata)):
return True