Beispiel #1
0
def test_create_process_group(regress_nifi):
    r = canvas.create_process_group(parent_pg=canvas.get_process_group(
        canvas.get_root_pg_id(), 'id'),
                                    new_pg_name=conftest.test_pg_name,
                                    location=(400.0, 400.0),
                                    comment='some comment')
    assert r.component.name == conftest.test_pg_name
    assert r.position.x == r.position.y == 400
    assert r.component.parent_group_id == canvas.get_root_pg_id()
    assert isinstance(r, nifi.ProcessGroupEntity)

    # Test process group creation on other than root process group.
    s = canvas.create_process_group(parent_pg=canvas.get_process_group(
        conftest.test_pg_name),
                                    location=(200.0, 200.0),
                                    new_pg_name=conftest.test_another_pg_name)
    assert s.component.name == conftest.test_another_pg_name
    assert s.position.x == s.position.y == 200
    assert s.component.parent_group_id == canvas.get_process_group(
        conftest.test_pg_name, "name").id
    assert isinstance(s, nifi.ProcessGroupEntity)

    with pytest.raises(ValueError):
        parent_pg = canvas.get_process_group('NiFi Flow')
        parent_pg.id = 'invalid'
        _ = canvas.create_process_group(parent_pg, 'irrelevant', (0, 0))
Beispiel #2
0
def test_deploy_flow_version(regress_flow_reg, fix_ver_flow):
    r1 = versioning.deploy_flow_version(
        parent_id=canvas.get_root_pg_id(),
        location=(0,0),
        bucket_id=fix_ver_flow.bucket.identifier,
        flow_id=fix_ver_flow.flow.identifier,
        reg_client_id=fix_ver_flow.client.id,
        version=1
    )
    assert isinstance(r1, nifi.ProcessGroupEntity)
    r2 = versioning.deploy_flow_version(
        parent_id=canvas.get_root_pg_id(),
        location=(0, 0),
        bucket_id=fix_ver_flow.bucket.identifier,
        flow_id=fix_ver_flow.flow.identifier,
        reg_client_id=fix_ver_flow.client.id,
        version=None
    )
    assert isinstance(r2, nifi.ProcessGroupEntity)
    with pytest.raises(ValueError):
        # can't deploy a pg inside itself
        _ = versioning.deploy_flow_version(
            parent_id=fix_ver_flow.pg.id,
            location=(0, 0),
            bucket_id=fix_ver_flow.bucket.identifier,
            flow_id=fix_ver_flow.flow.identifier,
            reg_client_id=fix_ver_flow.client.id,
            version=None
        )
Beispiel #3
0
def test_create_process_group(regress):
    r = canvas.create_process_group(canvas.get_process_group(
        canvas.get_root_pg_id(), 'id'),
                                    config.test_pg_name,
                                    location=(400.0, 400.0))
    assert r.component.name == config.test_pg_name
    assert r.position.x == r.position.y == 400
    assert r.component.parent_group_id == canvas.get_root_pg_id()
    with pytest.raises(ApiException):
        parent_pg = canvas.get_process_group('NiFi Flow')
        parent_pg.id = 'invalid'
        _ = canvas.create_process_group(parent_pg, 'irrelevant', (0, 0))
Beispiel #4
0
 def test_upload_template(self):
     r = templates.upload_template(
         pg_id=canvas.get_root_pg_id(),
         template_file='test_env_config/nipyapi_testTemplate_00.xml')
     assert isinstance(r, nifi_models.template_entity.TemplateEntity)
     with pytest.raises(AssertionError):
         r = templates.upload_template(
             pg_id=canvas.get_root_pg_id(),
             template_file='/tmp/haha/definitelynotafile.jpg')
     with pytest.raises(TypeError):
         r = templates.upload_template(
             pg_id=canvas.get_root_pg_id(),
             template_file='test_env_config/nipyapi_testFlow_00.xml')
    def cd(self, path):
        if path[:1] == SEPARATOR:
            self.cd_to_id(canvas.get_root_pg_id())  # Go to root
            path = path[1:]  # Remove top level SEPARATOR; traverse path relative from root

        if len(path) > 0:
            if path == "..":
                if self.current_id() == canvas.get_root_pg_id():
                    return
                return self.cd_to_id(self.current_parent_id())

            child_pg_names = path.split(SEPARATOR)
            for child_pg_name in child_pg_names:
                self.__cd_to_child(child_pg_name)
Beispiel #6
0
def test_input_output_ports(regress_nifi, fix_pg):
    root_input_port = canvas.create_port(pg_id=canvas.get_root_pg_id(),
                                         port_type='INPUT_PORT',
                                         name=conftest.test_basename +
                                         'input_port',
                                         state='STOPPED')
    assert isinstance(root_input_port, nifi.PortEntity)
    root_output_port = canvas.create_port(pg_id=canvas.get_root_pg_id(),
                                          port_type='OUTPUT_PORT',
                                          name=conftest.test_basename +
                                          'output_port',
                                          state='STOPPED')
    assert isinstance(root_output_port, nifi.PortEntity)
    input_ports = [
        x for x in canvas.list_all_by_kind('input_ports')
        if conftest.test_basename in x.status.name
    ]
    assert len(input_ports) == 1
    output_ports = [
        x for x in canvas.list_all_by_kind('output_ports')
        if conftest.test_basename in x.status.name
    ]
    assert len(output_ports) == 1
    f_pg = fix_pg.generate()
    f_pg_input_port = canvas.create_port(pg_id=f_pg.id,
                                         port_type='INPUT_PORT',
                                         name=conftest.test_basename +
                                         'input_port',
                                         state='STOPPED')
    assert isinstance(f_pg_input_port, nifi.PortEntity)
    f_pg_output_port = canvas.create_port(pg_id=f_pg.id,
                                          port_type='OUTPUT_PORT',
                                          name=conftest.test_basename +
                                          'output_port',
                                          state='STOPPED')
    assert isinstance(f_pg_output_port, nifi.PortEntity)
    input_ports = [
        x for x in canvas.list_all_by_kind('input_ports')
        if conftest.test_basename in x.status.name
    ]
    assert len(input_ports) == 2
    output_ports = [
        x for x in canvas.list_all_by_kind('output_ports')
        if conftest.test_basename in x.status.name
    ]
    assert len(output_ports) == 2
    d1 = canvas.delete_port(root_input_port)
    assert isinstance(d1, nifi.PortEntity)
    assert d1.status is None
    def setUpClass(cls):
        super(CanvasNavigatorTest, cls).setUpClass()
        print("Start of tests: preparing nifi objects")
        config.nifi_config.host = 'http://192.168.56.5:8080/nifi-api'

        root = canvas.get_process_group(canvas.get_root_pg_id(), 'id')
        # Create new process group in root
        CanvasNavigatorTest.pg_parent = canvas.create_process_group(
            root, "parent", CANVAS_CENTER)
        # Create new child process groups in unittest
        CanvasNavigatorTest.pg_child1 = canvas.create_process_group(
            CanvasNavigatorTest.pg_parent, "child1", CANVAS_CENTER)
        CanvasNavigatorTest.pg_child2 = canvas.create_process_group(
            CanvasNavigatorTest.pg_parent, "child2", CANVAS_CENTER)
        CanvasNavigatorTest.pg_child2_2 = canvas.create_process_group(
            CanvasNavigatorTest.pg_parent, "child2", CANVAS_CENTER)
        CanvasNavigatorTest.pg_grandchild1 = canvas.create_process_group(
            CanvasNavigatorTest.pg_child1, "grandchild1", CANVAS_CENTER)

        # Create other objects as well
        CanvasNavigatorTest.proc = canvas.create_processor(
            CanvasNavigatorTest.pg_parent,
            canvas.get_processor_type("GenerateFlowFile"), CANVAS_CENTER,
            "proc")
        CanvasNavigatorTest.input_port = canvas.create_port(
            CanvasNavigatorTest.pg_parent.component.id, "INPUT_PORT",
            "input_port", "STOPPED", CANVAS_CENTER)
        CanvasNavigatorTest.output_port = canvas.create_port(
            CanvasNavigatorTest.pg_parent.component.id, "OUTPUT_PORT",
            "output_port", "STOPPED", CANVAS_CENTER)
        CanvasNavigatorTest.controller = canvas.create_controller(
            CanvasNavigatorTest.pg_parent,
            canvas.list_all_controller_types()[0], "controller")
 def test_current_name(self):
     print("Testing current name")
     self.assertEqual(
         self.nav.current_name(),
         canvas.get_process_group(canvas.get_root_pg_id(),
                                  'id').component.name,
         'incorrect current name')
Beispiel #9
0
def set_environment(run_id):
    if not run_id:
        run_id = str(int(time.time()))

    # Initialize NiFi API
    config.nifi_config.host = _get_nifi_api_url()
    config.registry_config.host = _get_nifireg_api_url()
    if _IS_TLS_ENABLED:
        security.set_service_ssl_context(service='nifi', ca_file=_TRUSTSTORE)
        security.set_service_ssl_context(service='registry',
                                         ca_file=_TRUSTSTORE)
        security.service_login(service='nifi',
                               username='******',
                               password='******')
        security.service_login(service='registry',
                               username='******',
                               password='******')

    # Get NiFi root PG
    root_pg = canvas.get_process_group(canvas.get_root_pg_id(), 'id')

    # Get EFM flow
    flow_id, efm_pg_id = efm_get_flow('iot-1')

    return (run_id, root_pg, efm_pg_id, flow_id)
Beispiel #10
0
def test_list_all_connections(regress_nifi, fix_proc):
    f_p1 = fix_proc.generate()
    f_p2 = fix_proc.generate()
    r1 = [
        x for x in canvas.list_all_connections()
        if conftest.test_basename in x.component.name
    ]
    assert not r1
    # connect single relationship
    c1 = canvas.create_connection(f_p1, f_p2, ['success'],
                                  conftest.test_basename)
    r2 = [
        x for x in canvas.list_all_connections('root')
        if conftest.test_basename in x.component.name
    ]
    assert len(r2) == 1
    r3 = [
        x for x in canvas.list_all_connections(canvas.get_root_pg_id())
        if conftest.test_basename in x.component.name
    ]
    assert len(r3) == 1
    assert isinstance(r2[0], nifi.ConnectionEntity)
    c2 = canvas.create_connection(f_p1, f_p2, name=conftest.test_basename)
    r2 = [
        x for x in canvas.list_all_connections('root')
        if conftest.test_basename in x.component.name
    ]
    assert len(r2) == 2
    _ = canvas.delete_connection(c1)
    _ = canvas.delete_connection(c2)
    r3 = [
        x for x in canvas.list_all_connections('root')
        if conftest.test_basename in x.component.name
    ]
    assert not r3
Beispiel #11
0
def test_list_nested_processors(regress_nifi, fix_pg, fix_proc):
    pg_1 = fix_pg.generate(
        parent_pg=canvas.get_process_group(canvas.get_root_pg_id(), 'id'))
    pg_2 = fix_pg.generate(parent_pg=pg_1)
    root_proc_1 = fix_proc.generate()
    pg_1_proc_1 = fix_proc.generate(parent_pg=pg_1)
    pg_1_proc_2 = fix_proc.generate(parent_pg=pg_1)
    pg_2_proc_1 = fix_proc.generate(parent_pg=pg_2)
    pg_2_proc_2 = fix_proc.generate(parent_pg=pg_2)
    pg_2_proc_3 = fix_proc.generate(parent_pg=pg_2)
    pg_2_proc_4 = fix_proc.generate(parent_pg=pg_2)
    r1 = [
        x for x in canvas.list_all_processors('root')
        if conftest.test_basename in x.status.name
    ]
    assert len(r1) == 7
    r2 = [
        x for x in canvas.list_all_processors(pg_2.id)
        if conftest.test_basename in x.status.name
    ]
    assert len(r2) == 4
    r3 = [
        x for x in canvas.list_all_processors(pg_1.id)
        if conftest.test_basename in x.status.name
    ]
    assert len(r3) == 6
Beispiel #12
0
def test_create_controller(regress_nifi, fix_cont):
    root_pg = canvas.get_process_group(canvas.get_root_pg_id(), 'id')
    cont_type = canvas.list_all_controller_types()[0]
    r1 = canvas.create_controller(parent_pg=root_pg, controller=cont_type)
    assert isinstance(r1, nifi.ControllerServiceEntity)
    with pytest.raises(AssertionError):
        _ = canvas.create_controller('pie', cont_type)
    with pytest.raises(AssertionError):
        _ = canvas.create_controller(root_pg, 'pie')
Beispiel #13
0
def test_client_recursion_limit(fix_pg, fix_funnel, target=450):
    # https://github.com/Chaffelson/nipyapi/issues/147
    parent_pg = canvas.get_process_group('root')
    for i in range(0, target):
        parent_pg = fix_pg.generate(parent_pg, str(i))
        fix_funnel.generate(parent_pg)
    start = time.time()
    r1 = canvas.list_all_process_groups(canvas.get_root_pg_id())
    end = time.time()
    assert len(r1) == target + 1  # +1 to allow for root PG
    print("Len {0}  Set {1}".format(len(r1), len(set([x.id for x in r1]))))
    print("Elapsed r1: {0}".format((end - start)))
Beispiel #14
0
def set_environment(run_id):
    if not run_id:
        run_id = str(int(time.time()))

    # Initialize NiFi API
    config.nifi_config.host = _NIFI_API_URL
    config.registry_config.host = _NIFIREG_API_URL

    # Get NiFi root PG
    root_pg = canvas.get_process_group(canvas.get_root_pg_id(), 'id')

    # Get EFM flow
    flow_id, efm_pg_id = efm_get_flow('iot-1')

    return (run_id, root_pg, efm_pg_id, flow_id)
Beispiel #15
0
def test_list_all_connections(regress_nifi, fix_pg, fix_proc):
    f_p1 = fix_proc.generate()
    f_p2 = fix_proc.generate()
    r1 = [
        x for x in canvas.list_all_connections()
        if conftest.test_basename in x.component.name
    ]
    assert not r1
    # connect single relationship
    c1 = canvas.create_connection(f_p1, f_p2, ['success'],
                                  conftest.test_basename)
    r2 = [
        x for x in canvas.list_all_connections('root')
        if conftest.test_basename in x.component.name
    ]
    assert len(r2) == 1
    r3 = [
        x for x in canvas.list_all_connections(canvas.get_root_pg_id())
        if conftest.test_basename in x.component.name
    ]
    assert len(r3) == 1
    assert isinstance(r2[0], nifi.ConnectionEntity)
    c2 = canvas.create_connection(f_p1, f_p2, name=conftest.test_basename)
    r2 = [
        x for x in canvas.list_all_connections('root')
        if conftest.test_basename in x.component.name
    ]
    assert len(r2) == 2
    _ = canvas.delete_connection(c1)
    _ = canvas.delete_connection(c2)
    r4 = [
        x for x in canvas.list_all_connections('root')
        if conftest.test_basename in x.component.name
    ]
    assert not r4
    # Test Issue #129 - nested PGs with descendents missing nested content
    f_pg1 = fix_pg.generate()
    f_pg2 = fix_pg.generate(parent_pg=f_pg1)
    f_p3 = fix_proc.generate(parent_pg=f_pg2)
    f_p4 = fix_proc.generate(parent_pg=f_pg2)
    c2 = canvas.create_connection(f_p3, f_p4, ['success'],
                                  conftest.test_basename)
    r5 = [
        x for x in canvas.list_all_connections(f_pg2.id)
        if conftest.test_basename in x.component.name
    ]
    assert len(r5) == 1
    assert r5[0].id == c2.id
Beispiel #16
0
def test_get_component_connections(regress_nifi, fix_proc):
    f_p1 = fix_proc.generate()
    f_p2 = fix_proc.generate()
    f_p3 = canvas.create_processor(
        parent_pg=canvas.get_process_group(canvas.get_root_pg_id(), 'id'),
        processor=canvas.get_processor_type('AttributesToJSON'),
        location=(400.0, 425.0),
        name=conftest.test_processor_name + '_inbound')
    canvas.create_connection(f_p1, f_p3, name=conftest.test_basename)
    canvas.create_connection(f_p2, f_p3, name=conftest.test_basename)
    r1 = canvas.get_component_connections(f_p1)
    assert len(r1) == 1
    assert r1[0].source_id == f_p1.id
    r2 = canvas.get_component_connections(f_p3)
    assert len(r2) == 2
    assert r2[0].destination_id == f_p3.id
    assert r2[1].source_id in [f_p1.id, f_p2.id]
Beispiel #17
0
def set_environment():
    # Initialize NiFi API
    config.nifi_config.host = _get_api_url()
    config.registry_config.host = nifireg.get_api_url()
    if is_tls_enabled():
        security.set_service_ssl_context(service='nifi',
                                         ca_file=get_truststore_path())
        security.set_service_ssl_context(service='registry',
                                         ca_file=get_truststore_path())
        security.service_login(service='nifi',
                               username='******',
                               password=get_the_pwd())
        security.service_login(service='registry',
                               username='******',
                               password=get_the_pwd())

    # Get NiFi root PG
    root_pg = canvas.get_process_group(canvas.get_root_pg_id(), 'id')

    # Get EFM flow
    flow_id, efm_pg_id = efm.get_flow('iot-1')

    return root_pg, efm_pg_id, flow_id
Beispiel #18
0
def test_get_root_pg_id():
    r = canvas.get_root_pg_id()
    assert isinstance(r, str)
 def __init__(self):
     self.logger = logging.getLogger('CanvasNavigator')
     self.logger.setLevel(logging.DEBUG)
     self.current = nifi.ProcessGroupsApi().get_process_group(canvas.get_root_pg_id())
Beispiel #20
0
 def test_deploy_template(self):
     r = templates.deploy_template(
         canvas.get_root_pg_id(),
         templates.get_template_by_name('nipyapi_testTemplate_00').id)
     assert isinstance(r, nifi_models.flow_entity.FlowEntity)
 def test_current_id(self):
     print("Testing current id")
     self.assertEqual(self.nav.current_id(), canvas.get_root_pg_id(),
                      'incorrect current id')