Ejemplo n.º 1
0
def test_delete_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)
    data_pipeline.create_pipeline(connection, m)
    changed, result = data_pipeline.delete_pipeline(connection, m)
    assert changed is True
Ejemplo n.º 2
0
def dp_setup():
    """
    Yield a FakeModule object, data pipeline id of a vanilla data pipeline, and data pipeline objects

    This fixture is module-scoped, since this can be reused for multiple tests.
    """
    Dependencies = collections.namedtuple(
        "Dependencies", ["module", "data_pipeline_id", "objects"])

    # get objects to use to test populating and activating the data pipeline
    if not os.getenv('PLACEBO_RECORD'):
        objects = [{
            "name": "Every 1 day",
            "id": "DefaultSchedule",
            "fields": []
        }, {
            "name": "Default",
            "id": "Default",
            "fields": []
        }]
    else:
        s3 = boto3.client('s3')
        data = s3.get_object(Bucket="ansible-test-datapipeline",
                             Key="pipeline-object/new.json")
        objects = json.loads(to_text(data['Body'].read()))

    # create a module with vanilla data pipeline parameters
    params = {
        'name': 'ansible-test-create-pipeline',
        'description': 'ansible-datapipeline-unit-test',
        'state': 'present',
        'timeout': 300,
        'objects': [],
        'tags': {},
        'parameters': [],
        'values': []
    }
    module = FakeModule(**params)

    # yield a module, the data pipeline id, and the data pipeline objects (that are not yet defining the vanilla data pipeline)
    if not os.getenv('PLACEBO_RECORD'):
        yield Dependencies(module=module,
                           data_pipeline_id='df-0590406117G8DPQZY2HA',
                           objects=objects)
    else:
        connection = boto3.client('datapipeline')
        changed, result = data_pipeline.create_pipeline(connection, module)
        data_pipeline_id = result['data_pipeline']['pipeline_id']
        yield Dependencies(module=module,
                           data_pipeline_id=data_pipeline_id,
                           objects=objects)

    # remove data pipeline
    if os.getenv('PLACEBO_RECORD'):
        module.params.update(state='absent')
        data_pipeline.delete_pipeline(connection, module)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
def dp_setup():
    """
    Yield a FakeModule object, data pipeline id of a vanilla data pipeline, and data pipeline objects

    This fixture is module-scoped, since this can be reused for multiple tests.
    """
    Dependencies = collections.namedtuple("Dependencies", ["module", "data_pipeline_id", "objects"])

    # get objects to use to test populating and activating the data pipeline
    if not os.getenv('PLACEBO_RECORD'):
        objects = [{"name": "Every 1 day",
                    "id": "DefaultSchedule",
                    "fields": []},
                   {"name": "Default",
                    "id": "Default",
                    "fields": []}]
    else:
        s3 = boto3.client('s3')
        data = s3.get_object(Bucket="ansible-test-datapipeline", Key="pipeline-object/new.json")
        objects = json.loads(to_text(data['Body'].read()))

    # create a module with vanilla data pipeline parameters
    params = {'name': 'ansible-test-create-pipeline',
              'description': 'ansible-datapipeline-unit-test',
              'state': 'present',
              'timeout': 300,
              'objects': [],
              'tags': {},
              'parameters': [],
              'values': []}
    module = FakeModule(**params)

    # yield a module, the data pipeline id, and the data pipeline objects (that are not yet defining the vanilla data pipeline)
    if not os.getenv('PLACEBO_RECORD'):
        yield Dependencies(module=module, data_pipeline_id='df-0590406117G8DPQZY2HA', objects=objects)
    else:
        connection = boto3.client('datapipeline')
        changed, result = data_pipeline.create_pipeline(connection, module)
        data_pipeline_id = result['data_pipeline']['pipeline_id']
        yield Dependencies(module=module, data_pipeline_id=data_pipeline_id, objects=objects)

    # remove data pipeline
    if os.getenv('PLACEBO_RECORD'):
        module.params.update(state='absent')
        data_pipeline.delete_pipeline(connection, module)
Ejemplo n.º 6
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']