1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[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
This commit is contained in:
Artem Zinenko 2017-08-29 01:48:10 +03:00 committed by Jordan Borean
parent 468e71bf71
commit 1c958af88b
5 changed files with 184 additions and 5 deletions

1
.github/BOTMETA.yml vendored
View file

@ -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

View file

@ -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"

View file

@ -0,0 +1 @@
windows/ci/group3

View file

@ -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', '>=')

View file

@ -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 == []