-
Notifications
You must be signed in to change notification settings - Fork 17k
Fix GitDagBundle submodule clone not using SSH settings from connection #64879
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
Open
shunsuke-sugita
wants to merge
25
commits into
apache:main
Choose a base branch
from
shunsuke-sugita:provider-git-fix-fetch-submodul
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+54
−6
Open
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
4987c26
Fix Git bundle submodule fetch not using SSH settings from connection
shunsuke-sugita 46f66a4
Merge branch 'main' into provider-git-fix-fetch-submodul
shunsuke-sugita fd68b54
Rename cm to ssh_env_cm in _fetch_bare_repo and _fetch_submodules.
shunsuke-sugita 7e67b4c
Test GitDagBundle._fetch_submodules applies GIT_SSH_COMMAND via custo…
shunsuke-sugita ffb5e5a
Merge branch 'main' into provider-git-fix-fetch-submodul
shunsuke-sugita 799e084
Merge branch 'main' into provider-git-fix-fetch-submodul
shunsuke-sugita 21098f9
Merge branch 'main' into provider-git-fix-fetch-submodul
shunsuke-sugita 6346cb2
Use autospec for Git/Repo mocks in submodule fetch unit tests
shunsuke-sugita 2dcfd1d
Drop redundant mock_calls assertions in submodule fetch test
shunsuke-sugita fe31907
GitDagBundle: submodule custom_environment uses full hook.env
shunsuke-sugita 62d9068
Merge branch 'main' into provider-git-fix-fetch-submodul
shunsuke-sugita 6d27243
Rename submodule test for empty hook.env (custom_environment skip)
shunsuke-sugita 4f0d7fc
Update providers/git/tests/unit/git/bundles/test_git.py
shunsuke-sugita 9b6ca63
rm airflow
shunsuke-sugita 76fd8ca
Add missing blank line between submodule fetch tests
shunsuke-sugita 51f14ca
Fix submodule test call-order assertion (use mock_git.mock_calls, not…
shunsuke-sugita fa3f022
fix test
shunsuke-sugita 3ccbaf5
Merge branch 'main' into provider-git-fix-fetch-submodul
shunsuke-sugita b8084ed
Fix git bundle and Celery executor unit tests failing in provider CI
shunsuke-sugita 33def75
Fix git bundle and Celery executor unit tests for provider CI
shunsuke-sugita ce418f4
Merge branch 'main' into provider-git-fix-fetch-submodul
shunsuke-sugita 76cfd3a
Revert celery executor test changes (keep Git bundle PR scoped)
shunsuke-sugita 996de12
Merge branch 'main' into provider-git-fix-fetch-submodul
shunsuke-sugita cb599d8
Merge branch 'main' into provider-git-fix-fetch-submodul
shunsuke-sugita 6b1cc87
undo test_celery_executor fix
shunsuke-sugita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,47 @@ def bundle_temp_dir(tmp_path): | |
|
|
||
| GIT_DEFAULT_BRANCH = "main" | ||
|
|
||
|
|
||
| class _GitCustomEnvContextManager: | ||
| """Minimal context manager surface for Git.custom_environment() (autospec target).""" | ||
|
|
||
| def __enter__(self) -> None: | ||
| pass | ||
|
|
||
| def __exit__(self, exc_type, exc_val, exc_tb) -> None: | ||
| pass | ||
|
|
||
|
|
||
| def _stub_git_custom_environment(**_kwargs: object): | ||
| """Stand-in for ``git.cmd.Git.custom_environment`` (``create_autospec`` target only).""" | ||
| ... # Calls are intercepted by autospec mock; implementation is unused. | ||
|
|
||
|
|
||
| def _stub_git_submodule(*_args: object, **_kwargs: object) -> None: | ||
| """Stand-in for GitPython submodule subcommand calls (``create_autospec`` target only).""" | ||
| ... | ||
|
|
||
|
|
||
| # ``_fetch_submodules`` only uses ``repo.git.custom_environment`` and ``repo.git.submodule``. | ||
| # Use ``types.SimpleNamespace`` for ``bundle.repo`` / ``repo.git`` so ``.git`` / ``.submodule`` | ||
| # are plain instance attributes — **not** MagicMock children (nested ``Repo``/``Git`` mocks | ||
| # in unittest can lack ``submodule`` on lowest-dep / CI runs). | ||
| # ``custom_environment`` / ``submodule`` use ``create_autospec`` on small stubs so typos drift | ||
| # from the GitPython-like surface are caught (Airflow test convention). | ||
|
|
||
|
|
||
| def _repo_and_git_stubs_for_submodule_tests(ssh_ctx_cm): | ||
| """Return (repo_stub, git_cmd_stub) for ``GitDagBundle._fetch_submodules`` unit tests.""" | ||
| custom_environment = mock.create_autospec(_stub_git_custom_environment, spec_set=True) | ||
| custom_environment.return_value = ssh_ctx_cm | ||
| submodule = mock.create_autospec(_stub_git_submodule, spec_set=True) | ||
| git_cmd = types.SimpleNamespace( | ||
| custom_environment=custom_environment, | ||
| submodule=submodule, | ||
| ) | ||
|
shunsuke-sugita marked this conversation as resolved.
|
||
| return types.SimpleNamespace(git=git_cmd), git_cmd | ||
|
|
||
|
|
||
| AIRFLOW_HTTPS_URL = "https://github.com/apache/airflow.git" | ||
| ACCESS_TOKEN = "my_access_token" | ||
| CONN_HTTPS = "my_git_conn" | ||
|
|
@@ -920,6 +961,90 @@ def test_clone_bare_repo_invalid_repository_error_retry_fails( | |
| # Verify Repo was called twice (failed attempt + failed retry) | ||
| assert mock_repo_class.call_count == 2 | ||
|
|
||
| @mock.patch("airflow.providers.git.bundles.git.GitHook") | ||
| def test_fetch_submodules_uses_custom_environment_when_git_ssh_command_set(self, mock_githook_class): | ||
| """Non-empty hook.env is passed to custom_environment; submodule runs inside that context.""" | ||
| expected_ssh_cmd = "ssh -i /path/key -o IdentitiesOnly=yes -o UserKnownHostsFile=/path/known_hosts" | ||
| mock_hook = mock_githook_class.return_value | ||
| mock_hook.repo_url = "[email protected]:apache/airflow.git" | ||
| mock_hook.env = {"GIT_SSH_COMMAND": expected_ssh_cmd} | ||
|
|
||
| ssh_ctx = mock.create_autospec(_GitCustomEnvContextManager, instance=True) | ||
|
|
||
| bundle = GitDagBundle( | ||
| name="test", | ||
| git_conn_id="git_default", | ||
| tracking_ref="main", | ||
| version="123456", | ||
| submodules=True, | ||
| ) | ||
| bundle.repo, stub_git = _repo_and_git_stubs_for_submodule_tests(ssh_ctx) | ||
|
|
||
| bundle._fetch_submodules() | ||
|
|
||
| stub_git.custom_environment.assert_called_once_with(GIT_SSH_COMMAND=expected_ssh_cmd) | ||
| ssh_ctx.__enter__.assert_called_once_with() | ||
| ssh_ctx.__exit__.assert_called_once_with(None, None, None) | ||
| stub_git.submodule.assert_has_calls( | ||
| [ | ||
| mock.call("sync", "--recursive"), | ||
| mock.call("update", "--init", "--recursive", "--jobs", "1"), | ||
| ] | ||
| ) | ||
|
|
||
| @mock.patch("airflow.providers.git.bundles.git.GitHook") | ||
| def test_fetch_submodules_forwards_full_hook_env_including_passphrase_vars(self, mock_githook_class): | ||
| """SSH_ASKPASS / DISPLAY etc. must reach git subprocesses, not only GIT_SSH_COMMAND.""" | ||
| full_hook_env = { | ||
| "GIT_SSH_COMMAND": "ssh -i /path/key -o IdentitiesOnly=yes", | ||
| "SSH_ASKPASS": "/tmp/airflow-git-askpass.sh", | ||
| "SSH_ASKPASS_REQUIRE": "force", | ||
| "DISPLAY": ":0", | ||
| } | ||
| mock_hook = mock_githook_class.return_value | ||
| mock_hook.repo_url = "[email protected]:apache/airflow.git" | ||
| mock_hook.env = full_hook_env | ||
|
|
||
| ssh_ctx = mock.create_autospec(_GitCustomEnvContextManager, instance=True) | ||
|
|
||
| bundle = GitDagBundle( | ||
| name="test", | ||
| git_conn_id="git_default", | ||
| tracking_ref="main", | ||
| version="123456", | ||
| submodules=True, | ||
| ) | ||
| bundle.repo, stub_git = _repo_and_git_stubs_for_submodule_tests(ssh_ctx) | ||
|
|
||
| bundle._fetch_submodules() | ||
|
|
||
| stub_git.custom_environment.assert_called_once_with(**full_hook_env) | ||
|
|
||
| @mock.patch("airflow.providers.git.bundles.git.GitHook") | ||
| def test_fetch_submodules_skips_custom_environment_when_hook_env_empty(self, mock_githook_class): | ||
| """When hook.env is empty, submodule update does not use custom_environment.""" | ||
| mock_hook = mock_githook_class.return_value | ||
| mock_hook.repo_url = "[email protected]:apache/airflow.git" | ||
| mock_hook.env = {} | ||
|
|
||
| ssh_ctx = mock.create_autospec(_GitCustomEnvContextManager, instance=True) | ||
|
|
||
| bundle = GitDagBundle( | ||
| name="test", | ||
| git_conn_id="git_default", | ||
| tracking_ref="main", | ||
| version="123456", | ||
| submodules=True, | ||
| ) | ||
| bundle.repo, stub_git = _repo_and_git_stubs_for_submodule_tests(ssh_ctx) | ||
|
|
||
| bundle._fetch_submodules() | ||
|
|
||
| stub_git.custom_environment.assert_not_called() | ||
| stub_git.submodule.assert_has_calls( | ||
| [mock.call("sync", "--recursive"), mock.call("update", "--init", "--recursive", "--jobs", "1")] | ||
| ) | ||
|
|
||
| @mock.patch("airflow.providers.git.bundles.git.shutil.rmtree") | ||
| @mock.patch("airflow.providers.git.bundles.git.os.path.exists") | ||
| @mock.patch("airflow.providers.git.bundles.git.GitHook") | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.