2016-04-12 20:23:35 +00:00
|
|
|
import boto3
|
2023-08-16 10:10:41 +00:00
|
|
|
import pytest
|
2016-04-12 20:23:35 +00:00
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
from moto import mock_aws
|
2016-04-12 20:23:35 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2016-04-12 20:23:35 +00:00
|
|
|
def test_create_stack_response():
|
2016-04-18 20:03:13 +00:00
|
|
|
client = boto3.client("opsworks", region_name="us-east-1")
|
2016-04-12 20:23:35 +00:00
|
|
|
response = client.create_stack(
|
|
|
|
Name="test_stack_1",
|
|
|
|
Region="us-east-1",
|
|
|
|
ServiceRoleArn="service_arn",
|
|
|
|
DefaultInstanceProfileArn="profile_arn",
|
|
|
|
)
|
2023-08-16 10:10:41 +00:00
|
|
|
assert "StackId" in response
|
2016-04-12 20:23:35 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2016-04-12 20:23:35 +00:00
|
|
|
def test_describe_stacks():
|
2016-04-18 20:03:13 +00:00
|
|
|
client = boto3.client("opsworks", region_name="us-east-1")
|
2016-04-18 19:44:21 +00:00
|
|
|
for i in range(1, 4):
|
2016-04-12 20:23:35 +00:00
|
|
|
client.create_stack(
|
2022-11-17 22:41:08 +00:00
|
|
|
Name=f"test_stack_{i}",
|
2016-04-12 20:23:35 +00:00
|
|
|
Region="us-east-1",
|
|
|
|
ServiceRoleArn="service_arn",
|
|
|
|
DefaultInstanceProfileArn="profile_arn",
|
|
|
|
)
|
|
|
|
|
|
|
|
response = client.describe_stacks()
|
2023-08-16 10:10:41 +00:00
|
|
|
assert len(response["Stacks"]) == 3
|
2016-04-14 20:28:53 +00:00
|
|
|
for stack in response["Stacks"]:
|
2023-08-16 10:10:41 +00:00
|
|
|
assert stack["ServiceRoleArn"] == "service_arn"
|
|
|
|
assert stack["DefaultInstanceProfileArn"] == "profile_arn"
|
2016-04-12 20:23:35 +00:00
|
|
|
|
|
|
|
_id = response["Stacks"][0]["StackId"]
|
|
|
|
response = client.describe_stacks(StackIds=[_id])
|
2023-08-16 10:10:41 +00:00
|
|
|
assert len(response["Stacks"]) == 1
|
|
|
|
assert _id in response["Stacks"][0]["Arn"]
|
2016-04-12 20:23:35 +00:00
|
|
|
|
2016-04-14 20:28:53 +00:00
|
|
|
# ClientError/ResourceNotFoundException
|
2023-08-16 10:10:41 +00:00
|
|
|
with pytest.raises(Exception) as exc:
|
|
|
|
client.describe_stacks(StackIds=["foo"])
|
|
|
|
assert r"foo" in exc.value.response["Error"]["Message"]
|