ovirt_host_pm: Fix to powermanagement module (#47659)

This PR is fixing following issues:

 1) Don't try to check password.
 2) Check options.
 3) Order wasn't adding at the end, as doc says.

Signed-off-by: Ondra Machacek <omachace@redhat.com>
This commit is contained in:
Ondra Machacek 2018-10-26 14:51:39 +02:00 committed by Toshio Kuratomi
parent 853236d650
commit 6cf1814105
2 changed files with 19 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- ovirt_host_pm - Bug fixes for power management (https://github.com/ansible/ansible/pull/47659).

View file

@ -144,7 +144,13 @@ class HostModule(BaseModule):
class HostPmModule(BaseModule): class HostPmModule(BaseModule):
def pre_create(self, entity):
# Save the entity, so we know if Agent already existed
self.entity = entity
def build_entity(self): def build_entity(self):
last = next((s for s in sorted([a.order for a in self._service.list()])), 0)
order = self.param('order') if self.param('order') is not None else self.entity.order if self.entity else last + 1
return otypes.Agent( return otypes.Agent(
address=self._module.params['address'], address=self._module.params['address'],
encrypt_options=self._module.params['encrypt_options'], encrypt_options=self._module.params['encrypt_options'],
@ -158,14 +164,23 @@ class HostPmModule(BaseModule):
port=self._module.params['port'], port=self._module.params['port'],
type=self._module.params['type'], type=self._module.params['type'],
username=self._module.params['username'], username=self._module.params['username'],
order=self._module.params.get('order', 100), order=order,
) )
def update_check(self, entity): def update_check(self, entity):
def check_options():
if self.param('options'):
current = []
if entity.options:
current = [(opt.name, str(opt.value)) for opt in entity.options]
passed = [(k, str(v)) for k, v in self.param('options').items()]
return sorted(current) == sorted(passed)
return True
return ( return (
check_options() and
equal(self._module.params.get('address'), entity.address) and equal(self._module.params.get('address'), entity.address) and
equal(self._module.params.get('encrypt_options'), entity.encrypt_options) and equal(self._module.params.get('encrypt_options'), entity.encrypt_options) and
equal(self._module.params.get('password'), entity.password) and
equal(self._module.params.get('username'), entity.username) and equal(self._module.params.get('username'), entity.username) and
equal(self._module.params.get('port'), entity.port) and equal(self._module.params.get('port'), entity.port) and
equal(self._module.params.get('type'), entity.type) and equal(self._module.params.get('type'), entity.type) and