Uploaded image for project: 'Apache Airflow'
  1. Apache Airflow
  2. AIRFLOW-6800

SSHHook: Close file object when reading ssh config

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.10.9
    • Fix Version/s: 1.10.10
    • Component/s: hooks
    • Labels:
      None

      Description

      This line of code in ssh/hooks.py is opening a file object without closing it in the scope where it is opened.
      This causes unnecessary noise e.g. when py.test warns about unclosed file objects:

      ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/test/.ssh/config' mode='r' encoding='UTF-8'>
      Exception ignored in: <_io.FileIO name='/home/test/.ssh/config' mode='rb' closefd=True>
      

      Using context manager fixes this easily.

                  ssh_conf = paramiko.SSHConfig()
                  ssh_conf.parse(open(user_ssh_config_filename))
                  host_info = ssh_conf.lookup(self.remote_host)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                yuqian90 Qian Yu
                Reporter:
                yuqian90 Qian Yu
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: