diff --git a/CHANGELOG.md b/CHANGELOG.md index 0332913ae..eb0319120 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,11 +17,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed unused file transfer how to guides - Removed `pennylane` as a requirement from notebooks' requirements.txt as it comes with `covalent` +- Removed `validate_args` and `validate_region` method from `deploy_group` CLI as they were specific to AWS ### Docs - Added voice cloning tutorial +### Fixed + +- Fixed the scenario where any deploy commands would fail if the user had a non deploy compatible plugin installed + ## [0.233.0-rc.0] - 2024-01-07 ### Authors diff --git a/covalent_dispatcher/_cli/groups/deploy_group.py b/covalent_dispatcher/_cli/groups/deploy_group.py index a9510c09f..ff8c06a23 100644 --- a/covalent_dispatcher/_cli/groups/deploy_group.py +++ b/covalent_dispatcher/_cli/groups/deploy_group.py @@ -24,7 +24,6 @@ from pathlib import Path from typing import Callable, Dict, Tuple -import boto3 import click from rich.console import Console from rich.table import Table @@ -176,12 +175,20 @@ def up(executor_name: str, vars: Dict, help: bool, dry_run: bool, verbose: bool) $ covalent deploy up awslambda --verbose --region=us-east-1 --instance-type=t2.micro """ + cmd_options = {key[2:]: value for key, value in (var.split("=") for var in vars)} - if msg := validate_args(cmd_options): - # Message is not None, so there was an error. - click.echo(msg) + + try: + crm = get_crm_object(executor_name, cmd_options) + except (KeyError, AttributeError): + click.echo( + click.style( + f"Warning: '{executor_name}' is not a valid executor for deployment.", + fg="yellow", + ) + ) sys.exit(1) - crm = get_crm_object(executor_name, cmd_options) + if help: click.echo(Console().print(get_up_help_table(crm))) sys.exit(0) @@ -212,7 +219,18 @@ def down(executor_name: str, verbose: bool) -> None: $ covalent deploy down ecs --verbose """ - crm = get_crm_object(executor_name) + + try: + crm = get_crm_object(executor_name) + except (KeyError, AttributeError): + click.echo( + click.style( + f"Warning: '{executor_name}' is not a valid executor for deployment.", + fg="yellow", + ) + ) + sys.exit(1) + _command = partial(crm.down) _run_command_and_show_output(_command, "Destroying resources...", verbose=verbose) @@ -247,7 +265,7 @@ def status(executor_names: Tuple[str]) -> None: for name in _executor_manager.executor_plugins_map if name not in ["dask", "local", "remote_executor"] ] - click.echo(f"Executors: {', '.join(executor_names)}") + click.echo(f"Installed executors: {', '.join(executor_names)}") table = Table() table.add_column("Executor", justify="center") @@ -260,7 +278,9 @@ def status(executor_names: Tuple[str]) -> None: crm = get_crm_object(executor_name) crm_status = crm.status() table.add_row(executor_name, crm_status, description[crm_status]) - except KeyError: + except (KeyError, AttributeError): + # Added the AttributeError here as well in case the executor does not + # have the ExecutorPluginDefaults or ExecutorInfraDefaults classes. invalid_executor_names.append(executor_name) click.echo(Console().print(table)) @@ -268,23 +288,7 @@ def status(executor_names: Tuple[str]) -> None: if invalid_executor_names: click.echo( click.style( - f"Warning: {', '.join(invalid_executor_names)} are not valid executors.", + f"Warning: Invalid executors for deployment -> '{', '.join(invalid_executor_names)}'", fg="yellow", ) ) - - -def validate_args(args: dict): - message = None - if len(args) == 0: - return message - if "region" in args and args["region"] != "": - if not validate_region(args["region"]): - return f"Unable to find the provided region: {args['region']}" - - -def validate_region(region_name: str): - ec2_client = boto3.client("ec2") - response = ec2_client.describe_regions() - exists = region_name in [item["RegionName"] for item in response["Regions"]] - return exists diff --git a/tests/covalent_dispatcher_tests/_cli/cli_test.py b/tests/covalent_dispatcher_tests/_cli/cli_test.py index ec02aa3f0..a50b083da 100644 --- a/tests/covalent_dispatcher_tests/_cli/cli_test.py +++ b/tests/covalent_dispatcher_tests/_cli/cli_test.py @@ -184,22 +184,14 @@ def test_deploy_up(mocker): "covalent_dispatcher._cli.groups.deploy_group._run_command_and_show_output", ) - # Fail with invalid command options. - mocker.patch( - "covalent_dispatcher._cli.groups.deploy_group.validate_args", - return_value="Non-empty msg", - ) + # Fail with invalid executor name with pytest.raises(SystemExit) as exc_info: ctx = click.Context(up) - ctx.invoke(up) + ctx.invoke(up, executor_name="invalid") assert exc_info.value.code == 1 # Succeed but exit after help message. - mocker.patch( - "covalent_dispatcher._cli.groups.deploy_group.validate_args", - return_value=None, - ) mocker.patch( "covalent_dispatcher._cli.groups.deploy_group.get_crm_object", ) @@ -227,6 +219,15 @@ def test_deploy_down(mocker): mock_run_command_and_show_output = mocker.patch( "covalent_dispatcher._cli.groups.deploy_group._run_command_and_show_output", ) + + # Fail with invalid executor name + with pytest.raises(SystemExit) as exc_info: + ctx = click.Context(down) + ctx.invoke(down, executor_name="invalid") + + assert exc_info.value.code == 1 + + # Succeed with valid command options. mocker.patch( "covalent_dispatcher._cli.groups.deploy_group.get_crm_object", )