Example #1
0
 def behaves_like_regular_responder_by_default(self):
     r = FailingResponder(
         pattern='ju[^ ]{2}',
         response='how high?',
         sentinel='lolnope',
     )
     eq_(list(r.submit('jump, wait, jump, wait')), ['how high?'] * 2)
Example #2
0
 def behaves_like_regular_responder_by_default(self):
     r = FailingResponder(
         pattern='ju[^ ]{2}',
         response='how high?',
         sentinel='lolnope',
     )
     eq_(list(r.submit('jump, wait, jump, wait')), ['how high?'] * 2)
Example #3
0
 def raises_failure_exception_when_sentinel_detected(self):
     r = FailingResponder(
         pattern="ju[^ ]{2}", response="how high?", sentinel="lolnope"
     )
     # Behaves normally initially
     assert list(r.submit("jump")) == ["how high?"]
     # But then!
     try:
         r.submit("lolnope")
     except ResponseNotAccepted as e:
         message = str(e)
         # Expect useful bits in exception text
         err = "Didn't see pattern in {!r}".format(message)
         assert "ju[^ ]{2}" in message, err
         err = "Didn't see failure sentinel in {!r}".format(message)
         assert "lolnope" in message, err
     else:
         assert False, "Did not raise ResponseNotAccepted!"
Example #4
0
 def raises_failure_exception_when_sentinel_detected(self):
     r = FailingResponder(
         pattern='ju[^ ]{2}',
         response='how high?',
         sentinel='lolnope',
     )
     # Behaves normally initially
     eq_(list(r.submit('jump')), ['how high?'])
     # But then!
     try:
         r.submit('lolnope')
     except ResponseNotAccepted as e:
         message = str(e)
         # Expect useful bits in exception text
         err = "Didn't see pattern in {!r}".format(message)
         ok_("ju[^ ]{2}" in message, err)
         err = "Didn't see failure sentinel in {!r}".format(message)
         ok_("lolnope" in message, err)
     else:
         assert False, "Did not raise ResponseNotAccepted!"
Example #5
0
 def raises_failure_exception_when_sentinel_detected(self):
     r = FailingResponder(
         pattern='ju[^ ]{2}',
         response='how high?',
         sentinel='lolnope',
     )
     # Behaves normally initially
     eq_(list(r.submit('jump')), ['how high?'])
     # But then!
     try:
         r.submit('lolnope')
     except ResponseNotAccepted as e:
         message = str(e)
         # Expect useful bits in exception text
         err = "Didn't see pattern in {0!r}".format(message)
         ok_("ju[^ ]{2}" in message, err)
         err = "Didn't see failure sentinel in {0!r}".format(message)
         ok_("lolnope" in message, err)
     else:
         assert False, "Did not raise ResponseNotAccepted!"
Example #6
0
    def get_unknown_host_key_responder() -> FailingResponder:
        """
        Creates a responder for a host authenticity check with an unknown key. It replies ``yes`` to continue
        connecting. This is useful if you execute other ssh commands on the remote host, for example scp and rsync.

        :return: `FailingResponder` object
        """
        return FailingResponder(
            pattern=
            r"Are you sure you want to continue connecting \(yes/no\)\? ",
            response="yes\n",
            sentinel="Host key verification failed.\n")
Example #7
0
 def watcher_errors_become_Failures(self):
     watcher = FailingResponder(
         pattern=r"What's the password\?",
         response="Rosebud\n",
         sentinel="You're not Citizen Kane!",
     )
     try:
         run("python -u respond_fail.py", watchers=[watcher], hide=True)
     except Failure as e:
         assert isinstance(e.reason, WatcherError)
         assert e.result.exited is None
     else:
         assert False, "Did not raise Failure!"
Example #8
0
    def get_sudo_pass_responder(self) -> FailingResponder:
        """
        Creates a responder for the sudo password prompt. It replies with the password of the SSH connection.
        Note: only use this if the SSH connection is configured with a password and not a key.

        :return: `FailingResponder` object; raises `AirflowException` if no password was configured in the connection
        """
        if not self.password:
            raise AirflowException(
                "`add_sudo_password_responder` requires an SSH connection with a password."
            )

        return FailingResponder(pattern=r"\[sudo\] password for ",
                                response=f"{self.password}\n",
                                sentinel="Sorry, try again.\n")
Example #9
0
    def get_generic_pass_responder(self) -> FailingResponder:
        """
        Creates a responder for a generic password prompt. It replies with the password of the SSH connection. This is
        useful if you execute other ssh commands on the remote host, for example scp and rsync.
        Note: only use this if the SSH connection is configured with a password and not a key.

        :return: `FailingResponder` object; raises `AirflowException` if no password was configured in the connection
        """
        if not self.password:
            raise AirflowException(
                "`add_generic_password_responder` requires an SSH connection with a password."
            )

        return FailingResponder(pattern=r"password: "******"{self.password}\n",
                                sentinel="Permission denied")
Example #10
0
 def behaves_like_regular_responder_by_default(self):
     r = FailingResponder(
         pattern="ju[^ ]{2}", response="how high?", sentinel="lolnope"
     )
     assert list(r.submit("jump, wait, jump, wait")) == ["how high?"] * 2