diff --git a/noxfile.py b/noxfile.py index 48d40672f3eb..a6d958b40dad 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1981,3 +1981,41 @@ def ci_test_onedir_pkgs(session): on_rerun=True, ) sys.exit(0) + + +@nox.session(python="3", name="ci-test-installer") +def ci_test_installer(session): + """ + Test a dummy installer to make sure the installer logic is working correctly + """ + installers = ["nsis", "msi"] + if not session.posargs or session.posargs[0] not in installers: + installer = "nsis" + session.log("Choosing default 'nsis' installer type") + else: + installer = session.posargs.pop(0) + + # Build dummy installer + tests_root = REPO_ROOT / "tests" / "pytests" / "pkg" / "installer" / installer + setup_file = tests_root / "setup.ps1" + session.run("PowerShell", "-ExecutionPolicy", "RemoteSigned", "-File", setup_file) + + session.install("--progress-bar=off", "psutil", silent=PIP_INSTALL_SILENT) + + requirements_file = os.path.join("requirements", "pytest.txt") + install_command = ["--progress-bar=off", "-r", requirements_file] + session.install(*install_command, silent=PIP_INSTALL_SILENT) + + # Install the Salt requirements, though they're not needed for these tests + requirements_file = _get_pip_requirements_file(session, requirements_type="ci") + install_command = ["--progress-bar=off", "-r", requirements_file] + session.install(*install_command, silent=PIP_INSTALL_SILENT) + + # Run installer tests + cmd_args = ["-vvv", "--rootdir", str(tests_root), "--"] + if not session.posargs: + cmd_args.append(str(tests_root / "config_tests")) + else: + cmd_args.extend(session.posargs) + # os.chdir(tests_root) + session.run("python", "-m", "pytest", *cmd_args) diff --git a/tests/pytests/pkg/installer/nsis/_files/minion b/tests/pytests/pkg/installer/nsis/_files/minion new file mode 100644 index 000000000000..203eed5c97a9 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/_files/minion @@ -0,0 +1,8 @@ +# Default config from test suite line 1/6 +#master: salt +# Default config from test suite line 2/6 +#id: +# Default config from test suite line 3/6 +# Default config from test suite line 4/6 +# Default config from test suite line 5/6 +# Default config from test suite line 6/6 diff --git a/tests/pytests/pkg/installer/nsis/clean.cmd b/tests/pytests/pkg/installer/nsis/clean.cmd new file mode 100644 index 000000000000..a8392f6bc383 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/clean.cmd @@ -0,0 +1,3 @@ +@ echo off +Set "CurDir=%~dp0" +PowerShell -ExecutionPolicy RemoteSigned -File "%CurDir%\clean.ps1" %* diff --git a/tests/pytests/pkg/installer/nsis/clean.ps1 b/tests/pytests/pkg/installer/nsis/clean.ps1 new file mode 100644 index 000000000000..9cc7bb49e8b2 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/clean.ps1 @@ -0,0 +1,83 @@ +<# +.SYNOPSIS +Clean the NSIS Tests directory + +.DESCRIPTION +This script removes the venv directory and the test-setup.exe + +.EXAMPLE +clean.ps1 + +.EXAMPLE +clean.ps1 + +#> + +# Script Preferences +$ProgressPreference = "SilentlyContinue" +$ErrorActionPreference = "Stop" + +#------------------------------------------------------------------------------- +# Script Variables +#------------------------------------------------------------------------------- + +$SCRIPT_DIR = (Get-ChildItem "$($myInvocation.MyCommand.Definition)").DirectoryName + +#------------------------------------------------------------------------------- +# Script Functions +#------------------------------------------------------------------------------- + +function Write-Result($result, $ForegroundColor="Green") { + $position = 80 - $result.Length - [System.Console]::CursorLeft + Write-Host -ForegroundColor $ForegroundColor ("{0,$position}$result" -f "") +} + +#------------------------------------------------------------------------------- +# Start the Script +#------------------------------------------------------------------------------- +Write-Host $("=" * 80) +Write-Host "Clean NSIS Test Environment" -ForegroundColor Cyan +Write-Host $("-" * 80) + +#------------------------------------------------------------------------------- +# Make sure we're not in a virtual environment +#------------------------------------------------------------------------------- +if ( $env:VIRTUAL_ENV ) { + # I've tried deactivating from the script, but it doesn't work + Write-Host "Please deactive the virtual environment" + exit +} + +#------------------------------------------------------------------------------- +# Remove venv directory +#------------------------------------------------------------------------------- +if ( Test-Path -Path "$SCRIPT_DIR\venv" ) { + Write-Host "Removing venv directory: " -NoNewline + Remove-Item -Path "$SCRIPT_DIR\venv" -Recurse -Force + if ( Test-Path -Path "$SCRIPT_DIR\venv" ) { + Write-Result "Failed" -ForegroundColor Red + exit 1 + } else { + Write-Result "Success" -ForegroundColor Green + } +} +#------------------------------------------------------------------------------- +# Remove test-setup.exe +#------------------------------------------------------------------------------- +if ( Test-Path -Path "$SCRIPT_DIR\test-setup.exe" ) { + Write-Host "Removing test-setup.exe: " -NoNewline + Remove-Item -Path "$SCRIPT_DIR\test-setup.exe" -Recurse -Force + if ( Test-Path -Path "$SCRIPT_DIR\test-setup.exe" ) { + Write-Result "Failed" -ForegroundColor Red + exit 1 + } else { + Write-Result "Success" -ForegroundColor Green + } +} + +#------------------------------------------------------------------------------- +# Script Completed +#------------------------------------------------------------------------------- +Write-Host $("-" * 80) +Write-Host "Clean NSIS Test Environment Completed" -ForegroundColor Cyan +Write-Host $("=" * 80) diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_custom_full_path.py b/tests/pytests/pkg/installer/nsis/config_tests/test_custom_full_path.py new file mode 100644 index 000000000000..05f186f6c1bc --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_custom_full_path.py @@ -0,0 +1,38 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create a custom config + pytest.helpers.custom_config() + + full_path_conf = rf"{pytest.REPO_DIR}\custom_conf" + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", f"/custom-config={full_path_conf}"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config, unchanged + with open(rf"{pytest.REPO_DIR}\custom_conf") as f: + expected = f.readlines() + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_custom_master.py b/tests/pytests/pkg/installer/nsis/config_tests/test_custom_master.py new file mode 100644 index 000000000000..d332fea1964e --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_custom_master.py @@ -0,0 +1,44 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/custom-config=custom_conf", "/master=cli_master"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only master set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: custom_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_custom_master_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_custom_master_minion.py new file mode 100644 index 000000000000..0a862c12c724 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_custom_master_minion.py @@ -0,0 +1,50 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/custom-config=custom_conf", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with master and minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_custom_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_custom_minion.py new file mode 100644 index 000000000000..4274defbb5db --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_custom_minion.py @@ -0,0 +1,49 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/custom-config=custom_conf", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: custom_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_custom_rel_path.py b/tests/pytests/pkg/installer/nsis/config_tests/test_custom_rel_path.py new file mode 100644 index 000000000000..a54969faf20c --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_custom_rel_path.py @@ -0,0 +1,34 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command([pytest.INST_BIN, "/S", "/custom-config=custom_conf"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config, unchanged + with open(rf"{pytest.REPO_DIR}\custom_conf") as f: + expected = f.readlines() + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_default.py b/tests/pytests/pkg/installer/nsis/config_tests/test_default.py new file mode 100644 index 000000000000..7681b44e52b0 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_default.py @@ -0,0 +1,30 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + pytest.helpers.run_command([pytest.INST_BIN, "/S"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config, unchanged + with open(rf"{pytest.REPO_DIR}\_files\minion") as f: + expected = f.readlines() + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_default_master.py b/tests/pytests/pkg/installer/nsis/config_tests/test_default_master.py new file mode 100644 index 000000000000..d978f7b206ab --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_default_master.py @@ -0,0 +1,38 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + pytest.helpers.run_command([pytest.INST_BIN, "/S", "/master=cli_master"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config with only master set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "#id:\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_default_master_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_default_master_minion.py new file mode 100644 index 000000000000..4a23c362995a --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_default_master_minion.py @@ -0,0 +1,40 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/master=cli_master", "/minion-name=cli_minion"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config with master and minion set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_default_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_default_minion.py new file mode 100644 index 000000000000..c3f165a8ef9b --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_default_minion.py @@ -0,0 +1,38 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + pytest.helpers.run_command([pytest.INST_BIN, "/S", "/minion-name=cli_minion"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config with only minion set + expected = [ + "# Default config from test suite line 1/6\n", + "#master: salt\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_existing.py b/tests/pytests/pkg/installer/nsis/config_tests/test_existing.py new file mode 100644 index 000000000000..64baced527e1 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_existing.py @@ -0,0 +1,33 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + pytest.helpers.run_command([pytest.INST_BIN, "/S"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the existing config, unchanged + expected = pytest.EXISTING_CONTENT + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom.py b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom.py new file mode 100644 index 000000000000..6fb147739f24 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom.py @@ -0,0 +1,37 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command([pytest.INST_BIN, "/S", "/custom-config=custom_conf"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config, unchanged + with open(rf"{pytest.REPO_DIR}\custom_conf") as f: + expected = f.readlines() + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom_master.py b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom_master.py new file mode 100644 index 000000000000..78e80cea2653 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom_master.py @@ -0,0 +1,47 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/custom-config=custom_conf", "/master=cli_master"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only master set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: custom_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom_master_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom_master_minion.py new file mode 100644 index 000000000000..66e36c41262e --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom_master_minion.py @@ -0,0 +1,53 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/custom-config=custom_conf", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with master and minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom_minion.py new file mode 100644 index 000000000000..545e8219537a --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_custom_minion.py @@ -0,0 +1,51 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + # Create an existing config + pytest.helpers.existing_config() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/custom-config=custom_conf", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: custom_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default.py b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default.py new file mode 100644 index 000000000000..aaaa2622e02b --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default.py @@ -0,0 +1,34 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + pytest.helpers.run_command([pytest.INST_BIN, "/S", "/default-config"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config, unchanged + with open(rf"{pytest.REPO_DIR}\_files\minion") as f: + expected = f.readlines() + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default_master.py b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default_master.py new file mode 100644 index 000000000000..456080e49961 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default_master.py @@ -0,0 +1,44 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/default-config", "/master=cli_master"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config with only master set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "#id:\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default_master_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default_master_minion.py new file mode 100644 index 000000000000..90d262e9b0e8 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default_master_minion.py @@ -0,0 +1,50 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/default-config", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config with master and minion set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default_minion.py new file mode 100644 index 000000000000..16e41035c664 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_existing_default_minion.py @@ -0,0 +1,44 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/default-config", "/minion-name=cli_minion"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config with just the minion set + expected = [ + "# Default config from test suite line 1/6\n", + "#master: salt\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom.py b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom.py new file mode 100644 index 000000000000..a2fce64fe364 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom.py @@ -0,0 +1,46 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def inst_dir(): + return "C:\\custom_location" + + +@pytest.fixture(scope="module") +def install(inst_dir): + pytest.helpers.clean_env(inst_dir) + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + f"/install-dir={inst_dir}", + "/custom-config=custom_conf", + ] + ) + yield + pytest.helpers.clean_env(inst_dir) + + +def test_binaries_present(install, inst_dir): + assert os.path.exists(rf"{inst_dir}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config, unchanged + with open(rf"{pytest.REPO_DIR}\custom_conf") as f: + expected = f.readlines() + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom_master.py b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom_master.py new file mode 100644 index 000000000000..d47abd1df83d --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom_master.py @@ -0,0 +1,55 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def inst_dir(): + return "C:\\custom_location" + + +@pytest.fixture(scope="module") +def install(inst_dir): + pytest.helpers.clean_env(inst_dir) + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + f"/install-dir={inst_dir}", + "/custom-config=custom_conf", + "/master=cli_master", + ] + ) + yield + pytest.helpers.clean_env(inst_dir) + + +def test_binaries_present(install, inst_dir): + assert os.path.exists(rf"{inst_dir}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only master set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: custom_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom_master_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom_master_minion.py new file mode 100644 index 000000000000..bf039af4c20a --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom_master_minion.py @@ -0,0 +1,56 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def inst_dir(): + return "C:\\custom_location" + + +@pytest.fixture(scope="module") +def install(inst_dir): + pytest.helpers.clean_env(inst_dir) + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + f"/install-dir={inst_dir}", + "/custom-config=custom_conf", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env(inst_dir) + + +def test_binaries_present(install, inst_dir): + assert os.path.exists(rf"{inst_dir}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with master and minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom_minion.py new file mode 100644 index 000000000000..fcdf2146e0a3 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_custom_minion.py @@ -0,0 +1,55 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def inst_dir(): + return "C:\\custom_location" + + +@pytest.fixture(scope="module") +def install(inst_dir): + pytest.helpers.clean_env(inst_dir) + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + f"/install-dir={inst_dir}", + "/custom-config=custom_conf", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env(inst_dir) + + +def test_binaries_present(install, inst_dir): + assert os.path.exists(rf"{inst_dir}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: custom_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default.py b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default.py new file mode 100644 index 000000000000..ac3c403e2e6e --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default.py @@ -0,0 +1,35 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def inst_dir(): + return "C:\\custom_location" + + +@pytest.fixture(scope="module") +def install(inst_dir): + pytest.helpers.clean_env(inst_dir) + pytest.helpers.run_command([pytest.INST_BIN, "/S", f"/install-dir={inst_dir}"]) + yield + pytest.helpers.clean_env(inst_dir) + + +def test_binaries_present(install, inst_dir): + assert os.path.exists(rf"{inst_dir}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config, unchanged + with open(rf"{pytest.REPO_DIR}\_files\minion") as f: + expected = f.readlines() + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default_master.py b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default_master.py new file mode 100644 index 000000000000..2ac36f87e274 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default_master.py @@ -0,0 +1,45 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def inst_dir(): + return r"C:\custom_location" + + +@pytest.fixture(scope="module") +def install(inst_dir): + pytest.helpers.clean_env(inst_dir) + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", f"/install-dir={inst_dir}", "/master=cli_master"] + ) + yield + pytest.helpers.clean_env(inst_dir) + + +def test_binaries_present(install, inst_dir): + assert os.path.exists(rf"{inst_dir}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config with only master set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "#id:\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default_master_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default_master_minion.py new file mode 100644 index 000000000000..a2996764dd65 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default_master_minion.py @@ -0,0 +1,51 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def inst_dir(): + return r"C:\custom_location" + + +@pytest.fixture(scope="module") +def install(inst_dir): + pytest.helpers.clean_env(inst_dir) + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + f"/install-dir={inst_dir}", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env(inst_dir) + + +def test_binaries_present(install, inst_dir): + assert os.path.exists(rf"{inst_dir}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config with master and minion set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default_minion.py new file mode 100644 index 000000000000..6f8f9dc85905 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_default_minion.py @@ -0,0 +1,45 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def inst_dir(): + return r"C:\custom_location" + + +@pytest.fixture(scope="module") +def install(inst_dir): + pytest.helpers.clean_env(inst_dir) + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", f"/install-dir={inst_dir}", "/minion-name=cli_minion"] + ) + yield {"inst_dir": inst_dir} + pytest.helpers.clean_env(inst_dir) + + +def test_binaries_present(install, inst_dir): + assert os.path.exists(rf"{inst_dir}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config with just the minion set + expected = [ + "# Default config from test suite line 1/6\n", + "#master: salt\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_existing.py b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_existing.py new file mode 100644 index 000000000000..f28a61de6929 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_existing.py @@ -0,0 +1,38 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def inst_dir(): + return r"C:\custom_location" + + +@pytest.fixture(scope="module") +def install(inst_dir): + pytest.helpers.clean_env(inst_dir) + + # Create an existing config + pytest.helpers.existing_config() + + pytest.helpers.run_command([pytest.INST_BIN, "/S", f"/install-dir={inst_dir}"]) + yield + pytest.helpers.clean_env(inst_dir) + + +def test_binaries_present(install, inst_dir): + assert os.path.exists(rf"{inst_dir}\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the existing config, unchanged + expected = pytest.EXISTING_CONTENT + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_move_old_install.py b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_move_old_install.py new file mode 100644 index 000000000000..a556a2c3a98a --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_install_dir_move_old_install.py @@ -0,0 +1,43 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def inst_dir(): + return r"C:\custom_location" + + +@pytest.fixture(scope="module") +def install(inst_dir): + pytest.helpers.clean_env() + + # Create old install + pytest.helpers.old_install() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", f"/install-dir={inst_dir}", "/move-config"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present_old_location(install): + # Apparently we don't move the binaries even if they pass install-dir + # TODO: Decide if this is expected behavior + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the existing config in the new location, unchanged + expected = pytest.OLD_CONTENT + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install.py new file mode 100644 index 000000000000..f4ac2f8204fa --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install.py @@ -0,0 +1,37 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + pytest.helpers.run_command([pytest.INST_BIN, "/S"]) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the old existing config, unchanged + expected = pytest.OLD_CONTENT + + with open(rf"{pytest.OLD_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom.py new file mode 100644 index 000000000000..4e3dfdf3f78b --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom.py @@ -0,0 +1,41 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command([pytest.INST_BIN, "/S", "/custom-config=custom_conf"]) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config, unchanged + with open(rf"{pytest.REPO_DIR}\custom_conf") as f: + expected = f.readlines() + + with open(rf"{pytest.OLD_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom_master.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom_master.py new file mode 100644 index 000000000000..441221e9841a --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom_master.py @@ -0,0 +1,51 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/custom-config=custom_conf", "/master=cli_master"] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only master set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: custom_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.OLD_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom_master_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom_master_minion.py new file mode 100644 index 000000000000..0eb22436351d --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom_master_minion.py @@ -0,0 +1,57 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/custom-config=custom_conf", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with master and minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.OLD_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom_minion.py new file mode 100644 index 000000000000..0f265fd4fbea --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_custom_minion.py @@ -0,0 +1,51 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/custom-config=custom_conf", "/minion-name=cli_minion"] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: custom_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.OLD_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default.py new file mode 100644 index 000000000000..d3aed4f5fb1d --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default.py @@ -0,0 +1,38 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + pytest.helpers.run_command([pytest.INST_BIN, "/S", "/default-config"]) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config, unchanged + with open(rf"{pytest.REPO_DIR}\_files\minion") as f: + expected = f.readlines() + + with open(rf"{pytest.OLD_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default_master.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default_master.py new file mode 100644 index 000000000000..e0546759046d --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default_master.py @@ -0,0 +1,48 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/default-config", "/master=cli_master"] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config with only master set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "#id:\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.OLD_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default_master_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default_master_minion.py new file mode 100644 index 000000000000..c4f418a4a196 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default_master_minion.py @@ -0,0 +1,54 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/default-config", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config with master and minion set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.OLD_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default_minion.py new file mode 100644 index 000000000000..563b8125b48e --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_default_minion.py @@ -0,0 +1,48 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/default-config", "/minion-name=cli_minion"] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default with only minion set + expected = [ + "# Default config from test suite line 1/6\n", + "#master: salt\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.OLD_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move.py new file mode 100644 index 000000000000..d5328d82b3e2 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move.py @@ -0,0 +1,37 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + pytest.helpers.run_command([pytest.INST_BIN, "/S", "/move-config"]) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the old existing config in the new location, unchanged + expected = pytest.OLD_CONTENT + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom.py new file mode 100644 index 000000000000..eadd2fd10fa5 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom.py @@ -0,0 +1,43 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/custom-config=custom_conf", "/move-config"] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config in the new location, unchanged + with open(rf"{pytest.REPO_DIR}\custom_conf") as f: + expected = f.readlines() + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom_master.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom_master.py new file mode 100644 index 000000000000..5d0aa67d52a4 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom_master.py @@ -0,0 +1,57 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/custom-config=custom_conf", + "/move-config", + "/master=cli_master", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config in the new location with only master set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: custom_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom_master_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom_master_minion.py new file mode 100644 index 000000000000..da3e2916eb67 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom_master_minion.py @@ -0,0 +1,58 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/custom-config=custom_conf", + "/move-config", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config in the new location with master and minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom_minion.py new file mode 100644 index 000000000000..621c840ccd04 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_custom_minion.py @@ -0,0 +1,57 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/custom-config=custom_conf", + "/move-config", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the custom config in the new location with only minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: custom_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default.py new file mode 100644 index 000000000000..216a0b40c501 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default.py @@ -0,0 +1,40 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/move-config", "/default-config"] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config in the new location, unchanged + with open(rf"{pytest.REPO_DIR}\_files\minion") as f: + expected = f.readlines() + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default_master.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default_master.py new file mode 100644 index 000000000000..1d2d2a158c50 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default_master.py @@ -0,0 +1,48 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/S", "/default-config", "/move-config", "/master=cli_master"] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config in the new location with only master set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "#id:\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default_master_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default_master_minion.py new file mode 100644 index 000000000000..a46e1e5243dd --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default_master_minion.py @@ -0,0 +1,55 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/default-config", + "/move-config", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config in the new location with master and minion set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default_minion.py b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default_minion.py new file mode 100644 index 000000000000..2fdada9f21fc --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/config_tests/test_old_install_move_default_minion.py @@ -0,0 +1,54 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create old config + pytest.helpers.old_install() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/S", + "/default-config", + "/move-config", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_ssm_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\ssm.exe") + + +def test_binaries_present_old_location(install): + assert os.path.exists(rf"{pytest.OLD_DIR}\bin\python.exe") + + +def test_config_present_old_location(install): + assert os.path.exists(rf"{pytest.DATA_DIR}\conf\minion") + + +def test_config_correct(install): + # The config file should be the default config in the new location with only minion set + expected = [ + "# Default config from test suite line 1/6\n", + "#master: salt\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(rf"{pytest.DATA_DIR}\conf\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/conftest.py b/tests/pytests/pkg/installer/nsis/conftest.py new file mode 100644 index 000000000000..c71a6a7c62e3 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/conftest.py @@ -0,0 +1,183 @@ +import os +import shutil +import subprocess +import time +import winreg + +import psutil +import pytest + +pytest_plugins = ["helpers_namespace"] + +# \n characters are converted to os.linesep +existing_content = [ + "# Existing config from test suite line 1/6\n", + "master: existing_master\n", + "# Existing config from test suite line 2/6\n", + "id: existing_minion\n", + "# Existing config from test suite line 3/6\n", + "# Existing config from test suite line 4/6\n", + "# Existing config from test suite line 5/6\n", + "# Existing config from test suite line 6/6\n", +] + +# \n characters are converted to os.linesep +custom_content = [ + "# Custom config from test suite line 1/6\n", + "master: custom_master\n", + "# Custom config from test suite line 2/6\n", + "id: custom_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", +] + +# \n characters are converted to os.linesep +old_content = [ + "# Old config from test suite line 1/6\n", + "master: old_master\n", + "# Old config from test suite line 2/6\n", + "id: old_minion\n", + "# Old config from test suite line 3/6\n", + "# Old config from test suite line 4/6\n", + "# Old config from test suite line 5/6\n", + "# Old config from test suite line 6/6\n", +] + +INST_DIR = r"C:\Program Files\Salt Project\Salt" +DATA_DIR = r"C:\ProgramData\Salt Project\Salt" +SYSTEM_DRIVE = os.environ.get("SystemDrive") +OLD_DIR = f"{SYSTEM_DRIVE}\\salt" + + +def reg_key_exists(hive=winreg.HKEY_LOCAL_MACHINE, key=None): + try: + with winreg.OpenKey(hive, key, 0, winreg.KEY_READ): + exists = True + except: + exists = False + + return exists + + +def delete_key(hive=winreg.HKEY_LOCAL_MACHINE, key=None): + if reg_key_exists(hive=hive, key=key): + parent, _, base = key.rpartition("\\") + with winreg.OpenKey(hive, parent, 0, winreg.KEY_ALL_ACCESS) as reg: + winreg.DeleteKey(reg, base) + + +def pytest_configure(): + pytest.DATA_DIR = DATA_DIR + pytest.INST_DIR = INST_DIR + pytest.REPO_DIR = REPO_DIR + pytest.INST_BIN = INST_BIN + pytest.OLD_DIR = OLD_DIR + pytest.EXISTING_CONTENT = existing_content + pytest.CUSTOM_CONTENT = custom_content + pytest.OLD_CONTENT = old_content + + +@pytest.helpers.register +def clean_env(inst_dir=INST_DIR): + # Run uninstaller + for uninst_bin in [f"{inst_dir}\\uninst.exe", f"{OLD_DIR}\\uninst.exe"]: + if os.path.exists(uninst_bin): + run_command([uninst_bin, "/S", "/delete-root-dir", "/delete-install-dir"]) + # This is needed to avoid a race condition where the uninstall is completing + start_time = time.time() + while "Un_A.exe" in (p.name() for p in psutil.process_iter()): + # Sometimes the Uninstall binary hangs... we'll kill it after 10 seconds + if (time.time() - start_time) > 10: + for proc in psutil.process_iter(): + if proc.name() == "Un_A.exe": + proc.kill() + time.sleep(0.1) + + # This is needed to avoid a race condition where the installer isn't closed + start_time = time.time() + while os.path.basename(INST_BIN) in (p.name() for p in psutil.process_iter()): + if (time.time() - start_time) > 10: + # If it's not dead after 10 seconds, kill it + for proc in psutil.process_iter(): + if proc.name() == os.path.basename(INST_BIN): + proc.kill() + time.sleep(0.1) + + # Remove root_dir + if os.path.exists(DATA_DIR): + shutil.rmtree(DATA_DIR) + # Remove install dir + if os.path.exists(inst_dir): + shutil.rmtree(inst_dir) + # Remove old salt dir (C:\salt) + if os.path.exists(OLD_DIR): + shutil.rmtree(OLD_DIR) + # Remove custom config + if os.path.exists(rf"{REPO_DIR}\custom_conf"): + os.remove(rf"{REPO_DIR}\custom_conf") + # Remove registry entries + delete_key(key="SOFTWARE\\Salt Project\\Salt") + delete_key(key="SOFTWARE\\Salt Project") + + +@pytest.helpers.register +def existing_config(): + # Create an existing config + if not os.path.exists(f"{DATA_DIR}\\conf"): + os.makedirs(f"{DATA_DIR}\\conf") + with open(f"{DATA_DIR}\\conf\\minion", "w") as f: + # \n characters are converted to os.linesep + f.writelines(existing_content) + + +@pytest.helpers.register +def custom_config(): + if os.path.exists(rf"{REPO_DIR}\custom_conf"): + os.remove(rf"{REPO_DIR}\custom_conf") + # Create a custom config + with open(rf"{REPO_DIR}\custom_conf", "w") as f: + # \n characters are converted to os.linesep + f.writelines(custom_content) + + +@pytest.helpers.register +def old_install(): + # Create old binaries, don't have to be valid exe's + if not os.path.exists(f"{OLD_DIR}\\bin"): + os.makedirs(f"{OLD_DIR}\\bin") + with open(f"{OLD_DIR}\\bin\\python.exe", "w") as f: + f.write("binary data") + with open(f"{OLD_DIR}\\bin\\ssm.exe", "w") as f: + f.write("binary data") + + # Create an old config + if not os.path.exists(f"{OLD_DIR}\\conf"): + os.makedirs(f"{OLD_DIR}\\conf") + with open(f"{OLD_DIR}\\conf\\minion", "w") as f: + # \n characters are converted to os.linesep + f.writelines(old_content) + while not (os.path.exists(f"{OLD_DIR}\\bin\\python.exe")): + time.sleep(0.1) + while not (os.path.exists(f"{OLD_DIR}\\bin\\ssm.exe")): + time.sleep(0.1) + while not (os.path.exists(f"{OLD_DIR}\\conf\\minion")): + time.sleep(0.1) + assert os.path.exists(f"{OLD_DIR}\\bin\\python.exe") + assert os.path.exists(f"{OLD_DIR}\\bin\\ssm.exe") + assert os.path.exists(f"{OLD_DIR}\\conf\\minion") + + +@pytest.helpers.register +def run_command(cmd): + result = subprocess.run(cmd, capture_output=True, text=True) + return result.stdout.strip().replace("/", "\\") + + +# These are at the bottom because they depend on some of the functions +REPO_DIR = run_command(["git", "rev-parse", "--show-toplevel"]) +REPO_DIR = rf"{REPO_DIR}\tests\pytests\pkg\installer\nsis" +os.chdir(REPO_DIR) +INST_BIN = rf"{REPO_DIR}\test-setup.exe" + diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_full_path.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_full_path.py new file mode 100644 index 000000000000..6c543c1ccf9a --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_full_path.py @@ -0,0 +1,36 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create a custom config + pytest.helpers.custom_config() + + full_path_conf = f"{pytest.REPO_DIR}\\custom_conf" + + pytest.helpers.run_command([pytest.INST_BIN, f"/custom-config={full_path_conf}"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the default, unchanged + with open(f"{pytest.REPO_DIR}\\custom_conf") as f: + expected = f.readlines() + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_master.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_master.py new file mode 100644 index 000000000000..e95df53ff114 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_master.py @@ -0,0 +1,44 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/custom-config=custom_conf", "/master=cli_master"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only master set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: custom_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_master_minion.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_master_minion.py new file mode 100644 index 000000000000..b6fbc71d7784 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_master_minion.py @@ -0,0 +1,49 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/custom-config=custom_conf", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the custom config with master and minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_minion.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_minion.py new file mode 100644 index 000000000000..c90bfb159cfe --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_minion.py @@ -0,0 +1,44 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/custom-config=custom_conf", "/minion-name=cli_minion"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only master set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: custom_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_rel_path.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_rel_path.py new file mode 100644 index 000000000000..61458486a430 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_custom_rel_path.py @@ -0,0 +1,34 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command([pytest.INST_BIN, "/custom-config=custom_conf"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the default, unchanged + with open(f"{pytest.REPO_DIR}\\custom_conf") as f: + expected = f.readlines() + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default.py new file mode 100644 index 000000000000..3ad8cbde51f8 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default.py @@ -0,0 +1,30 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + pytest.helpers.run_command([pytest.INST_BIN]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the default, unchanged + with open(f"{pytest.REPO_DIR}\\tests\\_files\\minion") as f: + expected = f.readlines() + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default_master.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default_master.py new file mode 100644 index 000000000000..1b819c7db7dc --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default_master.py @@ -0,0 +1,38 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + pytest.helpers.run_command([pytest.INST_BIN, "/master=cli_master"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\bsm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the default with only master set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "#id:\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default_master_minion.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default_master_minion.py new file mode 100644 index 000000000000..101238d46238 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default_master_minion.py @@ -0,0 +1,40 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + pytest.helpers.run_command( + [pytest.INST_BIN, "/master=cli_master", "/minion-name=cli_minion"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the default with master and minion set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default_minion.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default_minion.py new file mode 100644 index 000000000000..538b63289689 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_default_minion.py @@ -0,0 +1,38 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + pytest.helpers.run_command([pytest.INST_BIN, "/minion-name=cli_minion"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the default with only master set + expected = [ + "# Default config from test suite line 1/6\n", + "#master: salt\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing.py new file mode 100644 index 000000000000..926637081c0e --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing.py @@ -0,0 +1,33 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + pytest.helpers.run_command([pytest.INST_BIN]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the existing config, unchanged + expected = pytest.EXISTING_CONTENT + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom.py new file mode 100644 index 000000000000..6d164e98a9c5 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom.py @@ -0,0 +1,37 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command([pytest.INST_BIN, "/custom-config=custom_conf"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the default, unchanged + with open(f"{pytest.REPO_DIR}\\custom_conf") as f: + expected = f.readlines() + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom_master.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom_master.py new file mode 100644 index 000000000000..26d182ca95bf --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom_master.py @@ -0,0 +1,47 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/custom-config=custom_conf", "/master=cli_master"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only master set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: custom_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom_master_minion.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom_master_minion.py new file mode 100644 index 000000000000..2c8ac4aafee4 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom_master_minion.py @@ -0,0 +1,52 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/custom-config=custom_conf", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the custom config with master and minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: cli_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom_minion.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom_minion.py new file mode 100644 index 000000000000..092857b39b97 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_custom_minion.py @@ -0,0 +1,46 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + # Create an existing config + pytest.helpers.existing_config() + + # Create a custom config + pytest.helpers.custom_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/custom-config=custom_conf", "/minion-name=cli_minion"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the custom config with only minion set + expected = [ + "# Custom config from test suite line 1/6\n", + "master: custom_master\n", + "# Custom config from test suite line 2/6\n", + "id: cli_minion\n", + "# Custom config from test suite line 3/6\n", + "# Custom config from test suite line 4/6\n", + "# Custom config from test suite line 5/6\n", + "# Custom config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_default.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_default.py new file mode 100644 index 000000000000..1007fcb97d4e --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_default.py @@ -0,0 +1,34 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + pytest.helpers.run_command([pytest.INST_BIN, "/default-config"]) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the default, unchanged + with open(f"{pytest.REPO_DIR}\\tests\\_files\\minion") as f: + expected = f.readlines() + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_default_master.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_default_master.py new file mode 100644 index 000000000000..81d66801cb5e --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_default_master.py @@ -0,0 +1,44 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/default-config", "/master=cli_master"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the default with only master set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "#id:\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_default_minion.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_default_minion.py new file mode 100644 index 000000000000..09db2177d5f5 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manual_existing_default_minion.py @@ -0,0 +1,44 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + pytest.helpers.run_command( + [pytest.INST_BIN, "/default-config", "/minion-name=cli_minion"] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the default with just the minion set + expected = [ + "# Default config from test suite line 1/6\n", + "#master: salt\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/manual_tests/test_manulal_existing_default_master_minion.py b/tests/pytests/pkg/installer/nsis/manual_tests/test_manulal_existing_default_master_minion.py new file mode 100644 index 000000000000..65c7dc8b0dfb --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/manual_tests/test_manulal_existing_default_master_minion.py @@ -0,0 +1,49 @@ +import os + +import pytest + + +@pytest.fixture(scope="module") +def install(): + pytest.helpers.clean_env() + + # Create an existing config + pytest.helpers.existing_config() + + pytest.helpers.run_command( + [ + pytest.INST_BIN, + "/default-config", + "/master=cli_master", + "/minion-name=cli_minion", + ] + ) + yield + pytest.helpers.clean_env() + + +def test_binaries_present(install): + assert os.path.exists(f"{pytest.INST_DIR}\\ssm.exe") + + +def test_config_present(install): + assert os.path.exists(f"{pytest.DATA_DIR}\\conf\\minion") + + +def test_config_correct(install): + # The config file should be the default with master and minion set + expected = [ + "# Default config from test suite line 1/6\n", + "master: cli_master\n", + "# Default config from test suite line 2/6\n", + "id: cli_minion\n", + "# Default config from test suite line 3/6\n", + "# Default config from test suite line 4/6\n", + "# Default config from test suite line 5/6\n", + "# Default config from test suite line 6/6\n", + ] + + with open(f"{pytest.DATA_DIR}\\conf\\minion") as f: + result = f.readlines() + + assert result == expected diff --git a/tests/pytests/pkg/installer/nsis/setup.cmd b/tests/pytests/pkg/installer/nsis/setup.cmd new file mode 100644 index 000000000000..b859326c4196 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/setup.cmd @@ -0,0 +1,3 @@ +@ echo off +Set "CurDir=%~dp0" +PowerShell -ExecutionPolicy RemoteSigned -File "%CurDir%\setup.ps1" %* diff --git a/tests/pytests/pkg/installer/nsis/setup.ps1 b/tests/pytests/pkg/installer/nsis/setup.ps1 new file mode 100644 index 000000000000..a167e7846844 --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/setup.ps1 @@ -0,0 +1,169 @@ +<# +.SYNOPSIS +Script that sets up the environment for testing + +.DESCRIPTION +This script creates the directory structure and files needed build a mock salt +installer for testing + +.EXAMPLE +setup.ps1 +#> + +#------------------------------------------------------------------------------- +# Script Preferences +#------------------------------------------------------------------------------- + +$ProgressPreference = "SilentlyContinue" +$ErrorActionPreference = "Stop" + +#------------------------------------------------------------------------------- +# Script Functions +#------------------------------------------------------------------------------- + +function Write-Result($result, $ForegroundColor="Green") { + $position = 80 - $result.Length - [System.Console]::CursorLeft + Write-Host -ForegroundColor $ForegroundColor ("{0,$position}$result" -f "") +} + +#------------------------------------------------------------------------------- +# Script Variables +#------------------------------------------------------------------------------- + +$PROJECT_DIR = $(git rev-parse --show-toplevel) +$SCRIPT_DIR = (Get-ChildItem "$($myInvocation.MyCommand.Definition)").DirectoryName +$WINDOWS_DIR = "$PROJECT_DIR\pkg\windows" +$NSIS_DIR = "$WINDOWS_DIR\nsis" +$BUILDENV_DIR = "$WINDOWS_DIR\buildenv" +$NSIS_BIN = "$( ${env:ProgramFiles(x86)} )\NSIS\makensis.exe" + +#------------------------------------------------------------------------------- +# Script Start +#------------------------------------------------------------------------------- + +Write-Host $("=" * 80) +Write-Host "Build Test Environment for NSIS Tests" -ForegroundColor Cyan +Write-Host $("-" * 80) + +#------------------------------------------------------------------------------- +# Setup Directories +#------------------------------------------------------------------------------- + +$directories = "$BUILDENV_DIR", + "$BUILDENV_DIR\configs" +$directories | ForEach-Object { + if ( ! (Test-Path -Path "$_") ) { + Write-Host "Creating $_`: " -NoNewline + New-Item -Path $_ -ItemType Directory | Out-Null + if ( Test-Path -Path "$_" ) { + Write-Result "Success" + } else { + Write-Result "Failed" -ForegroundColor Red + exit 1 + } + } +} + +#------------------------------------------------------------------------------- +# Create binaries +#------------------------------------------------------------------------------- + +$binary_files = "ssm.exe", + "python.exe" +$binary_files | ForEach-Object { + Write-Host "Creating $_`: " -NoNewline + Set-Content -Path "$BUILDENV_DIR\$_" -Value "binary" + if ( Test-Path -Path "$BUILDENV_DIR\$_" ) { + Write-Result "Success" + } else { + Write-Result "Failed" -ForegroundColor Red + exit 1 + } +} + +#------------------------------------------------------------------------------- +# Copy Configs +#------------------------------------------------------------------------------- + +Write-Host "Copy minion config: " -NoNewline +Copy-Item -Path "$NSIS_DIR\tests\_files\minion" ` + -Destination "$BUILDENV_DIR\configs\" +if ( Test-Path -Path "$BUILDENV_DIR\configs\minion" ) { + Write-Result "Success" +} else { + Write-Result "Failed" -ForegroundColor Red + exit 1 +} + +#------------------------------------------------------------------------------- +# Build mock installer +#------------------------------------------------------------------------------- +Write-Host "Building mock installer: " -NoNewline +Start-Process -FilePath $NSIS_BIN ` + -ArgumentList "/DSaltVersion=test", ` + "/DPythonArchitecture=AMD64", ` + "$NSIS_DIR\installer\Salt-Minion-Setup.nsi" ` + -Wait -WindowStyle Hidden +$installer = "$NSIS_DIR\installer\Salt-Minion-test-Py3-AMD64-Setup.exe" +if ( Test-Path -Path "$installer" ) { + Write-Result "Success" +} else { + Write-Result "Failed" -ForegroundColor Red + exit 1 +} + +Write-Host "Moving mock installer: " -NoNewline +$test_installer = "$SCRIPT_DIR\test-setup.exe" +Move-Item -Path $installer -Destination "$test_installer" -Force +if ( Test-Path -Path "$test_installer" ) { + Write-Result "Success" +} else { + Write-Result "Failed" -ForegroundColor Red + exit 1 +} + +#------------------------------------------------------------------------------- +# Setup pytest +#------------------------------------------------------------------------------- + +#Write-Host "Setting up venv: " -NoNewline +#python.exe -m venv venv +#if ( Test-Path -Path "$SCRIPT_DIR\venv" ) { +# Write-Result "Success" +#} else { +# Write-Result "Failed" -ForegroundColor Red +# exit 1 +#} +# +#Write-Host "Activating venv: " -NoNewline +#.\venv\Scripts\activate +#if ( "$env:VIRTUAL_ENV" ) { +# Write-Result "Success" +#} else { +# Write-Result "Failed" -ForegroundColor Red +# exit 1 +#} +# +#$pip_modules = "pytest", +# "pytest-helpers-namespace", +# "psutil" +#$pip_modules | ForEach-Object { +# Write-Host "Installing $_`: " -NoNewline +# Start-Process -FilePath pip ` +# -ArgumentList "install", "$_" ` +# -Wait -WindowStyle Hidden +# if ($( pip show $_ ) -contains "Name: $_") { +# Write-Result "Success" +# } else { +# Write-Result "Failed" -ForegroundColor Red +# exit 1 +# } +#} + +#------------------------------------------------------------------------------- +# Script Complete +#------------------------------------------------------------------------------- + +Write-Host $("-" * 80) +Write-Host "Build Test Environment for NSIS Tests Complete" -ForegroundColor Cyan +Write-Host $("=" * 80) diff --git a/tests/pytests/pkg/installer/nsis/test-setup.exe b/tests/pytests/pkg/installer/nsis/test-setup.exe new file mode 100644 index 000000000000..deb900f530f3 Binary files /dev/null and b/tests/pytests/pkg/installer/nsis/test-setup.exe differ diff --git a/tests/pytests/pkg/installer/nsis/test.cmd b/tests/pytests/pkg/installer/nsis/test.cmd new file mode 100644 index 000000000000..f7772094099f --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/test.cmd @@ -0,0 +1,3 @@ +@ echo off +Set "CurDir=%~dp0" +PowerShell -ExecutionPolicy RemoteSigned -File "%CurDir%\test.ps1" %* diff --git a/tests/pytests/pkg/installer/nsis/test.ps1 b/tests/pytests/pkg/installer/nsis/test.ps1 new file mode 100644 index 000000000000..015c8b8c60ee --- /dev/null +++ b/tests/pytests/pkg/installer/nsis/test.ps1 @@ -0,0 +1,59 @@ +<# +.SYNOPSIS +Script to run the tests + +.DESCRIPTION +This script activates the venv and launches pytest + +.EXAMPLE +test.ps1 +#> + +#------------------------------------------------------------------------------- +# Script Preferences +#------------------------------------------------------------------------------- + +$ProgressPreference = "SilentlyContinue" +$ErrorActionPreference = "Stop" + +#------------------------------------------------------------------------------- +# Script Functions +#------------------------------------------------------------------------------- + +function Write-Result($result, $ForegroundColor="Green") { + $position = 80 - $result.Length - [System.Console]::CursorLeft + Write-Host -ForegroundColor $ForegroundColor ("{0,$position}$result" -f "") +} + +#------------------------------------------------------------------------------- +# Script Start +#------------------------------------------------------------------------------- + +Write-Host $("=" * 80) +Write-Host "Run Tests" -ForegroundColor Cyan +Write-Host $("-" * 80) + +#------------------------------------------------------------------------------- +# Activating venv +#------------------------------------------------------------------------------- + +Write-Host "Activating venv: " -NoNewline +.\venv\Scripts\activate +if ( "$env:VIRTUAL_ENV" ) { + Write-Result "Success" +} else { + Write-Result "Failed" -ForegroundColor Red + exit 1 +} + +Write-Host "Running pytest..." +Write-Host "" +pytest -vvv -- .\config_tests\ + +#------------------------------------------------------------------------------- +# Script Complete +#------------------------------------------------------------------------------- + +Write-Host $("-" * 80) +Write-Host "Run Tests" -ForegroundColor Cyan +Write-Host $("=" * 80)