From a0f3b563860b624da1da4ca293a09a981a799e6d Mon Sep 17 00:00:00 2001 From: twangboy Date: Mon, 4 Nov 2024 13:18:55 -0700 Subject: [PATCH] Update tests on Windows --- .github/workflows/ci.yml | 17 ------- .github/workflows/templates/generate.py | 2 - .github/workflows/test-windows.yml | 61 +++---------------------- kitchen.windows.yml | 42 ----------------- tests/conftest.py | 36 +-------------- tests/integration/test_installation.py | 46 +++++++++++-------- tests/requirements.txt | 6 +-- 7 files changed, 34 insertions(+), 176 deletions(-) delete mode 100644 kitchen.windows.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c13c6fffe..fe021a312 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,22 +146,6 @@ jobs: instances: '["stable-3006", "stable-3006-8", "stable-3007", "stable-3007-1", "latest"]' - - windows-2019: - name: Windows 2019 - if: github.event_name == 'push' || needs.collect-changed-files.outputs.run-tests == 'true' - uses: ./.github/workflows/test-windows.yml - needs: - - lint - - generate-actions-workflow - with: - distro-slug: windows-2019 - display-name: Windows 2019 - timeout: 20 - runs-on: windows-2019 - instances: '["stable-3006", "stable-3006-8", "stable-3007", "stable-3007-1", "latest"]' - - windows-2022: name: Windows 2022 if: github.event_name == 'push' || needs.collect-changed-files.outputs.run-tests == 'true' @@ -482,7 +466,6 @@ jobs: - generate-actions-workflow - macos-12 - macos-13 - - windows-2019 - windows-2022 - almalinux-8 - almalinux-9 diff --git a/.github/workflows/templates/generate.py b/.github/workflows/templates/generate.py index 0fb618158..f285da8c4 100755 --- a/.github/workflows/templates/generate.py +++ b/.github/workflows/templates/generate.py @@ -32,7 +32,6 @@ "ubuntu-2404", ] WINDOWS = [ - "windows-2019", "windows-2022", ] @@ -265,7 +264,6 @@ "ubuntu-2404": "Ubuntu 24.04", "macos-12": "macOS 12", "macos-13": "macOS 13", - "windows-2019": "Windows 2019", "windows-2022": "Windows 2022", } diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index 25d300ce8..4e96d5dca 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -28,16 +28,10 @@ on: default: 20 description: The timeout(in minutes) for the workflow -env: - machine_user: kitchen - machine_pass: Password1 - machine_port: 5985 - KITCHEN_LOCAL_YAML: 'kitchen.windows.yml' - jobs: Test: name: ${{ matrix.instance }} - runs-on: ${{ inputs.runs-on }} + runs-on: windows-latest timeout-minutes: ${{ inputs.timeout }} strategy: fail-fast: false @@ -47,65 +41,22 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.6.10 - ## ruby-version: 3.3.4 - bundler-cache: true - - - name: Install Chef - uses: actionshub/chef-install@1.1.0 - with: - project: chef - version: 16.10.8 - - - name: Add Chef bindir to PATH - uses: myci-actions/export-env-var-powershell@1 - with: - name: PATH - value: "C:\\opscode\\chef\\bin;C:\\opscode\\chef\\embedded\\bin;$env:PATH" - - - name: Setup test user - run: | - $password = ConvertTo-SecureString $env:machine_pass -AsPlainText -Force - New-LocalUser $env:machine_user -Password $password - Add-LocalGroupMember -Group "Administrators" -Member $env:machine_user - Get-LocalUser - Get-LocalGroupMember -Group "Administrators" - - - name: Set up WinRM - run: | - Set-WSManQuickConfig -Force - winrm set winrm/config/service '@{AllowUnencrypted="True"}' - env - - name: Set up Python 3.10 uses: actions/setup-python@v5 with: python-version: "3.10" - - name: Install Python Dependencies + - name: Install Pytest run: | - pip install -U pip - pip install -r tests/requirements.txt + pip install -U pytest - - name: Create Test Instance + - name: Bootstrap Salt run: | - bundle exec kitchen create ${{ matrix.instance }}-${{ inputs.distro-slug }} - sleep 2 + . .\bootstrap-salt.ps1 - name: Test Bootstrap run: | - env - bundle exec kitchen verify ${{ matrix.instance }}-${{ inputs.distro-slug }} - sleep 2 - - - name: Destroy Test Instance - if: always() - run: | - bundle exec kitchen destroy ${{ matrix.instance }}-${{ inputs.distro-slug }} - sleep 2 + pytest --cache-clear -v -s -ra --log-cli-level=debug tests/integration/ - name: Set Exit Status if: always() diff --git a/kitchen.windows.yml b/kitchen.windows.yml deleted file mode 100644 index a2b88e2e3..000000000 --- a/kitchen.windows.yml +++ /dev/null @@ -1,42 +0,0 @@ ---- -driver: - name: proxy - host: localhost - reset_command: "exit 0" - port: 5985 - username: kitchen - password: Password1 - -provisioner: - salt_bootstrap_url: D:/a/salt-bootstrap/salt-bootstrap/bootstrap-salt.ps1 - salt_bootstrap_options: -Version %s -Verbose - init_environment: '' - -platforms: - - name: windows-2022 - - name: windows-2019 - -suites: - - name: stable-3006 - provisioner: - salt_version: 3006 - salt_call_command: c:\Program Files\Salt Project\Salt\salt-call.exe - - name: stable-3006-8 - provisioner: - salt_version: 3006.8 - salt_call_command: c:\Program Files\Salt Project\Salt\salt-call.exe - - name: stable-3007 - provisioner: - salt_version: 3007 - salt_call_command: c:\Program Files\Salt Project\Salt\salt-call.exe - - name: stable-3007-1 - provisioner: - salt_version: 3007.1 - salt_call_command: c:\Program Files\Salt Project\Salt\salt-call.exe - - name: latest - provisioner: - salt_version: latest - salt_call_command: c:\Program Files\Salt Project\Salt\salt-call.exe - -verifier: - command: pytest --cache-clear -v -s -ra --log-cli-level=debug -k "not test_ping" tests/integration/ diff --git a/tests/conftest.py b/tests/conftest.py index 864307c03..74ded3b2d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,45 +1,11 @@ import logging import os -import pprint import pytest -import testinfra log = logging.getLogger(__name__) -@pytest.fixture(scope="session") -def host(): - if ( - os.environ.get("RUNNER_OS", "") == "macOS" - and os.environ.get("KITCHEN_LOCAL_YAML", "") == "kitchen.macos.yml" - ): - # Adjust the `PATH` so that the `salt-call` executable can be found - os.environ["PATH"] = "/opt/salt/bin{}{}".format(os.pathsep, os.environ["PATH"]) - return testinfra.get_host("local://", sudo=True) - - if os.environ.get("KITCHEN_USERNAME") == "vagrant" or "windows" in os.environ.get( - "KITCHEN_INSTANCE" - ): - if "windows" in os.environ.get("KITCHEN_INSTANCE"): - _url = "winrm://{KITCHEN_USERNAME}:{KITCHEN_PASSWORD}@{KITCHEN_HOSTNAME}:{KITCHEN_PORT}".format( - **os.environ - ) - return testinfra.get_host( - _url, - no_ssl=True, - ) - return testinfra.get_host( - "paramiko://{KITCHEN_USERNAME}@{KITCHEN_HOSTNAME}:{KITCHEN_PORT}".format( - **os.environ - ), - ssh_identity_file=os.environ.get("KITCHEN_SSH_KEY"), - ) - return testinfra.get_host( - "docker://{KITCHEN_USERNAME}@{KITCHEN_CONTAINER_ID}".format(**os.environ) - ) - - @pytest.fixture(scope="session") def target_python_version(): return 3 @@ -53,7 +19,7 @@ def target_salt_version(): target_salt = ".".join( [ item - for item in os.environ["KITCHEN_SUITE"].split("-") + for item in os.environ.get("KITCHEN_SUITE", "").split("-") if item not in bootstrap_types ] ) diff --git a/tests/integration/test_installation.py b/tests/integration/test_installation.py index 9ee18d49c..e4a620090 100644 --- a/tests/integration/test_installation.py +++ b/tests/integration/test_installation.py @@ -1,31 +1,37 @@ import logging -import os -from contextlib import nullcontext +import subprocess +import json log = logging.getLogger(__name__) -def selected_context_manager(host): - if "windows" in os.environ.get("KITCHEN_INSTANCE"): - return nullcontext() - return host.sudo() +def run_salt_call(cmd): + """ + Runs salt call command and returns a dictionary + Accepts cmd as a list + """ + cmd.append("--out=json") + result = subprocess.run(cmd, capture_output=True, text=True) + json_data = json.loads(result.stdout) + return json_data["local"] -def test_ping(host): - with selected_context_manager(host): - assert host.salt("test.ping", "--timeout=120") +def test_ping(): + cmd = ["salt-call", "--local", "test.ping"] + result = run_salt_call(cmd) + assert result == True -def test_target_python_version(host, target_python_version): - with selected_context_manager(host): - ret = host.salt("grains.item", "pythonversion", "--timeout=120") - assert ret["pythonversion"][0] == target_python_version +def test_target_python_version(target_python_version): + cmd = ["salt-call", "--local", "grains.item", "pythonversion", "--timeout=120"] + result = run_salt_call(cmd) + # Returns: {'pythonversion': [3, 10, 11, 'final', 0]} + py_maj_ver = result["pythonversion"][0] + assert py_maj_ver == target_python_version -def test_target_salt_version(host, target_salt_version): - with selected_context_manager(host): - ret = host.salt("grains.item", "saltversion", "--timeout=120") - if target_salt_version.endswith(".0") or target_salt_version.endswith(".x"): - assert ret["saltversion"] == ".".join(target_salt_version.split(".")[:-1]) - else: - assert ret["saltversion"].startswith(target_salt_version) +def test_target_salt_version(target_salt_version): + cmd = ["salt-call", "--local", "grains.item", "saltversion", "--timeout=120"] + result = run_salt_call(cmd) + # Returns: {'saltversion': '3006.9+217.g53cfa53040'} + assert result["saltversion"] == target_salt_version diff --git a/tests/requirements.txt b/tests/requirements.txt index 21d133da8..55b033e90 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,5 +1 @@ -pytest-testinfra -paramiko -requests-ntlm==1.1.0; sys.platform == 'win32' -pywinrm; sys.platform == 'win32' -six>=1.10.0 +pytest \ No newline at end of file