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