Skip to content

Commit

Permalink
Kafka - Update responses for list_clusters_v2 (#8492)
Browse files Browse the repository at this point in the history
  • Loading branch information
jflim authored Jan 18, 2025
1 parent cfaa898 commit 4c1321a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
14 changes: 4 additions & 10 deletions moto/kafka/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,10 @@ def list_clusters_v2(
max_results: Optional[int],
next_token: Optional[str],
) -> Tuple[List[Dict[str, Any]], Optional[str]]:
cluster_info_list = [
{
"clusterArn": cluster.arn,
"clusterName": cluster.cluster_name,
"clusterType": cluster.cluster_type,
"state": cluster.state,
"creationTime": cluster.creation_time,
}
for cluster in self.clusters.values()
]
cluster_info_list = []
for cluster_arn in self.clusters.keys():
cluster_info = self.describe_cluster_v2(cluster_arn)
cluster_info_list.append(cluster_info)

return cluster_info_list, None

Expand Down
51 changes: 51 additions & 0 deletions tests/test_kafka/test_kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,54 @@ def test_delete_cluster():
client.delete_cluster(ClusterArn=create_resp["ClusterArn"])
clusters = client.list_clusters()
assert len(clusters["ClusterInfoList"]) == 0


@mock_aws
def test_list_clusters_v2():
client = boto3.client("kafka", region_name="ap-southeast-1")
s_cluster_name = "TestServerlessCluster"
p_cluster_name = "TestProvisionedCluster"

client.create_cluster_v2(
ClusterName=s_cluster_name,
Serverless={
"VpcConfigs": [
{
"SubnetIds": ["subnet-0123456789abcdef0"],
"SecurityGroupIds": ["sg-0123456789abcdef0"],
}
]
},
Tags=FAKE_TAGS,
)

client.create_cluster_v2(
ClusterName=p_cluster_name,
Provisioned={
"BrokerNodeGroupInfo": {
"InstanceType": "kafka.m5.large",
"ClientSubnets": ["subnet-0123456789abcdef0"],
"SecurityGroups": ["sg-0123456789abcdef0"],
},
"KafkaVersion": "2.8.1",
"NumberOfBrokerNodes": 3,
},
Tags=FAKE_TAGS,
)

clusters = client.list_clusters_v2()

assert len(clusters["ClusterInfoList"]) == 2
for cluster in clusters["ClusterInfoList"]:
assert "ActiveOperationArn" in cluster
assert "ClusterType" in cluster
assert "ClusterArn" in cluster
assert "ClusterName" in cluster
assert "CreationTime" in cluster
assert "CurrentVersion" in cluster
assert "State" in cluster
assert "StateInfo" in cluster
assert "Tags" in cluster

cluster_type = cluster["ClusterType"]
assert cluster_type[0].upper() + cluster_type[1:].lower() in cluster

0 comments on commit 4c1321a

Please sign in to comment.