2016-04-14 20:28:53 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
import boto3
|
2016-11-24 01:23:47 +00:00
|
|
|
from freezegun import freeze_time
|
2016-04-14 20:28:53 +00:00
|
|
|
import sure # noqa
|
|
|
|
import re
|
|
|
|
|
|
|
|
from moto import mock_opsworks
|
|
|
|
|
|
|
|
|
2016-11-24 01:23:47 +00:00
|
|
|
@freeze_time("2015-01-01")
|
2016-04-14 20:28:53 +00:00
|
|
|
@mock_opsworks
|
|
|
|
def test_create_layer_response():
|
2016-04-18 20:03:13 +00:00
|
|
|
client = boto3.client('opsworks', region_name='us-east-1')
|
2016-04-14 20:28:53 +00:00
|
|
|
stack_id = client.create_stack(
|
|
|
|
Name="test_stack_1",
|
|
|
|
Region="us-east-1",
|
|
|
|
ServiceRoleArn="service_arn",
|
|
|
|
DefaultInstanceProfileArn="profile_arn"
|
|
|
|
)['StackId']
|
|
|
|
|
|
|
|
response = client.create_layer(
|
|
|
|
StackId=stack_id,
|
|
|
|
Type="custom",
|
|
|
|
Name="TestLayer",
|
|
|
|
Shortname="TestLayerShortName"
|
|
|
|
)
|
|
|
|
|
|
|
|
response.should.contain("LayerId")
|
|
|
|
|
|
|
|
# ClientError
|
|
|
|
client.create_layer.when.called_with(
|
|
|
|
StackId=stack_id,
|
|
|
|
Type="custom",
|
|
|
|
Name="TestLayer",
|
|
|
|
Shortname="_"
|
|
|
|
).should.throw(
|
|
|
|
Exception, re.compile(r'already a layer named "TestLayer"')
|
|
|
|
)
|
|
|
|
# ClientError
|
|
|
|
client.create_layer.when.called_with(
|
|
|
|
StackId=stack_id,
|
|
|
|
Type="custom",
|
|
|
|
Name="_",
|
|
|
|
Shortname="TestLayerShortName"
|
|
|
|
).should.throw(
|
|
|
|
Exception, re.compile(r'already a layer with shortname "TestLayerShortName"')
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-11-24 01:23:47 +00:00
|
|
|
@freeze_time("2015-01-01")
|
2016-04-14 20:28:53 +00:00
|
|
|
@mock_opsworks
|
|
|
|
def test_describe_layers():
|
2016-04-18 20:03:13 +00:00
|
|
|
client = boto3.client('opsworks', region_name='us-east-1')
|
2016-04-14 20:28:53 +00:00
|
|
|
stack_id = client.create_stack(
|
|
|
|
Name="test_stack_1",
|
|
|
|
Region="us-east-1",
|
|
|
|
ServiceRoleArn="service_arn",
|
|
|
|
DefaultInstanceProfileArn="profile_arn"
|
|
|
|
)['StackId']
|
|
|
|
layer_id = client.create_layer(
|
|
|
|
StackId=stack_id,
|
|
|
|
Type="custom",
|
|
|
|
Name="TestLayer",
|
|
|
|
Shortname="TestLayerShortName"
|
|
|
|
)['LayerId']
|
|
|
|
|
|
|
|
rv1 = client.describe_layers(StackId=stack_id)
|
|
|
|
rv2 = client.describe_layers(LayerIds=[layer_id])
|
2017-02-16 03:35:45 +00:00
|
|
|
rv1['Layers'].should.equal(rv2['Layers'])
|
2016-04-14 20:28:53 +00:00
|
|
|
|
|
|
|
rv1['Layers'][0]['Name'].should.equal("TestLayer")
|
|
|
|
|