Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RPD-274] [BUG] Fix inaccurate provisioning messages #177

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/matcha_ml/runners/azure_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def provision(self) -> None:
self._validate_terraform_config()
self._validate_kubeconfig(base_path=".kube/config")
self._initialize_terraform(msg="Matcha")
self._apply_terraform()
self._apply_terraform(msg="Matcha")
tf_output = self.tfs.terraform_client.output()
matcha_state_service = MatchaStateService(terraform_output=tf_output)
self._show_terraform_outputs(matcha_state_service._state)
Expand Down
21 changes: 16 additions & 5 deletions src/matcha_ml/runners/base_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ def _check_matcha_directory_exists(self) -> None:
)
raise typer.Exit()

def _apply_terraform(self) -> None:
def _apply_terraform(self, msg: str = "") -> None:
"""Run terraform apply to create resources on cloud.

Args:
msg (str) : Name of the type of resource (e.g. "Remote State" or "Matcha").

Raises:
MatchaTerraformError: if 'terraform apply' failed.
"""
Expand All @@ -147,11 +150,19 @@ def _apply_terraform(self) -> None:

if tf_result.return_code != 0:
raise MatchaTerraformError(tf_error=tf_result.std_err)
print_status(
build_substep_success_status(
f"{Emojis.CHECKMARK.value} Matcha resources have been provisioned!\n"

if msg:
print_status(
build_substep_success_status(
f"{Emojis.CHECKMARK.value} {msg} resources have been provisioned!\n"
)
)
else:
print_status(
build_substep_success_status(
f"{Emojis.CHECKMARK.value} Resources have been provisioned!\n"
)
)
)

def _destroy_terraform(self, msg: str = "") -> None:
"""Destroy the provisioned resources.
Expand Down
2 changes: 1 addition & 1 deletion src/matcha_ml/runners/remote_state_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def provision(self) -> Tuple[str, str, str]:
self._validate_terraform_config()
self._validate_kubeconfig(base_path=".kube/config")
self._initialize_terraform(msg="Remote State")
self._apply_terraform()
self._apply_terraform(msg="Remote State")
return self._get_terraform_output()

def deprovision(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_runners/test_base_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ def test_apply_terraform(capsys: SysCapture):
"""
template_runner = BaseRunner()
template_runner.tfs.apply = MagicMock(return_value=TerraformResult(0, "", ""))
expected = "Matcha resources have been provisioned!"
expected = "Remote State resources have been provisioned!"

template_runner._apply_terraform()
template_runner._apply_terraform(msg="Remote State")
captured = capsys.readouterr()

assert expected in captured.out
Expand Down