Skip to content

Commit

Permalink
Update tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
twangboy committed Nov 4, 2024
1 parent 2233615 commit a0f3b56
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 176 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -482,7 +466,6 @@ jobs:
- generate-actions-workflow
- macos-12
- macos-13
- windows-2019
- windows-2022
- almalinux-8
- almalinux-9
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/templates/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"ubuntu-2404",
]
WINDOWS = [
"windows-2019",
"windows-2022",
]

Expand Down Expand Up @@ -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",
}

Expand Down
61 changes: 6 additions & 55 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/[email protected]
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()
Expand Down
42 changes: 0 additions & 42 deletions kitchen.windows.yml

This file was deleted.

36 changes: 1 addition & 35 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
]
)
Expand Down
46 changes: 26 additions & 20 deletions tests/integration/test_installation.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 1 addition & 5 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
pytest-testinfra
paramiko
requests-ntlm==1.1.0; sys.platform == 'win32'
pywinrm; sys.platform == 'win32'
six>=1.10.0
pytest

0 comments on commit a0f3b56

Please sign in to comment.