Пример #1
0
def test_target_size_bigger_than_allocated_subnets():
    assert_that(
        evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.1.0/24", "10.0.3.0/24"], target_size=500)
    ).is_equal_to("10.0.4.0/23")
    assert_that(
        evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.1.0/24", "10.0.4.0/24"], target_size=500)
    ).is_equal_to("10.0.2.0/23")
    assert_that(
        evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.1.0/24", "10.0.4.0/24"], target_size=1000)
    ).is_equal_to("10.0.8.0/22")
Пример #2
0
def test_fully_booked_vpc():
    assert_that(evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.0.0/16"], target_size=1)).is_none()
    assert_that(
        evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.0.0/17", "10.0.128.0/17"], target_size=1)
    ).is_none()
    assert_that(
        evaluate_cidr(
            vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.0.0/18", "10.0.64.0/18", "10.0.128.0/18"], target_size=16385
        )
    ).is_none()
    assert_that(
        evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.0.0/18", "10.0.128.0/17"], target_size=16385)
    ).is_none()
Пример #3
0
 def _create(self, vpc_id, vpc_cidr, subnet_cidrs, internet_gateway_id,
             compute_subnet_size):  # noqa D102
     public_cidr = evaluate_cidr(vpc_cidr=vpc_cidr,
                                 occupied_cidrs=subnet_cidrs,
                                 target_size=HEAD_NODE_SUBNET_IPS)
     _validate_cidr(public_cidr)
     subnet_cidrs.append(public_cidr)
     private_cidr = get_subnet_cidr(vpc_cidr=vpc_cidr,
                                    occupied_cidr=subnet_cidrs,
                                    min_subnet_size=compute_subnet_size)
     _validate_cidr(private_cidr)
     parameters = self.get_cfn_parameters(vpc_id, internet_gateway_id,
                                          public_cidr, private_cidr)
     stack_output = _create_network_stack(self, parameters)
     return {
         "head_node_subnet_id":
         get_stack_output_value(stack_output, "PublicSubnetId"),
         "compute_subnet_id":
         get_stack_output_value(stack_output, "PrivateSubnetId"),
     }
Пример #4
0
def test_target_size_smaller_than_allocated_subnets():
    assert_that(
        evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.1.0/24", "10.0.3.0/24"], target_size=250)
    ).is_equal_to("10.0.0.0/24")
    assert_that(
        evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.1.0/24", "10.0.2.0/24"], target_size=250)
    ).is_equal_to("10.0.0.0/24")
    assert_that(
        evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.3.0/24", "10.0.2.0/24"], target_size=250)
    ).is_equal_to("10.0.0.0/24")
    assert_that(
        evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.4.0/24", "10.0.2.0/24"], target_size=250)
    ).is_equal_to("10.0.0.0/24")
    assert_that(
        evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.4.0/24", "10.0.2.0/24"], target_size=120)
    ).is_equal_to("10.0.0.0/25")
    assert_that(
        evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=["10.0.1.0/24", "10.0.0.0/24"], target_size=120)
    ).is_equal_to("10.0.2.0/25")
Пример #5
0
def test_empty_vpc():
    assert_that(evaluate_cidr(vpc_cidr="10.0.0.0/16", occupied_cidrs=[], target_size=250)).is_equal_to("10.0.0.0/24")
    assert_that(evaluate_cidr(vpc_cidr="10.0.0.0/8", occupied_cidrs=[], target_size=250)).is_equal_to("10.0.0.0/24")
    assert_that(evaluate_cidr(vpc_cidr="10.2.0.0/16", occupied_cidrs=[], target_size=250)).is_equal_to("10.2.0.0/24")
    assert_that(evaluate_cidr(vpc_cidr="10.2.0.0/25", occupied_cidrs=[], target_size=500)).is_none()
    assert_that(evaluate_cidr(vpc_cidr="10.2.0.0/25", occupied_cidrs=[], target_size=100)).is_equal_to("10.2.0.0/25")