Beispiel #1
0
def test_elb_create_elb(mock_get_properties, mock_elb_json, mock_post_task,
                        mock_check_task, mock_listener_policy,
                        mock_backend_policy, mock_load_balancer_attributes):
    """Test SpinnakerELB create_elb method"""
    elb = SpinnakerELB(app='myapp', env='dev', region='us-east-1')
    elb.create_elb()
    mock_listener_policy.assert_called_with(mock_elb_json())
Beispiel #2
0
def test_elb_add_listener_policy(mock_get_properties, mock_boto3_session):

    json_data = {
        'job': [{
            'listeners': [
                {
                    'externalPort': 80,
                    'listenerPolicies': ['policy_name']
                },
            ],
        }],
    }
    client = mock_boto3_session.return_value.client.return_value

    elb = SpinnakerELB(app='myapp', env='dev', region='us-east-1')
    elb.add_listener_policy(json.dumps(json_data))
    assert client.set_load_balancer_policies_of_listener.called
Beispiel #3
0
def test_elb_add_backend_policy(mock_get_properties, mock_boto3_session):
    test_app = 'myapp'
    test_port = 80
    test_policy_list = ['policy_name']

    json_data = {
        'job': [{
            'listeners': [
                {
                    'internalPort': test_port,
                    'backendPolicies': test_policy_list
                },
            ],
        }],
    }
    client = mock_boto3_session.return_value.client.return_value

    elb = SpinnakerELB(app='myapp', env='dev', region='us-east-1')
    elb.add_backend_policy(json.dumps(json_data))
    client.set_load_balancer_policies_for_backend_server.assert_called_with(
        LoadBalancerName=test_app, InstancePort=test_port, PolicyNames=test_policy_list)
Beispiel #4
0
def test_elb_make_elb_json(mock_get_properties, mock_get_subnets, mock_format_listeners, mock_vpc_id):
    """Test SpinnakerELB make_elbj_json method"""
    properties = {
        'elb': {
            'health': {
                'interval': 10,
                'timeout': 1,
                'threshold': 2,
                'unhealthy_threshold': 3,
            }
        },
        'security_group': {
            'elb_extras': []
        },
    }

    subnets = {'us-east-1': ['subnet-1']}
    listeners = []

    mock_get_properties.return_value = properties
    mock_get_subnets.return_value = subnets
    mock_format_listeners.return_value = listeners

    # internal elb
    elb = SpinnakerELB(app='myapp', env='dev', region='us-east-1')
    elb_str = elb.make_elb_json()
    assert isinstance(elb_str, str)
    elb_json = json.loads(elb_str)
    assert elb_json['job'][0]['isInternal']

    # external elb
    properties['elb'].update({'subnet_purpose': 'external'})
    elb = SpinnakerELB(app='myapp', env='dev', region='us-east-1')
    elb_json = json.loads(elb.make_elb_json())
    assert not elb_json['job'][0]['isInternal']