Exemplo n.º 1
0
    def get_method(self, item, **kwargs):
        vpc = get_vpc(item["VpcId"], **kwargs)
        # Need to provide the friendly name:
        vpc["DEFERRED_ITEM_NAME"] = "{name} ({id})".format(
            name=vpc.get("Name"), id=vpc["Id"])

        return vpc
Exemplo n.º 2
0
def test_get_base_errors():
    from cloudaux.orchestration.aws.vpc import get_vpc

    # No Account Number:
    with pytest.raises(CloudAuxException) as cae:
        get_vpc("vpc-012345678")

    assert "account number" in cae.value.args[0]["message"]
    assert cae.value.args[0]["vpc_id"] == "vpc-012345678"

    # No Region:
    with pytest.raises(CloudAuxException) as cae:
        get_vpc("vpc-012345678", account_number="012345678912")

    assert "region" in cae.value.args[0]["message"]
    assert cae.value.args[0]["vpc_id"] == "vpc-012345678"
Exemplo n.º 3
0
def test_get_base(ec2, test_vpc, dhcp_options):
    from cloudaux.orchestration.aws.vpc import get_vpc, FLAGS

    result = get_vpc(test_vpc["VpcId"],
                     flags=FLAGS.BASE,
                     account_number="012345678912",
                     region="us-east-1")
    perform_base_tests(test_vpc, dhcp_options, result)

    # And without tags:
    ec2.delete_tags(Resources=[test_vpc["VpcId"]],
                    Tags=[{
                        "Key": "Name",
                        "Value": "myvpc"
                    }])
    result = get_vpc(test_vpc["VpcId"],
                     flags=FLAGS.BASE,
                     account_number="012345678912",
                     region="us-east-1")
    assert len(result["Tags"]) == 1
    assert not result["Name"]
Exemplo n.º 4
0
def test_get_subnets_no_subnet(test_vpc, dhcp_options):
    from cloudaux.orchestration.aws.vpc import get_vpc, get_subnets, FLAGS

    result = get_subnets({"id": test_vpc["VpcId"]})
    assert not result

    # With BASE:
    result = get_vpc(test_vpc["VpcId"],
                     flags=FLAGS.SUBNETS,
                     account_number="012345678912",
                     region="us-east-1")
    assert not result["Subnets"]
    perform_base_tests(test_vpc, dhcp_options, result)
Exemplo n.º 5
0
def test_get_vpc_peering_connections_no_connections(test_vpc, dhcp_options):
    from cloudaux.orchestration.aws.vpc import get_vpc, get_vpc_peering_connections, FLAGS

    result = get_vpc_peering_connections({"id": test_vpc["VpcId"]})
    assert not result

    # With BASE:
    result = get_vpc(test_vpc["VpcId"],
                     flags=FLAGS.VPC_PEERING_CONNECTIONS,
                     account_number="012345678912",
                     region="us-east-1")
    assert not result["VpcPeeringConnections"]
    perform_base_tests(test_vpc, dhcp_options, result)
Exemplo n.º 6
0
def test_get_internet_gateway_no_ig(test_vpc, dhcp_options):
    # Can't parametrize fixtures :(
    from cloudaux.orchestration.aws.vpc import get_vpc, get_internet_gateway, FLAGS

    result = get_internet_gateway({"id": test_vpc["VpcId"]})
    assert not result

    # With BASE:
    result = get_vpc(test_vpc["VpcId"],
                     flags=FLAGS.INTERNET_GATEWAY,
                     account_number="012345678912",
                     region="us-east-1")
    assert not result["InternetGateway"]
    perform_base_tests(test_vpc, dhcp_options, result)
Exemplo n.º 7
0
def test_get_vpc_peering_connections(test_vpc, dhcp_options,
                                     vpc_peering_connection):
    from cloudaux.orchestration.aws.vpc import get_vpc, get_vpc_peering_connections, FLAGS

    result = get_vpc_peering_connections({"id": test_vpc["VpcId"]})

    # Moto improperly returns a duplicate -- this should be 1.
    assert result[0] == vpc_peering_connection["VpcPeeringConnectionId"]

    # With BASE:
    result = get_vpc(test_vpc["VpcId"],
                     flags=FLAGS.VPC_PEERING_CONNECTIONS,
                     account_number="012345678912",
                     region="us-east-1")
    assert result["VpcPeeringConnections"][0] == \
        vpc_peering_connection["VpcPeeringConnectionId"]
    perform_base_tests(test_vpc, dhcp_options, result)
Exemplo n.º 8
0
def test_get_vpc_flow_logs(test_vpc, dhcp_options, mock_vpc_flow_logs):
    from cloudaux.orchestration.aws.vpc import get_vpc, get_vpc_flow_logs, FLAGS

    result = get_vpc_flow_logs({"id": test_vpc["VpcId"]},
                               force_client=mock_vpc_flow_logs)
    assert len(result) == 1
    assert result[0] == "fl-xxxxxxxx"

    # With BASE:
    result = get_vpc(test_vpc["VpcId"],
                     flags=FLAGS.FLOW_LOGS,
                     account_number="012345678912",
                     region="us-east-1",
                     force_client=mock_vpc_flow_logs)

    assert len(result["FlowLogs"]) == 1
    assert result["FlowLogs"][0] == "fl-xxxxxxxx"
    perform_base_tests(test_vpc, dhcp_options, result)
Exemplo n.º 9
0
def test_get_classic_link(test_vpc, dhcp_options, mock_classic_link):
    from cloudaux.orchestration.aws.vpc import get_vpc, get_classic_link, FLAGS

    result = get_classic_link({"id": test_vpc["VpcId"]},
                              force_client=mock_classic_link)
    assert result["Enabled"]
    assert result["DnsEnabled"]

    # With BASE:
    result = get_vpc(test_vpc["VpcId"],
                     flags=FLAGS.CLASSIC_LINK,
                     account_number="012345678912",
                     region="us-east-1",
                     force_client=mock_classic_link)

    assert result["ClassicLink"]["Enabled"]
    assert result["ClassicLink"]["DnsEnabled"]
    perform_base_tests(test_vpc, dhcp_options, result)
Exemplo n.º 10
0
def test_get_network_acls(test_vpc, dhcp_options, network_acl):
    from cloudaux.orchestration.aws.vpc import get_vpc, get_network_acls, FLAGS

    # Moto always returns a default:
    result = get_network_acls({"id": test_vpc["VpcId"]})
    assert len(result) == 2
    found = False
    for r in result:
        if r == network_acl["NetworkAclId"]:
            found = True
    assert found

    # With BASE:
    result = get_vpc(test_vpc["VpcId"],
                     flags=FLAGS.NETWORK_ACLS,
                     account_number="012345678912",
                     region="us-east-1")
    assert len(result["NetworkAcls"]) == 2
    found = False
    for r in result["NetworkAcls"]:
        if r == network_acl["NetworkAclId"]:
            found = True
    assert found
    perform_base_tests(test_vpc, dhcp_options, result)
Exemplo n.º 11
0
def test_get_route_tables(test_vpc, dhcp_options, route_table):
    from cloudaux.orchestration.aws.vpc import get_vpc, get_route_tables, FLAGS

    # Moto always returns a default:
    result = get_route_tables({"id": test_vpc["VpcId"]})
    assert len(result) == 2
    found = False
    for r in result:
        if r == route_table["RouteTableId"]:
            found = True
    assert found

    # With BASE:
    result = get_vpc(test_vpc["VpcId"],
                     flags=FLAGS.ROUTE_TABLES,
                     account_number="012345678912",
                     region="us-east-1")
    assert len(result["RouteTables"]) == 2
    found = False
    for r in result["RouteTables"]:
        if r == route_table["RouteTableId"]:
            found = True
    assert found
    perform_base_tests(test_vpc, dhcp_options, result)
Exemplo n.º 12
0
def test_classic_link_exception(test_vpc, dhcp_options, mock_classic_link):
    from cloudaux.orchestration.aws.vpc import get_vpc, get_classic_link, FLAGS

    # Return an unsupported operation exception:
    def raise_exception(**kwargs):
        raise ClientError({"Error": {
            "Code": "UnsupportedOperation"
        }}, "DescribeVpcClassicLink")

    mock_classic_link.describe_vpc_classic_link = raise_exception

    result = get_classic_link({"id": test_vpc["VpcId"]},
                              force_client=mock_classic_link)
    assert not result

    # With BASE:
    result = get_vpc(test_vpc["VpcId"],
                     flags=FLAGS.CLASSIC_LINK,
                     account_number="012345678912",
                     region="us-east-1",
                     force_client=mock_classic_link)

    assert not result["ClassicLink"]
    perform_base_tests(test_vpc, dhcp_options, result)
Exemplo n.º 13
0
    def get_method(self, item, **kwargs):
        vpc = get_vpc(item["VpcId"], **kwargs)
        # Need to provide the friendly name:
        vpc["DEFERRED_ITEM_NAME"] = "{name} ({id})".format(name=vpc.get("Name"), id=vpc["Id"])

        return vpc