diff --git a/.copier-answers.yml b/.copier-answers.yml new file mode 100644 index 0000000..3938c69 --- /dev/null +++ b/.copier-answers.yml @@ -0,0 +1,22 @@ +# Autogenerated. Do not edit this by hand, use `copier update`. +--- +_commit: 0.2.6 +_src_path: https://github.com/lkubb/salt-extension-copier +author: EITR Technologies, LLC +author_email: devops@eitr.tech +docs_url: '' +license: apache +loaders: + - engine + - returner +max_salt_version: 3006 +no_saltext_namespace: false +package_name: prometheus +project_name: prometheus +python_requires: '3.8' +salt_version: '3005' +source_url: https://github.com/salt-extensions/saltext-prometheus +ssh_fixtures: false +summary: Salt Extension for interacting with Prometheus +tracker_url: https://github.com/salt-extensions/saltext-prometheus/issues +url: https://github.com/salt-extensions/saltext-prometheus diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 136e41a..b232a42 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -21,6 +21,9 @@ Please be as specific as possible and give set-up details. - [ ] container (Kubernetes, Docker, containerd, etc. please specify) - [ ] or a combination, please be explicit - [ ] jails if it is FreeBSD +- [ ] classic packaging +- [ ] onedir packaging +- [ ] used bootstrap to install **Steps to Reproduce the behavior** @@ -36,7 +39,7 @@ If applicable, add screenshots to help explain your problem.
salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) -``` +```yaml PASTE HERE ```
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index dfec2ac..4cf0d28 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -10,5 +10,5 @@ contact_links: url: https://web.libera.chat/#salt about: Please ask and answer questions here. - name: Security vulnerabilities - email: security@saltstack.com + email: saltproject-security.pdl@broadcom.com about: Please report security vulnerabilities here. diff --git a/.github/ISSUE_TEMPLATE/docs.md b/.github/ISSUE_TEMPLATE/docs.md index 6a9d2fd..59af749 100644 --- a/.github/ISSUE_TEMPLATE/docs.md +++ b/.github/ISSUE_TEMPLATE/docs.md @@ -14,10 +14,10 @@ A clear and concise description of what the problem is. Ex. I'm always frustrate What did you expect to see in the documentation that is missing or needs updating? **Type of documentation** -This could be Salt modules or tutorital topics. +This could be module documentation or a guide. **Location or format of documentation** Insert page URL if applicable. **Additional context** -Add any other context or screenshots about the feature request here. +Add any other context or screenshots here. diff --git a/.github/ISSUE_TEMPLATE/tech-debt.md b/.github/ISSUE_TEMPLATE/tech-debt.md new file mode 100644 index 0000000..5a546c6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/tech-debt.md @@ -0,0 +1,13 @@ +--- +name: Tech Debt +about: Issue is related to tech debt. This includes compatibility changes for newer versions of software and OSes that salt interacts with. +title: "[TECH DEBT]" +labels: tech-debt +assignees: '' + +--- + +### Description of the tech debt to be addressed, include links and screenshots + +### Versions Report +(Provided by running `salt --versions-report`. Please also mention any differences in master/minion versions.) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..3a04455 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,19 @@ +name: Pull Request or Push + +on: + push: + branches: + - 'main' # Run on pushes to main + tags-ignore: + - '*' # Ignore pushes to tags + pull_request: + +jobs: + call_central_workflow: + name: CI + uses: salt-extensions/central-artifacts/.github/workflows/ci.yml@main + with: + setup-vault: true + permissions: + contents: write + pull-requests: read diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..abdd5e7 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,32 @@ +name: Tagged Releases + +on: + push: + tags: + - "v*" # Only tags starting with "v" for "v1.0.0", etc. + +jobs: + get_tag_version: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.get_version.outputs.version }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Extract tag name + id: get_version + run: echo "::set-output name=version::$(echo ${GITHUB_REF#refs/tags/v})" + + call_central_workflow: + needs: get_tag_version + uses: salt-extensions/central-artifacts/.github/workflows/ci.yml@main + with: + setup-vault: true + release: true + version: ${{ needs.get_tag_version.outputs.version }} + permissions: + contents: write + id-token: write + pull-requests: read + secrets: inherit diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index ac60494..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,417 +0,0 @@ - -name: Testing - -on: [push, pull_request] - -jobs: - Pre-Commit: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: Set Cache Key - run: echo "PY=$(python --version --version | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV - - name: Install System Deps - run: | - sudo apt-get update - sudo apt-get install -y libxml2 libxml2-dev libxslt-dev - - uses: actions/cache@v1 - with: - path: ~/.cache/pre-commit - key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} - - uses: pre-commit/action@v1.0.1 - - Docs: - runs-on: ubuntu-20.04 - needs: Pre-Commit - - timeout-minutes: 10 - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python 3.7 For Nox - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - - name: Install Nox - run: | - python -m pip install --upgrade pip - pip install nox - - - name: Install Doc Requirements - run: | - nox --force-color -e docs --install-only - - - name: Build Docs - env: - SKIP_REQUIREMENTS_INSTALL: YES - run: | - nox --force-color -e docs - - Linux: - runs-on: ubuntu-20.04 - needs: Pre-Commit - - timeout-minutes: 15 - - strategy: - fail-fast: false - max-parallel: 4 - matrix: - python-version: - - 3.7 - - 3.8 - - 3.9 - - "3.10" - salt-version: - - 3004.1 - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Nox - run: | - python -m pip install --upgrade pip - pip install nox - - - name: Install Test Requirements - env: - SALT_REQUIREMENT: salt==${{ matrix.salt-version }} - run: | - nox --force-color -e tests-3 --install-only - - - name: Test - env: - SALT_REQUIREMENT: salt==${{ matrix.salt-version }} - SKIP_REQUIREMENTS_INSTALL: YES - run: | - nox --force-color -e tests-3 -- -vv tests/ - - - name: Create CodeCov Flags - if: always() - id: codecov-flags - run: | - echo ::set-output name=flags::$(python -c "import sys; print('{},{},salt_{}'.format('${{ runner.os }}'.replace('-20.04', ''), 'py{}{}'.format(*sys.version_info), '_'.join(str(v) for v in '${{ matrix.salt-version }}'.replace('==', '_').split('.'))))") - - - name: Upload Project Code Coverage - if: always() - shell: bash - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},project - REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-project - REPORT_PATH: artifacts/coverage-project.xml - run: | - if [ ! -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - if [ -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - - - name: Upload Tests Code Coverage - if: always() - shell: bash - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},tests - REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-tests - REPORT_PATH: artifacts/coverage-tests.xml - run: | - if [ ! -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - if [ -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - - - name: Upload Logs - if: always() - uses: actions/upload-artifact@main - with: - name: runtests-${{ runner.os }}-py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}.log - path: artifacts/runtests-*.log - - Windows: - runs-on: windows-2019 - needs: Pre-Commit - - timeout-minutes: 40 - - strategy: - fail-fast: false - max-parallel: 3 - matrix: - python-version: - - 3.7 - salt-version: - - 3004.1 - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Nox - run: | - python -m pip install --upgrade pip - pip install nox - - - name: Install Test Requirements - shell: bash - env: - SALT_REQUIREMENT: salt==${{ matrix.salt-version }} - EXTRA_REQUIREMENTS_INSTALL: Cython - run: | - export PATH="/C/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64;$PATH" - nox --force-color -e tests-3 --install-only - - - name: Test - shell: bash - env: - SALT_REQUIREMENT: salt==${{ matrix.salt-version }} - SKIP_REQUIREMENTS_INSTALL: YES - run: | - export PATH="/C/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64;$PATH" - nox --force-color -e tests-3 -- -vv tests/ - - - name: Create CodeCov Flags - if: always() - id: codecov-flags - run: | - echo ::set-output name=flags::$(python -c "import sys; print('{},{},salt_{}'.format('${{ runner.os }}'.replace('-2019', ''), 'py{}{}'.format(*sys.version_info), '_'.join(str(v) for v in '${{ matrix.salt-version }}'.replace('==', '_').split('.'))))") - - - name: Upload Project Code Coverage - if: always() - shell: bash - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},project - REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-project - REPORT_PATH: artifacts/coverage-project.xml - run: | - if [ ! -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - if [ -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - - - name: Upload Tests Code Coverage - if: always() - shell: bash - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},tests - REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-tests - REPORT_PATH: artifacts/coverage-tests.xml - run: | - if [ ! -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - if [ -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - - - name: Upload Logs - if: always() - uses: actions/upload-artifact@main - with: - name: runtests-${{ runner.os }}-py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}.log - path: artifacts/runtests-*.log - - macOS: - runs-on: macOS-10.15 - needs: Pre-Commit - - timeout-minutes: 40 - - strategy: - fail-fast: false - max-parallel: 3 - matrix: - python-version: - - 3.7 - - 3.8 - salt-version: - - 3004.1 - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Nox - run: | - python -m pip install --upgrade pip - pip install nox - - - name: Install Test Requirements - env: - SALT_REQUIREMENT: salt==${{ matrix.salt-version }} - run: | - nox --force-color -e tests-3 --install-only - - - name: Test - env: - SALT_REQUIREMENT: salt==${{ matrix.salt-version }} - SKIP_REQUIREMENTS_INSTALL: YES - run: | - nox --force-color -e tests-3 -- -vv tests/ - - - name: Create CodeCov Flags - if: always() - id: codecov-flags - run: | - echo ::set-output name=flags::$(python -c "import sys; print('{},{},salt_{}'.format('${{ runner.os }}'.replace('-10.15', ''), 'py{}{}'.format(*sys.version_info), '_'.join(str(v) for v in '${{ matrix.salt-version }}'.replace('==', '_').split('.'))))") - - - name: Upload Project Code Coverage - if: always() - shell: bash - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},project - REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-project - REPORT_PATH: artifacts/coverage-project.xml - run: | - if [ ! -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - if [ -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - - - name: Upload Tests Code Coverage - if: always() - shell: bash - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},tests - REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-tests - REPORT_PATH: artifacts/coverage-tests.xml - run: | - if [ ! -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - if [ -f codecov.sh ]; then - n=0 - until [ "$n" -ge 5 ] - do - if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then - break - fi - n=$((n+1)) - sleep 15 - done - fi - - - name: Upload Logs - if: always() - uses: actions/upload-artifact@main - with: - name: runtests-${{ runner.os }}-py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}.log - path: artifacts/runtests-*.log diff --git a/.gitignore b/.gitignore index 737a78f..e9a082d 100644 --- a/.gitignore +++ b/.gitignore @@ -110,12 +110,6 @@ ENV/ env.bak/ venv.bak/ -# vscode -.vscode/ - -#salt env -Saltfile - # Spyder project settings .spyderproject .spyproject @@ -134,15 +128,17 @@ dmypy.json # Pyre type checker .pyre/ +# Ignore the setuptools_scm auto-generated version module +src/saltext/prometheus/version.py + # Ignore CI generated artifacts artifacts/ -# Just a dir for local whatever -local/ - +# IDE +.vscode/ .DS_Store .idea/ -src/.DS_Store -src/saltext/.DS_Store -.vscode/ *.swp + +#salt env +Saltfile diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml old mode 100644 new mode 100755 index 5bc91f1..52af702 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,16 +2,14 @@ minimum_pre_commit_version: 2.4.0 repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.4.0 hooks: - id: check-merge-conflict # Check for files that contain merge conflict strings. - id: trailing-whitespace # Trims trailing whitespace. - exclude: ^(docs/.*\.rst)$ args: [--markdown-linebreak-ext=md] - id: mixed-line-ending # Replaces or checks mixed line ending. args: [--fix=lf] - id: end-of-file-fixer # Makes sure files end in a newline and only a newline. - exclude: ^(docs/.*\.rst)$ - id: check-merge-conflict # Check for files that contain merge conflict strings. - id: check-ast # Simply check whether files parse as valid python. @@ -39,13 +37,18 @@ repos: - repo: https://github.com/s0undt3ch/salt-rewrite # Automatically rewrite code with known rules - rev: 1.3.3 + rev: 2.5.2 hooks: - id: salt-rewrite alias: rewrite-docstrings name: Salt extensions docstrings auto-fixes files: ^src/saltext/prometheus/.*\.py$ args: [--silent] + + - repo: https://github.com/s0undt3ch/salt-rewrite + # Automatically rewrite code with known rules + rev: 2.5.2 + hooks: - id: salt-rewrite alias: rewrite-tests name: Rewrite the test suite @@ -53,49 +56,53 @@ repos: args: [--silent, -E, fix_docstrings] - repo: https://github.com/asottile/pyupgrade - rev: v2.38.4 + rev: v2.37.2 hooks: - id: pyupgrade - name: Rewrite Code to be Py3+ + name: Rewrite Code to be Py3.8+ args: [ - --py3-plus + --py38-plus ] exclude: src/saltext/prometheus/version.py - repo: https://github.com/asottile/reorder_python_imports - rev: v2.6.0 + rev: v3.10.0 hooks: - id: reorder-python-imports args: [ - --py3-plus, + --py38-plus, ] exclude: src/saltext/prometheus/version.py - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 22.6.0 hooks: - id: black args: [-l 100] exclude: src/saltext/prometheus/version.py - - repo: https://github.com/asottile/blacken-docs - rev: v1.10.0 + - repo: https://github.com/adamchainz/blacken-docs + rev: v1.12.1 hooks: - id: blacken-docs args: [--skip-errors] files: ^(docs/.*\.rst|src/saltext/prometheus/.*\.py)$ - additional_dependencies: [black==21.7b0] + additional_dependencies: + - black==22.6.0 # <---- Formatting ----------------------------------------------------------------------------- # ----- Security ------------------------------------------------------------------------------> - repo: https://github.com/PyCQA/bandit - rev: "1.7.0" + rev: "1.7.4" hooks: - id: bandit alias: bandit-salt name: Run bandit against the code base args: [--silent, -lll, --skip, B701] exclude: src/saltext/prometheus/version.py + - repo: https://github.com/PyCQA/bandit + rev: "1.7.4" + hooks: - id: bandit alias: bandit-tests name: Run bandit against the test suite @@ -116,6 +123,10 @@ repos: - -e - lint-code-pre-commit - -- + + - repo: https://github.com/saltstack/mirrors-nox + rev: v2021.6.12 + hooks: - id: nox alias: lint-tests name: Lint Tests @@ -126,177 +137,3 @@ repos: - lint-tests-pre-commit - -- # <---- Code Analysis -------------------------------------------------------------------------- - - # ----- Static Test Requirements --------------------------------------------------------------> - - repo: https://github.com/saltstack/pip-tools-compile-impersonate - rev: '4.1' - hooks: - - id: pip-tools-compile - alias: compile-3.6-test-requirements - name: Py3.6 Test Requirements - files: ^requirements/tests.in$ - pass_filenames: false - args: - - -v - - --py-version=3.6 - - --platform=linux - - requirements/tests.in - - - id: pip-tools-compile - alias: compile-3.7-test-requirements - name: Py3.7 Test Requirements - files: ^requirements/tests.in$ - pass_filenames: false - args: - - -v - - --py-version=3.7 - - --platform=linux - - requirements/tests.in - - - id: pip-tools-compile - alias: compile-3.8-test-requirements - name: Py3.8 Test Requirements - files: ^requirements/tests.in$ - pass_filenames: false - args: - - -v - - --py-version=3.8 - - --platform=linux - - requirements/tests.in - - - id: pip-tools-compile - alias: compile-3.9-test-requirements - name: Py3.9 Test Requirements - files: ^requirements/tests.in$ - pass_filenames: false - args: - - -v - - --py-version=3.9 - - --platform=linux - - requirements/tests.in - - - id: pip-tools-compile - alias: compile-3.10-test-requirements - name: Py3.10 Test Requirements - files: ^requirements/tests.in$ - pass_filenames: false - args: - - -v - - --py-version=3.10 - - --platform=linux - - requirements/tests.in - # <---- Static Test Requirements --------------------------------------------------------------- - - # ----- Static Lint Requirements --------------------------------------------------------------> - - id: pip-tools-compile - alias: compile-3.6-test-requirements - name: Py3.6 Lint Requirements - files: ^requirements/lint.in$ - pass_filenames: false - args: - - -v - - --py-version=3.6 - - --platform=linux - - requirements/lint.in - - - id: pip-tools-compile - alias: compile-3.7-test-requirements - name: Py3.7 Lint Requirements - files: ^requirements/lint.in$ - pass_filenames: false - args: - - -v - - --py-version=3.7 - - --platform=linux - - requirements/lint.in - - - id: pip-tools-compile - alias: compile-3.8-test-requirements - name: Py3.8 Lint Requirements - files: ^requirements/lint.in$ - pass_filenames: false - args: - - -v - - --py-version=3.8 - - --platform=linux - - requirements/lint.in - - - id: pip-tools-compile - alias: compile-3.9-test-requirements - name: Py3.9 Lint Requirements - files: ^requirements/lint.in$ - pass_filenames: false - args: - - -v - - --py-version=3.9 - - --platform=linux - - requirements/lint.in - - - id: pip-tools-compile - alias: compile-3.10-test-requirements - name: Py3.10 Lint Requirements - files: ^requirements/lint.in$ - pass_filenames: false - args: - - -v - - --py-version=3.10 - - --platform=linux - - requirements/lint.in - # <---- Static Lint Requirements --------------------------------------------------------------- - - # ----- Static Docs Requirements --------------------------------------------------------------> - - id: pip-tools-compile - alias: compile-3.6-test-requirements - name: Py3.6 Docs Requirements - files: ^requirements/docs.in$ - pass_filenames: false - args: - - -v - - --py-version=3.6 - - --platform=linux - - requirements/docs.in - - - id: pip-tools-compile - alias: compile-3.7-test-requirements - name: Py3.7 Docs Requirements - files: ^requirements/docs.in$ - pass_filenames: false - args: - - -v - - --py-version=3.7 - - --platform=linux - - requirements/docs.in - - - id: pip-tools-compile - alias: compile-3.8-test-requirements - name: Py3.8 Docs Requirements - files: ^requirements/docs.in$ - pass_filenames: false - args: - - -v - - --py-version=3.8 - - --platform=linux - - requirements/docs.in - - - id: pip-tools-compile - alias: compile-3.9-test-requirements - name: Py3.9 Docs Requirements - files: ^requirements/docs.in$ - pass_filenames: false - args: - - -v - - --py-version=3.9 - - --platform=linux - - requirements/docs.in - - - id: pip-tools-compile - alias: compile-3.10-test-requirements - name: Py3.10 Docs Requirements - files: ^requirements/docs.in$ - pass_filenames: false - args: - - -v - - --py-version=3.10 - - --platform=linux - - requirements/docs.in - # <---- Static Docs Requirements --------------------------------------------------------------- diff --git a/.pre-commit-hooks/make-autodocs.py b/.pre-commit-hooks/make-autodocs.py index c290c0a..88e9088 100644 --- a/.pre-commit-hooks/make-autodocs.py +++ b/.pre-commit-hooks/make-autodocs.py @@ -1,58 +1,119 @@ +import ast +import os.path +import subprocess from pathlib import Path -autodocs = {} +repo_path = Path(subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode().strip()) +src_dir = repo_path / "src" / "saltext" / "prometheus" +doc_dir = repo_path / "docs" -loader_dirs = ( - "engines", - "modules", - "returners", - "states", -) +docs_by_kind = {} +changed_something = False -for ldir in loader_dirs: - autodocs[ldir] = [] -trans = str.maketrans({"_": r"\_"}) -docs_path = Path("docs") -ref_path = docs_path / "ref" +def _find_virtualname(path): + tree = ast.parse(path.read_text()) + for node in ast.walk(tree): + if isinstance(node, ast.Assign): + for target in node.targets: + if isinstance(target, ast.Name) and target.id == "__virtualname__": + if isinstance(node.value, ast.Str): + virtualname = node.value.s + break + else: + continue + break + else: + virtualname = path.with_suffix("").name + return virtualname -for path in Path("src").glob("**/*.py"): - kind = path.parent.name - if kind in loader_dirs: - import_path = ".".join(path.with_suffix("").parts[1:]) - autodocs[kind].append(import_path) - rst_path = ref_path / kind / (import_path + ".rst") - if rst_path.is_file(): - continue - rst_path.parent.mkdir(parents=True, exist_ok=True) - rst_path.write_text( - f"""{import_path.translate(trans)} -{'='*len(import_path.translate(trans))} -.. currentmodule:: {'.'.join(import_path.split('.')[:-1])} +def write_module(rst_path, path, use_virtualname=True): + if use_virtualname: + virtualname = "``" + _find_virtualname(path) + "``" + else: + virtualname = make_import_path(path) + module_contents = f"""\ +{virtualname} +{'='*len(virtualname)} + +.. automodule:: {make_import_path(path)} + :members: +""" + if not rst_path.exists() or rst_path.read_text() != module_contents: + print(rst_path) + rst_path.write_text(module_contents) + return True + return False -.. autodata:: {import_path.split('.')[-1]}""" + +def write_index(index_rst, import_paths, kind): + if kind == "utils": + header_text = "Utilities" + common_path = os.path.commonpath(tuple(x.replace(".", "/") for x in import_paths)).replace( + "/", "." + ) + if any(x == common_path for x in import_paths): + common_path = common_path[: common_path.rfind(".")] + else: + header_text = ( + "execution modules" if kind.lower() == "modules" else kind.rstrip("s") + " modules" ) + common_path = import_paths[0][: import_paths[0].rfind(".")] + header = f"{'_'*len(header_text)}\n{header_text.title()}\n{'_'*len(header_text)}" + index_contents = f"""\ +.. all-saltext.prometheus.{kind}: -for ldir in autodocs: - if not autodocs[ldir]: - continue - all_rst = ref_path / ldir / "all.rst" - if all_rst.is_file(): - continue - all_rst.parent.mkdir(parents=True, exist_ok=True) - all_rst.write_text( - f""" -.. all-saltext.prometheus.{ldir}: +{header} -{'-'*len(ldir)}-------- -{ldir.title()} Modules -{'-'*len(ldir)}-------- +.. currentmodule:: {common_path} .. autosummary:: :toctree: -{chr(10).join(sorted(' '+mod for mod in autodocs[ldir]))} +{chr(10).join(sorted(' '+p[len(common_path)+1:] for p in import_paths))} """ - ) + if not index_rst.exists() or index_rst.read_text() != index_contents: + print(index_rst) + index_rst.write_text(index_contents) + return True + return False + + +def make_import_path(path): + if path.name == "__init__.py": + path = path.parent + return ".".join(path.relative_to(repo_path / "src").with_suffix("").parts) + + +for path in src_dir.glob("*/*.py"): + if path.name != "__init__.py": + kind = path.parent.name + if kind != "utils": + docs_by_kind.setdefault(kind, set()).add(path) + +# Utils can have subdirectories, treat them separately +for path in (src_dir / "utils").rglob("*.py"): + if path.name == "__init__.py" and not path.read_text(): + continue + docs_by_kind.setdefault("utils", set()).add(path) + +for kind in docs_by_kind: + kind_path = doc_dir / "ref" / kind + index_rst = kind_path / "index.rst" + import_paths = [] + for path in sorted(docs_by_kind[kind]): + import_path = make_import_path(path) + import_paths.append(import_path) + rst_path = kind_path / (import_path + ".rst") + rst_path.parent.mkdir(parents=True, exist_ok=True) + change = write_module(rst_path, path, use_virtualname=kind != "utils") + changed_something = changed_something or change + + write_index(index_rst, import_paths, kind) + + +# Ensure pre-commit realizes we did something +if changed_something: + exit(2) diff --git a/.pylintrc b/.pylintrc old mode 100644 new mode 100755 index 82c7df4..5692f3b --- a/.pylintrc +++ b/.pylintrc @@ -1,409 +1,681 @@ -[MASTER] +[MAIN] -# Specify a configuration file. -#rcfile= +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Clear in-memory caches upon conclusion of linting. Useful if running pylint +# in a server-like mode. +clear-cache-post-run=no + +# Load and enable all available extensions. Use --list-extensions to see a list +# all available extensions. +#enable-all-extensions= + +# In error mode, messages with a category besides ERROR or FATAL are +# suppressed, and no reports are done by default. Error mode is compatible with +# disabling specific errors. +#errors-only= + +# Always return a 0 (non-error) status code, even if lint errors are found. +# This is primarily useful in continuous integration scripts. +#exit-zero= + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. +extension-pkg-allow-list= + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. (This is an alternative name to extension-pkg-allow-list +# for backward compatibility.) +extension-pkg-whitelist= + +# Return non-zero exit code if any of these messages/categories are detected, +# even if score is above --fail-under value. Syntax same as enable. Messages +# specified are enabled, while categories only check already-enabled messages. +fail-on= + +# Specify a score threshold under which the program will exit with error. +fail-under=10 + +# Interpret the stdin as a python script, whose filename needs to be passed as +# the module_or_package argument. +#from-stdin= + +# Files or directories to be skipped. They should be base names, not paths. +ignore=CVS + +# Add files or directories matching the regular expressions patterns to the +# ignore-list. The regex matches against paths and can be in Posix or Windows +# format. Because '\\' represents the directory delimiter on Windows systems, +# it can't be used as an escape character. +ignore-paths= + +# Files or directories matching the regular expression patterns are skipped. +# The regex matches against base names, not paths. The default value ignores +# Emacs file locks +ignore-patterns=^\.# + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis). It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= # Python code to execute, usually for sys.path manipulation such as # pygtk.require(). #init-hook= -# Profiled execution. -profile=no +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use, and will cap the count on Windows to +# avoid hangs. +jobs=0 -# Add files or directories to the blacklist. They should be base names, not -# paths. -ignore=CVS,_version.py +# Control the amount of potential inferred values when inferring a single +# object. This can help the performance when dealing with large functions or +# complex, nested conditions. +limit-inference-results=100 + +# List of plugins (as comma separated values of python module names) to load, +# usually to register additional checkers. +load-plugins= # Pickle collected data for later comparisons. persistent=yes -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins=saltpylint.pep8, - saltpylint.strings +# Minimum Python version to use for version dependent checks. Will default to +# the version used to run pylint. +py-version=3.10 + +# Discover python modules and packages in the file system subtree. +recursive=no -# Use multiple processes to speed up Pylint. -jobs=1 +# Add paths to the list of the source roots. Supports globbing patterns. The +# source root is an absolute path or a path relative to the current working +# directory used to determine a package namespace for modules located under the +# source root. +source-roots= + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages. +suggestion-mode=yes # Allow loading of arbitrary C extensions. Extensions are imported into the # active Python interpreter and may run arbitrary code. unsafe-load-any-extension=no -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist= - -[MESSAGES CONTROL] +# In verbose mode, extra non-checker-related info will be displayed. +#verbose= -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time. See also the "--disable" option for examples. -#enable= +[BASIC] -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -#disable= -disable=R, - I0011, - I0012, - I0013, - C0330, - E8116, - E812, - wrong-import-position, - wrong-import-order, - un-indexed-curly-braces-error, - consider-using-f-string, - fixme - -# Disabled: -# R* [refactoring suggestions & reports] -# I0011 (locally-disabling) -# I0012 (locally-enabling) -# I0013 (file-ignored) -# C0330 (bad-continuation) Wrong hanging indentation before block (add 4 spaces). -# E8116 PEP8 E116: unexpected indentation (comment) -# E812* All PEP8 E12* +# Naming style matching correct argument names. +argument-naming-style=snake_case -[REPORTS] +# Regular expression matching correct argument names. Overrides argument- +# naming-style. If left empty, argument names will be checked with the set +# naming style. +#argument-rgx= -# Set the output format. Available formats are text, parseable, colorized, msvs -# (visual studio) and html. You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text +# Naming style matching correct attribute names. +attr-naming-style=snake_case -# Put messages in a separate file for each module / package specified on the -# command line instead of printing them on stdout. Reports (if any) will be -# written in a file name "pylint_global.[txt|html]". -files-output=no +# Regular expression matching correct attribute names. Overrides attr-naming- +# style. If left empty, attribute names will be checked with the set naming +# style. +#attr-rgx= -# Tells whether to display a full report or only the messages -reports=no +# Bad variable names which should always be refused, separated by a comma. +bad-names=foo, + bar, + baz, + toto, + tutu, + tata -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) +# Bad variable names regexes, separated by a comma. If names match any regex, +# they will always be refused +bad-names-rgxs= -# Add a comment according to your evaluation note. This is used by the global -# evaluation report (RP0004). -comment=no +# Naming style matching correct class attribute names. +class-attribute-naming-style=any -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style. If left empty, class attribute names will be checked +# with the set naming style. +#class-attribute-rgx= +# Naming style matching correct class constant names. +class-const-naming-style=UPPER_CASE -[LOGGING] +# Regular expression matching correct class constant names. Overrides class- +# const-naming-style. If left empty, class constant names will be checked with +# the set naming style. +#class-const-rgx= -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging +# Naming style matching correct class names. +class-naming-style=PascalCase +# Regular expression matching correct class names. Overrides class-naming- +# style. If left empty, class names will be checked with the set naming style. +#class-rgx= -[SPELLING] +# Naming style matching correct constant names. +const-naming-style=UPPER_CASE -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= +# Regular expression matching correct constant names. Overrides const-naming- +# style. If left empty, constant names will be checked with the set naming +# style. +#const-rgx= -# List of comma separated words that should not be checked. -spelling-ignore-words= +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file=.pylint-spelling-words +# Naming style matching correct function names. +function-naming-style=snake_case -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no +# Regular expression matching correct function names. Overrides function- +# naming-style. If left empty, function names will be checked with the set +# naming style. +#function-rgx= +# Good variable names which should always be accepted, separated by a comma. +good-names=i, + j, + k, + ex, + Run, + _ -[SIMILARITIES] +# Good variable names regexes, separated by a comma. If names match any regex, +# they will always be accepted +good-names-rgxs= -# Minimum lines number of a similarity. -min-similarity-lines=4 +# Include a hint for the correct naming format with invalid-name. +include-naming-hint=no -# Ignore comments when computing similarities. -ignore-comments=yes +# Naming style matching correct inline iteration names. +inlinevar-naming-style=any -# Ignore docstrings when computing similarities. -ignore-docstrings=yes +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style. If left empty, inline iteration names will be checked +# with the set naming style. +#inlinevar-rgx= -# Ignore imports when computing similarities. -ignore-imports=no +# Naming style matching correct method names. +method-naming-style=snake_case +# Regular expression matching correct method names. Overrides method-naming- +# style. If left empty, method names will be checked with the set naming style. +#method-rgx= -[VARIABLES] +# Naming style matching correct module names. +module-naming-style=snake_case -# Tells whether we should check for unused import in __init__ files. -init-import=no +# Regular expression matching correct module names. Overrides module-naming- +# style. If left empty, module names will be checked with the set naming style. +#module-rgx= -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_$|dummy +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins=__opts__, - __utils__, - __salt__, - __pillar__, - __grains__, - __context__, - __runner__, - __ret__, - __env__, - __low__, - __states__, - __lowstate__, - __running__, - __active_provider_name__, - __master_opts__, - __jid_event__, - __instance_id__, - __salt_system_encoding__, - __proxy__, - __serializers__, - __reg__, - __executors__, - __events__ +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +# These decorators are taken in consideration only for invalid-name. +property-classes=abc.abstractproperty +# Regular expression matching correct type alias names. If left empty, type +# alias names will be checked with the set naming style. +#typealias-rgx= -[MISCELLANEOUS] +# Regular expression matching correct type variable names. If left empty, type +# variable names will be checked with the set naming style. +#typevar-rgx= -# List of note tags to take in consideration, separated by a comma. -notes=FIXME,XXX,TODO +# Naming style matching correct variable names. +variable-naming-style=snake_case +# Regular expression matching correct variable names. Overrides variable- +# naming-style. If left empty, variable names will be checked with the set +# naming style. +#variable-rgx= -[BASIC] -# List of builtins function names that should not be used, separated by a comma -bad-functions=map,filter,input +[CLASSES] -# Good variable names which should always be accepted, separated by a comma -good-names=i,j,k,ex,Run,_,log,pytest_plugins,__opts__,__context__ +# Warn about protected attribute access inside special methods +check-protected-access-in-special-methods=no -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__, + __new__, + setUp, + asyncSetUp, + __post_init__ -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict,_fields,_replace,_source,_make,os._exit -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls -# Regular expression matching correct function names -function-rgx=[a-z_][a-z0-9_]{2,60}$ +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs -# Naming hint for function names -function-name-hint=[a-z_][a-z0-9_]{2,60}$ -# Regular expression matching correct variable names -variable-rgx=[a-z_][a-z0-9_]{2,60}$ +[DESIGN] -# Naming hint for variable names -variable-name-hint=[a-z_][a-z0-9_]{2,60}$ +# List of regular expressions of class ancestor names to ignore when counting +# public methods (see R0903) +exclude-too-few-public-methods= -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ +# List of qualified class names to ignore when counting class parents (see +# R0901) +ignored-parents= -# Naming hint for constant names -const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ +# Maximum number of arguments for function / method. +max-args=15 -# Regular expression matching correct attribute names -attr-rgx=[a-z_][a-z0-9_]{2,60}$ +# Maximum number of attributes for a class (see R0902). +max-attributes=7 -# Naming hint for attribute names -attr-name-hint=[a-z_][a-z0-9_]{2,60}$ +# Maximum number of boolean expressions in an if statement (see R0916). +max-bool-expr=5 -# Regular expression matching correct argument names -argument-rgx=[a-z_][a-z0-9_]{2,60}$ +# Maximum number of branch for function / method body. +max-branches=12 -# Naming hint for argument names -argument-name-hint=[a-z_][a-z0-9_]{2,60}$ +# Maximum number of locals for function / method body. +max-locals=15 -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,60}|(__.*__))$ +# Maximum number of parents for a class (see R0901). +max-parents=7 -# Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,60}|(__.*__))$ +# Maximum number of public methods for a class (see R0904). +max-public-methods=25 -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ +# Maximum number of return / yield for function / method body. +max-returns=6 -# Naming hint for inline iteration names -inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ +# Maximum number of statements in function / method body. +max-statements=50 -# Regular expression matching correct class names -class-rgx=[A-Z_][a-zA-Z0-9]+$ +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 -# Naming hint for class names -class-name-hint=[A-Z_][a-zA-Z0-9]+$ -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ +[EXCEPTIONS] -# Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ +# Exceptions that will emit a warning when caught. +overgeneral-exceptions=builtins.BaseException,builtins.Exception -# Regular expression matching correct method names -method-rgx=[a-z_][a-z0-9_]{2,60}$ -# Naming hint for method names -method-name-hint=[a-z_][a-z0-9_]{2,60}$ +[FORMAT] -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=__.*__ +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 -[FORMAT] +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' # Maximum number of characters on a single line. -max-line-length=120 +max-line-length=100 -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ +# Maximum number of lines in a module. +max-module-lines=2000 + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no # Allow the body of an if to be on the same line as the test if there is no # else. single-line-if-stmt=no -# List of optional constructs for which whitespace checking is disabled -no-space-check=trailing-comma,dict-separator -# Maximum number of lines in a module -max-module-lines=1000 +[IMPORTS] -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' +# List of modules that can be imported at any level, not just the top level +# one. +allow-any-import-level= -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 +# Allow explicit reexports by alias from a package __init__. +allow-reexport-from-package=no -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -expected-line-ending-format=LF +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no +# Deprecated modules which should not be used, separated by a comma. +deprecated-modules= -[TYPECHECK] +# Output a graph (.gv or any supported image format) of external dependencies +# to the given file (report RP0402 must not be disabled). +ext-import-graph= -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes +# Output a graph (.gv or any supported image format) of all (i.e. internal and +# external) dependencies to the given file (report RP0402 must not be +# disabled). +import-graph= -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis -ignored-modules= +# Output a graph (.gv or any supported image format) of internal dependencies +# to the given file (report RP0402 must not be disabled). +int-import-graph= -# List of classes names for which member attributes should not be checked -# (useful for classes with attributes dynamically set). -ignored-classes= +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= -# When zope mode is activated, add a predefined set of Zope acquired attributes -# to generated-members. -zope=no +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E0201 when accessed. Python regular -# expressions are accepted. -generated-members= +# Couples of modules and preferred modules, separated by a comma. +preferred-modules= -[IMPORTS] +[LOGGING] -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=regsub,TERMIOS,Bastion,rexec +# The type of string formatting that logging methods do. `old` means using % +# formatting, `new` is for `{}` formatting. +logging-format-style=old -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= +# Logging modules to check that the string format arguments are in logging +# function parameter format. +logging-modules=logging -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= +[MESSAGES CONTROL] +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, +# UNDEFINED. +confidence=HIGH, + CONTROL_FLOW, + INFERENCE, + INFERENCE_FAILURE, + UNDEFINED -[DESIGN] +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=all" to +# disable everything first and then re-enable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable=R, + locally-disabled, + file-ignored, + unexpected-special-method-signature, + import-error, + no-member, + unsubscriptable-object, + blacklisted-name, + invalid-name, + missing-docstring, + empty-docstring, + unidiomatic-typecheck, + wrong-import-order, + ungrouped-imports, + wrong-import-position, + bad-mcs-method-argument, + bad-mcs-classmethod-argument, + line-too-long, + too-many-lines, + bad-continuation, + exec-used, + attribute-defined-outside-init, + protected-access, + reimported, + fixme, + global-statement, + unused-variable, + unused-argument, + redefined-outer-name, + redefined-builtin, + undefined-loop-variable, + logging-format-interpolation, + invalid-format-index, + line-too-long, + import-outside-toplevel, + deprecated-method, + keyword-arg-before-vararg, -# Maximum number of arguments for function / method -max-args=5 +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable=c-extension-no-member -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.* -# Maximum number of locals for function / method body -max-locals=15 +[METHOD_ARGS] -# Maximum number of return / yield for function / method body -max-returns=6 +# List of qualified names (i.e., library.method) which require a timeout +# parameter e.g. 'requests.api.get,requests.api.post' +timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request -# Maximum number of branch for function / method body -max-branches=12 -# Maximum number of statements in function / method body -max-statements=50 +[MISCELLANEOUS] -# Maximum number of parents for a class (see R0901). -max-parents=7 +# List of note tags to take in consideration, separated by a comma. +notes=FIXME, + XXX, + TODO -# Maximum number of attributes for a class (see R0902). -max-attributes=7 +# Regular expression of note tags to take in consideration. +notes-rgx= -# Minimum number of public methods for a class (see R0903). -min-public-methods=2 -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 +[REFACTORING] +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 -[CLASSES] +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=sys.exit,argparse.parse_error -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls +[REPORTS] -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs +# Python expression which should return a score less than or equal to 10. You +# have access to the variables 'fatal', 'error', 'warning', 'refactor', +# 'convention', and 'info' which contain the number of messages in each +# category, as well as 'statement' which is the total number of statements +# analyzed. This score is used by the global evaluation report (RP0004). +evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)) -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details. +msg-template= +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio). You can also give a reporter class, e.g. +# mypackage.mymodule.MyReporterClass. +#output-format= -[EXCEPTIONS] +# Tells whether to display a full report or only the messages. +reports=no + +# Activate the evaluation score. +score=yes + + +[SIMILARITIES] + +# Comments are removed from the similarity computation +ignore-comments=yes + +# Docstrings are removed from the similarity computation +ignore-docstrings=yes + +# Imports are removed from the similarity computation +ignore-imports=yes + +# Signatures are removed from the similarity computation +ignore-signatures=yes + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[SPELLING] + +# Limits count of emitted suggestions for spelling mistakes. +max-spelling-suggestions=4 + +# Spelling dictionary name. No available dictionaries : You need to install the +# system dependency for enchant to work.. +spelling-dict= + +# List of comma separated words that should be considered directives if they +# appear at the beginning of a comment and should not be checked. +spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy: + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains the private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to the private dictionary (see the +# --spelling-private-dict-file option) instead of raising a message. +spelling-store-unknown-words=no + + +[STRING] + +# This flag controls whether inconsistent-quotes generates a warning when the +# character used as a quote delimiter is used inconsistently within a module. +check-quote-consistency=no + +# This flag controls whether the implicit-str-concat should generate a warning +# on implicit string concatenation in sequences defined over several lines. +check-str-concat-over-line-jumps=no + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether to warn about missing members when the owner of the attribute +# is inferred to be None. +ignore-none=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of symbolic message names to ignore for Mixin members. +ignored-checks-for-mixins=no-member, + not-async-context-manager, + not-context-manager, + attribute-defined-outside-init + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + +# Regex pattern to define which classes are considered mixins. +mixin-class-rgx=.*[Mm]ixin + +# List of decorators that change the signature of a decorated function. +signature-mutators= + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid defining new builtins when possible. +additional-builtins=__opts__, + __salt__, + __pillar__, + __grains__, + __context__, + __runner__, + __ret__, + __env__, + __low__, + __states__, + __lowstate__, + __running__, + __active_provider_name__, + __master_opts__, + __jid_event__, + __instance_id__, + __salt_system_encoding__, + __proxy__, + __serializers__, + __reg__, + __executors__, + __events__ + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of names allowed to shadow builtins +allowed-redefined-builtins= + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_, + _cb + +# A regular expression matching the name of dummy variables (i.e. expected to +# not be used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=Exception +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io diff --git a/changelog/.template.jinja b/changelog/.template.jinja new file mode 100644 index 0000000..0cf429a --- /dev/null +++ b/changelog/.template.jinja @@ -0,0 +1,15 @@ +{% if sections[""] %} +{% for category, val in definitions.items() if category in sections[""] %} + +### {{ definitions[category]['name'] }} + +{% for text, values in sections[""][category].items() %} +- {{ text }} {{ values|join(', ') }} +{% endfor %} + +{% endfor %} +{% else %} +No significant changes. + + +{% endif %} diff --git a/docs/all.rst b/docs/all.rst deleted file mode 100644 index c9a3398..0000000 --- a/docs/all.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. _all the states/modules: - -Complete List of Prometheus Modules -=================================== - -.. toctree:: - :maxdepth: 2 - :glob: - - ref/engines/all - ref/returners/all diff --git a/docs/changelog.md b/docs/changelog.md new file mode 100644 index 0000000..2f5367b --- /dev/null +++ b/docs/changelog.md @@ -0,0 +1,12 @@ +# Changelog + +The changelog format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). + +This project uses [Semantic Versioning](https://semver.org/) - MAJOR.MINOR.PATCH + +```{towncrier-draft-entries} +``` + +```{include} ../CHANGELOG.md +:start-after: '# Changelog' +``` diff --git a/docs/conf.py b/docs/conf.py old mode 100644 new mode 100755 index ab373a6..df51f80 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,8 +9,10 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. # import datetime +import email.policy import os import sys +from pathlib import Path try: from importlib_metadata import distribution @@ -25,8 +27,10 @@ # assume we're in the doc/ directory docs_basepath = os.path.abspath(os.path.dirname(".")) +PROJECT_ROOT_DIR = Path(docs_basepath).parent + addtl_paths = ( - os.path.join(os.pardir, "src"), # saltext.ttp itself (for autodoc) + os.path.join(os.pardir, "src"), # saltext.prometheus itself (for autodoc) "_ext", # custom Sphinx extensions ) @@ -44,6 +48,19 @@ copyright_year = f"2021 - {this_year}" project = dist.metadata["Summary"] author = dist.metadata["Author"] + +if author is None: + # Core metadata is serialized differently with pyproject.toml: + # https://packaging.python.org/en/latest/specifications/pyproject-toml/#authors-maintainers + author_email = dist.metadata["Author-email"] + em = email.message_from_string( + f"To: {author_email}", + policy=email.policy.default, + ) + if em["To"].addresses and em["To"].addresses[0]: + author = em["To"].addresses[0].display_name + author = author or "" + copyright = f"{copyright_year}, {author}" # The full version, including alpha/beta/rc tags @@ -75,6 +92,15 @@ "sphinx.ext.coverage", "sphinx_copybutton", "sphinxcontrib.spelling", + "sphinxcontrib.towncrier.ext", + "myst_parser", + "sphinx_inline_tabs", +] + +myst_enable_extensions = [ + "colon_fence", + "deflist", + "tasklist", ] # Add any paths that contain templates here, relative to this directory. @@ -97,6 +123,8 @@ autosummary_generate = False +suppress_warnings = ["myst.header"] + # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for @@ -136,7 +164,7 @@ # ----- Intersphinx Config ----------------------------------------------------------------------------------------> intersphinx_mapping = { "python": ("https://docs.python.org/3", None), - "pytest": ("https://pytest.readthedocs.io/en/stable", None), + "pytest": ("https://docs.pytest.org/en/stable", None), "salt": ("https://docs.saltproject.io/en/latest", None), } # <---- Intersphinx Config ----------------------------------------------------------------------------------------- @@ -146,6 +174,11 @@ autodoc_mock_imports = ["salt"] # <---- Autodoc Config ----------------------------------------------------------------------------------------------- +# Towncrier draft config +towncrier_draft_autoversion_mode = "sphinx-release" +towncrier_draft_include_empty = True +towncrier_draft_working_directory = str(PROJECT_ROOT_DIR) + def setup(app): app.add_crossref_type( diff --git a/docs/index.rst b/docs/index.rst index dab82a2..4b7978b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,5 +1,7 @@ -Welcome to Prometheus Salt Extension Documentation! -=================================================== +``saltext-prometheus``: Integrate Salt with Prometheus +====================================================== + +Salt Extension for interacting with Prometheus This guide will walk you through the process of installing and setting up the Prometheus Salt extension on your machine. @@ -14,10 +16,33 @@ Contents -------- .. toctree:: - :maxdepth: 2 - :glob: + :maxdepth: 2 + :caption: Guides + :hidden: + + topics/quick_start + topics/installation + topics/user_documentation + +.. toctree:: + :maxdepth: 2 + :caption: Provided Modules + :hidden: + + ref/engines/index + ref/returners/index + +.. toctree:: + :maxdepth: 2 + :caption: Reference + :hidden: + + changelog + + +Indices and tables +================== - quick_start - user_documentation - all - +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/ref/engines/all.rst b/docs/ref/engines/all.rst deleted file mode 100644 index ae2c8cb..0000000 --- a/docs/ref/engines/all.rst +++ /dev/null @@ -1,12 +0,0 @@ - -.. all-saltext.prometheus.engines: - ---------------- -Engines Modules ---------------- - -.. autosummary:: - :toctree: - - saltext.prometheus.engines.__init__ - saltext.prometheus.engines.prometheus_mod diff --git a/docs/ref/engines/index.rst b/docs/ref/engines/index.rst new file mode 100644 index 0000000..ceaf2fd --- /dev/null +++ b/docs/ref/engines/index.rst @@ -0,0 +1,12 @@ +.. all-saltext.prometheus.engines: + +______________ +Engine Modules +______________ + +.. currentmodule:: saltext.prometheus.engines + +.. autosummary:: + :toctree: + + prometheus_mod diff --git a/docs/ref/engines/saltext.prometheus.engines.__init__.rst b/docs/ref/engines/saltext.prometheus.engines.__init__.rst deleted file mode 100644 index 72478d8..0000000 --- a/docs/ref/engines/saltext.prometheus.engines.__init__.rst +++ /dev/null @@ -1,6 +0,0 @@ -saltext.prometheus.engines.\_\_init\_\_ -======================================= - -.. currentmodule:: saltext.prometheus.engines - -.. autodata:: __init__ \ No newline at end of file diff --git a/docs/ref/engines/saltext.prometheus.engines.prometheus_mod.rst b/docs/ref/engines/saltext.prometheus.engines.prometheus_mod.rst index d84552f..8db436d 100644 --- a/docs/ref/engines/saltext.prometheus.engines.prometheus_mod.rst +++ b/docs/ref/engines/saltext.prometheus.engines.prometheus_mod.rst @@ -1,23 +1,5 @@ -saltext.prometheus.engines.prometheus\_mod -========================================== +``prometheus`` +============== .. automodule:: saltext.prometheus.engines.prometheus_mod - - - - - - - - - - - - - - - - - - - + :members: diff --git a/docs/ref/returners/all.rst b/docs/ref/returners/all.rst deleted file mode 100644 index 7d7e3bb..0000000 --- a/docs/ref/returners/all.rst +++ /dev/null @@ -1,12 +0,0 @@ - -.. all-saltext.prometheus.returners: - ------------------ -Returners Modules ------------------ - -.. autosummary:: - :toctree: - - saltext.prometheus.returners.__init__ - saltext.prometheus.returners.prometheus_textfile diff --git a/docs/ref/returners/index.rst b/docs/ref/returners/index.rst new file mode 100644 index 0000000..b96ee7e --- /dev/null +++ b/docs/ref/returners/index.rst @@ -0,0 +1,12 @@ +.. all-saltext.prometheus.returners: + +________________ +Returner Modules +________________ + +.. currentmodule:: saltext.prometheus.returners + +.. autosummary:: + :toctree: + + prometheus_textfile diff --git a/docs/ref/returners/saltext.prometheus.returners.__init__.rst b/docs/ref/returners/saltext.prometheus.returners.__init__.rst deleted file mode 100644 index 8b8ff31..0000000 --- a/docs/ref/returners/saltext.prometheus.returners.__init__.rst +++ /dev/null @@ -1,6 +0,0 @@ -saltext.prometheus.returners.\_\_init\_\_ -========================================= - -.. currentmodule:: saltext.prometheus.returners - -.. autodata:: __init__ \ No newline at end of file diff --git a/docs/ref/returners/saltext.prometheus.returners.prometheus_textfile.rst b/docs/ref/returners/saltext.prometheus.returners.prometheus_textfile.rst index 49ca03b..6dfc713 100644 --- a/docs/ref/returners/saltext.prometheus.returners.prometheus_textfile.rst +++ b/docs/ref/returners/saltext.prometheus.returners.prometheus_textfile.rst @@ -1,7 +1,5 @@ -.. _prometheus_textfile: - -saltext.prometheus.returners.prometheus\_textfile -================================================= +``prometheus_textfile`` +======================= .. automodule:: saltext.prometheus.returners.prometheus_textfile :members: diff --git a/docs/topics/installation.md b/docs/topics/installation.md new file mode 100644 index 0000000..79cec87 --- /dev/null +++ b/docs/topics/installation.md @@ -0,0 +1,36 @@ +# Installation + +Generally, extensions need to be installed into the same Python environment Salt uses. + +:::{tab} State +```yaml +Install Salt Prometheus extension: + pip.installed: + - name: saltext-prometheus +``` +::: + +:::{tab} Onedir installation +```bash +salt-pip install saltext-prometheus +``` +::: + +:::{tab} Regular installation +```bash +pip install saltext-prometheus +``` +::: + +:::{important} +Currently, there is [an issue][issue-second-saltext] where the installation of a Saltext fails silently +if the environment already has another one installed. You can workaround this by +removing all Saltexts and reinstalling them in one transaction. +::: + +:::{hint} +Saltexts are not distributed automatically via the fileserver like custom modules, they need to be installed +on each node you want them to be available on. +::: + +[issue-second-saltext]: https://github.com/saltstack/salt/issues/65433 diff --git a/docs/quick_start.rst b/docs/topics/quick_start.rst similarity index 89% rename from docs/quick_start.rst rename to docs/topics/quick_start.rst index e99bfc4..2f09f0c 100644 --- a/docs/quick_start.rst +++ b/docs/topics/quick_start.rst @@ -19,7 +19,7 @@ Several methods are available for installing the Prometheus Salt extension: - **Method 1: Using pip** -.. code-block:: +.. code-block:: pip install saltext-prometheus @@ -31,10 +31,10 @@ Several methods are available for installing the Prometheus Salt extension: Use an execution module like: -.. code-block:: +.. code-block:: salt \* pip.install saltext-prometheus - + Note: The extension can be installed and used on all minions or specific minions where reporting data is needed @@ -44,8 +44,8 @@ Verify Installation - (Optional) Verify that the extension is installed -.. code-block:: - +.. code-block:: + salt --versions-report You should see `saltext.prometheus` listed under Salt extensions. @@ -54,15 +54,15 @@ You should see `saltext.prometheus` listed under Salt extensions. Getting Started --------------- -After successfully installing the extension, you are prepared to execute Prometheus Salt extension modules. +After successfully installing the extension, you are prepared to execute Prometheus Salt extension modules. .. raw:: html
-**Example:** Apply a test state using the prometheus_textfile as the returner +**Example:** Apply a test state using the prometheus_textfile as the returner -Create a test.sls file in directory /srv/salt +Create a test.sls file in directory /srv/salt /srv/salt/test.sls @@ -76,8 +76,8 @@ Create a test.sls file in directory /srv/salt Execute the following command -.. code-block:: - +.. code-block:: + salt \* state.apply test --return prometheus_textfile @@ -85,7 +85,7 @@ You should see an output file created on the minion machine (default location: * **Example output file:** - .. code-block:: + .. code-block:: salt_last_completed 1.698364953e+09 # HELP salt_version Version of installed Salt package @@ -99,4 +99,4 @@ You should see an output file created on the minion machine (default location: * Additional Resources -------------------- -For more detailed information on functionality, use cases, and configuration, please vist our :ref:`user-documentation` \ No newline at end of file +For more detailed information on functionality, use cases, and configuration, please vist our :ref:`user-documentation` diff --git a/docs/user_documentation.rst b/docs/topics/user_documentation.rst similarity index 95% rename from docs/user_documentation.rst rename to docs/topics/user_documentation.rst index 2278840..0603f90 100644 --- a/docs/user_documentation.rst +++ b/docs/topics/user_documentation.rst @@ -35,7 +35,7 @@ Prometheus textfile module is a custom returner module. **What's a salt returner module?** A returner module defines the method and format in which the results of Salt execution commands are transmitted from the minions back to the master. -This module is used to output a `Text Exposition Format `_ file on the minion. The output includes salt specific metrics gathered from the minion. The output is formatted to a file that can be ingested by Prometheus infrastructure for monitoring purposes. See detailed module documentation: :ref:`prometheus_textfile` +This module is used to output a `Text Exposition Format `_ file on the minion. The output includes salt specific metrics gathered from the minion. The output is formatted to a file that can be ingested by Prometheus infrastructure for monitoring purposes. To use the extension, you will need to provide a Salt state command and add a return flag pointed to the `prometheus_textfile` module. You can also utilize different configuration files to set the returner module. @@ -105,11 +105,11 @@ Method 1: Using pip
-Method 2: Using salt +Method 2: Using salt ~~~~~~~~~~~~~~~~~~~~ 1. Verify salt is installed on the target machine 2. Run the following command to install the Prometheus Salt extension: - + .. code-block:: bash salt \* pip.install saltext-prometheus @@ -121,12 +121,12 @@ Method 2: Using salt Verify that the extension is installed by running the following command: -.. code-block:: - +.. code-block:: + salt --versions-report -You should see `saltext.prometheus` listed under Salt extensions. +You should see `saltext.prometheus` listed under Salt extensions. @@ -138,7 +138,7 @@ After successfully installing the extension, you are ready to execute Prometheus
-**Example:** Apply a test state using the prometheus_textfile as the returner +**Example:** Apply a test state using the prometheus_textfile as the returner 1. Create a test.sls file in the directory /srv/salt @@ -154,8 +154,8 @@ After successfully installing the extension, you are ready to execute Prometheus 2. Execute the following command: -.. code-block:: - +.. code-block:: + salt \* state.apply test --return prometheus_textfile @@ -163,7 +163,7 @@ After successfully installing the extension, you are ready to execute Prometheus **Example output file:** - .. code-block:: + .. code-block:: salt_last_completed 1.698364953e+09 # HELP salt_version Version of installed Salt package @@ -194,9 +194,9 @@ In directory **/etc/salt/minion.d** we created a file called **prometheus.conf** `The example configuration sets the return to the prometheus_textfile and sets the prometheus_textfile location to a custom location.` -**Configurable Options** +**Configurable Options** -Prometheus Textfile: See module documentation - :ref:`prometheus_textfile` +Prometheus Textfile: See module documentation Uninstall @@ -204,7 +204,6 @@ Uninstall You can uninstall the Prometheus Salt Extension using pip: -.. code-block:: +.. code-block:: pip uninstall prometheus-salt - diff --git a/noxfile.py b/noxfile.py old mode 100644 new mode 100755 index 653a875..f31cee7 --- a/noxfile.py +++ b/noxfile.py @@ -1,4 +1,4 @@ -# pylint: disable=missing-module-docstring,import-error,protected-access,missing-function-docstring,consider-using-f-string +# pylint: disable=missing-module-docstring,import-error,protected-access,missing-function-docstring import datetime import json import os @@ -19,7 +19,7 @@ nox.options.error_on_missing_interpreters = False # Python versions to test against -PYTHON_VERSIONS = ("3", "3.7", "3.8", "3.9", "3.10") +PYTHON_VERSIONS = ("3", "3.8", "3.9", "3.10") # Be verbose when running under a CI context CI_RUN = ( os.environ.get("JENKINS_URL") or os.environ.get("CI") or os.environ.get("DRONE") is not None @@ -29,7 +29,7 @@ EXTRA_REQUIREMENTS_INSTALL = os.environ.get("EXTRA_REQUIREMENTS_INSTALL") COVERAGE_VERSION_REQUIREMENT = "coverage==5.2" -SALT_REQUIREMENT = os.environ.get("SALT_REQUIREMENT") or "salt>=3003rc1" +SALT_REQUIREMENT = os.environ.get("SALT_REQUIREMENT") or "salt>=3005" if SALT_REQUIREMENT == "salt==master": SALT_REQUIREMENT = "git+https://github.com/saltstack/salt.git@master" @@ -44,9 +44,8 @@ ARTIFACTS_DIR = REPO_ROOT / "artifacts" # Make sure the artifacts directory exists ARTIFACTS_DIR.mkdir(parents=True, exist_ok=True) -RUNTESTS_LOGFILE = ARTIFACTS_DIR / "runtests-{}.log".format( - datetime.datetime.now().strftime("%Y%m%d%H%M%S.%f") -) +CUR_TIME = datetime.datetime.now().strftime("%Y%m%d%H%M%S.%f") +RUNTESTS_LOGFILE = ARTIFACTS_DIR / f"runtests-{CUR_TIME}.log" COVERAGE_REPORT_DB = REPO_ROOT / ".coverage" COVERAGE_REPORT_PROJECT = ARTIFACTS_DIR.relative_to(REPO_ROOT) / "coverage-project.xml" COVERAGE_REPORT_TESTS = ARTIFACTS_DIR.relative_to(REPO_ROOT) / "coverage-tests.xml" @@ -59,7 +58,8 @@ def _get_session_python_version_info(session): except AttributeError: session_py_version = session.run_always( "python", - "-c" 'import sys; sys.stdout.write("{}.{}.{}".format(*sys.version_info))', + "-c", + 'import sys; sys.stdout.write("{}.{}.{}".format(*sys.version_info))', silent=True, log=False, ) @@ -70,9 +70,9 @@ def _get_session_python_version_info(session): def _get_pydir(session): version_info = _get_session_python_version_info(session) - if version_info < (3, 5): - session.error("Only Python >= 3.5 is supported") - return "py{}.{}".format(*version_info) + if version_info < (3, 8): + session.error("Only Python >= 3.8 is supported") + return f"py{version_info[0]}.{version_info[1]}" def _install_requirements( @@ -292,9 +292,7 @@ def _lint(session, rcfile, flags, paths, tee_output=True): sys.stdout.flush() if pylint_report_path: # Write report - with open( # pylint: disable=unspecified-encoding - pylint_report_path, "w" - ) as wfh: + with open(pylint_report_path, "w", encoding="utf-8") as wfh: wfh.write(contents) session.log("Report file written to %r", pylint_report_path) stdout.close() @@ -309,9 +307,7 @@ def _lint_pre_commit(session, rcfile, flags, paths): if "pre-commit" not in os.environ["VIRTUAL_ENV"]: session.error( "This should be running from within a pre-commit virtualenv and " - "'VIRTUAL_ENV'({}) does not appear to be a pre-commit virtualenv.".format( - os.environ["VIRTUAL_ENV"] - ) + f"'VIRTUAL_ENV'({os.environ['VIRTUAL_ENV']}) does not appear to be a pre-commit virtualenv." ) # Let's patch nox to make it run inside the pre-commit virtualenv @@ -491,20 +487,15 @@ def docs_crosslink_info(session): log=False, ) ) + intersphinx_mapping_list = ", ".join(list(intersphinx_mapping)) try: mapping_entry = intersphinx_mapping[session.posargs[0]] except IndexError: session.error( - "You need to pass at least one argument whose value must be one of: {}".format( - ", ".join(list(intersphinx_mapping)) - ) + f"You need to pass at least one argument whose value must be one of: {intersphinx_mapping_list}" ) except KeyError: - session.error( - "Only acceptable values for first argument are: {}".format( - ", ".join(list(intersphinx_mapping)) - ) - ) + session.error(f"Only acceptable values for first argument are: {intersphinx_mapping_list}") session.run( "python", "-m", "sphinx.ext.intersphinx", mapping_entry[0].rstrip("/") + "/objects.inv" ) diff --git a/pyproject.toml b/pyproject.toml index f30b8eb..4447e1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,15 +1,118 @@ [build-system] -requires = ["setuptools>=50.3.2", "wheel", "setuptools-declarative-requirements"] +requires = [ + "wheel", + "setuptools>=50.3.2", + "setuptools_scm[toml]>=3.4", +] build-backend = "setuptools.build_meta" +[tool.setuptools_scm] +write_to = "src/saltext/prometheus/version.py" +write_to_template = "__version__ = \"{version}\"" + +[project] +name = "saltext.prometheus" +description = "Salt Extension for interacting with Prometheus" +authors = [ + {name = "EITR Technologies, LLC", email = "devops@eitr.tech"}, +] +keywords = [ + "salt-extension", +] +license = {text = "Apache Software License"} +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Cython", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", +] +requires-python = ">= 3.8" +dynamic = ["version"] +dependencies = [ + "prometheus_client", + "salt>=3005", +] + +[project.readme] +file = "README.md" +content-type = "text/markdown" + +[project.urls] +Homepage = "https://github.com/salt-extensions/saltext-prometheus" +Source = "https://github.com/salt-extensions/saltext-prometheus" +Tracker = "https://github.com/salt-extensions/saltext-prometheus/issues" + +[project.optional-dependencies] +changelog = ["towncrier==22.12.0"] +dev = [ + "nox", + "pre-commit>=2.4.0", + "pylint", + "saltpylint", +] +docs = [ + "sphinx", + "sphinx-prompt", + "sphinxcontrib-spelling", + "sphinx-copybutton", + "towncrier==22.12.0", + "sphinxcontrib-towncrier", + "myst_parser", + "furo", + "sphinx-inline-tabs", +] +docsauto = ["sphinx-autobuild"] +lint = [ + "pylint", + "saltpylint", +] +tests = [ + "pytest>=6.1.0", + "pytest-salt-factories>=1.0.0rc19", +] + +[project.entry-points."salt.loader"] +"saltext.prometheus" = "saltext.prometheus" + +[tool.setuptools] +zip-safe = false +include-package-data = true +platforms = ["any"] + +[tool.setuptools.packages.find] +where = ["src"] +exclude = ["tests"] + +[tool.distutils.bdist_wheel] +# Use this option if your package is pure-python +universal = 1 + +[tool.distutils.sdist] +owner = "root" +group = "root" + +[tool.build_sphinx] +source_dir = "docs" +build_dir = "build/sphinx" + [tool.black] line-length = 100 [tool.towncrier] package = "saltext.prometheus" filename = "CHANGELOG.md" + template = "changelog/.template.jinja" directory = "changelog/" start_string = "# Changelog\n" + underlines = ["", "", ""] + title_format = "## {version} ({project_date})" + issue_format = "[#{issue}](https://github.com/salt-extensions/saltext-prometheus/issues/{issue})" [[tool.towncrier.type]] directory = "removed" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 4081f45..0000000 --- a/setup.cfg +++ /dev/null @@ -1,86 +0,0 @@ -[metadata] -name = saltext.prometheus -description = Salt Extension Modules for Prometheus -long_description = file: README.md -long_description_content_type = text/markdown -author = EITR Technologies, LLC -author_email = devops@eitr.tech -keywords = salt-extension, salt, prometheus -url = https://github.com/salt-extensions/saltext-prometheus -project_urls = - Source=https://github.com/salt-extensions/saltext-prometheus - Tracker=https://github.com/salt-extensions/saltext-prometheus/issues -license = Apache Software License -classifiers = - Programming Language :: Python - Programming Language :: Cython - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Development Status :: 4 - Beta - Intended Audience :: Developers - License :: OSI Approved :: Apache Software License -platforms = any - -[options] -zip_safe = False -include_package_data = True -package_dir = - =src -packages = find_namespace: -python_requires = >= 3.6 -setup_requires = - wheel - setuptools>=50.3.2 - setuptools-declarative-requirements -install_requires = - prometheus_client - # Add other module install requirements above this line - -[options.packages.find] -where = src -exclude = - tests - - -[options.entry_points] -salt.loader= - saltext.prometheus = saltext.prometheus - - -[options.extras_require] -tests = - mock==3.0.5 - pytest==7.2.0 - pytest-salt-factories>=1.0.0rc23 - Jinja2 -dev = - nox==2022.1.7 - pre-commit==2.13.0 - pylint<2.14.0 - SaltPyLint -docs = - sphinx>=3.5.1 - Jinja2 - furo - sphinx-copybutton - sphinx-prompt - sphinxcontrib-spelling - importlib_metadata; python_version < "3.8" -docsauto = - sphinx-autobuild -release = - twine - wheel - -[bdist_wheel] -# Use this option if your package is pure-python -universal = 1 - -[build_sphinx] -source_dir = docs -build_dir = build/sphinx diff --git a/setup.py b/setup.py index 40704fa..f999679 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,5 @@ # pylint: disable=missing-module-docstring -from pathlib import Path - import setuptools -version_path = Path(__file__).parent / "src" / "saltext" / "prometheus" / "version.py" - -with version_path.open() as f: - for line in f: - if line.startswith("__version__"): - # We only want the bare string pls - version = line.partition("=")[-1].strip().strip('"').strip("'") - break - else: - version = "0.0.1dev1" # pylint: disable=invalid-name - - if __name__ == "__main__": - setuptools.setup(use_scm_version=True, version=version) + setuptools.setup(use_scm_version=True) diff --git a/src/saltext/prometheus/returners/prometheus_textfile.py b/src/saltext/prometheus/returners/prometheus_textfile.py index c745343..917f57f 100644 --- a/src/saltext/prometheus/returners/prometheus_textfile.py +++ b/src/saltext/prometheus/returners/prometheus_textfile.py @@ -364,12 +364,10 @@ def returner(ret): for state_id, state_return in ret["return"].items(): if state_return["result"] is False: failed_comment = state_return.get("comment", "").replace('"', "").replace("\n", " ") - # pylint: disable=whitespace-before-colon label_values = [ state_id.split("_|-")[1], failed_comment[0 : opts["fail_comment_length"]], ] - # pylint: enable=whitespace-before-colon if opts["add_state_name"]: label_values.append(prom_state) gauge_show_failed_states.labels(*label_values).set(1) @@ -388,7 +386,7 @@ def returner(ret): if opts["add_state_name"]: old_name, ext = os.path.splitext(opts["filename"]) - opts["filename"] = "{}-{}{}".format(old_name, prom_state, ext) + opts["filename"] = f"{old_name}-{prom_state}{ext}" log.debug( "Modified Prometheus filename from %s to %s", old_name + ext, diff --git a/src/saltext/prometheus/version.py b/src/saltext/prometheus/version.py deleted file mode 100644 index 795f1a8..0000000 --- a/src/saltext/prometheus/version.py +++ /dev/null @@ -1,2 +0,0 @@ -# pylint: disable=missing-module-docstring -__version__ = "2.0.3" diff --git a/tests/conftest.py b/tests/conftest.py index f628e0f..d73622a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,4 @@ +import logging import os import pytest @@ -5,6 +6,17 @@ from saltfactories.utils import random_string +# Reset the root logger to its default level(because salt changed it) +logging.root.setLevel(logging.WARNING) + + +# This swallows all logging to stdout. +# To show select logs, set --log-cli-level= +for handler in logging.root.handlers[:]: + logging.root.removeHandler(handler) + handler.close() + + @pytest.fixture(scope="session") def salt_factories_config(): """ @@ -12,7 +24,6 @@ def salt_factories_config(): """ return { "code_dir": str(PACKAGE_ROOT), - "inject_coverage": "COVERAGE_PROCESS_START" in os.environ, "inject_sitecustomize": "COVERAGE_PROCESS_START" in os.environ, "start_timeout": 120 if os.environ.get("CI") else 60, } diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py new file mode 100644 index 0000000..2c7c84a --- /dev/null +++ b/tests/functional/conftest.py @@ -0,0 +1,150 @@ +import logging +import shutil + +import pytest +from saltfactories.utils.functional import Loaders + +log = logging.getLogger(__name__) + + +@pytest.fixture(scope="package") +def minion_id(): + return "func-tests-minion-opts" + + +@pytest.fixture(scope="module") +def state_tree(tmp_path_factory): + state_tree_path = tmp_path_factory.mktemp("state-tree-base") + try: + yield state_tree_path + finally: + shutil.rmtree(str(state_tree_path), ignore_errors=True) + + +@pytest.fixture(scope="module") +def state_tree_prod(tmp_path_factory): + state_tree_path = tmp_path_factory.mktemp("state-tree-prod") + try: + yield state_tree_path + finally: + shutil.rmtree(str(state_tree_path), ignore_errors=True) + + +@pytest.fixture(scope="module") +def minion_config_defaults(): + """ + Functional test modules can provide this fixture to tweak the default + configuration dictionary passed to the minion factory + """ + return {} + + +@pytest.fixture(scope="module") +def minion_config_overrides(): + """ + Functional test modules can provide this fixture to tweak the configuration + overrides dictionary passed to the minion factory + """ + return {} + + +@pytest.fixture(scope="module") +def minion_opts( + salt_factories, + minion_id, + state_tree, + state_tree_prod, + minion_config_defaults, + minion_config_overrides, +): + minion_config_overrides.update( + { + "file_client": "local", + "file_roots": { + "base": [ + str(state_tree), + ], + "prod": [ + str(state_tree_prod), + ], + }, + } + ) + factory = salt_factories.salt_minion_daemon( + minion_id, + defaults=minion_config_defaults or None, + overrides=minion_config_overrides, + ) + return factory.config.copy() + + +@pytest.fixture(scope="module") +def master_config_defaults(): + """ + Functional test modules can provide this fixture to tweak the default + configuration dictionary passed to the master factory + """ + return {} + + +@pytest.fixture(scope="module") +def master_config_overrides(): + """ + Functional test modules can provide this fixture to tweak the configuration + overrides dictionary passed to the master factory + """ + return {} + + +@pytest.fixture(scope="module") +def master_opts( + salt_factories, + state_tree, + state_tree_prod, + master_config_defaults, + master_config_overrides, +): + master_config_overrides.update( + { + "file_client": "local", + "file_roots": { + "base": [ + str(state_tree), + ], + "prod": [ + str(state_tree_prod), + ], + }, + } + ) + factory = salt_factories.salt_master_daemon( + "func-tests-master-opts", + defaults=master_config_defaults or None, + overrides=master_config_overrides, + ) + return factory.config.copy() + + +@pytest.fixture(scope="module") +def loaders(minion_opts): + return Loaders(minion_opts, loaded_base_name=f"{__name__}.loaded") + + +@pytest.fixture(autouse=True) +def reset_loaders_state(loaders): + try: + # Run the tests + yield + finally: + # Reset the loaders state + loaders.reset_state() + + +@pytest.fixture(scope="module") +def modules(loaders): + return loaders.modules + + +@pytest.fixture(scope="module") +def states(loaders): + return loaders.states diff --git a/tests/functional/engines/__init__.py b/tests/functional/engines/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/returners/__init__.py b/tests/functional/returners/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 532de7d..9bd9458 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -15,14 +15,14 @@ def minion(minion): @pytest.fixture def salt_run_cli(master): - return master.get_salt_run_cli() + return master.salt_run_cli() @pytest.fixture def salt_cli(master): - return master.get_salt_cli() + return master.salt_cli() @pytest.fixture def salt_call_cli(minion): - return minion.get_salt_call_cli() + return minion.salt_call_cli() diff --git a/tests/support/mock.py b/tests/support/mock.py index 1fb5cb4..6e167e0 100644 --- a/tests/support/mock.py +++ b/tests/support/mock.py @@ -112,14 +112,12 @@ def __check_read_data(self): if self.binary_mode: if not isinstance(self.read_data, bytes): raise TypeError( - "{} opened in binary mode, expected read_data to be " - "bytes, not {}".format(self.filename, type(self.read_data).__name__) + f"{self.filename} opened in binary mode, expected read_data to be bytes, not {type(self.read_data).__name__}" ) else: if not isinstance(self.read_data, str): raise TypeError( - "{} opened in non-binary mode, expected read_data to " - "be str, not {}".format(self.filename, type(self.read_data).__name__) + f"{self.filename} opened in non-binary mode, expected read_data to be str, not {type(self.read_data).__name__}" ) # No need to repeat this the next time we check self.__read_data_ok = True @@ -184,13 +182,9 @@ def _write(self, content): else: content_type = type(content) if self.binary_mode and content_type is not bytes: - raise TypeError( - "a bytes-like object is required, not '{}'".format(content_type.__name__) - ) + raise TypeError(f"a bytes-like object is required, not '{content_type.__name__}'") elif not self.binary_mode and content_type is not str: - raise TypeError( - "write() argument must be str, not {}".format(content_type.__name__) - ) + raise TypeError(f"write() argument must be str, not {content_type.__name__}") def _writelines(self, lines): if not self.write_mode: @@ -224,7 +218,7 @@ def __repr__(self): ret = ret[:-2] else: for key, val in self.kwargs.items(): - ret += "{}={}".format(salt.utils.stringutils.to_str(key), repr(val)) + ret += f"{salt.utils.stringutils.to_str(key)}={repr(val)}" ret += ")" return ret @@ -380,8 +374,7 @@ def __call__(self, name, *args, **kwargs): except IndexError: # We've run out of file contents, abort! raise RuntimeError( - "File matching expression '{}' opened more times than " - "expected".format(matched_pattern) + f"File matching expression '{matched_pattern}' opened more times than expected" ) from None try: diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py new file mode 100644 index 0000000..3e3fa4a --- /dev/null +++ b/tests/unit/conftest.py @@ -0,0 +1,57 @@ +import pytest +import salt.config + + +@pytest.fixture +def minion_opts(tmp_path): + """ + Default minion configuration with relative temporary paths to not + require root permissions. + """ + root_dir = tmp_path / "minion" + opts = salt.config.DEFAULT_MINION_OPTS.copy() + opts["__role"] = "minion" + opts["root_dir"] = str(root_dir) + for name in ("cachedir", "pki_dir", "sock_dir", "conf_dir"): + dirpath = root_dir / name + dirpath.mkdir(parents=True) + opts[name] = str(dirpath) + opts["log_file"] = "logs/minion.log" + return opts + + +@pytest.fixture +def master_opts(tmp_path): + """ + Default master configuration with relative temporary paths to not + require root permissions. + """ + root_dir = tmp_path / "master" + opts = salt.config.master_config(None) + opts["__role"] = "master" + opts["root_dir"] = str(root_dir) + for name in ("cachedir", "pki_dir", "sock_dir", "conf_dir"): + dirpath = root_dir / name + dirpath.mkdir(parents=True) + opts[name] = str(dirpath) + opts["log_file"] = "logs/master.log" + return opts + + +@pytest.fixture +def syndic_opts(tmp_path): + """ + Default master configuration with relative temporary paths to not + require root permissions. + """ + root_dir = tmp_path / "syndic" + opts = salt.config.DEFAULT_MINION_OPTS.copy() + opts["syndic_master"] = "127.0.0.1" + opts["__role"] = "minion" + opts["root_dir"] = str(root_dir) + for name in ("cachedir", "pki_dir", "sock_dir", "conf_dir"): + dirpath = root_dir / name + dirpath.mkdir(parents=True) + opts[name] = str(dirpath) + opts["log_file"] = "logs/syndic.log" + return opts diff --git a/tests/unit/returners/test_prometheus_textfile_return.py b/tests/unit/returners/test_prometheus_textfile_return.py index 0fef735..f2bfe03 100644 --- a/tests/unit/returners/test_prometheus_textfile_return.py +++ b/tests/unit/returners/test_prometheus_textfile_return.py @@ -117,10 +117,12 @@ def test_basic_prometheus_output_with_default_options(patch_dunders, job_ret, ca "# TYPE salt_last_completed gauge", "# HELP salt_version Version of installed Salt package", "# TYPE salt_version gauge", - "salt_version {}".format(salt.version.__version__.split("rc", maxsplit=1)[0]), + "salt_version {}".format( # pylint: disable=consider-using-f-string + salt.version.__version__.split("rc", maxsplit=1)[0] + ), "# HELP salt_version_tagged Version of installed Salt package as a tag", "# TYPE salt_version_tagged gauge", - 'salt_version_tagged{{salt_version="{}"}} 1.0'.format(salt.version.__version__), + f'salt_version_tagged{{salt_version="{salt.version.__version__}"}} 1.0', ] ) ) @@ -170,43 +172,43 @@ def test_when_add_state_name_is_set_then_correct_output_should_be_in_correct_fil [ "# HELP salt_procs Number of salt minion processes running", "# TYPE salt_procs gauge", - 'salt_procs{{state="{}"}} 0.0'.format(state_name), + f'salt_procs{{state="{state_name}"}} 0.0', "# HELP salt_states_succeeded Number of successful states in the run", "# TYPE salt_states_succeeded gauge", - 'salt_states_succeeded{{state="{}"}} 2.0'.format(state_name), + f'salt_states_succeeded{{state="{state_name}"}} 2.0', "# HELP salt_states_failed Number of failed states in the run", "# TYPE salt_states_failed gauge", - 'salt_states_failed{{state="{}"}} 0.0'.format(state_name), + f'salt_states_failed{{state="{state_name}"}} 0.0', "# HELP salt_states_changed Number of changed states in the run", "# TYPE salt_states_changed gauge", - 'salt_states_changed{{state="{}"}} 2.0'.format(state_name), + f'salt_states_changed{{state="{state_name}"}} 2.0', "# HELP salt_states_total Total states in the run", "# TYPE salt_states_total gauge", - 'salt_states_total{{state="{}"}} 2.0'.format(state_name), + f'salt_states_total{{state="{state_name}"}} 2.0', "# HELP salt_states_success_pct Percent of successful states in the run", "# TYPE salt_states_success_pct gauge", - 'salt_states_success_pct{{state="{}"}} 100.0'.format(state_name), + f'salt_states_success_pct{{state="{state_name}"}} 100.0', "# HELP salt_states_failure_pct Percent of failed states in the run", "# TYPE salt_states_failure_pct gauge", - 'salt_states_failure_pct{{state="{}"}} 0.0'.format(state_name), + f'salt_states_failure_pct{{state="{state_name}"}} 0.0', "# HELP salt_states_changed_pct Percent of changed states in the run", "# TYPE salt_states_changed_pct gauge", - 'salt_states_changed_pct{{state="{}"}} 100.0'.format(state_name), + f'salt_states_changed_pct{{state="{state_name}"}} 100.0', "# HELP salt_elapsed_time Time spent for all operations during the state run", "# TYPE salt_elapsed_time gauge", - 'salt_elapsed_time{{state="{}"}} 13.695'.format(state_name), + f'salt_elapsed_time{{state="{state_name}"}} 13.695', "# HELP salt_last_started Estimated time the state run started", "# TYPE salt_last_started gauge", "# HELP salt_last_completed Time of last state run completion", "# TYPE salt_last_completed gauge", "# HELP salt_version Version of installed Salt package", "# TYPE salt_version gauge", - 'salt_version{{state="{}"}} {}'.format( + 'salt_version{{state="{}"}} {}'.format( # pylint: disable=consider-using-f-string state_name, salt.version.__version__.split("rc", maxsplit=1)[0] ), "# HELP salt_version_tagged Version of installed Salt package as a tag", "# TYPE salt_version_tagged gauge", - 'salt_version_tagged{{salt_version="{}",state="{}"}} 1.0'.format( + 'salt_version_tagged{{salt_version="{}",state="{}"}} 1.0'.format( # pylint: disable=consider-using-f-string salt.version.__version__, state_name ), ] @@ -267,10 +269,12 @@ def test_prometheus_output_with_show_failed_state_option_and_abort_state_ids( "# TYPE salt_last_completed gauge", "# HELP salt_version Version of installed Salt package", "# TYPE salt_version gauge", - "salt_version {}".format(salt.version.__version__.split("rc", maxsplit=1)[0]), + "salt_version {}".format( # pylint: disable=consider-using-f-string + salt.version.__version__.split("rc", maxsplit=1)[0] + ), "# HELP salt_version_tagged Version of installed Salt package as a tag", "# TYPE salt_version_tagged gauge", - 'salt_version_tagged{{salt_version="{}"}} 1.0'.format(salt.version.__version__), + f'salt_version_tagged{{salt_version="{salt.version.__version__}"}} 1.0', "# HELP salt_failed Information regarding state with failure condition", "# TYPE salt_failed gauge", 'salt_failed{state_comment="Command echo includeme run",state_id="echo includeme"} 1.0', @@ -385,10 +389,12 @@ def test_fail_comments_lengths(patch_dunders, job_ret, cache_dir, minion): "# TYPE salt_last_completed gauge", "# HELP salt_version Version of installed Salt package", "# TYPE salt_version gauge", - "salt_version {}".format(salt.version.__version__.split("rc", maxsplit=1)[0]), + "salt_version {}".format( # pylint: disable=consider-using-f-string + salt.version.__version__.split("rc", maxsplit=1)[0] + ), "# HELP salt_version_tagged Version of installed Salt package as a tag", "# TYPE salt_version_tagged gauge", - 'salt_version_tagged{{salt_version="{}"}} 1.0'.format(salt.version.__version__), + f'salt_version_tagged{{salt_version="{salt.version.__version__}"}} 1.0', "# HELP salt_failed Information regarding state with failure condition", "# TYPE salt_failed gauge", 'salt_failed{state_comment="Command echo includeme run",state_id="echo includeme"} 1.0', @@ -454,10 +460,12 @@ def test_fail_comments_lengths(patch_dunders, job_ret, cache_dir, minion): "# TYPE salt_last_completed gauge", "# HELP salt_version Version of installed Salt package", "# TYPE salt_version gauge", - "salt_version {}".format(salt.version.__version__.split("rc", maxsplit=1)[0]), + "salt_version {}".format( # pylint: disable=consider-using-f-string + salt.version.__version__.split("rc", maxsplit=1)[0] + ), "# HELP salt_version_tagged Version of installed Salt package as a tag", "# TYPE salt_version_tagged gauge", - 'salt_version_tagged{{salt_version="{}"}} 1.0'.format(salt.version.__version__), + f'salt_version_tagged{{salt_version="{salt.version.__version__}"}} 1.0', "# HELP salt_failed Information regarding state with failure condition", "# TYPE salt_failed gauge", 'salt_failed{state_comment="Command echo in",state_id="echo includeme"} 1.0', @@ -574,6 +582,7 @@ def test_requisite_handling(patch_dunders, cache_dir, minion): assert Path(os.path.join(cache_dir, "prometheus_textfile", "salt.prom")).exists() +@pytest.mark.skip_on_windows(reason="mode setting not available on Windows") def test_mode_passed_to_set_mode(patch_dunders, cache_dir, job_ret, minion): mock_set_mode = MagicMock(return_value=True) prometheus_textfile.__opts__.update({"mode": "0644"})