def test_update_processor(regress_nifi, fix_proc): # TODO: Add way more tests to this f_p1 = fix_proc.generate() update = nifi.ProcessorConfigDTO(scheduling_period='3s') r1 = canvas.update_processor(f_p1, update) with pytest.raises(ValueError, match='update param is not an instance'): _ = canvas.update_processor(f_p1, 'FakeNews')
def run(self, input_name, flowfile, output_attributes=None, timeout=5): """ Runs the actual test with the flowfile provided. Builds the test components on the nifi canvas Starts the base process group Post flowfile via http to initiate test Destroys all test components on the nifi canvas Returns output: flowfile in output.text, attributes in output.headers Args: input_name (str): The input to post the message to flowfile (FlowFile): The flowfile and attributes to post output_attributes (collections.Iterable of str): List of attributes to capture in the test output timeout (integer): Timeout in seconds. Will throw requests.exceptions.ReadTimeout when timeout expires Returns: (FlowFile) """ assert isinstance(flowfile, FlowFile) # Set up testing infrastructure. This will stop the base self.__build() # Adding requested attributes as header parameters if output_attributes is not None: for attr in output_attributes: canvas.update_processor( self.http_out, nifi.ProcessorConfigDTO( properties={attr: "${" + attr + "}"})) # Start complete process group self.__start_base() # Prepare request parsed_url = urlparse(config.nifi_config.host) url = parsed_url.scheme + '://' + parsed_url.hostname + ':' + str( self.port) + '/' + self.name headers = flowfile.attributes headers["test_input_name"] = input_name # Perform actual request response = requests.post(url, data=flowfile.content, headers=headers, timeout=timeout) # Clean up testing infrastructure self.__destroy() # Should always be 200 assert response.status_code == 200 response.headers.pop('Date') response.headers.pop('Transfer-Encoding') response.headers.pop('Server') return FlowFile(response.text, dict(response.headers))
def test_update_processor(fixture_processor, regress): test_proc = fixture_processor.generate() update = nifi.ProcessorConfigDTO( scheduling_period='3s' ) r1 = canvas.update_processor(test_proc, update) with pytest.raises(ValueError, match='update param is not an instance'): _ = canvas.update_processor(test_proc, 'FakeNews')
def setUpClass(cls): super(Test1ToNTest, cls).setUpClass() print("Start of tests: preparing nifi objects") config.nifi_config.host = 'http://192.168.56.5:8080/nifi-api' flow_name = "Test1ToNTest" nav = CanvasNavigator() # Delete all leftovers from previous (failed?) tests pgs_to_be_deleted = nav.groups(flow_name) for pg in pgs_to_be_deleted: canvas.delete_process_group(pg, force=True) # Create new process group in root Test1ToNTest.pg_test = canvas.create_process_group(nav.current, flow_name, (0, 0)) # Create simple flow to test Test1ToNTest.proc_start = canvas.create_processor( Test1ToNTest.pg_test, canvas.get_processor_type("GenerateFlowFile"), CANVAS_CENTER, "Start") Test1ToNTest.proc_2 = canvas.create_processor( Test1ToNTest.pg_test, canvas.get_processor_type("DebugFlow"), CANVAS_CENTER, "Processor 2") Test1ToNTest.proc_3 = canvas.create_processor( Test1ToNTest.pg_test, canvas.get_processor_type("DebugFlow"), CANVAS_CENTER, "Processor 3") Test1ToNTest.proc_end_1 = canvas.create_processor( Test1ToNTest.pg_test, canvas.get_processor_type("DebugFlow"), CANVAS_CENTER, "End 1") Test1ToNTest.proc_end_2 = canvas.create_processor( Test1ToNTest.pg_test, canvas.get_processor_type("DebugFlow"), CANVAS_CENTER, "End 2") canvas.update_processor(Test1ToNTest.proc_end_1, nifi.ProcessorConfigDTO(auto_terminated_relationships=["success", "failure"])) canvas.update_processor(Test1ToNTest.proc_end_2, nifi.ProcessorConfigDTO(auto_terminated_relationships=["success", "failure"])) Test1ToNTest.conn_1 = canvas.create_connection(Test1ToNTest.proc_start, Test1ToNTest.proc_2, ["success"]) Test1ToNTest.conn_2 = canvas.create_connection(Test1ToNTest.proc_2, Test1ToNTest.proc_3, ["success", "failure"]) Test1ToNTest.conn_3 = canvas.create_connection(Test1ToNTest.proc_3, Test1ToNTest.proc_end_1, ["success", "failure"]) Test1ToNTest.conn_4 = canvas.create_connection(Test1ToNTest.proc_3, Test1ToNTest.proc_end_2, ["success", "failure"]) canvas.schedule_process_group(Test1ToNTest.pg_test.component.id, scheduled=True)
root_pg = canvas.get_process_group(root_pg_id, 'id') location_x = 2000 location_y = 2000 location = (location_x, location_y) template_entity = nipyapi.templates.upload_template(root_pg_id, 'jangowave_demo.xml') flow = nipyapi.templates.deploy_template(root_pg_id, template_entity.id, 2000, 2000) jd = canvas.get_process_group('jangowave_demo') for cs in canvas.list_all_processors(jd.id): if cs.status.run_status != "ENABLED" and cs.component.name == "RecordIngest": config_update = nifi.models.processor_config_dto.ProcessorConfigDTO( properties={ "Accumulo User": "******", "Instance Name": instance, "Accumulo Password": "******", "ZooKeeper Quorum": zookeeper_list }) canvas.update_processor(cs, config_update) for cs in canvas.list_all_controllers(jd.id): canvas.schedule_controller(cs, True) for cs in canvas.list_all_processors(jd.id): canvas.schedule_processor(cs, True) canvas.schedule_process_group(jd.id, True)