Ah, I missed your earlier email. Yes, that's right observation. One way to get around the issue is to configure the ansible_terminal_stdout_re for a given task to match the error and prompt in first chunk itself. However, I agree that is not the best of the solution. Please raise an issue here https://github.com/ansible-collections/ansible.netcommon/issues to track it.
On Fri, Apr 10, 2020 at 2:39 PM Ganesh Nalawade <ganesh...@gmail.com> wrote: > > The regex match is done for each chunk (256 bytes) received to identify if > the chunk has error/prompt string. > Based on your problem description, if the first chunk matches the error > regex it will raise an error exception and not read second chunk at all. > > However, if the error string is split across two chunks, in that case, it > might not detect the error string as the default error regex won't match. > For such case regex can be configured to handle this scenario > > On Fri, Apr 10, 2020 at 2:33 PM Yann <yann.vercuc...@gmail.com> wrote: > >> Thx for the answer. >> >> But the problem is the same when it return several chunck of data : >> >> 1st chunk : ["Command unknown", "Lorem", "ipsum"] >> 2st chunk : ["Lorem2", "MyPrompt >"] >> >> In this case no error is raise, because between the 2 chunk, the variable >> : is_error_message is set to False >> >> *In network_cli.py* >> >> def receive([...]) >> [...] >> if self._find_prompt(window): # window = chunk of data >> >> # expected True; else still wait chunk of data >> >> def _find_prompt(self, response): >> '''Searches the buffered response for a matching command prompt >> ''' >> errored_response = None >> is_error_message = False >> >> for regex in self._terminal_stderr_re: # First chunk - match / Second >> chunk - no match >> if regex.search(response): >> is_error_message = True >> >> # Check if error response ends with command prompt if not >> # receive it buffered prompt >> for regex in self._terminal_stdout_re: # First chunk - no match >> - so errored_response is not set >> match = regex.search(response) >> if match: >> errored_response = response >> self._matched_pattern = regex.pattern >> self._matched_prompt = match.group() >> self._log_messages("matched error regex '%s' from >> response '%s'" % (self._matched_pattern, errored_response)) >> break >> >> if not is_error_message: # Second chunk, is_error_message was reset to >> False, so the condition are True. >> for regex in self._terminal_stdout_re: >> match = regex.search(response) >> if match: >> self._matched_pattern = regex.pattern >> self._matched_prompt = match.group() >> self._log_messages("matched cli prompt '%s' with regex '%s' >> from response '%s'" % (self._matched_prompt, self._matched_pattern, >> response)) >> if not errored_response: >> return True # Finally return "Everything is okkayyy" >> >> if errored_response: # First chunk - errored_response is still None -> >> not triggered - no error raise >> raise AnsibleConnectionFailure(errored_response) >> >> return False >> >> >> That's why I would like to overload this method. >> >> >> Le vendredi 10 avril 2020 10:42:37 UTC+2, Ganesh Nalawade a écrit : >>> >>> >>> From Ansible version 2.9 onwards you can configure a list of >>> terminal regex (ansible_terminal_stderr_re and ansible_terminal_stdout_re) >>> to identify if the response is an error or valid output. >>> Refer: >>> https://docs.ansible.com/ansible/devel/network/user_guide/network_debug_troubleshooting.html#task-failure-due-to-mismatched-error-regex-within-command-response-using-network-cli-connection-type >>> >>> On Fri, Apr 10, 2020 at 1:41 PM Yann <yann.v...@gmail.com> wrote: >>> >>>> Hi, >>>> >>>> In my team we are using several custom modules based on network_cli / >>>> cliconf. >>>> >>>> For one of our manufacturer, we have a issue with the method >>>> "_find_prompt" of the "network_cli.py", we would like to know if its >>>> possible to overload "network_cli.py" and how ? >>>> >>>> For now, we put a modified "network_cli.py" on the module folder called >>>> "connection_plugins", but we would like to only overload the method >>>> "_find_prompt". >>>> >>>> >>>> About the issue that we face : >>>> In a custom module, you have to set, in the terminal_plugins, some info >>>> about the "stderr" and "stdout". >>>> For example : >>>> stderr = "command unknown" >>>> stdout = "MyPrompt >" >>>> >>>> When stderr match, an error should be raise. >>>> And the data are catched until the "stdout" match. >>>> >>>> When you have a chunk of data like : ["Command unknown", "MyPrompt >"] >>>> => No problem, an error is raise >>>> >>>> BUT, when you have several chunk of data like : >>>> 1st chunk : ["Command unknown", "Lorem", "ipsum"] >>>> 2st chunk : ["Lorem2", "MyPrompt >"] >>>> >>>> In this case no error is raise ! >>>> >>>> So I have two questions :) >>>> >>>> * How to deal with this kind of behaviour ? >>>> * How to overload a specific function in "network_cli.py" ? >>>> >>>> >>>> Thanks :) >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Ansible Development" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to ansibl...@googlegroups.com. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/ansible-devel/c33895c4-b69e-4336-a795-e59cbe496dd3%40googlegroups.com >>>> <https://groups.google.com/d/msgid/ansible-devel/c33895c4-b69e-4336-a795-e59cbe496dd3%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> >>> >>> -- >>> Regards, >>> Ganesh B. Nalawade >>> >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Ansible Development" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to ansible-devel+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-devel/9b2a9624-2050-4da5-891d-616cd2f0e6d9%40googlegroups.com >> <https://groups.google.com/d/msgid/ansible-devel/9b2a9624-2050-4da5-891d-616cd2f0e6d9%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > > -- You received this message because you are subscribed to the Google Groups "Ansible Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/CA%2B6y2sFAqMxZqSO89yg8cigcC-q%2B25BwNuSpm8zPJ7e6Nq4%3DRA%40mail.gmail.com.