Skip to content

Commit

Permalink
delint
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Hellegouarch <sh@defuze.org>
  • Loading branch information
Lawouach committed Jun 15, 2024
1 parent 1cb0a39 commit 10cec5d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 50 deletions.
6 changes: 3 additions & 3 deletions chaosaws/cloudwatch/probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ def get_metric_data(
}

if dimensions:
args["MetricDataQueries"][0]["MetricStat"]["Metric"][
"Dimensions"
] = dimensions
args["MetricDataQueries"][0]["MetricStat"]["Metric"]["Dimensions"] = (
dimensions
)
elif dimension_name and dimension_value:
args["MetricDataQueries"][0]["MetricStat"]["Metric"]["Dimensions"] = [
{"Name": dimension_name, "Value": dimension_value}
Expand Down
10 changes: 5 additions & 5 deletions chaosaws/elbv2/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ def get_targets_health_description(tg_arns: Dict, client: boto3.client) -> Dict:
for tg in tg_arns:
tg_health_descr[tg] = {}
tg_health_descr[tg]["TargetGroupArn"] = tg_arns[tg]
tg_health_descr[tg][
"TargetHealthDescriptions"
] = client.describe_target_health(TargetGroupArn=tg_arns[tg])[
"TargetHealthDescriptions"
]
tg_health_descr[tg]["TargetHealthDescriptions"] = (
client.describe_target_health(
TargetGroupArn=tg_arns[tg]
)["TargetHealthDescriptions"]
)
logger.debug(
f"Health descriptions for target group(s) are: {str(tg_health_descr)}"
)
Expand Down
10 changes: 5 additions & 5 deletions chaosaws/elbv2/probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ def get_targets_health_description(tg_arns: Dict, client: boto3.client) -> Dict:
for tg in tg_arns:
tg_health_descr[tg] = {}
tg_health_descr[tg]["TargetGroupArn"] = tg_arns[tg]
tg_health_descr[tg][
"TargetHealthDescriptions"
] = client.describe_target_health(TargetGroupArn=tg_arns[tg])[
"TargetHealthDescriptions"
]
tg_health_descr[tg]["TargetHealthDescriptions"] = (
client.describe_target_health(
TargetGroupArn=tg_arns[tg]
)["TargetHealthDescriptions"]
)
logger.debug(
f"Health descriptions for target group(s) are: {str(tg_health_descr)}"
)
Expand Down
9 changes: 4 additions & 5 deletions chaosaws/msk/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ def reboot_msk_broker(
client = aws_client("kafka", configuration, secrets)
logger.debug(
f"Rebooting MSK brokers: {broker_ids} in cluster {cluster_arn}"
)
)
try:
return client.reboot_broker(
ClusterArn=cluster_arn,
BrokerIds=broker_ids
ClusterArn=cluster_arn, BrokerIds=broker_ids
)
except client.exceptions.NotFoundException:
raise FailedActivity("The specified cluster was not found" )
raise FailedActivity("The specified cluster was not found")


def delete_cluster(
Expand All @@ -46,4 +45,4 @@ def delete_cluster(
try:
return client.delete_cluster(ClusterArn=cluster_arn)
except client.exceptions.NotFoundException:
raise FailedActivity("The specified cluster was not found")
raise FailedActivity("The specified cluster was not found")
32 changes: 10 additions & 22 deletions tests/msk/test_msk_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ def test_reboot_msk_broker_success(aws_client):
cluster_arn = "arn_msk_cluster"
broker_ids = ["1"]
client.reboot_broker.return_value = {
"ResponseMetadata": {
"HTTPStatusCode": 200
}
"ResponseMetadata": {"HTTPStatusCode": 200}
}

response = reboot_msk_broker(cluster_arn=cluster_arn,
broker_ids=broker_ids)
response = reboot_msk_broker(cluster_arn=cluster_arn, broker_ids=broker_ids)

client.reboot_broker.assert_called_with(ClusterArn=cluster_arn,
BrokerIds=broker_ids)
client.reboot_broker.assert_called_with(
ClusterArn=cluster_arn, BrokerIds=broker_ids
)
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200


Expand All @@ -38,18 +36,14 @@ def test_reboot_msk_broker_not_found(aws_client):

client.exceptions = MagicMock()
client.exceptions.NotFoundException = NotFoundException
client.reboot_broker.side_effect = NotFoundException(
"Cluster not found"
)
client.reboot_broker.side_effect = NotFoundException("Cluster not found")

expected_error_message = "The specified cluster was not found"

with pytest.raises(FailedActivity) as exc_info:
reboot_msk_broker(cluster_arn=cluster_arn, broker_ids=broker_ids)

assert expected_error_message in str(
exc_info.value
)
assert expected_error_message in str(exc_info.value)


@patch("chaosaws.msk.actions.aws_client", autospec=True)
Expand All @@ -58,9 +52,7 @@ def test_delete_cluster_success(aws_client):
aws_client.return_value = client
cluster_arn = "arn_msk_cluster"
client.delete_cluster.return_value = {
"ResponseMetadata": {
"HTTPStatusCode": 200
}
"ResponseMetadata": {"HTTPStatusCode": 200}
}

response = delete_cluster(cluster_arn=cluster_arn)
Expand All @@ -77,15 +69,11 @@ def test_delete_cluster_not_found(aws_client):

client.exceptions = MagicMock()
client.exceptions.NotFoundException = NotFoundException
client.delete_cluster.side_effect = NotFoundException(
"Cluster not found"
)
client.delete_cluster.side_effect = NotFoundException("Cluster not found")

expected_error_message = "The specified cluster was not found"

with pytest.raises(FailedActivity) as exc_info:
delete_cluster(cluster_arn=cluster_arn)

assert expected_error_message in str(
exc_info.value
)
assert expected_error_message in str(exc_info.value)
14 changes: 4 additions & 10 deletions tests/msk/test_msk_probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ def test_describe_msk_cluster_not_found(aws_client):

client.exceptions = MagicMock()
client.exceptions.NotFoundException = NotFoundException
client.describe_cluster.side_effect = NotFoundException(
"Cluster not found"
)
client.describe_cluster.side_effect = NotFoundException("Cluster not found")

expected_error_message = "The specified cluster was not found"

with pytest.raises(FailedActivity) as exc_info:
describe_msk_cluster(cluster_arn=cluster_arn)

assert expected_error_message in str(
exc_info.value
)

assert expected_error_message in str(exc_info.value)


@patch("chaosaws.msk.probes.aws_client", autospec=True)
Expand Down Expand Up @@ -79,6 +75,4 @@ def test_get_bootstrap_server_cluster_not_found(aws_client):
with pytest.raises(FailedActivity) as exc_info:
get_bootstrap_servers(cluster_arn=cluster_arn)

assert expected_error_message in str(
exc_info.value
)
assert expected_error_message in str(exc_info.value)

0 comments on commit 10cec5d

Please sign in to comment.