Skip to content

fix: update git utils temp file #2057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/sagemaker/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ def _run_clone_command(repo_url, dest_dir):
write_pipe = open(sshnoprompt.name, "w")
write_pipe.write("ssh -oBatchMode=yes $@")
write_pipe.close()
# 511 in decimal is same as 777 in octal
os.chmod(sshnoprompt.name, 511)
os.chmod(sshnoprompt.name, 0o511)
my_env["GIT_SSH"] = sshnoprompt.name
subprocess.check_call(["git", "clone", repo_url, dest_dir], env=my_env)

Expand Down
8 changes: 5 additions & 3 deletions tests/unit/test_git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pytest
import os
import subprocess
from mock import patch
from mock import patch, ANY

from sagemaker import git_utils

Expand Down Expand Up @@ -180,7 +180,7 @@ def test_git_clone_repo_dependencies_not_exist(exists, isdir, isfile, mkdtemp, c
@patch("subprocess.check_call")
@patch("tempfile.mkdtemp", return_value=REPO_DIR)
@patch("os.path.isfile", return_value=True)
def test_git_clone_repo_with_username_password_no_2fa(sfile, mkdtemp, check_call):
def test_git_clone_repo_with_username_password_no_2fa(isfile, mkdtemp, check_call):
git_config = {
"repo": PRIVATE_GIT_REPO,
"branch": PRIVATE_BRANCH,
Expand Down Expand Up @@ -262,12 +262,14 @@ def test_git_clone_repo_with_token_2fa(isfile, mkdtemp, check_call):


@patch("subprocess.check_call")
@patch("os.chmod")
@patch("tempfile.mkdtemp", return_value=REPO_DIR)
@patch("os.path.isfile", return_value=True)
def test_git_clone_repo_ssh(isfile, mkdtemp, check_call):
def test_git_clone_repo_ssh(isfile, mkdtemp, chmod, check_call):
git_config = {"repo": PRIVATE_GIT_REPO_SSH, "branch": PRIVATE_BRANCH, "commit": PRIVATE_COMMIT}
entry_point = "entry_point"
ret = git_utils.git_clone_repo(git_config, entry_point)
chmod.assert_any_call(ANY, 0o511)
assert ret["entry_point"] == "/tmp/repo_dir/entry_point"
assert ret["source_dir"] is None
assert ret["dependencies"] is None
Expand Down