Skip to content

Commit

Permalink
Updated CRM to return installed plugin status.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArunPsiog committed Nov 1, 2023
1 parent 84e8cbb commit e1198d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 12 additions & 8 deletions covalent/cloud_resource_manager/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from types import ModuleType
from typing import Callable, Dict, List, Optional

from covalent._shared_files.config import get_config, set_config
from covalent._shared_files.config import set_config
from covalent.executor import _executor_manager

logger = logging.getLogger()
Expand Down Expand Up @@ -194,16 +194,11 @@ def _parse_terraform_error_log(self) -> List[str]:
"""
with open(Path(self.executor_tf_path) / "terraform-error.log", "r") as f:
lines = f.readlines()
for index, line in enumerate(lines):
for _, line in enumerate(lines):
error_index = line.strip().find("error:")
if error_index != -1:
error_message = line.strip()[error_index + len("error:") :]
logger.error("Error while:")
logger.error(error_message)
logger.error("_________________________")
with open(Path(self.executor_tf_path) / "terraform-error.log", "w"):
pass
f.close()
return lines

def _run_in_subprocess(
Expand Down Expand Up @@ -238,6 +233,15 @@ def _run_in_subprocess(
"PATH": "$PATH:/usr/bin",
},
)
TERRAFORM_STATE = "state list -state"
if TERRAFORM_STATE in cmd:
stdout, stderr = proc.communicate()
if stderr is None:
return "down" if "No state file was found!" in str(stdout) else "up"
else:
raise subprocess.CalledProcessError(
returncode=1, cmd=cmd, stderr=self._parse_terraform_error_log()
)
retcode = self._print_stdout(proc, print_callback)

if retcode != 0:
Expand Down Expand Up @@ -312,7 +316,7 @@ def _get_tf_statefile_path(self) -> str:
"""
# Saving in a directory which doesn't get deleted on purge
return str(Path(get_config("dispatcher.db_path")).parent / f"{self.executor_name}.tfstate")
return str(Path(self.executor_tf_path) / "terraform.tfstate")

def up(self, print_callback: Callable, dry_run: bool = True) -> None:
"""
Expand Down
8 changes: 2 additions & 6 deletions covalent_dispatcher/_cli/groups/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ def up(executor_name: str, vars: Dict, help: bool, dry_run: bool, verbose: bool)
),
)
except subprocess.CalledProcessError as e:
# click.echo(
# f"Unable to provision resources due to the following error:\n\n{e}"
# )
click.echo(f"Unable to provision resources due to the following error:\n\n{e}")
return

click.echo(Console().print(get_settings_table(crm)))
Expand Down Expand Up @@ -234,9 +232,7 @@ 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.stderr[-1]}"
)
click.echo(f"Unable to destroy resources due to the following error:\n\n{e}")
return

click.echo("Completed.")
Expand Down

0 comments on commit e1198d2

Please sign in to comment.