summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNijin Ashok <nashok@redhat.com>2018-10-21 12:54:10 +0530
committerToshio Kuratomi <a.badger@gmail.com>2018-10-23 06:29:26 -0700
commit025c183307d93ef3aff1d1318ec2f113088b96b9 (patch)
tree96a027b11afa94dbf49b8d9d805c08e8819dbede
parent3b2a0de548b4dbf348cd8400294ec8b0e84ee836 (diff)
downloadansible-025c183307d93ef3aff1d1318ec2f113088b96b9.tar.gz
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>
-rw-r--r--changelogs/fragments/ovirt_vm_fix_issue_in_setting_the_custom_compatibility_version_to_NULL.yaml2
-rw-r--r--lib/ansible/module_utils/ovirt.py4
-rw-r--r--lib/ansible/modules/cloud/ovirt/ovirt_vm.py13
3 files changed, 13 insertions, 6 deletions
diff --git a/changelogs/fragments/ovirt_vm_fix_issue_in_setting_the_custom_compatibility_version_to_NULL.yaml b/changelogs/fragments/ovirt_vm_fix_issue_in_setting_the_custom_compatibility_version_to_NULL.yaml
new file mode 100644
index 0000000000..2755793512
--- /dev/null
+++ b/changelogs/fragments/ovirt_vm_fix_issue_in_setting_the_custom_compatibility_version_to_NULL.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+ - ovirt_vm - Fix issue in setting the custom_compatibility_version to NULL (https://github.com/ansible/ansible/pull/47388).
diff --git a/lib/ansible/module_utils/ovirt.py b/lib/ansible/module_utils/ovirt.py
index 0ff02a2392..367eb258f3 100644
--- a/lib/ansible/module_utils/ovirt.py
+++ b/lib/ansible/module_utils/ovirt.py
@@ -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)
diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_vm.py b/lib/ansible/modules/cloud/ovirt/ovirt_vm.py
index 3e307e1469..8db5bc2ac3 100644
--- a/lib/ansible/modules/cloud/ovirt/ovirt_vm.py
+++ b/lib/ansible/modules/cloud/ovirt/ovirt_vm.py
@@ -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