Skip to content

Commit

Permalink
fix backwards drs vmotion rate
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemorency committed Oct 8, 2024
1 parent 69443e8 commit 98ddcfd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/73-fix_drs_backwards_vmotion_rate.yml
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 10 additions & 1 deletion plugins/modules/cluster_drs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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.
Expand Down
21 changes: 20 additions & 1 deletion tests/integration/targets/vmware_cluster_drs/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 - <user_input>)
- 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] }}"
Expand Down

0 comments on commit 98ddcfd

Please sign in to comment.