Skip to content

Remove os.chdir() method; add support for other key_file types other than RSA - #275

Merged
njzjz merged 19 commits into
deepmodeling:masterfrom
Cloudac7:master
Nov 24, 2022
Merged

njzjz merged 19 commits into
deepmodeling:masterfrom
Cloudac7:master

Conversation

@Cloudac7

Copy link
Copy Markdown
Contributor

For what has been mentioned in the WeChat Group, it is in need to support not only the RSA type key and thus it is add in this PR.

Also, I found unexpected cwd change in a dpdispatcher submission, which could be OK when tasks submitted in serial, whose cwd is just the same for each single task. However, it might be a severe bug when tasks submitted in a parallel way, which might result in single task that just start in a WRONG work_path and thus it could not find the files in the right place. For some workflow management system (such as prefect), the bug was observed.

While in the former implementation, os.chdir() is only used in 3 situations. For os.symlink(), it seems dpdispatcher just not using relevant path so there is no need to change cwd. For tarfile.add(), abspath could be used to find the file while using arcname parameter could recover the relevant path in the tar file. For subprocess.Popen(), its cwd parameter is just the key to the door. So with just os.path dealing with the relevant path in the code, we could just drop os.chdir() out to make cwd not change in a python run.

The changed way is test to be OK in the Unittests and cluster environment for LocalContext and SSHContext. However, I am not sure whether it would be OK for Bohrium and more tests might be in need.

@codecov-commenter

codecov-commenter commented Nov 24, 2022 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.70588% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.83%. Comparing base (e59e73a) to head (2fca02d).
⚠️ Report is 259 commits behind head on master.

Files with missing lines Patch % Lines
dpdispatcher/hdfs_context.py 0.00% 7 Missing ⚠️
dpdispatcher/ssh_context.py 84.84% 5 Missing ⚠️
dpdispatcher/lazy_local_context.py 40.00% 3 Missing ⚠️
dpdispatcher/local_context.py 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #275      +/-   ##
==========================================
+ Coverage   59.44%   59.83%   +0.39%     
==========================================
  Files          27       27              
  Lines        2895     2846      -49     
==========================================
- Hits         1721     1703      -18     
+ Misses       1174     1143      -31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@njzjz njzjz closed this Nov 24, 2022
@njzjz njzjz reopened this Nov 24, 2022
Comment thread dpdispatcher/ssh_context.py Outdated
]:
for directory in [".ssh", "ssh"]:
full_path = os.path.expanduser(
"~/{}/id_{}".format(directory, name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the compatibility on the Windows platform. Use os.path.join or Pathlib instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.path.expanduser is just a Windows compatible implementation while add ssh in loop is an official implementation from paramiko.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my result on Windows:

PS C:\Program Files\Microsoft Visual Studio\2022\Community> python.exe
Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.expanduser("~/.ssh/id_rsa")
'C:\\Users\\njzjz/.ssh/id_rsa'

The correct output should be 'C:\\Users\\njzjz\\.ssh\\id_rsa'.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I understand. Using pathlib might be a better choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants