@mock_opsworks
@mock_ec2
def test_ec2_integration():
 opsworks = boto3.client(u'opsworks', region_name=u'us-east-1')
 stack_id = opsworks.create_stack(Name=u'S1', Region=u'us-east-1', ServiceRoleArn=u'service_arn', DefaultInstanceProfileArn=u'profile_arn')[u'StackId']
 layer_id = opsworks.create_layer(StackId=stack_id, Type=u'custom', Name=u'S1L1', Shortname=u'S1L1')[u'LayerId']
 instance_id = opsworks.create_instance(StackId=stack_id, LayerIds=[layer_id], InstanceType=u't2.micro')[u'InstanceId']
 ec2 = boto3.client(u'ec2', region_name=u'us-east-1')
 reservations = ec2.describe_instances()[u'Reservations']
 assert reservations.should.be.empty
 opsworks.start_instance(InstanceId=instance_id)
 reservations = ec2.describe_instances()[u'Reservations']
 reservations[0][u'Instances'].should.have.length_of(1)
 instance = reservations[0][u'Instances'][0]
 opsworks_instance = opsworks.describe_instances(StackId=stack_id)[u'Instances'][0]
 instance[u'InstanceId'].should.equal(opsworks_instance[u'Ec2InstanceId'])
 instance[u'PrivateIpAddress'].should.equal(opsworks_instance[u'PrivateIp'])

@ mock_opsworks @ mock_ec2 def test_ec2_integration ( ) : opsworks = boto3 . client ( u'opsworks' , region_name = u'us-east-1' ) stack_id = opsworks . create_stack ( Name = u'S1' , Region = u'us-east-1' , ServiceRoleArn = u'service_arn' , DefaultInstanceProfileArn = u'profile_arn' ) [ u'StackId' ] layer_id = opsworks . create_layer ( StackId = stack_id , Type = u'custom' , Name = u'S1L1' , Shortname = u'S1L1' ) [ u'LayerId' ] instance_id = opsworks . create_instance ( StackId = stack_id , LayerIds = [ layer_id ] , InstanceType = u't2.micro' ) [ u'InstanceId' ] ec2 = boto3 . client ( u'ec2' , region_name = u'us-east-1' ) reservations = ec2 . describe_instances ( ) [ u'Reservations' ] assert reservations . should . be . empty opsworks . start_instance ( InstanceId = instance_id ) reservations = ec2 . describe_instances ( ) [ u'Reservations' ] reservations [ 0 ] [ u'Instances' ] . should . have . length_of ( 1 ) instance = reservations [ 0 ] [ u'Instances' ] [ 0 ] opsworks_instance = opsworks . describe_instances ( StackId = stack_id ) [ u'Instances' ] [ 0 ] instance [ u'InstanceId' ] . should . equal ( opsworks_instance [ u'Ec2InstanceId' ] ) instance [ u'PrivateIpAddress' ] . should . equal ( opsworks_instance [ u'PrivateIp' ] )
instances created via opsworks should be discoverable via ec2 .