Skip to content

Commit

Permalink
Fix - executor's deploy message for verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
mpvgithub committed Nov 1, 2023
1 parent e1198d2 commit 3bea43b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion covalent/cloud_resource_manager/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ def down(self, print_callback: Callable) -> None:

if Path(tf_state_file).exists():
Path(tf_state_file).unlink()
Path(f"{tf_state_file}.backup").unlink()
if Path(f"{tf_state_file}.backup").exists():
Path(f"{tf_state_file}.backup").unlink()

def status(self) -> None:
"""
Expand Down
30 changes: 20 additions & 10 deletions covalent_dispatcher/_cli/groups/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@


import subprocess
import sys
from pathlib import Path
from typing import Dict, Tuple

Expand All @@ -32,9 +31,13 @@
from rich.console import Console
from rich.table import Table

from covalent.cloud_resource_manager.core import CloudResourceManager, logger
from covalent.cloud_resource_manager.core import CloudResourceManager
from covalent.executor import _executor_manager

RESOURCE_ALREADY_EXISTS = "Resources already deployed"
RESOURCE_ALREADY_DESTROYED = "Resources already destroyed"
COMPLETED = "Completed"


def get_crm_object(executor_name: str, options: Dict = None) -> CloudResourceManager:
"""
Expand Down Expand Up @@ -70,9 +73,6 @@ def get_print_callback(

def inline_print_callback(msg):
console_status.update(f"{prepend_msg} {msg}")
if msg == "No changes. No objects need to be destroyed.":
logger.error("Resources already destroyed")
sys.exit()

return inline_print_callback

Expand Down Expand Up @@ -173,7 +173,7 @@ def up(executor_name: str, vars: Dict, help: bool, dry_run: bool, verbose: bool)
click.echo(Console().print(get_up_help_table(crm)))
return

console = Console()
console = Console(record=True)
prepend_msg = "[bold green] Provisioning resources..."

with console.status(prepend_msg) as status:
Expand All @@ -192,7 +192,13 @@ def up(executor_name: str, vars: Dict, help: bool, dry_run: bool, verbose: bool)
return

click.echo(Console().print(get_settings_table(crm)))
click.echo("Completed.")
exists_msg_with_verbose = "Apply complete! Resources: 0 added, 0 changed, 0 destroyed"
exists_msg_without_verbose = "found no differences, so no changes are needed"
export_data = console.export_text()
if exists_msg_with_verbose in export_data or exists_msg_without_verbose in export_data:
click.echo(RESOURCE_ALREADY_EXISTS)
else:
click.echo(COMPLETED)


@deploy.command()
Expand All @@ -219,7 +225,7 @@ def down(executor_name: str, verbose: bool) -> None:
"""
crm = get_crm_object(executor_name)

console = Console()
console = Console(record=True)
prepend_msg = "[bold green] Destroying resources..."
with console.status(prepend_msg) as status:
try:
Expand All @@ -234,8 +240,12 @@ def down(executor_name: str, verbose: bool) -> None:
except subprocess.CalledProcessError as e:
click.echo(f"Unable to destroy resources due to the following error:\n\n{e}")
return

click.echo("Completed.")
destroyed_msg = "Destroy complete! Resources: 0 destroyed."
export_data = console.export_text()
if destroyed_msg in export_data:
click.echo(RESOURCE_ALREADY_DESTROYED)
else:
click.echo(COMPLETED)


# TODO - Color code status.
Expand Down

0 comments on commit 3bea43b

Please sign in to comment.