Skip to content

Commit

Permalink
Initial Shell pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
dmurphy18 committed Nov 4, 2024
1 parent 0899e72 commit db97436
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 132 deletions.
40 changes: 26 additions & 14 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,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
## DGM - name: Setup Ruby
## DGM uses: ruby/setup-ruby@v1
## DGM with:
## DGM ruby-version: 2.6.10
## DGM ## ruby-version: 3.3.4
## DGM bundler-cache: true

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
## DGM - name: Set up Python 3.10
## DGM uses: actions/setup-python@v5
## DGM with:
## DGM python-version: "3.10"

- name: Install Python Dependencies
run: |
python3 -m pip install -U pip
python3 -m pip install -r tests/requirements.txt
## DGM - name: Install Python Dependencies
## DGM run: |
## DGM python3 -m pip install -U pip
## DGM python3 -m pip install -r tests/requirements.txt

## DGM - name: Create Test Instance
## DGM run: |
Expand All @@ -71,6 +71,18 @@ jobs:
## DGM bundle exec kitchen destroy ${{ matrix.instance }}-${{ inputs.distro-slug }}
## DGM sleep 2

- name: Install Pytest
run: |
pip install -U pytest
- name: Bootstrap Salt
run: |
. ./bootstrap.sh
- name: Test Bootstrap
run: |
pytest --cache-clear -v -s -ra --log-cli-level=debug tests/integration/
- name: Set Exit Status
if: always()
run: |
Expand Down
47 changes: 30 additions & 17 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ on:
default: 20
description: The timeout(in minutes) for the workflow

env:
KITCHEN_LOCAL_YAML: 'kitchen.macos.yml'
## DGM env:
## DGM KITCHEN_LOCAL_YAML: 'kitchen.macos.yml'

jobs:
Test:
name: ${{ matrix.instance }}
runs-on: ${{ inputs.runs-on }}
## DGM runs-on: ${{ inputs.runs-on }}
runs-on: macos-12
timeout-minutes: ${{ inputs.timeout }}
strategy:
fail-fast: false
Expand All @@ -44,22 +45,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
## DGM - name: Setup Ruby
## DGM uses: ruby/setup-ruby@v1
## DGM with:
## DGM ruby-version: 2.6.10
## DGM ## ruby-version: 3.3.4
## DGM bundler-cache: true

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
## DGM - name: Set up Python 3.10
## DGM uses: actions/setup-python@v5
## DGM with:
## DGM python-version: "3.10"

- name: Install Python Dependencies
run: |
pip install -U pip
pip install -r tests/requirements.txt
## DGM - name: Install Python Dependencies
## DGM run: |
## DGM pip install -U pip
## DGM pip install -r tests/requirements.txt

## DGM - name: Create Test Instance
## DGM run: |
Expand All @@ -78,6 +79,18 @@ jobs:
## DGM bundle exec kitchen destroy ${{ matrix.instance }}-${{ inputs.distro-slug }}
## DGM sleep 2

- name: Install Pytest
run: |
pip install -U pytest
- name: Bootstrap Salt
run: |
. ./bootstrap.sh
- name: Test Bootstrap
run: |
pytest --cache-clear -v -s -ra --log-cli-level=debug tests/integration/
- name: Set Exit Status
if: always()
run: |
Expand Down
100 changes: 60 additions & 40 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ 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'
## DGM env:
## DGM machine_user: kitchen
## DGM machine_pass: Password1
## DGM machine_port: 5985
## DGM KITCHEN_LOCAL_YAML: 'kitchen.windows.yml'

jobs:
Test:
name: ${{ matrix.instance }}
runs-on: ${{ inputs.runs-on }}
## DGM runs-on: ${{ inputs.runs-on }}
runs-on: windows-latest
timeout-minutes: ${{ inputs.timeout }}
strategy:
fail-fast: false
Expand All @@ -47,48 +48,50 @@ 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"
## DGM - name: Setup Ruby
## DGM uses: ruby/setup-ruby@v1
## DGM with:
## DGM ruby-version: 2.6.10
## DGM ## ruby-version: 3.3.4
## DGM bundler-cache: true

## DGM - name: Install Chef
## DGM uses: actionshub/[email protected]
## DGM with:
## DGM project: chef
## DGM version: 16.10.8

## DGM - name: Add Chef bindir to PATH
## DGM uses: myci-actions/export-env-var-powershell@1
## DGM with:
## DGM name: PATH
## DGM value: "C:\\opscode\\chef\\bin;C:\\opscode\\chef\\embedded\\bin;$env:PATH"

## DGM - name: Setup test user
## DGM run: |
## DGM $password = ConvertTo-SecureString $env:machine_pass -AsPlainText -Force
## DGM New-LocalUser $env:machine_user -Password $password
## DGM Add-LocalGroupMember -Group "Administrators" -Member $env:machine_user
## DGM Get-LocalUser
## DGM Get-LocalGroupMember -Group "Administrators"

- name: Set up WinRM
run: |
Set-WSManQuickConfig -Force
winrm set winrm/config/service '@{AllowUnencrypted="True"}'
env
## DGM - name: Set up WinRM
## DGM run: |
## DGM Set-WSManQuickConfig -Force
## DGM winrm set winrm/config/service '@{AllowUnencrypted="True"}'
## DGM env

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install Python Dependencies
## DGM - name: Install Python Dependencies
- name: Install Pytest
run: |
pip install -U pip
pip install -r tests/requirements.txt
## DGM pip install -U pip
## DGM pip install -r tests/requirements.txt
pip install -U pytest
## DGM - name: Create Test Instance
## DGM run: |
Expand All @@ -107,6 +110,23 @@ jobs:
## DGM bundle exec kitchen destroy ${{ matrix.instance }}-${{ inputs.distro-slug }}
## DGM sleep 2

- name: Bootstrap Salt
run: |
. ./bootstrap-salt.ps1 -RunService $false
- name: Set Environment Variables
run: |
$env:Path = "$env:Path;C:\Program Files\Salt Project\Salt"
$env:Instance = ${{ matrix.instance }}
Write-Output "Path:"
Write-Output $env:Path
Write-Output "Environment Variables"
Get-ChildItem Env:
- name: Test Bootstrap
run: |
pytest --cache-clear -v -s -ra --log-cli-level=debug tests/integration/
- name: Set Exit Status
if: always()
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.sw?
*.un~
.vagrant
*__pycache__
tools
venv

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ repos:
args: [--py310-plus]

- repo: https://github.com/psf/black
rev: 24.1.0
rev: 24.10.0
hooks:
- id: black
args: []
Expand Down
37 changes: 2 additions & 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,8 @@ def target_salt_version():
target_salt = ".".join(
[
item
for item in os.environ["KITCHEN_SUITE"].split("-")
## DGM 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
Loading

0 comments on commit db97436

Please sign in to comment.