Example #1
0
def test_create_flow_version(regress_flow_reg, fix_ver_flow):
    new_ver_stub = versioning.create_flow(
        bucket_id=fix_ver_flow.bucket.identifier,
        flow_name=conftest.test_cloned_ver_flow_name,
    )
    ver_flow_snapshot_0 = versioning.get_latest_flow_ver(
        fix_ver_flow.bucket.identifier,
        fix_ver_flow.flow.identifier
    )
    r1 = versioning.create_flow_version(
        flow=new_ver_stub,
        flow_snapshot=ver_flow_snapshot_0
    )
    assert isinstance(r1, registry.VersionedFlowSnapshot)
    # registry bug https://issues.apache.org/jira/browse/NIFIREG-135
    # assert r1.flow.version_count == 2
    assert DeepDiff(
        ver_flow_snapshot_0.flow_contents,
        r1.flow_contents,
        ignore_order=False,
        verbose_level=2
    ) == {}
    # Write it again to increment the version, check it's consistent
    r2 = versioning.create_flow_version(
        flow=new_ver_stub,
        flow_snapshot=ver_flow_snapshot_0
    )
    assert isinstance(r2, registry.VersionedFlowSnapshot)
    assert DeepDiff(
        ver_flow_snapshot_0.flow_contents,
        r2.flow_contents,
        ignore_order=False,
        verbose_level=2
    ) == {}
Example #2
0
def test_get_flow_version(regress_flow_reg, fix_ver_flow):
    r1 = versioning.get_flow_version(bucket_id=fix_ver_flow.bucket.identifier,
                                     flow_id=fix_ver_flow.flow.identifier,
                                     version=None)
    assert isinstance(r1, registry.VersionedFlowSnapshot)
    assert r1.snapshot_metadata.version == 1
    test_vf_2 = versioning.create_flow_version(flow=r1.flow, flow_snapshot=r1)
    assert isinstance(test_vf_2, registry.VersionedFlowSnapshot)
    assert test_vf_2.snapshot_metadata.version == 2
    r2 = versioning.get_flow_version(
        bucket_id=test_vf_2.flow.bucket_identifier,
        flow_id=test_vf_2.flow.identifier,
        version=None)
    assert r2.flow.version_count == 2
    assert r2.snapshot_metadata.version == 2
    r3 = versioning.get_flow_version(
        bucket_id=test_vf_2.flow.bucket_identifier,
        flow_id=test_vf_2.flow.identifier,
        version='1',
    )
    assert r3.snapshot_metadata.version == 1
    assert r3.flow.version_count == 2
    r4 = versioning.get_flow_version(
        bucket_id=test_vf_2.flow.bucket_identifier,
        flow_id=test_vf_2.flow.identifier,
        version=None,
        export=True)
    assert isinstance(r4, bytes)
    assert isinstance(utils.load(r4), dict)
Example #3
0
def test_complex_template_versioning(regress_flow_reg, fix_ctv):
    # There is a complex bug where a new flow version cannot be switched to
    # and generates a NiFi NPE if attempted when create_flow_version is used
    # BUG FIXED: issue with variable name found in Swagger definition
    # https://github.com/apache/nifi/pull/2479#issuecomment-366582829

    # Create a new flow version
    vers = versioning.list_flow_versions(fix_ctv.bucket.identifier,
                                         fix_ctv.flow.identifier)
    assert vers[0].version == 2
    # create_flow_version is the problem
    new_ss = versioning.create_flow_version(
        flow=fix_ctv.flow,
        flow_snapshot=fix_ctv.snapshot_w_template,
        refresh=True)
    assert isinstance(new_ss, registry.VersionedFlowSnapshot)
    vers = versioning.list_flow_versions(fix_ctv.bucket.identifier,
                                         fix_ctv.flow.identifier)
    assert vers[0].version == 3
    new_ver_info = versioning.get_version_info(fix_ctv.pg)
    r1 = versioning.update_flow_ver(fix_ctv.pg)
    assert r1.request.complete is True
    assert r1.request.failure_reason is None
    r2 = canvas.schedule_process_group(fix_ctv.pg.id, True)
    status = canvas.get_process_group(fix_ctv.pg.id, 'id')
    assert status.running_count >= 5
    with pytest.raises(ValueError):
        _ = versioning.update_flow_ver(fix_ctv.pg, 'bob')
    with pytest.raises(ValueError):
        _ = versioning.update_flow_ver(fix_ctv.pg, '9999999')
Example #4
0
def test_import_flow_version(regress_flow_reg, fix_flow_serde):
    compare_obj = fix_flow_serde.snapshot
    test_obj = fix_flow_serde.raw
    # Test that our test_obj serialises and deserialises through the layers of
    # json reformatting. This is because we load the NiFi Java json object,
    # dump it using the Python json library, and load it again using
    # ruamel.yaml.
    assert DeepDiff(compare_obj,
                    utils.load(utils.dump(utils.load(obj=test_obj),
                                          mode='json'),
                               dto=fix_flow_serde.dto),
                    ignore_order=False,
                    verbose_level=2) == {}
    # Test that we can issue a simple create_flow with this object
    r0 = versioning.create_flow_version(flow=fix_flow_serde.flow,
                                        flow_snapshot=utils.load(
                                            obj=fix_flow_serde.json,
                                            dto=fix_flow_serde.dto))
    assert isinstance(r0, registry.VersionedFlowSnapshot)
    assert DeepDiff(compare_obj.flow_contents,
                    r0.flow_contents,
                    ignore_order=False,
                    verbose_level=2) == {}
    # Test we can import from a String in memory
    # Test we can import as new version in existing bucket
    r1 = versioning.import_flow_version(
        bucket_id=fix_flow_serde.bucket.identifier,
        encoded_flow=fix_flow_serde.json,
        flow_id=fix_flow_serde.flow.identifier)
    assert isinstance(r1, registry.VersionedFlowSnapshot)
    assert DeepDiff(compare_obj.flow_contents,
                    r1.flow_contents,
                    ignore_order=False,
                    verbose_level=2) == {}
    # Test we can also import from a file
    r2 = versioning.import_flow_version(
        bucket_id=fix_flow_serde.bucket.identifier,
        file_path=fix_flow_serde.filepath + '.yaml',
        flow_id=fix_flow_serde.flow.identifier)
    assert isinstance(r2, registry.VersionedFlowSnapshot)
    assert DeepDiff(compare_obj.flow_contents,
                    r2.flow_contents,
                    ignore_order=False,
                    verbose_level=2) == {}
    # Test import into another bucket as first version
    f_bucket_2 = versioning.create_registry_bucket(conftest.test_bucket_name +
                                                   '_02')
    r3 = versioning.import_flow_version(
        bucket_id=f_bucket_2.identifier,
        encoded_flow=fix_flow_serde.yaml,
        flow_name=conftest.test_cloned_ver_flow_name + '_01')
    assert isinstance(r3, registry.VersionedFlowSnapshot)
    assert DeepDiff(compare_obj.flow_contents,
                    r3.flow_contents,
                    ignore_order=False,
                    verbose_level=2) == {}