summaryrefslogtreecommitdiffstats
path: root/ansible_collections/lowlydba/sqlserver/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ansible_collections/lowlydba/sqlserver/tests')
-rw-r--r--ansible_collections/lowlydba/sqlserver/tests/integration/targets/agent_job_schedule/tasks/main.yml6
-rw-r--r--ansible_collections/lowlydba/sqlserver/tests/integration/targets/login/tasks/main.yml13
-rw-r--r--ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver/tasks/main.yml3
-rw-r--r--ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver/vars/main.yml9
-rw-r--r--ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/connection_plugins/local_pwsh.py1
-rw-r--r--ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/_Ansible.Basic.cs (renamed from ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/Ansible.Basic.cs)18
-rw-r--r--ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/_Ansible.ModuleUtils.AddType.psm1 (renamed from ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/Ansible.ModuleUtils.AddType.psm1)0
-rw-r--r--ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/shell_plugins/pwsh.py44
-rw-r--r--ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_win_sqlserver/tasks/main.yml3
-rw-r--r--ansible_collections/lowlydba/sqlserver/tests/integration/targets/win_ag_replica/tasks/main.yml5
10 files changed, 69 insertions, 33 deletions
diff --git a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/agent_job_schedule/tasks/main.yml b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/agent_job_schedule/tasks/main.yml
index 5bd266548..8f0e367ad 100644
--- a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/agent_job_schedule/tasks/main.yml
+++ b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/agent_job_schedule/tasks/main.yml
@@ -26,7 +26,6 @@
sql_password: "{{ sqlserver_password }}"
start_date: "{{ start_date }}"
start_time: "{{ start_time }}"
- end_date: "{{ end_date }}"
end_time: "{{ end_time }}"
frequency_type: "{{ frequency_type }}"
frequency_interval: "{{ frequency_interval }}"
@@ -44,8 +43,9 @@
- assert:
that:
- result is changed
+ - result.data.Name == "{{ job_name }}"
- - name: Create job schedule with force
+ - name: Create job schedule with force, no end date
lowlydba.sqlserver.agent_job_schedule:
schedule: "{{ forced_schedule_name }}"
force: true
@@ -55,7 +55,7 @@
that:
- result.data.ScheduleUid != None
- result.data.ActiveStartDate == "3020-05-25T00:00:00.0000000"
- - result.data.ActiveEndDate == "3020-05-25T00:00:00.0000000"
+ - result.data.ActiveEndDate == "9999-12-31T00:00:00.0000000"
- result.data.JobCount == 1
- result.data.IsEnabled is true
- result.data.ScheduleName == "{{ forced_schedule_name }}"
diff --git a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/login/tasks/main.yml b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/login/tasks/main.yml
index da938fc53..da9b60254 100644
--- a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/login/tasks/main.yml
+++ b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/login/tasks/main.yml
@@ -6,6 +6,7 @@
password_expiration_enabled: false
password_policy_enforced: false
password_must_change: false
+ sid: "0x918315B409D64E4BABB31DF2D9FEA879"
enabled: false
default_database: "master"
language: "us_english"
@@ -19,6 +20,7 @@
password: "{{ plain_password }}"
password_expiration_enabled: "{{ password_expiration_enabled }}"
password_must_change: "{{ password_must_change }}"
+ sid: "{{ sid }}"
enabled: "{{ enabled }}"
language: "{{ language }}"
state: present
@@ -47,6 +49,17 @@
- result.data.Name == "{{ login_name }}"
- result.data.DefaultDatabase == "model"
+ - name: Skip pwd reset
+ lowlydba.sqlserver.login:
+ default_database: "model"
+ password: "ItWasA11ADream!"
+ skip_password_reset: true
+ enabled: true
+ register: result
+ - assert:
+ that:
+ - result is not changed
+
- name: Drop login
lowlydba.sqlserver.login:
state: "absent"
diff --git a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver/tasks/main.yml b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver/tasks/main.yml
index 28c3c1cd7..d01023640 100644
--- a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver/tasks/main.yml
+++ b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver/tasks/main.yml
@@ -3,7 +3,6 @@
when: not sqlserver_windows
ansible.builtin.command: >
pwsh -Command "{{ item }}"
- no_log: "{{ ansible_verbosity | int < 3 }}"
loop:
- - "{{ dbatools_install_cmd }}"
- "{{ dbops_install_cmd }}"
+ - "{{ dbatools_install_cmd }}"
diff --git a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver/vars/main.yml b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver/vars/main.yml
index 3f8503300..bece0f6fb 100644
--- a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver/vars/main.yml
+++ b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver/vars/main.yml
@@ -1,12 +1,13 @@
---
-dbatools_min_version: 1.1.112
+dbatools_min_version: 2.0.0
dbatools_install_cmd: >
if (-not(Get-Module -FullyQualifiedName @{ModuleName='dbatools';ModuleVersion='{{ dbatools_min_version }}'} -ListAvailable)) {
- Install-Module dbatools -MinimumVersion {{ dbatools_min_version }} -Force
+ Install-Module dbatools -MinimumVersion {{ dbatools_min_version }} -Force -SkipPublisherCheck -AllowClobber
+ Set-DbatoolsInsecureConnection -Scope FileUserLocal
}
-dbops_min_version: 0.8.0
+dbops_min_version: 0.9.0
dbops_install_cmd: >
if (-not(Get-Module -FullyQualifiedName @{ModuleName='dbops';ModuleVersion='{{ dbops_min_version }}'} -ListAvailable)) {
- Install-Module dbops -MinimumVersion {{ dbops_min_version }} -Force
+ Install-Module dbops -MinimumVersion {{ dbops_min_version }} -Force -SkipPublisherCheck -AllowClobber
}
diff --git a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/connection_plugins/local_pwsh.py b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/connection_plugins/local_pwsh.py
index 18ec57fd3..138eb1ec6 100644
--- a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/connection_plugins/local_pwsh.py
+++ b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/connection_plugins/local_pwsh.py
@@ -26,7 +26,6 @@ import subprocess
import fcntl
import getpass
-import ansible.constants as C
from ansible.errors import AnsibleError, AnsibleFileNotFound
from ansible.module_utils.compat import selectors
from ansible.module_utils.six import text_type, binary_type
diff --git a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/Ansible.Basic.cs b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/_Ansible.Basic.cs
index 484f75751..c68281ef1 100644
--- a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/Ansible.Basic.cs
+++ b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/_Ansible.Basic.cs
@@ -16,6 +16,10 @@ using Newtonsoft.Json;
using System.Web.Script.Serialization;
#endif
+// Newtonsoft.Json may reference a different System.Runtime version (6.x) than loaded by PowerShell 7.3 (7.x).
+// Ignore CS1701 so the code can be compiled when warnings are reported as errors.
+//NoWarn -Name CS1701 -CLR Core
+
// System.Diagnostics.EventLog.dll reference different versioned dlls that are
// loaded in PSCore, ignore CS1702 so the code will ignore this warning
//NoWarn -Name CS1702 -CLR Core
@@ -128,6 +132,7 @@ namespace Ansible.Basic
{
if (tmpdir == null)
{
+#if WINDOWS
SecurityIdentifier user = WindowsIdentity.GetCurrent().User;
DirectorySecurity dirSecurity = new DirectorySecurity();
dirSecurity.SetOwner(user);
@@ -183,6 +188,9 @@ namespace Ansible.Basic
if (!KeepRemoteFiles)
cleanupFiles.Add(tmpdir);
+#else
+ throw new NotImplementedException("Tmpdir is only supported on Windows");
+#endif
}
return tmpdir;
}
@@ -336,13 +344,10 @@ namespace Ansible.Basic
public void LogEvent(string message, EventLogEntryType logEntryType = EventLogEntryType.Information, bool sanitise = true)
{
- // non-Windows hack; event log is not supported, not implementing a x-plat compat logger at this time
- // original content left as comment, because it may make it easier to update this
- return;
- /*
if (NoLog)
return;
+#if WINDOWS
string logSource = "Ansible";
bool logSourceExists = false;
try
@@ -382,7 +387,10 @@ namespace Ansible.Basic
warnings.Add(String.Format("Unknown error when creating event log entry: {0}", e.Message));
}
}
- */
+#else
+ // Windows Event Log is only available on Windows
+ return;
+#endif
}
public void Warn(string message)
diff --git a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/Ansible.ModuleUtils.AddType.psm1 b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/_Ansible.ModuleUtils.AddType.psm1
index 673070263..673070263 100644
--- a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/Ansible.ModuleUtils.AddType.psm1
+++ b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/module_utils/_Ansible.ModuleUtils.AddType.psm1
diff --git a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/shell_plugins/pwsh.py b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/shell_plugins/pwsh.py
index 468c54069..9b1601046 100644
--- a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/shell_plugins/pwsh.py
+++ b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_sqlserver_test_plugins/shell_plugins/pwsh.py
@@ -59,10 +59,15 @@ import re
import shlex
import pkgutil
import xml.etree.ElementTree as ET
-import ntpath
+
+from packaging import version
from ansible.module_utils._text import to_bytes, to_text
from ansible.plugins.shell import ShellBase
+from ansible.release import __version__ as ansible_version
+from ansible.utils.display import Display
+
+display = Display()
_common_args = ['pwsh', '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Unrestricted']
@@ -223,18 +228,12 @@ class ShellModule(ShellBase):
def build_module_command(self, env_string, shebang, cmd, arg_path=None):
bootstrap_wrapper = pkgutil.get_data("ansible.executor.powershell", "bootstrap_wrapper.ps1")
- # pipelining bypass
- if cmd == '':
- return self._encode_script(script=bootstrap_wrapper, strict_mode=False, preserve_rc=False)
-
- # non-pipelining
-
- cmd_parts = shlex.split(cmd, posix=False)
- cmd_parts = list(map(to_text, cmd_parts))
- if shebang and shebang.lower() == '#!powershell':
- if not self._unquote(cmd_parts[0]).lower().endswith('.ps1'):
- # we're running a module via the bootstrap wrapper
- cmd_parts[0] = '"%s.ps1"' % self._unquote(cmd_parts[0])
+ # TODO: remove when support for ansible-core <2.13 is dropped
+ ver = version.parse(ansible_version)
+ cutoff = version.parse('2.13')
+ info = "ansible_version (parsed) [<2.13]: %s (%s) [%r]" % (ansible_version, ver, (ver < cutoff))
+ display.vvv(info)
+ if ver < cutoff:
# HACK begin dirty, dirty hack
# we need to override the built-in Ansible.Basic module util
# to one that will work on non-Windows platforms.
@@ -246,8 +245,8 @@ class ShellModule(ShellBase):
# before it made it to the remote host. The reason we can't just embed it in commands as strings is because
# it will be too big.
local_mu = os.path.join(os.path.dirname(__file__), '..', 'module_utils')
- ansible_basic_cs = os.path.join(local_mu, 'Ansible.Basic.cs')
- addtype_ps = os.path.join(local_mu, 'Ansible.ModuleUtils.AddType.psm1')
+ ansible_basic_cs = os.path.join(local_mu, '_Ansible.Basic.cs')
+ addtype_ps = os.path.join(local_mu, '_Ansible.ModuleUtils.AddType.psm1')
wrapper_hacked = '''
&chcp.com 65001 > $null
$exec_wrapper_str = $input | Out-String
@@ -286,6 +285,21 @@ class ShellModule(ShellBase):
&$exec_wrapper
''' % (ansible_basic_cs, addtype_ps)
bootstrap_wrapper = wrapper_hacked
+ # end hack for ansible-core < 2.13
+
+ # pipelining bypass
+ if cmd == '':
+ return self._encode_script(script=bootstrap_wrapper, strict_mode=False, preserve_rc=False)
+
+ # non-pipelining
+
+ cmd_parts = shlex.split(cmd, posix=False)
+ cmd_parts = list(map(to_text, cmd_parts))
+ if shebang and shebang.lower() == '#!powershell':
+ if not self._unquote(cmd_parts[0]).lower().endswith('.ps1'):
+ # we're running a module via the bootstrap wrapper
+ cmd_parts[0] = '"%s.ps1"' % self._unquote(cmd_parts[0])
+
wrapper_cmd = "cat " + cmd_parts[0] + " | " + self._encode_script(script=bootstrap_wrapper, strict_mode=False, preserve_rc=False)
return wrapper_cmd
elif shebang and shebang.startswith('#!'):
diff --git a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_win_sqlserver/tasks/main.yml b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_win_sqlserver/tasks/main.yml
index acc1dbeb4..0928ecc1c 100644
--- a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_win_sqlserver/tasks/main.yml
+++ b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/setup_win_sqlserver/tasks/main.yml
@@ -2,7 +2,6 @@
- name: Install Powershell modules
ansible.windows.win_shell: |
{{ item }}
- no_log: "{{ ansible_verbosity | int < 3 }}"
loop:
- - "{{ dbatools_install_cmd }}"
- "{{ dbops_install_cmd }}"
+ - "{{ dbatools_install_cmd }}"
diff --git a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/win_ag_replica/tasks/main.yml b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/win_ag_replica/tasks/main.yml
index 8a8990789..feb3acb55 100644
--- a/ansible_collections/lowlydba/sqlserver/tests/integration/targets/win_ag_replica/tasks/main.yml
+++ b/ansible_collections/lowlydba/sqlserver/tests/integration/targets/win_ag_replica/tasks/main.yml
@@ -56,6 +56,10 @@
lowlydba.sqlserver.availability_group:
register: ag
+ - name: Set ag SqlInstance fact
+ set_fact:
+ ag_sql_instance: "{{ ag.data.SqlInstance }}"
+
- name: Set replica
lowlydba.sqlserver.ag_replica:
session_timeout: 20
@@ -72,7 +76,6 @@
- result.data.AvailabilityMode == availability_mode
- result.data.SessionTimeout == 20
- result.data.FailoverMode == failover_mode
- - result.data.EndpointUrl == "TCP://{{ ag.data.SqlInstance }}:5022"
- result is changed
always: