Skip to content

Commit

Permalink
Additional missed docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Dec 4, 2024
1 parent 07fb71b commit b81f75a
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 20 deletions.
77 changes: 66 additions & 11 deletions src/molecule/provisioner/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,12 @@ def config_options(self) -> dict[str, Any]:
)

@property
def options(self) -> Options: # noqa: D102
def options(self) -> Options:
"""Appropriate options for provisioner.
Returns:
Dictionary of provisioner options.
"""
if self._config.action in ["create", "destroy"]:
return self.default_options

Expand All @@ -592,7 +597,12 @@ def options(self) -> Options: # noqa: D102
return util.merge_dicts(self.default_options, opts)

@property
def env(self) -> dict[str, str]: # noqa: D102
def env(self) -> dict[str, str]:
"""Full computed environment variables for provisioner.
Returns:
Complete set of collected environment variables.
"""
default_env = self.default_env
env = self._config.config["provisioner"]["env"].copy()
# ensure that all keys and values are strings
Expand All @@ -619,19 +629,39 @@ def env(self) -> dict[str, str]: # noqa: D102
return util.merge_dicts(default_env, env)

@property
def hosts(self) -> dict[str, str]: # noqa: D102
def hosts(self) -> dict[str, str]:
"""Provisioner inventory hosts.
Returns:
Dictionary of host names.
"""
return self._config.config["provisioner"]["inventory"]["hosts"]

@property
def host_vars(self) -> dict[str, str]: # noqa: D102
def host_vars(self) -> dict[str, str]:
"""Provisioner inventory host vars.
Returns:
Dictionary of host vars.
"""
return self._config.config["provisioner"]["inventory"]["host_vars"]

@property
def group_vars(self) -> dict[str, str]: # noqa: D102
def group_vars(self) -> dict[str, str]:
"""Provisioner inventory group vars.
Returns:
Dictionary of group vars.
"""
return self._config.config["provisioner"]["inventory"]["group_vars"]

@property
def links(self) -> dict[str, str]: # noqa: D102
def links(self) -> dict[str, str]:
"""Provisioner inventory links.
Returns:
Dictionary of links.
"""
return self._config.config["provisioner"]["inventory"]["links"]

@property
Expand Down Expand Up @@ -688,15 +718,30 @@ def inventory(self) -> dict[str, str]:
return self._default_to_regular(dd)

@property
def inventory_directory(self) -> str: # noqa: D102
def inventory_directory(self) -> str:
"""Inventory directory path.
Returns:
Path to the directory containing inventory files.
"""
return self._config.scenario.inventory_directory

@property
def inventory_file(self) -> str: # noqa: D102
def inventory_file(self) -> str:
"""Inventory file path.
Returns:
Path to ansible_inventory.yml
"""
return str(Path(self.inventory_directory, "ansible_inventory.yml"))

@property
def config_file(self) -> str: # noqa: D102
def config_file(self) -> str:
"""Configuration file path.
Returns:
Path to ansible.cfg.
"""
return str(
Path(
self._config.scenario.ephemeral_directory,
Expand All @@ -705,11 +750,21 @@ def config_file(self) -> str: # noqa: D102
)

@cached_property
def playbooks(self) -> ansible_playbooks.AnsiblePlaybooks: # noqa: D102
def playbooks(self) -> ansible_playbooks.AnsiblePlaybooks:
"""Ansible playbooks provisioner instance.
Returns:
AnsiblePlaybooks instance based on this config.
"""
return ansible_playbooks.AnsiblePlaybooks(self._config)

@property
def directory(self) -> str: # noqa: D102
def directory(self) -> str:
"""Ansible provisioner directory.
Returns:
Path to the ansible provisioner directory.
"""
return str(Path(__file__).parent.parent.parent / "molecule" / "provisioner" / "ansible")

def cleanup(self) -> None:
Expand Down
59 changes: 50 additions & 9 deletions src/molecule/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,39 +120,80 @@ def __init__(self, config: Config) -> None:
self._write_state_file()

@property
def state_file(self) -> str: # noqa: D102
def state_file(self) -> str:
"""State file path.
Returns:
Path to the state file.
"""
return str(self._state_file)

@property
def converged(self) -> bool: # noqa: D102
def converged(self) -> bool:
"""Is run converged.
Returns:
Whether the run has converged.
"""
return self._data["converged"]

@property
def created(self) -> bool: # noqa: D102
def created(self) -> bool:
"""Has scenario been created.
Returns:
Whether scenario has been created.
"""
return self._data["created"]

@property
def driver(self) -> str | None: # noqa: D102
def driver(self) -> str | None:
"""Driver for scenario.
Returns:
Name of the driver for the scenario.
"""
return self._data["driver"]

@property
def prepared(self) -> bool: # noqa: D102
def prepared(self) -> bool:
"""Has scenario prepare run.
Returns:
Whether scenario prepare has run.
"""
return self._data["prepared"]

@property
def run_uuid(self) -> str: # noqa: D102
def run_uuid(self) -> str:
"""Scenario run UUID.
Returns:
The UUID for this scenario run.
"""
return self._data["run_uuid"]

@property
def is_parallel(self) -> bool: # noqa: D102
def is_parallel(self) -> bool:
"""Is molecule in parallel mode.
Returns:
Whether Molecule is in parallel mode.
"""
return self._data["is_parallel"]

@property
def molecule_yml_date_modified(self) -> float | None: # noqa: D102
def molecule_yml_date_modified(self) -> float | None:
"""The modified date of molecule.yml.
Returns:
The timestamp of the last modification date of molecule.yml.
"""
return self._data["molecule_yml_date_modified"]

@marshal
def reset(self) -> None: # noqa: D102
def reset(self) -> None:
"""Reset state data."""
self._data = self._default_data()

@marshal
Expand Down

0 comments on commit b81f75a

Please sign in to comment.