Пример #1
0
def test_weighted_dns_load_balancer_v2(monkeypatch, boto_client, boto_resource):  # noqa: F811
    senza.traffic.DNS_ZONE_CACHE = {}

    configuration = {
        "Name": "MyLB",
        "SecurityGroups": "",
        "HTTPPort": "9999",
        'MainDomain': 'great.api.zo.ne',
        'VersionDomain': 'version.api.zo.ne',
        # test overwritting specific properties in one of the resources
        'TargetGroupAttributes': [{'Key': 'deregistration_delay.timeout_seconds', 'Value': '123'}],
        # test that Security Groups are resolved
        'SecurityGroups': ['foo-security-group']
    }
    info = {'StackName': 'foobar', 'StackVersion': '0.1'}
    definition = {"Resources": {}}

    args = MagicMock()
    args.region = "foo"

    mock_string_result = MagicMock()
    mock_string_result.return_value = ['sg-foo']
    monkeypatch.setattr('senza.components.elastic_load_balancer_v2.resolve_security_groups', mock_string_result)

    get_ssl_cert = MagicMock()
    get_ssl_cert.return_value = 'arn:aws:42'
    monkeypatch.setattr('senza.components.elastic_load_balancer_v2.get_ssl_cert', get_ssl_cert)

    result = component_weighted_dns_elastic_load_balancer_v2(definition,
                                                             configuration,
                                                             args,
                                                             info,
                                                             False,
                                                             AccountArguments('dummyregion'))

    assert 'MyLB' in result["Resources"]
    assert 'MyLBListener' in result["Resources"]
    assert 'MyLBTargetGroup' in result["Resources"]

    target_group = result['Resources']['MyLBTargetGroup']
    lb_listener = result['Resources']['MyLBListener']

    assert target_group['Properties']['HealthCheckPort'] == '9999'
    assert lb_listener['Properties']['Certificates'] == [
        {'CertificateArn': 'arn:aws:42'}
    ]
    # test that our custom drain setting works
    assert target_group['Properties']['TargetGroupAttributes'] == [
        {'Key': 'deregistration_delay.timeout_seconds',
         'Value': '123'}
    ]
    assert result['Resources']['MyLB']['Properties']['SecurityGroups'] == ['sg-foo']
Пример #2
0
def test_weighted_dns_load_balancer_v2(monkeypatch, boto_client, boto_resource):  # noqa: F811
    senza.traffic.DNS_ZONE_CACHE = {}

    configuration = {
        "Name": "MyLB",
        "SecurityGroups": "",
        "HTTPPort": "9999",
        'MainDomain': 'great.api.zo.ne',
        'VersionDomain': 'version.api.zo.ne',
        # test overwritting specific properties in one of the resources
        'TargetGroupAttributes': [{'Key': 'deregistration_delay.timeout_seconds', 'Value': '123'}],
        # test that Security Groups are resolved
        'SecurityGroups': ['foo-security-group']
    }
    info = {'StackName': 'foobar', 'StackVersion': '0.1'}
    definition = {"Resources": {}}

    args = MagicMock()
    args.region = "foo"

    mock_string_result = MagicMock()
    mock_string_result.return_value = ['sg-foo']
    monkeypatch.setattr('senza.components.elastic_load_balancer_v2.resolve_security_groups', mock_string_result)

    get_ssl_cert = MagicMock()
    get_ssl_cert.return_value = 'arn:aws:42'
    monkeypatch.setattr('senza.components.elastic_load_balancer_v2.get_ssl_cert', get_ssl_cert)

    result = component_weighted_dns_elastic_load_balancer_v2(definition,
                                                             configuration,
                                                             args,
                                                             info,
                                                             False,
                                                             AccountArguments('dummyregion'))

    assert 'MyLB' in result["Resources"]
    assert 'MyLBListener' in result["Resources"]
    assert 'MyLBTargetGroup' in result["Resources"]

    target_group = result['Resources']['MyLBTargetGroup']
    lb_listener = result['Resources']['MyLBListener']

    assert target_group['Properties']['HealthCheckPort'] == '9999'
    assert lb_listener['Properties']['Certificates'] == [
        {'CertificateArn': 'arn:aws:42'}
    ]
    # test that our custom drain setting works
    assert target_group['Properties']['TargetGroupAttributes'] == [
        {'Key': 'deregistration_delay.timeout_seconds',
         'Value': '123'}
    ]
    assert result['Resources']['MyLB']['Properties']['SecurityGroups'] == ['sg-foo']