Skip to content

Commit

Permalink
Merge pull request #7 from ircwaves/make-call-set-exit-code-correctly
Browse files Browse the repository at this point in the history
set exit status appropriately, and skip stack trace in CLI mode
  • Loading branch information
ircwaves authored Nov 2, 2023
2 parents e91faa2 + 0967d0a commit 4f82880
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Return correct execution(`[-1]`), as new Step Function executions are
appended to the `executions` list, from the StateDB
Item. ([#6](https://github.com/cirrus-geo/cirrus-mgmt/pull/6))
- Enable both `call` CLI to set exit status code based of `Deployment.call`,
and exception raised from `subprocess.check_call` if used as a
library. ([#7](https://github.com/cirrus-geo/cirrus-mgmt/pull/7)

## [v0.1.0] - 2023-08-01

Expand Down
11 changes: 9 additions & 2 deletions src/cirrus/plugins/management/commands/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from cirrus.cli.utils import click as utils_click
from click_option_group import RequiredMutuallyExclusiveOptionGroup, optgroup

from cirrus.plugins.management.deployment import WORKFLOW_POLL_INTERVAL, Deployment
from cirrus.plugins.management.deployment import (
WORKFLOW_POLL_INTERVAL,
CalledProcessError,
Deployment,
)
from cirrus.plugins.management.utils.click import (
additional_variables,
silence_templating_errors,
Expand Down Expand Up @@ -304,7 +308,10 @@ def _call(ctx, deployment, command, include_user_vars):
"""Run an executable, in a new process, with the deployment environment vars loaded"""
if not command:
return
deployment.call(command, include_user_vars=include_user_vars)
try:
deployment.call(command, include_user_vars=include_user_vars)
except CalledProcessError as cpe:
sys.exit(cpe.returncode)


@manage.command()
Expand Down
2 changes: 1 addition & 1 deletion src/cirrus/plugins/management/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from datetime import datetime, timezone
from pathlib import Path
from subprocess import check_call
from subprocess import CalledProcessError, check_call
from time import sleep, time

import backoff
Expand Down
10 changes: 9 additions & 1 deletion tests/test_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ def test_manage_refresh(deployment, mock_lambda_get_conf, lambda_env):
assert new["environment"] == lambda_env


# @pytest.mark.parametrize("item", (
def test_manage_get_execution_by_payload_id(deployment, basic_payloads, statedb):
"""Adds causes two workflow executions, and confirms that the second call to
get_execution_by_payload_id gets a different executionArn value from the first execution.
"""
current_env = deepcopy(os.environ) # stash env
deployment.set_env()
basic_payloads.process()
Expand All @@ -113,3 +115,9 @@ def test_manage_get_execution_by_payload_id(deployment, basic_payloads, statedb)
sfn_exe2 = deployment.get_execution_by_payload_id(pid)
assert sfn_exe1["executionArn"] != sfn_exe2["executionArn"]
os.environ = current_env # pop stash


@pytest.mark.parametrize("command,expect_exit_zero", (("true", True), ("false", False)))
def test_call_cli_return_values(deployment, command, expect_exit_zero):
result = deployment(f"call {command}")
assert result.exit_code == 0 if expect_exit_zero else result.exit_code != 0

0 comments on commit 4f82880

Please # to comment.