def test_delete_lag_with_connections_without_force_delete(
        placeboify, maybe_sleep, dependencies):
    client = placeboify.client("directconnect")
    with pytest.raises(Exception) as error_message:
        lag_module.ensure_absent(client, dependencies.lag_1.get("lag_id"),
                                 "ansible_lag_1", False, True, True, 120)
        assert "To force deletion of the LAG use delete_force: True" in error_message
def test_nonexistent_lag_does_not_exist(placeboify, maybe_sleep):
    client = placeboify.client("directconnect")
    exists = lag_module.lag_exists(client=client,
                                   lag_id="dxlag-XXXXXXXX",
                                   lag_name="doesntexist",
                                   verify=True)
    assert not exists
Esempio n. 3
0
def test_create_pipeline_already_exists(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    changed, result = data_pipeline.create_pipeline(connection,
                                                    dp_setup.module)
    assert changed is False
    assert "Data Pipeline ansible-test-create-pipeline is present" in result[
        'msg']
Esempio n. 4
0
def test_define_pipeline(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    changed, result = data_pipeline.define_pipeline(connection,
                                                    dp_setup.module,
                                                    dp_setup.objects,
                                                    dp_setup.data_pipeline_id)
    assert 'has been updated' in result
def test_lag_exists_using_name(placeboify, maybe_sleep, dependencies):
    client = placeboify.client("directconnect")
    exists = lag_module.lag_exists(client=client,
                                   lag_id=None,
                                   lag_name=dependencies.lag_1.get("name"),
                                   verify=True)
    assert exists
Esempio n. 6
0
def test_pipeline_description_nonexistent(placeboify, maybe_sleep):
    hypothetical_pipeline_id = "df-015440025PF7YGLDK47C"
    connection = placeboify.client('datapipeline')
    with pytest.raises(Exception) as error:
        data_pipeline.pipeline_description(connection,
                                           hypothetical_pipeline_id)
        assert error == data_pipeline.DataPipelineNotFound
def test_nonexistent_lag_status(placeboify, maybe_sleep):
    client = placeboify.client("directconnect")
    exists = lag_module.lag_exists(client=client,
                                   lag_id="doesntexist",
                                   lag_name="doesntexist",
                                   verify=True)
    assert not exists
Esempio n. 8
0
def test_check_dp_status(placeboify, maybe_sleep, dp_setup):
    inactive_states = ['INACTIVE', 'PENDING', 'FINISHED', 'DELETING']
    connection = placeboify.client('datapipeline')
    state = data_pipeline.check_dp_status(connection,
                                          dp_setup.data_pipeline_id,
                                          inactive_states)
    assert state is True
Esempio n. 9
0
def test_associations_are_not_updated(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    status = aws_direct_connect_connection.connection_status(
        client, connection_id)['connection']
    lag_id = status.get('lagId')
    assert aws_direct_connect_connection.update_associations(
        client, status, connection_id, lag_id) is False
def test_lag_exists_using_name(placeboify, maybe_sleep, dependencies):
    client = placeboify.client("directconnect")
    exists = lag_module.lag_exists(client=client,
                                   lag_id=None,
                                   lag_name=dependencies.lag_1.get("name"),
                                   verify=True)
    assert exists
Esempio n. 11
0
def test_changed_properties(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    status = aws_direct_connect_connection.connection_status(
        client, connection_id)['connection']
    location = "differentlocation"
    bandwidth = status['bandwidth']
    assert aws_direct_connect_connection.changed_properties(
        status, location, bandwidth) is True
Esempio n. 12
0
def test_activate_pipeline(placeboify, maybe_sleep, dp_setup):
    # use objects to define pipeline before activating
    connection = placeboify.client('datapipeline')
    data_pipeline.define_pipeline(connection,
                                  module=dp_setup.module,
                                  objects=dp_setup.objects,
                                  dp_id=dp_setup.data_pipeline_id)
    changed, result = data_pipeline.activate_pipeline(connection, dp_setup.module)
    assert changed is True
Esempio n. 13
0
def test_activate_pipeline(placeboify, maybe_sleep, dp_setup):
    # use objects to define pipeline before activating
    connection = placeboify.client('datapipeline')
    data_pipeline.define_pipeline(connection,
                                  module=dp_setup.module,
                                  objects=dp_setup.objects,
                                  dp_id=dp_setup.data_pipeline_id)
    changed, result = data_pipeline.activate_pipeline(connection,
                                                      dp_setup.module)
    assert changed is True
Esempio n. 14
0
def test_invalid_template_json(placeboify):
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-wrong-json',
        'TemplateBody': bad_json_tpl,
    }
    m = FakeModule(disable_rollback=False)
    with pytest.raises(Exception, message='Malformed JSON should cause the test to fail') as exc_info:
        cfn_module.create_stack(m, params, connection)
    assert exc_info.match('FAIL')
    assert "ValidationError" in m.exit_kwargs['msg']
Esempio n. 15
0
def test_delete_nonexistent_pipeline(placeboify, maybe_sleep):
    connection = placeboify.client('datapipeline')
    params = {'name': 'ansible-test-nonexistent',
              'description': 'ansible-test-nonexistent',
              'state': 'absent',
              'objects': [],
              'tags': {'ansible': 'test'},
              'timeout': 300}
    m = FakeModule(**params)
    changed, result = data_pipeline.delete_pipeline(connection, m)
    assert changed is False
Esempio n. 16
0
def test_invalid_template_json(placeboify):
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-wrong-json',
        'TemplateBody': bad_json_tpl,
    }
    m = FakeModule(disable_rollback=False)
    with pytest.raises(Exception,
                       message='Malformed JSON should cause the test to fail'
                       ) as exc_info:
        cfn_module.create_stack(m, params, connection, default_events_limit)
    assert exc_info.match('FAIL')
    assert "ValidationError" in m.exit_kwargs['msg']
Esempio n. 17
0
def test_create_pipeline_with_tags(placeboify, maybe_sleep):
    connection = placeboify.client('datapipeline')
    params = {'name': 'ansible-unittest-create-pipeline_tags',
              'description': 'ansible-datapipeline-unit-test',
              'state': 'present',
              'tags': {'ansible': 'test'},
              'timeout': 300}
    m = FakeModule(**params)
    changed, result = data_pipeline.create_pipeline(connection, m)
    assert changed is True
    assert result['msg'] == "Data Pipeline ansible-unittest-create-pipeline_tags created."

    data_pipeline.delete_pipeline(connection, m)
def test_basic_s3_stack(maybe_sleep, placeboify):
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-basic-yaml',
        'TemplateBody': basic_yaml_tpl
    }
    m = FakeModule(disable_rollback=False)
    result = cfn_module.create_stack(m, params, connection)
    assert result['changed']
    assert len(result['events']) > 1
    # require that the final recorded stack state was CREATE_COMPLETE
    # events are retrieved newest-first, so 0 is the latest
    assert 'CREATE_COMPLETE' in result['events'][0]
    connection.delete_stack(StackName='ansible-test-basic-yaml')
Esempio n. 19
0
def test_basic_s3_stack(maybe_sleep, placeboify):
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-basic-yaml',
        'TemplateBody': basic_yaml_tpl
    }
    m = FakeModule(disable_rollback=False)
    result = cfn_module.create_stack(m, params, connection)
    assert result['changed']
    assert len(result['events']) > 1
    # require that the final recorded stack state was CREATE_COMPLETE
    # events are retrieved newest-first, so 0 is the latest
    assert 'CREATE_COMPLETE' in result['events'][0]
    connection.delete_stack(StackName='ansible-test-basic-yaml')
Esempio n. 20
0
def test_client_request_token_s3_stack(maybe_sleep, placeboify):
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-client-request-token-yaml',
        'TemplateBody': basic_yaml_tpl,
        'ClientRequestToken': '3faf3fb5-b289-41fc-b940-44151828f6cf',
    }
    m = FakeModule(disable_rollback=False)
    result = cfn_module.create_stack(m, params, connection, default_events_limit)
    assert result['changed']
    assert len(result['events']) > 1
    # require that the final recorded stack state was CREATE_COMPLETE
    # events are retrieved newest-first, so 0 is the latest
    assert 'CREATE_COMPLETE' in result['events'][0]
    connection.delete_stack(StackName='ansible-test-client-request-token-yaml')
Esempio n. 21
0
def test_delete_nonexistent_pipeline(placeboify, maybe_sleep):
    connection = placeboify.client('datapipeline')
    params = {
        'name': 'ansible-test-nonexistent',
        'description': 'ansible-test-nonexistent',
        'state': 'absent',
        'objects': [],
        'tags': {
            'ansible': 'test'
        },
        'timeout': 300
    }
    m = FakeModule(**params)
    changed, result = data_pipeline.delete_pipeline(connection, m)
    assert changed is False
Esempio n. 22
0
def test_create_pipeline(placeboify, maybe_sleep):
    connection = placeboify.client('datapipeline')
    params = {
        'name': 'ansible-unittest-create-pipeline',
        'description': 'ansible-datapipeline-unit-test',
        'state': 'present',
        'timeout': 300,
        'tags': {}
    }
    m = FakeModule(**params)
    changed, result = data_pipeline.create_pipeline(connection, m)
    assert changed is True
    assert result[
        'msg'] == "Data Pipeline ansible-unittest-create-pipeline created."

    data_pipeline.delete_pipeline(connection, m)
def test_update_lag(placeboify, maybe_sleep, dependencies):
    client = placeboify.client("directconnect")
    status_before = lag_module.lag_status(client=client, lag_id=dependencies.lag_2.get("lag_id"))
    lag_module.update_lag(client,
                          lag_id=dependencies.lag_2.get("lag_id"),
                          lag_name="ansible_lag_2_update",
                          min_links=0,
                          wait=False,
                          wait_timeout=0,
                          num_connections=1)
    status_after = lag_module.lag_status(client=client, lag_id=dependencies.lag_2.get("lag_id"))
    assert status_before != status_after

    # remove the lag name from the statuses and verify it was the only thing changed
    del status_before['lagName']
    del status_after['lagName']
    assert status_before == status_after
Esempio n. 24
0
def test_on_create_failure_delete(maybe_sleep, placeboify):
    m = FakeModule(
        on_create_failure='DELETE',
        disable_rollback=False,
    )
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-on-create-failure-delete',
        'TemplateBody': failing_yaml_tpl
    }
    result = cfn_module.create_stack(m, params, connection, default_events_limit)
    assert result['changed']
    assert result['failed']
    assert len(result['events']) > 1
    # require that the final recorded stack state was DELETE_COMPLETE
    # events are retrieved newest-first, so 0 is the latest
    assert 'DELETE_COMPLETE' in result['events'][0]
def test_update_lag(placeboify, maybe_sleep, dependencies):
    client = placeboify.client("directconnect")
    status_before = lag_module.lag_status(
        client=client, lag_id=dependencies.lag_2.get("lag_id"))
    lag_module.update_lag(client,
                          lag_id=dependencies.lag_2.get("lag_id"),
                          lag_name="ansible_lag_2_update",
                          min_links=0,
                          wait=False,
                          wait_timeout=0,
                          num_connections=1)
    status_after = lag_module.lag_status(
        client=client, lag_id=dependencies.lag_2.get("lag_id"))
    assert status_before != status_after

    # remove the lag name from the statuses and verify it was the only thing changed
    del status_before['lagName']
    del status_after['lagName']
    assert status_before == status_after
Esempio n. 26
0
def test_connection_exists_by_name(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    exists = aws_direct_connect_connection.connection_exists(
        client, None, connection_name)
    assert exists == connection_id
def test_delete_lag_with_connections(placeboify, maybe_sleep, dependencies):
    client = placeboify.client("directconnect")
    changed = lag_module.ensure_absent(client, dependencies.lag_1.get("lag_id"), "ansible_lag_1", True, True, True, 120)
    assert changed
def test_lag_status(placeboify, maybe_sleep, dependencies):
    client = placeboify.client("directconnect")
    status = lag_module.lag_status(client, lag_id=dependencies.lag_1.get("lag_id"))
    assert status.get("lagId") == dependencies.lag_1.get("lag_id")
    assert status.get("lagName") == "ansible_lag_1"
def test_associations_are_not_updated(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    status = aws_direct_connect_connection.connection_status(client, connection_id)['connection']
    lag_id = status.get('lagId')
    assert aws_direct_connect_connection.update_associations(client, status, connection_id, lag_id) is False
Esempio n. 30
0
def test_get_nonexistent_stack(placeboify):
    connection = placeboify.client('cloudformation')
    assert cfn_module.get_stack_facts(connection, 'ansible-test-nonexist') is None
Esempio n. 31
0
def test_check_dp_exists_false(placeboify, maybe_sleep):
    hypothetical_pipeline_id = "df-015440025PF7YGLDK47C"
    connection = placeboify.client('datapipeline')
    exists = data_pipeline.check_dp_exists(connection,
                                           hypothetical_pipeline_id)
    assert exists is False
Esempio n. 32
0
def test_create_pipeline_already_exists(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    changed, result = data_pipeline.create_pipeline(connection, dp_setup.module)
    assert changed is False
    assert "Data Pipeline ansible-test-create-pipeline is present" in result['msg']
def test_create_and_delete(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    created_conn = verify_create_works(placeboify, maybe_sleep, client)
    deleted_conn = verify_delete_works(placeboify, maybe_sleep, client, created_conn)
Esempio n. 34
0
def test_activate_without_population(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    with pytest.raises(Exception) as error_message:
        changed, result = data_pipeline.activate_pipeline(connection, dp_setup.module)
        assert error_message == "You need to populate your pipeline before activation."
def test_connection_status(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    status = aws_direct_connect_connection.connection_status(client, connection_id)['connection']
    assert status['connectionName'] == connection_name
    assert status['connectionId'] == connection_id
Esempio n. 36
0
def test_check_dp_exists_false(placeboify, maybe_sleep):
    hypothetical_pipeline_id = "df-015440025PF7YGLDK47C"
    connection = placeboify.client('datapipeline')
    exists = data_pipeline.check_dp_exists(connection, hypothetical_pipeline_id)
    assert exists is False
Esempio n. 37
0
def test_check_dp_exists_true(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    exists = data_pipeline.check_dp_exists(connection, dp_setup.data_pipeline_id)
    assert exists is True
Esempio n. 38
0
def test_pipeline_description_nonexistent(placeboify, maybe_sleep):
    hypothetical_pipeline_id = "df-015440025PF7YGLDK47C"
    connection = placeboify.client('datapipeline')
    with pytest.raises(Exception) as error:
        data_pipeline.pipeline_description(connection, hypothetical_pipeline_id)
        assert error == data_pipeline.DataPipelineNotFound
Esempio n. 39
0
def test_pipeline_description(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    dp_id = dp_setup.data_pipeline_id
    pipelines = data_pipeline.pipeline_description(connection, dp_id)
    assert dp_id == pipelines['pipelineDescriptionList'][0]['pipelineId']
Esempio n. 40
0
def setup_mod_conn(placeboify, params):
    conn = placeboify.client('ec2')
    m = FakeModule(**params)
    return m, conn
Esempio n. 41
0
def test_pipeline_field(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    pipeline_field_info = data_pipeline.pipeline_field(connection, dp_setup.data_pipeline_id, "@pipelineState")
    assert pipeline_field_info == "PENDING"
Esempio n. 42
0
def test_deactivate_pipeline(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    changed, result = data_pipeline.deactivate_pipeline(connection, dp_setup.module)
    assert "Data Pipeline ansible-test-create-pipeline deactivated" in result['msg']
Esempio n. 43
0
def test_pipeline_description(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    dp_id = dp_setup.data_pipeline_id
    pipelines = data_pipeline.pipeline_description(connection, dp_id)
    assert dp_id == pipelines['pipelineDescriptionList'][0]['pipelineId']
Esempio n. 44
0
def test_define_pipeline(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    changed, result = data_pipeline.define_pipeline(connection, dp_setup.module, dp_setup.objects, dp_setup.data_pipeline_id)
    assert 'has been updated' in result
Esempio n. 45
0
def test_check_dp_exists_true(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    exists = data_pipeline.check_dp_exists(connection,
                                           dp_setup.data_pipeline_id)
    assert exists is True
Esempio n. 46
0
def test_create_and_delete(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    created_conn = verify_create_works(placeboify, maybe_sleep, client)
    deleted_conn = verify_delete_works(placeboify, maybe_sleep, client,
                                       created_conn)
Esempio n. 47
0
def test_delete_nonexistent_stack(maybe_sleep, placeboify):
    connection = placeboify.client('cloudformation')
    result = cfn_module.stack_operation(connection, 'ansible-test-nonexist', 'DELETE')
    assert result['changed']
    assert 'Stack does not exist.' in result['log']
Esempio n. 48
0
def test_get_nonexistent_stack(placeboify):
    connection = placeboify.client('cloudformation')
    assert cfn_module.get_stack_facts(connection,
                                      'ansible-test-nonexist') is None
Esempio n. 49
0
def setup_mod_conn(placeboify, params):
    conn = placeboify.client('ec2')
    m = FakeModule(**params)
    return m, conn
def test_changed_properties(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    status = aws_direct_connect_connection.connection_status(client, connection_id)['connection']
    location = "differentlocation"
    bandwidth = status['bandwidth']
    assert aws_direct_connect_connection.changed_properties(status, location, bandwidth) is True
Esempio n. 51
0
def test_connection_status(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    status = aws_direct_connect_connection.connection_status(
        client, connection_id)['connection']
    assert status['connectionName'] == connection_name
    assert status['connectionId'] == connection_id
Esempio n. 52
0
def test_deactivate_pipeline(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    changed, result = data_pipeline.deactivate_pipeline(
        connection, dp_setup.module)
    assert "Data Pipeline ansible-test-create-pipeline deactivated" in result[
        'msg']
Esempio n. 53
0
def test_connection_does_not_exist(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    exists = aws_direct_connect_connection.connection_exists(
        client, 'dxcon-notthere')
    assert exists is False
Esempio n. 54
0
def test_activate_without_population(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    with pytest.raises(Exception) as error_message:
        changed, result = data_pipeline.activate_pipeline(
            connection, dp_setup.module)
        assert error_message == "You need to populate your pipeline before activation."
def test_delete_lag_with_connections_without_force_delete(placeboify, maybe_sleep, dependencies):
    client = placeboify.client("directconnect")
    with pytest.raises(Exception) as error_message:
        lag_module.ensure_absent(client, dependencies.lag_1.get("lag_id"), "ansible_lag_1", False, True, True, 120)
        assert "To force deletion of the LAG use delete_force: True" in error_message
def test_connection_exists_by_name(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    exists = aws_direct_connect_connection.connection_exists(client, None, connection_name)
    assert exists == connection_id
Esempio n. 57
0
def test_delete_nonexistent_stack(maybe_sleep, placeboify):
    connection = placeboify.client('cloudformation')
    result = cfn_module.stack_operation(connection, 'ansible-test-nonexist',
                                        'DELETE', default_events_limit)
    assert result['changed']
    assert 'Stack does not exist.' in result['log']
Esempio n. 58
0
def test_pipeline_field(placeboify, maybe_sleep, dp_setup):
    connection = placeboify.client('datapipeline')
    pipeline_field_info = data_pipeline.pipeline_field(
        connection, dp_setup.data_pipeline_id, "@pipelineState")
    assert pipeline_field_info == "PENDING"
Esempio n. 59
0
def test_check_dp_status(placeboify, maybe_sleep, dp_setup):
    inactive_states = ['INACTIVE', 'PENDING', 'FINISHED', 'DELETING']
    connection = placeboify.client('datapipeline')
    state = data_pipeline.check_dp_status(connection, dp_setup.data_pipeline_id, inactive_states)
    assert state is True
def test_connection_does_not_exist(placeboify, maybe_sleep):
    client = placeboify.client('directconnect')
    exists = aws_direct_connect_connection.connection_exists(client, 'dxcon-notthere')
    assert exists is False