Skip to main content

Juju-doctor is a pypi package which helps validate Juju deployments using probes.

Project description

🩺 juju-doctor 🩺

PyPI Release

Run a configurable set of probes (assertions) against Juju deployment artifacts, which are the output of other tools like juju, sosreport, and kubectl. To enforce best practices, these probes are organized into a ruleset, which acts as a guide for correct deployment configurations.

Usage

Here's some typical usage examples:

 juju-doctor check --help # displays the help

You can run juju-doctor against a solution archive:

∮ juju-doctor check \
    --probe file://tests/resources/probes/python/failing.py \
    --probe file://tests/resources/probes/python/passing.py \
    --status=status.yaml \
    --status=status.yaml

If you have a live deplyoment, you can also run juju-doctor against that:

∮ juju-doctor check \
    --probe file://tests/resources/probes/python/failing.py \
    --probe file://tests/resources/probes/python/passing.py \
    --model testy \
    --model testy-two

In either case, the output will look like so (configurable with --format and --verbose):

Results
├── fail
│   └── 🔴 tests_resources_probes_python_failing.py (bundle, show_unit, status)
└── pass
    └── 🟢 tests_resources_probes_python_passing.py


Total: 🟢 3 🔴 3

The path to a probe can also be a url:

# Run a remote probe against a live model juju-doctor check --model cos --probe github://canonical/grafana-k8s-operator//probes/some_probe.py

Writing Probes

Scriptlet

Scriptlet probes are written in Python, and can run on standardized artifacts that can be provided either as static files, or gathered from a live model.

Currently, we support the following artifacts:

  • status: juju status --format=yaml
  • bundle: juju export-bundle
  • show_unit: juju show-unit --format=yaml

To write a probe, you should start by choosing an artifact. Your code will only have access to one artifact type at a time, but the input information can span multiple models.

Then, write a function named after your artifact (e.g., status, bundle, etc.) that takes one Dict argument: the artifact of choice indexed by model name. The function should raise an exception if you want your probe to fail, explaining why it failed.

Let's look at an example.

from typing import Dict

def status(juju_statuses: Dict[str, Dict]): # {'cos': juju_status_dict, ...}
    ... # do things with the Juju statuses
    if not all_good:
        raise Exception("'coconut' charm shouldn't be there!")

def bundle(juju_bundles: Dict[str, Dict]):
    ... # do things with the Juju bundles
    if not passing:
      raise Exception("who deployed the 'coconut' charm?")

def _first_check(...):
    ...

def _second_check(...):
    ...

# You can split multiple checks in functions
def show_unit(juju_show_units):
    ...
    _first_check()
    _second_check()

Remember: juju-doctor will only run functions that exactly match a supported artifact name, and will always pass to them a dictionary of model name mapped to the proper artifact.

Ruleset

Ruleset probes are written in YAML, specifying which probes should be coordinated for a deployment validation.

Currently, we support the following probe types:

  • scriptlet: A Python probe
  • ruleset: A declarative deployment RuleSet
  • directory: A directory of probes (from the types in this list)
name: A declarative deployment RuleSet
probes:
  - name: Local probe - passing
    type: scriptlet
    url: file://tests/resources/probes/python/passing.py
  - name: Local ruleset
    type: ruleset
    url: file://tests/resources/probes/ruleset/ruleset.yaml
  - name: Local probe directory (may contain scriptlets and/or rulesets)
    type: directory
    url: file://tests/resources/probes/ruleset/small-dir

Development

git clone https://github.com/canonical/juju-doctor.git
uv sync --extra=dev && source .venv/bin/activate
uv pip install -e .
juju-doctor check --help

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

juju_doctor-0.1.5.tar.gz (183.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

juju_doctor-0.1.5-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file juju_doctor-0.1.5.tar.gz.

File metadata

  • Download URL: juju_doctor-0.1.5.tar.gz
  • Upload date:
  • Size: 183.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for juju_doctor-0.1.5.tar.gz
Algorithm Hash digest
SHA256 7516cbe7029fbfa2cd5c0beffaaa2b77f1b509c87a16b4dfc3766094dc1524be
MD5 bdc8b1b9244ad18098b8f405125d34c0
BLAKE2b-256 50b1c7e6122d136142b0e50460c33b2407def49636d9f006f7ce84b327567f61

See more details on using hashes here.

Provenance

The following attestation bundles were made for juju_doctor-0.1.5.tar.gz:

Publisher: release.yaml on canonical/juju-doctor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file juju_doctor-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: juju_doctor-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for juju_doctor-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2d55d7d512ef73244880744313fa81a413c0d9ecbd4332374fa3aa7a96ab483f
MD5 7843f13633107bcdc5586181a9cb4cc7
BLAKE2b-256 1c6fc9a22dadf542e1c71673b55a6f68ec0d40a794a92118fefa133062a14642

See more details on using hashes here.

Provenance

The following attestation bundles were made for juju_doctor-0.1.5-py3-none-any.whl:

Publisher: release.yaml on canonical/juju-doctor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page