Address SFN.Client.exceptions.ExecutionAlreadyExists Not implemented (#3263)
* Add check for existing execution, fix issue with make init * Remove f-string usage * Remove fstring usage in test * Pin black and run formatting on test_stepfunction * Reverse changes made by black 20.8b1
This commit is contained in:
parent
55b02c6ee9
commit
3b06ce689e
@ -18,6 +18,11 @@ class AWSError(Exception):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ExecutionAlreadyExists(AWSError):
|
||||||
|
TYPE = "ExecutionAlreadyExists"
|
||||||
|
STATUS = 400
|
||||||
|
|
||||||
|
|
||||||
class ExecutionDoesNotExist(AWSError):
|
class ExecutionDoesNotExist(AWSError):
|
||||||
TYPE = "ExecutionDoesNotExist"
|
TYPE = "ExecutionDoesNotExist"
|
||||||
STATUS = 400
|
STATUS = 400
|
||||||
|
@ -8,6 +8,7 @@ from moto.core.utils import iso_8601_datetime_without_milliseconds
|
|||||||
from moto.sts.models import ACCOUNT_ID
|
from moto.sts.models import ACCOUNT_ID
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
|
ExecutionAlreadyExists,
|
||||||
ExecutionDoesNotExist,
|
ExecutionDoesNotExist,
|
||||||
InvalidArn,
|
InvalidArn,
|
||||||
InvalidName,
|
InvalidName,
|
||||||
@ -205,6 +206,7 @@ class StepFunctionBackend(BaseBackend):
|
|||||||
|
|
||||||
def start_execution(self, state_machine_arn, name=None):
|
def start_execution(self, state_machine_arn, name=None):
|
||||||
state_machine_name = self.describe_state_machine(state_machine_arn).name
|
state_machine_name = self.describe_state_machine(state_machine_arn).name
|
||||||
|
self._ensure_execution_name_doesnt_exist(name)
|
||||||
execution = Execution(
|
execution = Execution(
|
||||||
region_name=self.region_name,
|
region_name=self.region_name,
|
||||||
account_id=self._get_account_id(),
|
account_id=self._get_account_id(),
|
||||||
@ -278,6 +280,13 @@ class StepFunctionBackend(BaseBackend):
|
|||||||
if not arn or not match:
|
if not arn or not match:
|
||||||
raise InvalidArn(invalid_msg)
|
raise InvalidArn(invalid_msg)
|
||||||
|
|
||||||
|
def _ensure_execution_name_doesnt_exist(self, name):
|
||||||
|
for execution in self.executions:
|
||||||
|
if execution.name == name:
|
||||||
|
raise ExecutionAlreadyExists(
|
||||||
|
"Execution Already Exists: '" + execution.execution_arn + "'"
|
||||||
|
)
|
||||||
|
|
||||||
def _get_account_id(self):
|
def _get_account_id(self):
|
||||||
return ACCOUNT_ID
|
return ACCOUNT_ID
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
-r requirements.txt
|
-r requirements.txt
|
||||||
nose
|
nose
|
||||||
black; python_version >= '3.6'
|
black==19.10b0; python_version >= '3.6'
|
||||||
regex==2019.11.1; python_version >= '3.6' # Needed for black
|
regex==2019.11.1; python_version >= '3.6' # Needed for black
|
||||||
sure==1.4.11
|
sure==1.4.11
|
||||||
coverage==4.5.4
|
coverage==4.5.4
|
||||||
|
1
setup.py
1
setup.py
@ -40,6 +40,7 @@ install_requires = [
|
|||||||
"werkzeug",
|
"werkzeug",
|
||||||
"PyYAML>=5.1",
|
"PyYAML>=5.1",
|
||||||
"pytz",
|
"pytz",
|
||||||
|
"ecdsa<0.15",
|
||||||
"python-dateutil<3.0.0,>=2.1",
|
"python-dateutil<3.0.0,>=2.1",
|
||||||
"python-jose[cryptography]>=3.1.0,<4.0.0",
|
"python-jose[cryptography]>=3.1.0,<4.0.0",
|
||||||
"docker>=2.5.1",
|
"docker>=2.5.1",
|
||||||
|
@ -404,6 +404,27 @@ def test_state_machine_start_execution_with_custom_name():
|
|||||||
execution["startDate"].should.be.a(datetime)
|
execution["startDate"].should.be.a(datetime)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_stepfunctions
|
||||||
|
@mock_sts
|
||||||
|
def test_state_machine_start_execution_fails_on_duplicate_execution_name():
|
||||||
|
client = boto3.client("stepfunctions", region_name=region)
|
||||||
|
#
|
||||||
|
sm = client.create_state_machine(
|
||||||
|
name="name", definition=str(simple_definition), roleArn=_get_default_role()
|
||||||
|
)
|
||||||
|
execution_one = client.start_execution(
|
||||||
|
stateMachineArn=sm["stateMachineArn"], name="execution_name"
|
||||||
|
)
|
||||||
|
#
|
||||||
|
with assert_raises(ClientError) as exc:
|
||||||
|
_ = client.start_execution(
|
||||||
|
stateMachineArn=sm["stateMachineArn"], name="execution_name"
|
||||||
|
)
|
||||||
|
exc.exception.response["Error"]["Message"].should.equal(
|
||||||
|
"Execution Already Exists: '" + execution_one["executionArn"] + "'"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_stepfunctions
|
@mock_stepfunctions
|
||||||
@mock_sts
|
@mock_sts
|
||||||
def test_state_machine_list_executions():
|
def test_state_machine_list_executions():
|
||||||
|
Loading…
Reference in New Issue
Block a user