ovirt_vm: Fix issue in setting the custom_compatibility_version to NULL
Currently there is no way to reset the custom_compatibility_version to NULL. If we provide a empty string('') to custom_compatibility_version, it will fail with error "IndexError: list index out of range" at _get_minor function. To reset the custom_compatibility_version, we have to pass None value to types.Version. The PR fixes the same. Signed-off-by: Ondra Machacek <omachace@redhat.com>
This commit is contained in:
parent
3b2a0de548
commit
025c183307
3 changed files with 13 additions and 6 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- ovirt_vm - Fix issue in setting the custom_compatibility_version to NULL (https://github.com/ansible/ansible/pull/47388).
|
|
@ -789,14 +789,14 @@ class BaseModule(object):
|
|||
return entity
|
||||
|
||||
def _get_major(self, full_version):
|
||||
if full_version is None:
|
||||
if full_version is None or full_version == "":
|
||||
return None
|
||||
if isinstance(full_version, otypes.Version):
|
||||
return int(full_version.major)
|
||||
return int(full_version.split('.')[0])
|
||||
|
||||
def _get_minor(self, full_version):
|
||||
if full_version is None:
|
||||
if full_version is None or full_version == "":
|
||||
return None
|
||||
if isinstance(full_version, otypes.Version):
|
||||
return int(full_version.minor)
|
||||
|
|
|
@ -1103,7 +1103,7 @@ class VmsModule(BaseModule):
|
|||
custom_compatibility_version=otypes.Version(
|
||||
major=self._get_major(self.param('custom_compatibility_version')),
|
||||
minor=self._get_minor(self.param('custom_compatibility_version')),
|
||||
) if self.param('custom_compatibility_version') else None,
|
||||
) if self.param('custom_compatibility_version') is not None else None,
|
||||
description=self.param('description'),
|
||||
comment=self.param('comment'),
|
||||
time_zone=otypes.TimeZone(
|
||||
|
@ -1169,12 +1169,19 @@ class VmsModule(BaseModule):
|
|||
return self.param('host') in [self._connection.follow_link(host).name for host in getattr(entity.placement_policy, 'hosts', None) or []]
|
||||
return True
|
||||
|
||||
def check_custom_compatibility_version():
|
||||
if self.param('custom_compatibility_version') is not None:
|
||||
return (self._get_minor(self.param('custom_compatibility_version')) == self._get_minor(entity.custom_compatibility_version) and
|
||||
self._get_major(self.param('custom_compatibility_version')) == self._get_major(entity.custom_compatibility_version))
|
||||
return True
|
||||
|
||||
cpu_mode = getattr(entity.cpu, 'mode')
|
||||
vm_display = entity.display
|
||||
return (
|
||||
check_cpu_pinning() and
|
||||
check_custom_properties() and
|
||||
check_host() and
|
||||
check_custom_compatibility_version() and
|
||||
not self.param('cloud_init_persist') and
|
||||
equal(self.param('cluster'), get_link_name(self._connection, entity.cluster)) and equal(convert_to_bytes(self.param('memory')), entity.memory) and
|
||||
equal(convert_to_bytes(self.param('memory_guaranteed')), entity.memory_policy.guaranteed) and
|
||||
|
@ -1190,9 +1197,7 @@ class VmsModule(BaseModule):
|
|||
equal(self.param('smartcard_enabled'), getattr(vm_display, 'smartcard_enabled', False)) and
|
||||
equal(self.param('io_threads'), entity.io.threads) and
|
||||
equal(self.param('ballooning_enabled'), entity.memory_policy.ballooning) and
|
||||
equal(self.param('serial_console'), entity.console.enabled) and
|
||||
equal(self._get_minor(self.param('custom_compatibility_version')), self._get_minor(entity.custom_compatibility_version)) and
|
||||
equal(self._get_major(self.param('custom_compatibility_version')), self._get_major(entity.custom_compatibility_version)) and
|
||||
equal(self.param('serial_console'), getattr(entity.console, 'enabled', None)) and
|
||||
equal(self.param('usb_support'), entity.usb.enabled) and
|
||||
equal(self.param('sso'), True if entity.sso.methods else False) and
|
||||
equal(self.param('quota_id'), getattr(entity.quota, 'id', None)) and
|
||||
|
|
Loading…
Reference in a new issue