From 1c958af88bfc154d7d1b108c4fa5e2404d5acb9a Mon Sep 17 00:00:00 2001 From: Artem Zinenko Date: Tue, 29 Aug 2017 01:48:10 +0300 Subject: [PATCH] [28017] Integration tests for win_rabbitmq_plugin (#28118) * Check registry to find RabbitMQ installation path * Integration tests for win_rabbitmq_plugin * Added himself to BOTMETA.yml * Skipped running tests on Windows 2008 SP2 --- .github/BOTMETA.yml | 1 + .../modules/windows/win_rabbitmq_plugin.ps1 | 46 +++++- .../targets/win_rabbitmq_plugin/aliases | 1 + .../win_rabbitmq_plugin/tasks/main.yml | 7 + .../win_rabbitmq_plugin/tasks/tests.yml | 134 ++++++++++++++++++ 5 files changed, 184 insertions(+), 5 deletions(-) create mode 100644 test/integration/targets/win_rabbitmq_plugin/aliases create mode 100644 test/integration/targets/win_rabbitmq_plugin/tasks/main.yml create mode 100644 test/integration/targets/win_rabbitmq_plugin/tasks/tests.yml diff --git a/.github/BOTMETA.yml b/.github/BOTMETA.yml index 42166db89f..9222b42ec7 100644 --- a/.github/BOTMETA.yml +++ b/.github/BOTMETA.yml @@ -748,6 +748,7 @@ files: $modules/windows/win_psexec.py: dagwieers $modules/windows/win_psmodule.ps1: $team_windows $modules/windows/win_psmodule.py: $team_windows + $modules/windows/win_rabbitmq_plugin.py: ar7z1 $modules/windows/win_reboot.py: nitzmahone $modules/windows/win_reg_stat.ps1: jborean93 $modules/windows/win_reg_stat.py: jborean93 diff --git a/lib/ansible/modules/windows/win_rabbitmq_plugin.ps1 b/lib/ansible/modules/windows/win_rabbitmq_plugin.ps1 index 210db06763..aae9a639d2 100644 --- a/lib/ansible/modules/windows/win_rabbitmq_plugin.ps1 +++ b/lib/ansible/modules/windows/win_rabbitmq_plugin.ps1 @@ -39,6 +39,37 @@ function Disable-Plugin($rabbitmq_plugins_cmd, $plugin_name) } } +function Get-RabbitmqPathFromRegistry +{ + $reg64Path = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ" + $reg32Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ" + + if (Test-Path $reg64Path) { + $regPath = $reg64Path + } elseif (Test-Path $reg32Path) { + $regPath = $reg32Path + } + + if ($regPath) { + $path = Split-Path -Parent (Get-ItemProperty $regPath "UninstallString").UninstallString + $version = (Get-ItemProperty $regPath "DisplayVersion").DisplayVersion + return "$path\rabbitmq_server-$version" + } +} + +function Get-RabbitmqBinPath($installation_path) +{ + $result = Join-Path -Path $installation_path -ChildPath 'bin' + if (Test-Path $result) { + return $result + } + + $result = Join-Path -Path $installation_path -ChildPath 'sbin' + if (Test-Path $result) { + return $result + } +} + $ErrorActionPreference = "Stop" $result = @{ @@ -64,13 +95,18 @@ if ($diff_support) { $plugins = $names.Split(",") if ($prefix) { - if (Test-Path (Join-Path -Path $prefix -ChildPath 'bin')) { - $rabbitmq_bin_path = Join-Path -Path $prefix -ChildPath 'bin' - } elseif (Test-Path (Join-Path -Path $prefix -ChildPath 'sbin')) { - $rabbitmq_bin_path = Join-Path -Path $prefix -ChildPath 'sbin' - } else { + $rabbitmq_bin_path = Get-RabbitmqBinPath -installation_path $prefix + if (-not $rabbitmq_bin_path) { Fail-Json -obj $result -message "No binary folder in prefix `"$($prefix)`"" } +} else { + $rabbitmq_reg_path = Get-RabbitmqPathFromRegistry + if ($rabbitmq_reg_path) { + $rabbitmq_bin_path = Get-RabbitmqBinPath -installation_path $rabbitmq_reg_path + } +} + +if ($rabbitmq_bin_path) { $rabbitmq_plugins_cmd = "'$(Join-Path -Path $rabbitmq_bin_path -ChildPath "rabbitmq-plugins")'" } else { $rabbitmq_plugins_cmd = "rabbitmq-plugins" diff --git a/test/integration/targets/win_rabbitmq_plugin/aliases b/test/integration/targets/win_rabbitmq_plugin/aliases new file mode 100644 index 0000000000..c6d6198167 --- /dev/null +++ b/test/integration/targets/win_rabbitmq_plugin/aliases @@ -0,0 +1 @@ +windows/ci/group3 diff --git a/test/integration/targets/win_rabbitmq_plugin/tasks/main.yml b/test/integration/targets/win_rabbitmq_plugin/tasks/main.yml new file mode 100644 index 0000000000..39ef7c9738 --- /dev/null +++ b/test/integration/targets/win_rabbitmq_plugin/tasks/main.yml @@ -0,0 +1,7 @@ +# Setup action creates ansible_distribution_version variable +- action: setup + +- include_tasks: tasks/tests.yml + # Works on windows >= Windows 7/Windows Server 2008 R2 + # See https://github.com/ansible/ansible/pull/28118#issuecomment-323684042 for additional info. + when: ansible_distribution_version | version_compare('6.1', '>=') diff --git a/test/integration/targets/win_rabbitmq_plugin/tasks/tests.yml b/test/integration/targets/win_rabbitmq_plugin/tasks/tests.yml new file mode 100644 index 0000000000..3603a9cfbd --- /dev/null +++ b/test/integration/targets/win_rabbitmq_plugin/tasks/tests.yml @@ -0,0 +1,134 @@ +- name: Ensure RabbitMQ installed + win_chocolatey: + name: rabbitmq + state: present + +- name: Ensure that rabbitmq_management plugin disabled + win_rabbitmq_plugin: + names: rabbitmq_management + state: disabled + +- name: Enable rabbitmq_management plugin in check mode + win_rabbitmq_plugin: + names: rabbitmq_management + state: enabled + check_mode: yes + register: enable_plugin_in_check_mode + +- name: Check that enabling plugin in check mode succeeds with a change + assert: + that: + - enable_plugin_in_check_mode.changed == true + +- name: Enable rabbitmq_management plugin in check mode again + win_rabbitmq_plugin: + names: rabbitmq_management + state: enabled + check_mode: yes + register: enable_plugin_in_check_mode_again + +- name: Check that enabling plugin in check mode does not make changes + assert: + that: + - enable_plugin_in_check_mode_again.changed == true + +- name: Enable rabbitmq_management plugin + win_rabbitmq_plugin: + names: rabbitmq_management + state: enabled + register: enable_plugin + +- name: Check that enabling plugin succeeds with a change + assert: + that: + - enable_plugin.changed == true + - enable_plugin.enabled == ['rabbitmq_management'] + +- name: Enable enabled rabbitmq_management plugin + win_rabbitmq_plugin: + names: rabbitmq_management + state: enabled + register: enable_plugin_again + +- name: Check that enabling enabled plugin succeeds without a change + assert: + that: + - enable_plugin_again.changed == false + - enable_plugin_again.enabled == [] + +- name: Enable new plugin when 'new_only' option is 'no' (by default) and there are installed plugins + win_rabbitmq_plugin: + names: rabbitmq_mqtt + state: enabled + check_mode: yes + register: enable_plugin_without_new_only + +- name: Check that 'new_only == no' option enables new plugin and disables the old one + assert: + that: + - enable_plugin_without_new_only.changed == true + - enable_plugin_without_new_only.enabled == ['rabbitmq_mqtt'] + - enable_plugin_without_new_only.disabled == ['rabbitmq_management'] + +- name: Enable new plugin when 'new_only' option is 'yes' and there are installed plugins + win_rabbitmq_plugin: + names: rabbitmq_mqtt + state: enabled + new_only: yes + check_mode: yes + register: enable_plugin_with_new_only + +- name: Check that 'new_only == yes' option just enables new plugin + assert: + that: + - enable_plugin_with_new_only.changed == true + - enable_plugin_with_new_only.enabled == ['rabbitmq_mqtt'] + - enable_plugin_with_new_only.disabled == [] + +- name: Disable rabbitmq_management plugin in check mode + win_rabbitmq_plugin: + names: rabbitmq_management + state: disabled + check_mode: yes + register: disable_plugin_in_check_mode + +- name: Check that disabling plugin in check mode succeeds with a change + assert: + that: + - disable_plugin_in_check_mode.changed == true + +- name: Disable rabbitmq_management plugin in check mode again + win_rabbitmq_plugin: + names: rabbitmq_management + state: disabled + check_mode: yes + register: disable_plugin_in_check_mode_again + +- name: Check that disabling plugin in check mode does not make changes + assert: + that: + - disable_plugin_in_check_mode_again.changed == true + +- name: Disable rabbitmq_management plugin + win_rabbitmq_plugin: + names: rabbitmq_management + state: disabled + register: disable_plugin + +- name: Check that disabling plugin succeeds with a change + assert: + that: + - disable_plugin.changed == true + - disable_plugin.disabled == ['rabbitmq_management'] + +- name: Disable disabled rabbitmq_management plugin + win_rabbitmq_plugin: + names: rabbitmq_management + state: disabled + register: disable_plugin_again + +- name: Check that disabling disabled plugin succeeds without a change + assert: + that: + - disable_plugin_again.changed == false + - disable_plugin_again.disabled == []