Jubilant

1.8.0 · active · verified Fri Apr 17

Jubilant is a Python library that provides a high-level, asynchronous wrapper around the Juju CLI, primarily designed for integration testing of Juju charms. It simplifies programmatic interactions with Juju controllers and models, allowing for automation of deployments, configurations, and status checks. The library is actively maintained by Canonical, with frequent minor releases, and is currently at version 1.8.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Juju` client, add a temporary Juju model, deploy a charm, wait for its status, and then destroy the model. This example is asynchronous and requires the 'juju' CLI to be installed and configured on your system. Using `Juju.temp_model()` as a context manager is generally preferred for testing scenarios to ensure cleanup.

import asyncio
from jubilant import Juju

async def main():
    juju = Juju()
    model_name = "my-temp-test-model"
    print(f"Attempting to add Juju model: {model_name}")
    try:
        # Add a temporary model. For real tests, consider juju.temp_model()
        # which uses a context manager for automatic cleanup.
        await juju.add_model(model_name)
        print(f"Successfully added model '{model_name}'. Deploying charm...")
        
        # Deploy a simple charm
        await juju.deploy("ch:ubuntu", model=model_name)
        print("Ubuntu charm deployment initiated.")
        
        # Wait for the charm to be active
        await juju.wait_for_idle(apps=["ubuntu"], model=model_name)
        print("Ubuntu charm is active and idle.")
        
        status = await juju.get_status(model=model_name)
        print(f"Model '{model_name}' status: {status.model.status}")
        
    except Exception as e:
        print(f"An error occurred during Juju operations: {e}")
    finally:
        print(f"Attempting to destroy Juju model: {model_name}")
        await juju.destroy_model(model_name)
        print(f"Model '{model_name}' destroyed.")

if __name__ == "__main__":
    # This example requires the Juju CLI to be installed and configured
    # on your system, and supports Python 3.8+.
    asyncio.run(main())

view raw JSON →