Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Stephan Huber 2019-12-23 08:38:53 +01:00
commit 0527e88d46
541 changed files with 75504 additions and 51429 deletions

View file

@ -10,19 +10,15 @@ from moto import mock_opsworks
@freeze_time("2015-01-01")
@mock_opsworks
def test_create_app_response():
client = boto3.client('opsworks', region_name='us-east-1')
client = boto3.client("opsworks", region_name="us-east-1")
stack_id = client.create_stack(
Name="test_stack_1",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)['StackId']
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
response = client.create_app(
StackId=stack_id,
Type="other",
Name="TestApp"
)
response = client.create_app(StackId=stack_id, Type="other", Name="TestApp")
response.should.contain("AppId")
@ -30,73 +26,51 @@ def test_create_app_response():
Name="test_stack_2",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)['StackId']
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
response = client.create_app(
StackId=second_stack_id,
Type="other",
Name="TestApp"
)
response = client.create_app(StackId=second_stack_id, Type="other", Name="TestApp")
response.should.contain("AppId")
# ClientError
client.create_app.when.called_with(
StackId=stack_id,
Type="other",
Name="TestApp"
).should.throw(
Exception, re.compile(r'already an app named "TestApp"')
)
StackId=stack_id, Type="other", Name="TestApp"
).should.throw(Exception, re.compile(r'already an app named "TestApp"'))
# ClientError
client.create_app.when.called_with(
StackId="nothere",
Type="other",
Name="TestApp"
).should.throw(
Exception, "nothere"
)
StackId="nothere", Type="other", Name="TestApp"
).should.throw(Exception, "nothere")
@freeze_time("2015-01-01")
@mock_opsworks
def test_describe_apps():
client = boto3.client('opsworks', region_name='us-east-1')
client = boto3.client("opsworks", region_name="us-east-1")
stack_id = client.create_stack(
Name="test_stack_1",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)['StackId']
app_id = client.create_app(
StackId=stack_id,
Type="other",
Name="TestApp"
)['AppId']
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
app_id = client.create_app(StackId=stack_id, Type="other", Name="TestApp")["AppId"]
rv1 = client.describe_apps(StackId=stack_id)
rv2 = client.describe_apps(AppIds=[app_id])
rv1['Apps'].should.equal(rv2['Apps'])
rv1["Apps"].should.equal(rv2["Apps"])
rv1['Apps'][0]['Name'].should.equal("TestApp")
rv1["Apps"][0]["Name"].should.equal("TestApp")
# ClientError
client.describe_apps.when.called_with(
StackId=stack_id,
AppIds=[app_id]
).should.throw(
Exception, "Please provide one or more app IDs or a stack ID"
)
StackId=stack_id, AppIds=[app_id]
).should.throw(Exception, "Please provide one or more app IDs or a stack ID")
# ClientError
client.describe_apps.when.called_with(
StackId="nothere"
).should.throw(
client.describe_apps.when.called_with(StackId="nothere").should.throw(
Exception, "Unable to find stack with ID nothere"
)
# ClientError
client.describe_apps.when.called_with(
AppIds=["nothere"]
).should.throw(
client.describe_apps.when.called_with(AppIds=["nothere"]).should.throw(
Exception, "nothere"
)

View file

@ -8,34 +8,34 @@ from moto import mock_ec2
@mock_opsworks
def test_create_instance():
client = boto3.client('opsworks', region_name='us-east-1')
client = boto3.client("opsworks", region_name="us-east-1")
stack_id = client.create_stack(
Name="test_stack_1",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)['StackId']
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
layer_id = client.create_layer(
StackId=stack_id,
Type="custom",
Name="TestLayer",
Shortname="TestLayerShortName"
)['LayerId']
Shortname="TestLayerShortName",
)["LayerId"]
second_stack_id = client.create_stack(
Name="test_stack_2",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)['StackId']
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
second_layer_id = client.create_layer(
StackId=second_stack_id,
Type="custom",
Name="SecondTestLayer",
Shortname="SecondTestLayerShortName"
)['LayerId']
Shortname="SecondTestLayerShortName",
)["LayerId"]
response = client.create_instance(
StackId=stack_id, LayerIds=[layer_id], InstanceType="t2.micro"
@ -55,9 +55,9 @@ def test_create_instance():
StackId=stack_id, LayerIds=[second_layer_id], InstanceType="t2.micro"
).should.throw(Exception, "Please only provide layer IDs from the same stack")
# ClientError
client.start_instance.when.called_with(
InstanceId="nothere"
).should.throw(Exception, "Unable to find instance with ID nothere")
client.start_instance.when.called_with(InstanceId="nothere").should.throw(
Exception, "Unable to find instance with ID nothere"
)
@mock_opsworks
@ -70,112 +70,95 @@ def test_describe_instances():
populate S2L2 with 3 instances (S2L2_i1..2)
"""
client = boto3.client('opsworks', region_name='us-east-1')
client = boto3.client("opsworks", region_name="us-east-1")
S1 = client.create_stack(
Name="S1",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)['StackId']
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
S1L1 = client.create_layer(
StackId=S1,
Type="custom",
Name="S1L1",
Shortname="S1L1"
)['LayerId']
StackId=S1, Type="custom", Name="S1L1", Shortname="S1L1"
)["LayerId"]
S2 = client.create_stack(
Name="S2",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)['StackId']
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
S2L1 = client.create_layer(
StackId=S2,
Type="custom",
Name="S2L1",
Shortname="S2L1"
)['LayerId']
StackId=S2, Type="custom", Name="S2L1", Shortname="S2L1"
)["LayerId"]
S2L2 = client.create_layer(
StackId=S2,
Type="custom",
Name="S2L2",
Shortname="S2L2"
)['LayerId']
StackId=S2, Type="custom", Name="S2L2", Shortname="S2L2"
)["LayerId"]
S1L1_i1 = client.create_instance(
StackId=S1, LayerIds=[S1L1], InstanceType="t2.micro"
)['InstanceId']
)["InstanceId"]
S1L1_i2 = client.create_instance(
StackId=S1, LayerIds=[S1L1], InstanceType="t2.micro"
)['InstanceId']
)["InstanceId"]
S2L1_i1 = client.create_instance(
StackId=S2, LayerIds=[S2L1], InstanceType="t2.micro"
)['InstanceId']
)["InstanceId"]
S2L2_i1 = client.create_instance(
StackId=S2, LayerIds=[S2L2], InstanceType="t2.micro"
)['InstanceId']
)["InstanceId"]
S2L2_i2 = client.create_instance(
StackId=S2, LayerIds=[S2L2], InstanceType="t2.micro"
)['InstanceId']
)["InstanceId"]
# instances in Stack 1
response = client.describe_instances(StackId=S1)['Instances']
response = client.describe_instances(StackId=S1)["Instances"]
response.should.have.length_of(2)
S1L1_i1.should.be.within([i["InstanceId"] for i in response])
S1L1_i2.should.be.within([i["InstanceId"] for i in response])
response2 = client.describe_instances(
InstanceIds=[S1L1_i1, S1L1_i2])['Instances']
sorted(response2, key=lambda d: d['InstanceId']).should.equal(
sorted(response, key=lambda d: d['InstanceId']))
response2 = client.describe_instances(InstanceIds=[S1L1_i1, S1L1_i2])["Instances"]
sorted(response2, key=lambda d: d["InstanceId"]).should.equal(
sorted(response, key=lambda d: d["InstanceId"])
)
response3 = client.describe_instances(LayerId=S1L1)['Instances']
sorted(response3, key=lambda d: d['InstanceId']).should.equal(
sorted(response, key=lambda d: d['InstanceId']))
response3 = client.describe_instances(LayerId=S1L1)["Instances"]
sorted(response3, key=lambda d: d["InstanceId"]).should.equal(
sorted(response, key=lambda d: d["InstanceId"])
)
response = client.describe_instances(StackId=S1)['Instances']
response = client.describe_instances(StackId=S1)["Instances"]
response.should.have.length_of(2)
S1L1_i1.should.be.within([i["InstanceId"] for i in response])
S1L1_i2.should.be.within([i["InstanceId"] for i in response])
# instances in Stack 2
response = client.describe_instances(StackId=S2)['Instances']
response = client.describe_instances(StackId=S2)["Instances"]
response.should.have.length_of(3)
S2L1_i1.should.be.within([i["InstanceId"] for i in response])
S2L2_i1.should.be.within([i["InstanceId"] for i in response])
S2L2_i2.should.be.within([i["InstanceId"] for i in response])
response = client.describe_instances(LayerId=S2L1)['Instances']
response = client.describe_instances(LayerId=S2L1)["Instances"]
response.should.have.length_of(1)
S2L1_i1.should.be.within([i["InstanceId"] for i in response])
response = client.describe_instances(LayerId=S2L2)['Instances']
response = client.describe_instances(LayerId=S2L2)["Instances"]
response.should.have.length_of(2)
S2L1_i1.should_not.be.within([i["InstanceId"] for i in response])
# ClientError
client.describe_instances.when.called_with(
StackId=S1,
LayerId=S1L1
).should.throw(
client.describe_instances.when.called_with(StackId=S1, LayerId=S1L1).should.throw(
Exception, "Please provide either one or more"
)
# ClientError
client.describe_instances.when.called_with(
StackId="nothere"
).should.throw(
client.describe_instances.when.called_with(StackId="nothere").should.throw(
Exception, "nothere"
)
# ClientError
client.describe_instances.when.called_with(
LayerId="nothere"
).should.throw(
client.describe_instances.when.called_with(LayerId="nothere").should.throw(
Exception, "nothere"
)
# ClientError
client.describe_instances.when.called_with(
InstanceIds=["nothere"]
).should.throw(
client.describe_instances.when.called_with(InstanceIds=["nothere"]).should.throw(
Exception, "nothere"
)
@ -187,38 +170,37 @@ def test_ec2_integration():
instances created via OpsWorks should be discoverable via ec2
"""
opsworks = boto3.client('opsworks', region_name='us-east-1')
opsworks = boto3.client("opsworks", region_name="us-east-1")
stack_id = opsworks.create_stack(
Name="S1",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)['StackId']
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
layer_id = opsworks.create_layer(
StackId=stack_id,
Type="custom",
Name="S1L1",
Shortname="S1L1"
)['LayerId']
StackId=stack_id, Type="custom", Name="S1L1", Shortname="S1L1"
)["LayerId"]
instance_id = opsworks.create_instance(
StackId=stack_id, LayerIds=[layer_id], InstanceType="t2.micro", SshKeyName="testSSH"
)['InstanceId']
StackId=stack_id,
LayerIds=[layer_id],
InstanceType="t2.micro",
SshKeyName="testSSH",
)["InstanceId"]
ec2 = boto3.client('ec2', region_name='us-east-1')
ec2 = boto3.client("ec2", region_name="us-east-1")
# Before starting the instance, it shouldn't be discoverable via ec2
reservations = ec2.describe_instances()['Reservations']
reservations = ec2.describe_instances()["Reservations"]
assert reservations.should.be.empty
# After starting the instance, it should be discoverable via ec2
opsworks.start_instance(InstanceId=instance_id)
reservations = ec2.describe_instances()['Reservations']
reservations[0]['Instances'].should.have.length_of(1)
instance = reservations[0]['Instances'][0]
opsworks_instance = opsworks.describe_instances(StackId=stack_id)[
'Instances'][0]
reservations = ec2.describe_instances()["Reservations"]
reservations[0]["Instances"].should.have.length_of(1)
instance = reservations[0]["Instances"][0]
opsworks_instance = opsworks.describe_instances(StackId=stack_id)["Instances"][0]
instance['InstanceId'].should.equal(opsworks_instance['Ec2InstanceId'])
instance['PrivateIpAddress'].should.equal(opsworks_instance['PrivateIp'])
instance["InstanceId"].should.equal(opsworks_instance["Ec2InstanceId"])
instance["PrivateIpAddress"].should.equal(opsworks_instance["PrivateIp"])

View file

@ -10,19 +10,19 @@ from moto import mock_opsworks
@freeze_time("2015-01-01")
@mock_opsworks
def test_create_layer_response():
client = boto3.client('opsworks', region_name='us-east-1')
client = boto3.client("opsworks", region_name="us-east-1")
stack_id = client.create_stack(
Name="test_stack_1",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)['StackId']
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
response = client.create_layer(
StackId=stack_id,
Type="custom",
Name="TestLayer",
Shortname="TestLayerShortName"
Shortname="TestLayerShortName",
)
response.should.contain("LayerId")
@ -31,87 +31,66 @@ def test_create_layer_response():
Name="test_stack_2",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)['StackId']
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
response = client.create_layer(
StackId=second_stack_id,
Type="custom",
Name="TestLayer",
Shortname="TestLayerShortName"
Shortname="TestLayerShortName",
)
response.should.contain("LayerId")
# ClientError
client.create_layer.when.called_with(
StackId=stack_id,
Type="custom",
Name="TestLayer",
Shortname="_"
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 named "TestLayer"')
Exception, re.compile(r'already a layer with shortname "TestLayerShortName"')
)
# 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"')
)
# ClientError
client.create_layer.when.called_with(
StackId="nothere",
Type="custom",
Name="TestLayer",
Shortname="_"
).should.throw(
Exception, "nothere"
)
StackId="nothere", Type="custom", Name="TestLayer", Shortname="_"
).should.throw(Exception, "nothere")
@freeze_time("2015-01-01")
@mock_opsworks
def test_describe_layers():
client = boto3.client('opsworks', region_name='us-east-1')
client = boto3.client("opsworks", region_name="us-east-1")
stack_id = client.create_stack(
Name="test_stack_1",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)['StackId']
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
layer_id = client.create_layer(
StackId=stack_id,
Type="custom",
Name="TestLayer",
Shortname="TestLayerShortName"
)['LayerId']
Shortname="TestLayerShortName",
)["LayerId"]
rv1 = client.describe_layers(StackId=stack_id)
rv2 = client.describe_layers(LayerIds=[layer_id])
rv1['Layers'].should.equal(rv2['Layers'])
rv1["Layers"].should.equal(rv2["Layers"])
rv1['Layers'][0]['Name'].should.equal("TestLayer")
rv1["Layers"][0]["Name"].should.equal("TestLayer")
# ClientError
client.describe_layers.when.called_with(
StackId=stack_id,
LayerIds=[layer_id]
).should.throw(
Exception, "Please provide one or more layer IDs or a stack ID"
)
StackId=stack_id, LayerIds=[layer_id]
).should.throw(Exception, "Please provide one or more layer IDs or a stack ID")
# ClientError
client.describe_layers.when.called_with(
StackId="nothere"
).should.throw(
client.describe_layers.when.called_with(StackId="nothere").should.throw(
Exception, "Unable to find stack with ID nothere"
)
# ClientError
client.describe_layers.when.called_with(
LayerIds=["nothere"]
).should.throw(
client.describe_layers.when.called_with(LayerIds=["nothere"]).should.throw(
Exception, "nothere"
)

View file

@ -1,46 +1,46 @@
from __future__ import unicode_literals
import boto3
import sure # noqa
import re
from moto import mock_opsworks
@mock_opsworks
def test_create_stack_response():
client = boto3.client('opsworks', region_name='us-east-1')
response = client.create_stack(
Name="test_stack_1",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)
response.should.contain("StackId")
@mock_opsworks
def test_describe_stacks():
client = boto3.client('opsworks', region_name='us-east-1')
for i in range(1, 4):
client.create_stack(
Name="test_stack_{0}".format(i),
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn"
)
response = client.describe_stacks()
response['Stacks'].should.have.length_of(3)
for stack in response['Stacks']:
stack['ServiceRoleArn'].should.equal("service_arn")
stack['DefaultInstanceProfileArn'].should.equal("profile_arn")
_id = response['Stacks'][0]['StackId']
response = client.describe_stacks(StackIds=[_id])
response['Stacks'].should.have.length_of(1)
response['Stacks'][0]['Arn'].should.contain(_id)
# ClientError/ResourceNotFoundException
client.describe_stacks.when.called_with(StackIds=["foo"]).should.throw(
Exception, re.compile(r'foo')
)
from __future__ import unicode_literals
import boto3
import sure # noqa
import re
from moto import mock_opsworks
@mock_opsworks
def test_create_stack_response():
client = boto3.client("opsworks", region_name="us-east-1")
response = client.create_stack(
Name="test_stack_1",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn",
)
response.should.contain("StackId")
@mock_opsworks
def test_describe_stacks():
client = boto3.client("opsworks", region_name="us-east-1")
for i in range(1, 4):
client.create_stack(
Name="test_stack_{0}".format(i),
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn",
)
response = client.describe_stacks()
response["Stacks"].should.have.length_of(3)
for stack in response["Stacks"]:
stack["ServiceRoleArn"].should.equal("service_arn")
stack["DefaultInstanceProfileArn"].should.equal("profile_arn")
_id = response["Stacks"][0]["StackId"]
response = client.describe_stacks(StackIds=[_id])
response["Stacks"].should.have.length_of(1)
response["Stacks"][0]["Arn"].should.contain(_id)
# ClientError/ResourceNotFoundException
client.describe_stacks.when.called_with(StackIds=["foo"]).should.throw(
Exception, re.compile(r"foo")
)