juju_verify.utils.unit module¶
Helper function to manage Juju unit.
- juju_verify.utils.unit.find_unit_by_hostname(model: Model, hostname: str, charm: str) Unit¶
Find unit by hostname.
- async juju_verify.utils.unit.find_units(model: Model, units: List[str]) List[Unit]¶
Return list of juju.Unit objects that match with names in ‘units’ parameter.
This function will exit program with error message if any of units is not found in the juju model.
- Parameters:
model – Juju model to search units in
units – List of unit names to search
- Returns:
List of matching juju.Unit objects
- async juju_verify.utils.unit.find_units_on_machine(model: Model, machines: List[str]) List[Unit]¶
Find all principal units that run on selected machines.
- Parameters:
model – Juju model to search units in
machines – names of Juju machines on which to search units
- Returns:
List of juju.Unit objects that match units running on the machines
- juju_verify.utils.unit.get_applications_names(model: Model, application: str) List[str]¶
Get all names of application based on the same charm.
- juju_verify.utils.unit.get_cache_key(unit: Unit, action: str, **params: Any) int¶
Create hash key from unit, action and params.
- juju_verify.utils.unit.get_first_active_unit(units: List[Unit]) Optional[Unit]¶
Find first unit in active workload status.
Get all units for the same charm related to application.
- Parameters:
application – Juju application
charm – charm name, e.g. ceph-osd
- juju_verify.utils.unit.parse_charm_name(charm_url: str) str¶
Parse charm name from full charm url.
Example: ‘cs:focal/nova-compute-141’ -> ‘nova-compute’
- juju_verify.utils.unit.run_action_on_unit(unit: Unit, action: str, use_cache: bool = True, params: Optional[Dict[str, Any]] = None) Action¶
Run juju action on single unit.
For more info, see docstring for ‘run_action_on_units’. The only difference is that this function returns Action object directly, not dict {unit_id: action}.
- juju_verify.utils.unit.run_action_on_units(units: List[Unit], action: str, use_cache: bool = True, params: Optional[Dict[str, Any]] = None) Dict[str, Action]¶
Run Juju action on specified units.
- Parameters:
units – List/Tuple of Unit object
action – Action to run on units
use_cache – Use the cache to gather the result of the action
params – Additional parameters for the action
- Returns:
Dict in format {unit_id: action} where unit_ids are strings provided in ‘units’ and actions are their matching, juju.Action objects that have been executed and awaited.
- juju_verify.utils.unit.run_command_on_unit(unit: Unit, command: str, use_cache: bool = True) Action¶
Run command on unit.
Execute is same as juju run –unit <unit> – <command>
- juju_verify.utils.unit.verify_charm_unit(charm_name: str, *units: Unit) None¶
Verify that units are based on required charm.