From 3bb93817850cb62aad34962acf4fa426aaedf3dc Mon Sep 17 00:00:00 2001 From: Mike Morency Date: Tue, 1 Oct 2024 08:58:13 -0400 Subject: [PATCH] fix backwards drs vmotion rate --- .../73-fix_drs_backwards_vmotion_rate.yml | 3 +++ plugins/modules/cluster_drs.py | 11 +++++++++- .../targets/vmware_cluster_drs/tasks/main.yml | 21 ++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/73-fix_drs_backwards_vmotion_rate.yml diff --git a/changelogs/fragments/73-fix_drs_backwards_vmotion_rate.yml b/changelogs/fragments/73-fix_drs_backwards_vmotion_rate.yml new file mode 100644 index 00000000..55123493 --- /dev/null +++ b/changelogs/fragments/73-fix_drs_backwards_vmotion_rate.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - cluster_drs - fixed backwards vMotion rate (input 1 set rate to 5 in vCenter) (https://github.com/ansible-collections/vmware.vmware/issues/68) diff --git a/plugins/modules/cluster_drs.py b/plugins/modules/cluster_drs.py index f9e8e09f..06f96d84 100644 --- a/plugins/modules/cluster_drs.py +++ b/plugins/modules/cluster_drs.py @@ -158,7 +158,6 @@ def __init__(self, module): self.cluster = self.get_cluster_by_name(self.params.get('cluster'), fail_on_missing=True, datacenter=datacenter) self.enable_drs = self.params.get('enable') - self.drs_vmotion_rate = self.params.get('drs_vmotion_rate') self.drs_enable_vm_behavior_overrides = self.params.get('drs_enable_vm_behavior_overrides') self.drs_default_vm_behavior = self.params.get('drs_default_vm_behavior') self.predictive_drs = self.params.get('predictive_drs') @@ -168,6 +167,16 @@ def __init__(self, module): self.cluster.configurationEx.drsConfig.option ) + @property + def drs_vmotion_rate(self): + """ + When applying or reading this rate from the vCenter config, the values are reversed. So + for example, vCenter thinks 1 is the most aggressive when docs/UI say 5 is most aggressive. + We present the scale seen in the docs/UI to the user and then adjust the value here to ensure + vCenter behaves as intended. + """ + return 6 - self.params.get('drs_vmotion_rate') + def check_drs_config_diff(self): """ Check the active DRS configuration and determine if desired configuration is different. diff --git a/tests/integration/targets/vmware_cluster_drs/tasks/main.yml b/tests/integration/targets/vmware_cluster_drs/tasks/main.yml index 646b386a..cf08a801 100644 --- a/tests/integration/targets/vmware_cluster_drs/tasks/main.yml +++ b/tests/integration/targets/vmware_cluster_drs/tasks/main.yml @@ -49,6 +49,21 @@ advanced_settings: "{{ drs_advanced_settings }}" predictive_drs: "{{ drs_predictive_drs }}" register: _out + - name: Set DRS Settings In Test Cluster Again - Idempotence + vmware.vmware.cluster_drs: + validate_certs: false + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + datacenter: "{{ vcenter_datacenter }}" + cluster: "{{ test_cluster }}" + port: "{{ vcenter_port }}" + drs_enable_vm_behavior_overrides: "{{ drs_enable_vm_behavior_overrides}}" + drs_default_vm_behavior: "{{ drs_default_vm_behavior }}" + drs_vmotion_rate: "{{ drs_vmotion_rate }}" + advanced_settings: "{{ drs_advanced_settings }}" + predictive_drs: "{{ drs_predictive_drs }}" + register: _idempotence_check - name: Gather Cluster Settings community.vmware.vmware_cluster_info: validate_certs: false @@ -59,12 +74,16 @@ cluster_name: "{{ test_cluster }}" port: "{{ vcenter_port }}" register: _cluster_info + # drs vmotion rate reported by vcenter api is backwards. So 1 is actually 5 in the UI + # and 5 is actually 1 in the UI. When we migrate cluster_info there is a ticket to fix the output + # so the number we return to the user makes sense, but for now we will fix it here with (6 - ) - name: Check DRS Settings Were Applied ansible.builtin.assert: that: + - _idempotence_check is not changed - _config.drs_default_vm_behavior == drs_default_vm_behavior - _config.drs_enable_vm_behavior_overrides == drs_enable_vm_behavior_overrides - - _config.drs_vmotion_rate == drs_vmotion_rate + - _config.drs_vmotion_rate == (6 - drs_vmotion_rate) - _config.enabled_drs == drs_enable vars: _config: "{{ _cluster_info.clusters[test_cluster] }}"