8000 Triage a few aws_unknown markers (sfn, cfn & others) (#9141) · codeperl/localstack@fa10d1d · GitHub
[go: up one dir, main page]

Skip to content

Commit fa10d1d

Browse files
Triage a few aws_unknown markers (sfn, cfn & others) (localstack#9141)
1 parent c35d069 commit fa10d1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1508
-276
lines changed

localstack/services/stepfunctions/asl/component/intrinsic/function/statesfunction/math_operations/math_add.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import decimal
12
from typing import Any
23

34
from localstack.services.stepfunctions.asl.component.intrinsic.argument.function_argument_list import (
@@ -15,6 +16,18 @@
1516
from localstack.services.stepfunctions.asl.eval.environment import Environment
1617

1718

19+
def _round_like_java(f: float) -> int:
20+
# this behaves a bit weird for boundary values
21+
# AWS stepfunctions is implemented in Java, so we need to adjust the rounding accordingly
22+
# python by default rounds half to even
23+
if f >= 0:
24+
decimal.getcontext().rounding = decimal.ROUND_HALF_UP
25+
else:
26+
decimal.getcontext().rounding = decimal.ROUND_HALF_DOWN
27+
d = decimal.Decimal(f)
28+
return round(d, 0)
29+
30+
1831
class MathAdd(StatesFunction):
1932
# Returns the sum of two numbers.
2033
#
@@ -47,7 +60,12 @@ def _validate_integer_value(value: Any) -> int:
4760
raise TypeError(f"Expected integer value, but got: '{value}'.")
4861
# If you specify a non-integer value for one or both the arguments,
4962
# Step Functions will round it off to the nearest integer.
50-
return int(value)
63+
64+
if isinstance(value, float):
65+
result = _round_like_java(value)
66+
return int(result)
67+
68+
return value
5169

5270
def _eval_body(self, env: Environment) -> None:
5371
self.arg_list.eval(env=env)

tests/aws/services/cloudformation/api/test_changesets.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from localstack.utils.sync import ShortCircuitWaitException, poll_condition, wait_until
1515

1616

17-
@markers.aws.unknown
17+
@markers.aws.validated
1818
def test_create_change_set_without_parameters(
1919
cleanup_stacks, cleanup_changesets, is_change_set_created_and_available, aws_client
2020
):
@@ -145,17 +145,13 @@ def test_create_change_set_update_without_parameters(
145145
cleanup_stacks(stacks=[stack_id])
146146

147147

148-
@pytest.mark.skip(reason="TODO")
149-
@markers.aws.unknown
150-
def test_create_change_set_with_template_url():
151-
pass
148+
# def test_create_change_set_with_template_url():
149+
# pass
152150

153151

154-
@pytest.mark.xfail(reason="change set type not implemented")
155-
@markers.aws.unknown
156-
def test_create_change_set_create_existing(
157-
is_stack_created, cleanup_changesets, cleanup_stacks, aws_client
158-
):
152+
@pytest.mark.skipif(condition=not is_aws_cloud(), reason="change set type not implemented")
153+
@markers.aws.validated
154+
def test_create_change_set_create_existing(cleanup_changesets, cleanup_stacks, aws_client):
159155
"""tries to create an already existing stack"""
160156

161157
stack_name = f"stack-{short_uid()}"
@@ -171,12 +167,15 @@ def test_create_change_set_create_existing(
171167
ChangeSetType="CREATE",
172168
)
173169
change_set_id = response["Id"]
170+
aws_client.cloudformation.get_waiter("change_set_create_complete").wait(
171+
ChangeSetName=change_set_id
172+
)
174173
stack_id = response["StackId"]
175174
assert change_set_id
176175
assert stack_id
177176
try:
178177
aws_client.cloudformation.execute_change_set(ChangeSetName=change_set_id)
179-
wait_until(is_stack_created(stack_id))
178+
aws_client.cloudformation.get_waiter("stack_create_complete").wait(StackName=stack_id)
180179

181180
with pytest.raises(Exception) as ex:
182181
change_set_name2 = f"change-set-{short_uid()}"
@@ -192,7 +191,7 @@ def test_create_change_set_create_existing(
192191
cleanup_stacks([stack_id])
193192

194193

195-
@markers.aws.unknown
194+
@markers.aws.validated
196195
def test_create_change_set_update_nonexisting(aws_client):
197196
stack_name = f"stack-{short_uid()}"
198197
change_set_name = f"change-set-{short_uid()}"
@@ -216,14 +215,7 @@ def test_create_change_set_update_nonexisting(aws_client):
216215
assert "does not exist" in err["Message"]
217216

218217

219-
@pytest.mark.skip(reason="TODO")
220-
@markers.aws.unknown
221-
def test_create_change_set_import():
222-
"""test importing existing resources into a stack via the change set"""
223-
pass # TODO
224-
225-
226-
@markers.aws.unknown
218+
@markers.aws.validated
227219
def test_create_change_set_invalid_params(aws_client):
228220
stack_name = f"stack-{short_uid()}"
229221
change_set_name = f"change-set-{short_uid()}"
@@ -241,7 +233,7 @@ def test_create_change_set_invalid_params(aws_client):
241233
assert err["Code"] == "ValidationError"
242234

243235

244-
@markers.aws.unknown
236+
@markers.aws.validated
245237
def test_create_change_set_missing_stackname(aws_client):
246238
"""in this case boto doesn't even let us send the request"""
247239
change_set_name = f"change-set-{short_uid()}"
@@ -349,8 +341,11 @@ def test_describe_change_set_nonexisting(snapshot, aws_client):
349341
snapshot.match("exception", ex.value)
350342

351343

352-
@pytest.mark.skip(reason="fails because of the properties mutation in the result_handler")
353-
@markers.aws.unknown
344+
@pytest.mark.skipif(
345+
condition=not is_aws_cloud(),
346+
reason="fails because of the properties mutation in the result_handler",
347+
)
348+
@markers.aws.validated
354349
def test_execute_change_set(
355350
is_change_set_finished,
356351
is_change_set_created_and_available,

tests/aws/services/cloudformation/api/test_stacks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def test_stack_update_resources(
173173
resources = aws_client.cloudformation.describe_stack_resources(StackName=stack_name)
174174
snapshot.match("stack_resources", resources)
175175

176-
@markers.aws.unknown
176+
@markers.aws.needs_fixing
177177
def test_list_stack_resources_for_removed_resource(self, deploy_cfn_template, aws_client):
178178
template_path = os.path.join(
179179
os.path.dirname(__file__), "../../../templates/eventbridge_policy.yaml"
@@ -212,7 +212,7 @@ def test_list_stack_resources_for_removed_resource(self, deploy_cfn_template, aw
212212
statuses = set([res["ResourceStatus"] for res in resources])
213213
assert statuses == {"UPDATE_COMPLETE"}
214214

215-
@markers.aws.unknown
215+
@markers.aws.needs_fixing
216216
def test_update_stack_with_same_template_withoutchange(self, deploy_cfn_template, aws_client):
217217
template = load_file(
218218
os.path.join(os.path.dirname(__file__), "../../../templates/fifo_queue.json")

tests/aws/services/cloudformation/resources/test_events.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
LOG = logging.getLogger(__name__)
1111

1212

13-
@markers.aws.unknown
13+
@markers.aws.validated
1414
def test_eventbus_policies(deploy_cfn_template, aws_client):
1515
event_bus_name = f"event-bus-{short_uid()}"
1616

@@ -51,7 +51,7 @@ def test_eventbus_policies(deploy_cfn_template, aws_client):
5151
assert len(policy["Statement"]) == 1
5252

5353

54-
@markers.aws.unknown
54+
@markers.aws.validated
5555
def test_eventbus_policy_statement(deploy_cfn_template, aws_client):
5656
event_bus_name = f"event-bus-{short_uid()}"
5757
statement_id = f"statement-{short_uid()}"
@@ -75,7 +75,7 @@ def test_eventbus_policy_statement(deploy_cfn_template, aws_client):
7575
assert event_bus_name in statement["Resource"]
7676

7777

78-
@markers.aws.unknown
78+
@markers.aws.validated
7979
def test_event_rule_to_logs(deploy_cfn_template, aws_client):
8080
event_rule_name = f"event-rule-{short_uid()}"
8181
log_group_name = f"log-group-{short_uid()}"
@@ -126,7 +126,8 @@ def test_event_rule_to_logs(deploy_cfn_template, aws_client):
126126
assert message_token in log_events["events"][0]["message"]
127127

128128

129-
@markers.aws.unknown
129+
# {"LogicalResourceId": "TestRule99A50909", "ResourceType": "AWS::Events::Rule", "ResourceStatus": "CREATE_FAILED", "ResourceStatusReason": "Parameter ScheduleExpression is not valid."}
130+
@markers.aws.needs_fixing
130131
def test_event_rule_creation_without_target(deploy_cfn_template, aws_client):
131132
event_rule_name = f"event-rule-{short_uid()}"
132133
deploy_cfn_template(
@@ -142,7 +143,7 @@ def test_event_rule_creation_without_target(deploy_cfn_template, aws_client):
142143
assert response
143144

144145

145-
@markers.aws.unknown
146+
@markers.aws.validated
146147
def test_cfn_event_bus_resource(deploy_cfn_template, aws_client):
147148
def _assert(expected_len):
148149
rs = aws_client.events.list_event_buses()
@@ -211,7 +212,8 @@ def _assert(expected_len):
211212
"""
212213

213214

214-
@markers.aws.unknown
215+
# {"LogicalResourceId": "ScheduledRule", "ResourceType": "AWS::Events::Rule", "ResourceStatus": "CREATE_FAILED", "ResourceStatusReason": "s3 is not a supported service for a target."}
216+
@markers.aws.needs_fixing
215217
def test_cfn_handle_events_rule(deploy_cfn_template, aws_client):
216218
bucket_name = f"target-{short_uid()}"
217219
rule_prefix = f"s3-rule-{short_uid()}"
@@ -234,7 +236,8 @@ def test_cfn_handle_events_rule(deploy_cfn_template, aws_client):
234236
assert rule_name not in [rule["Name"] for rule in rs["Rules"]]
235237

236238

237-
@markers.aws.unknown
239+
# {"LogicalResourceId": "TestStateMachine", "ResourceType": "AWS::StepFunctions::StateMachine", "ResourceStatus": "CREATE_FAILED", "ResourceStatusReason": "Resource handler returned message: \"Cross-account pass role is not allowed."}
240+
@markers.aws.needs_fixing
238241
def test_cfn_handle_events_rule_without_name(deploy_cfn_template, aws_client):
239242
rs = aws_client.events.list_rules()
240243
rule_names = [rule["Name"] for rule in rs["Rules"]]

tests/aws/services/cloudformation/resources/test_stepfunctions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from tests.aws.services.stepfunctions.utils import await_execution_terminated
1111

1212

13-
@markers.aws.unknown
13+
@markers.aws.validated
1414
def test_statemachine_definitionsubstitution(deploy_cfn_template, aws_client):
1515
stack = deploy_cfn_template(
1616
template_path=os.path.join(
@@ -44,7 +44,7 @@ def _is_executed():
4444
assert "hello from statemachine" in execution_desc["output"]
4545

4646

47-
@markers.aws.unknown
47+
@markers.aws.validated
4848
def test_nested_statemachine_with_sync2(deploy_cfn_template, aws_client):
4949
stack = deploy_cfn_template(
5050
template_path=os.path.join(
@@ -76,7 +76,7 @@ def _is_executed():
7676
assert output["Value"] == 3
7777

7878

79-
@markers.aws.unknown
79+
@markers.aws.needs_fixing
8080
def test_apigateway_invoke(deploy_cfn_template, aws_client):
8181
deploy_result = deploy_cfn_template(
8282
template_path=os.path.join(
@@ -102,7 +102,7 @@ def _sfn_finished_running():
102102
assert "hello from stepfunctions" in execution_result["output"]
103103

104104

105-
@markers.aws.unknown
105+
@markers.aws.validated
106106
def test_apigateway_invoke_with_path(deploy_cfn_template, aws_client):
107107
deploy_result = deploy_cfn_template(
108108
template_path=os.path.join(
@@ -128,7 +128,7 @@ def _sfn_finished_running():
128128
assert "hello_with_path from stepfunctions" in execution_result["output"]
129129

130130

131-
@markers.aws.unknown
131+
@markers.aws.only_localstack
132132
def test_apigateway_invoke_localhost(deploy_cfn_template, aws_client):
133133
"""tests the same as above but with the "generic" localhost version of invoking the apigateway"""
134134
deploy_result = deploy_cfn_template(
@@ -174,7 +174,7 @@ def _sfn_finished_running():
174174
assert "hello from stepfunctions" in execution_result["output"]
175175

176176

177-
@markers.aws.unknown
177+
@markers.aws.only_localstack
178178
def test_apigateway_invoke_localhost_with_path(deploy_cfn_template, aws_client):
179179
"""tests the same as above but with the "generic" localhost version of invoking the apigateway"""
180180
deploy_result = deploy_cfn_template(

tests/aws/services/cloudformation/test_template_engine.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class TestIntrinsicFunctions:
117117
("Fn::Or", "1", "1", True),
118118
],
119119
)
120-
@markers.aws.unknown
120+
@markers.aws.validated
121121
def test_and_or_functions(
122122
self,
123123
intrinsic_fn,
@@ -329,7 +329,7 @@ def test_create_stack_with_ssm_parameters(
329329
tags = aws_client.sns.list_tags_for_resource(ResourceArn=matching[0])
330330
snapshot.match("topic-tags", tags)
331331

332-
@markers.aws.unknown
332+
@markers.aws.validated
333333
def test_resolve_ssm(self, create_parameter, deploy_cfn_template):
334334
parameter_key = f"param-key-{short_uid()}"
335335
parameter_value = f"param-value-{short_uid()}"
@@ -345,7 +345,7 @@ def test_resolve_ssm(self, create_parameter, deploy_cfn_template):
345345
topic_name = result.outputs["TopicName"]
346346
assert topic_name == parameter_value
347347

348-
@markers.aws.unknown
348+
@markers.aws.validated
349349
def test_resolve_ssm_with_version(self, create_parameter, deploy_cfn_template, aws_client):
350350
parameter_key = f"param-key-{short_uid()}"
351351
parameter_value_v0 = f"param-value-{short_uid()}"
@@ -371,7 +371,7 @@ def test_resolve_ssm_with_version(self, create_parameter, deploy_cfn_template, a
371371
topic_name = result.outputs["TopicName"]
372372
assert topic_name == parameter_value_v1
373373

374-
@markers.aws.unknown
374+
@markers.aws.needs_fixing
375375
def test_resolve_ssm_secure(self, create_parameter, deploy_cfn_template):
376376
parameter_key = f"param-key-{short_uid()}"
377377
parameter_value = f"param-value-{short_uid()}"
@@ -398,7 +398,7 @@ class TestSecretsManagerParameters:
398398
"resolve_secretsmanager.yaml",
399399
],
400400
)
401-
@markers.aws.unknown
401+
@markers.aws.validated
402402
def test_resolve_secretsmanager(self, create_secret, deploy_cfn_template, template_name):
403403
parameter_key = f"param-key-{short_uid()}"
404404
parameter_value = f"param-value-{short_uid()}"

tests/aws/services/lambda_/test_lambda_common.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ def test_runtime_wrapper_invoke(self, multiruntime_lambda, snapshot, tmp_path, a
250250

251251

252252
# TODO: Split this and move to PRO
253-
@pytest.mark.whitebox
254253
@pytest.mark.skipif(
255254
condition=is_old_provider(),
256255
reason="Local executor does not support the majority of the runtimes",
@@ -271,7 +270,7 @@ class TestLambdaCallingLocalstack:
271270
"dotnet6", # TODO: does not yet support transparent endpoint injection
272271
],
273272
)
274-
@markers.aws.unknown
273+
@markers.aws.only_localstack
275274
def test_calling_localstack_from_lambda(self, multiruntime_lambda, tmp_path, aws_client):
276275
create_function_result = multiruntime_lambda.create_function(
277276
MemorySize=1024,

0 commit comments

Comments
 (0)
0