Exemplo n.º 1
0
def fxt_ami_custom(ec2: botostubs.EC2, public_subnet):
    instance = ec2.run_instances(**DEFAULT_INSTANCE_KWARGS, ImageId=IMAGE_NAME)
    instance_id = instance["Instances"][0]["InstanceId"]

    image = ec2.create_image(Name="mock_custom_application",
                             InstanceId=instance_id)
    yield image
Exemplo n.º 2
0
def fxt_ami_centos(ec2: botostubs.EC2, public_subnet):
    instance = ec2.run_instances(**DEFAULT_INSTANCE_KWARGS, ImageId=IMAGE_NAME)
    instance_id = instance["Instances"][0]["InstanceId"]

    image = ec2.create_image(
        Description="Mock CentOS Linux Image",
        Name="mock_centos_linux",
        InstanceId=instance_id,
    )
    yield image
Exemplo n.º 3
0
def test_no_description_username_fallback(ec2: botostubs.EC2, ami_custom,
                                          public_subnet):
    """Tests username resolution expecting the default fallback to ec2-user."""
    new_instance = ec2.run_instances(
        **DEFAULT_INSTANCE_KWARGS,
        ImageId=ami_custom["ImageId"],
        SubnetId=public_subnet["SubnetId"],
    )
    instance_id = new_instance["Instances"][0]["InstanceId"]
    instances = ec2.describe_instances(InstanceIds=[instance_id])
    instance = Instance(instances["Reservations"][0]["Instances"][0])

    assert instance.default_username() == "ec2-user"
Exemplo n.º 4
0
def test_centos_username_retreival(ec2: botostubs.EC2, ami_centos,
                                   public_subnet):
    """Tests username resolution expecting centos."""
    new_centos_instance = ec2.run_instances(
        **DEFAULT_INSTANCE_KWARGS,
        ImageId=ami_centos["ImageId"],
        SubnetId=public_subnet["SubnetId"],
    )
    instance_id = new_centos_instance["Instances"][0]["InstanceId"]
    instances = ec2.describe_instances(InstanceIds=[instance_id])
    instance = Instance(instances["Reservations"][0]["Instances"][0])

    assert instance.default_username() == "centos"
Exemplo n.º 5
0
def fxt_terminated_aws_instance(ec2: botostubs.EC2, public_subnet, ami_amzn):
    new_instance = ec2.run_instances(
        **DEFAULT_INSTANCE_KWARGS,
        ImageId=ami_amzn["ImageId"],
        SubnetId=public_subnet["SubnetId"],
        TagSpecifications=[{
            "ResourceType":
            "instance",
            "Tags": [{
                "Key": "Name",
                "Value": "Terminated Instance"
            }],
        }],
    )
    instance_id = new_instance["Instances"][0]["InstanceId"]
    ec2.terminate_instances(InstanceIds=[instance_id])
Exemplo n.º 6
0
def fxt_public_aws_instance(ec2: botostubs.EC2, public_subnet, ami_amzn):
    new_instance = ec2.run_instances(
        **DEFAULT_INSTANCE_KWARGS,
        ImageId=ami_amzn["ImageId"],
        SubnetId=public_subnet["SubnetId"],
        TagSpecifications=[{
            "ResourceType":
            "instance",
            "Tags": [{
                "Key": "Name",
                "Value": PUBLIC_INSTANCE_NAME
            }],
        }],
    )
    instance_id = new_instance["Instances"][0]["InstanceId"]
    instances = ec2.describe_instances(InstanceIds=[instance_id])
    yield instances["Reservations"][0]["Instances"][0]
Exemplo n.º 7
0
def test_custom_username_matcher(ec2: botostubs.EC2, ami_ubuntu,
                                 public_subnet):
    """Test custom username matchers."""
    new_instance = ec2.run_instances(
        **DEFAULT_INSTANCE_KWARGS,
        ImageId=ami_ubuntu["ImageId"],
        SubnetId=public_subnet["SubnetId"],
    )
    instance_id = new_instance["Instances"][0]["InstanceId"]
    instances = ec2.describe_instances(InstanceIds=[instance_id])
    instance = Instance(instances["Reservations"][0]["Instances"][0])

    image_name_ubuntu_test = {"username": "******", "image-name": "ubuntu"}
    assert instance.default_username([image_name_ubuntu_test]) == "test"

    image_name_ubuntu_regex = {
        "username": "******",
        "image-name": "^.*ubuntu.*$"
    }
    assert instance.default_username([image_name_ubuntu_regex]) == "test"

    description_ubuntu_test2 = {"username": "******", "description": "ubuntu"}
    assert instance.default_username([description_ubuntu_test2]) == "test2"
Exemplo n.º 8
0
def waitInstanceTerminated(instanceId, client: botostubs.EC2):
    waiter: botostubs.EC2.InstanceTerminatedWaiter = client.get_waiter(
        'instance_terminated')
    waiter.wait(InstanceIds=[instanceId])
Exemplo n.º 9
0
def waitInstanceStopped(instanceId, client: botostubs.EC2):
    waiter: botostubs.EC2.InstanceStoppedWaiter = client.get_waiter(
        'instance_stopped')
    waiter.wait(InstanceIds=[instanceId])
Exemplo n.º 10
0
def waitInstanceStatusOK(instanceId, client: botostubs.EC2):
    waiter: botostubs.EC2.InstanceStatusOkWaiter = client.get_waiter(
        'instance_status_ok')
    waiter.wait(InstanceIds=[instanceId])
Exemplo n.º 11
0
def fxt_private_subnet(ec2: botostubs.EC2, vpc):
    subnet = ec2.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.1.0/24")

    yield subnet["Subnet"]
Exemplo n.º 12
0
def fxt_public_subnet(ec2: botostubs.EC2, vpc):
    subnet = ec2.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.0.0/24")
    ec2.modify_subnet_attribute(SubnetId=subnet["Subnet"]["SubnetId"],
                                MapPublicIpOnLaunch={"Value": True})

    yield subnet["Subnet"]
Exemplo n.º 13
0
def fxt_vpc(ec2: botostubs.EC2):
    vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16", DryRun=False)

    yield vpc["Vpc"]