Skip to content
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

Fix setting of project ID in provide_authorized_gcloud #20428

Merged
merged 4 commits into from
Dec 31, 2021

Conversation

jobegrabber
Copy link
Contributor

@jobegrabber jobegrabber commented Dec 20, 2021

fixes: #20426 and change in logic introduced (seemingly accidentally) in 2fadf3c

@boring-cyborg boring-cyborg bot added area:providers provider:google Google (including GCP) related issues labels Dec 20, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 20, 2021

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@github-actions
Copy link

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label Dec 20, 2021
@potiuk
Copy link
Member

potiuk commented Dec 20, 2021

Would it be possible to add a unit test covering this case @jobegrabber ? Woudl be great to avoid regressions in the future

@jobegrabber
Copy link
Contributor Author

jobegrabber commented Dec 20, 2021

Would it be possible to add a unit test covering this case @jobegrabber ?

I'll try and see if I can set one up, I haven't contributed anything yet so I'll need to check out the dev setup first 🙂

Some tests use has_calls instead of assert_has_calls, but don't assert
on the returned value..
@jobegrabber
Copy link
Contributor Author

jobegrabber commented Dec 21, 2021

@potiuk I didn't have to add new tests, some of the existing ones are broken, among them the one that checks authentication with Google ADC.

For some reason, has_calls is used instead of assert_has_calls. I couldn't find any documentation of has_calls, but it seems to do the same thing as assert_has_calls, just that it returns a boolean instead of doing an assertion on its own. (EDIT: I'm wrong, it just seems to create a new mock ad-hoc..)This means the affected tests don't actually assert anything, making them pass although they shouldn't.

There are a couple of other places where has_calls is used:

(airflow-env) ➜  airflow git:(main) ✗ egrep -ir '[^_]has_calls' .
./tests/providers/google/common/hooks/test_base_google.py:        mock_check_output.has_calls(
./tests/providers/google/common/hooks/test_base_google.py:        mock_check_output.has_calls(
./tests/providers/google/cloud/transfers/test_sheets_to_gcs.py:        mock_sheet_hook.return_value.get_values.has_calls(calls)
./tests/providers/google/cloud/transfers/test_sheets_to_gcs.py:        mock_upload_data.has_calls(calls)
./tests/providers/google/cloud/hooks/test_bigquery.py:        mock_poll_job_complete.has_calls(mock.call(running_job_id), mock.call(running_job_id))
./tests/providers/google/cloud/hooks/test_bigquery.py:        mock_schema.has_calls([mock.call(x, "") for x in ["field_1", "field_2"]])
./tests/providers/google/cloud/hooks/test_bigquery.py:        assert mock_insert.has_calls(
./tests/providers/google/cloud/hooks/test_pubsub.py:        publish_method.has_calls(calls)
./tests/providers/google/cloud/hooks/test_cloud_memorystore.py:        mock_get_conn.return_value.get_instance.has_calls(
./tests/providers/google/cloud/hooks/test_cloud_memorystore.py:        mock_get_conn.return_value.get_instance.has_calls(
./tests/providers/google/cloud/hooks/test_cloud_memorystore.py:        mock_get_conn.return_value.get_instance.has_calls(
./tests/providers/google/cloud/hooks/test_dataproc.py:        mock_get_job.has_calls(calls)
./tests/providers/google/cloud/hooks/test_dataproc.py:            mock_get_job.has_calls(calls)
./tests/providers/google/suite/operators/test_sheets.py:        mock_xcom.has_calls(calls)
./tests/providers/http/operators/test_http.py:            mock_info.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)

I don't think I have the time to fix all these in a short time frame, I haven't looked at these parts at all..

@jobegrabber
Copy link
Contributor Author

jobegrabber commented Dec 21, 2021

@potiuk I didn't have to add new tests, some of the existing ones are broken, among them the one that checks authentication with Google ADC.

For some reason, has_calls is used instead of assert_has_calls. I couldn't find any documentation of has_calls, but it seems to do the same thing as assert_has_calls, just that it returns a boolean instead of doing an assertion on its own. This means the affected tests don't actually assert anything, making them pass although they shouldn't.

There are a couple of other places where has_calls is used:

(airflow-env) ➜  airflow git:(main) ✗ egrep -ir '[^_]has_calls' .
./tests/providers/google/common/hooks/test_base_google.py:        mock_check_output.has_calls(
./tests/providers/google/common/hooks/test_base_google.py:        mock_check_output.has_calls(
./tests/providers/google/cloud/transfers/test_sheets_to_gcs.py:        mock_sheet_hook.return_value.get_values.has_calls(calls)
./tests/providers/google/cloud/transfers/test_sheets_to_gcs.py:        mock_upload_data.has_calls(calls)
./tests/providers/google/cloud/hooks/test_bigquery.py:        mock_poll_job_complete.has_calls(mock.call(running_job_id), mock.call(running_job_id))
./tests/providers/google/cloud/hooks/test_bigquery.py:        mock_schema.has_calls([mock.call(x, "") for x in ["field_1", "field_2"]])
./tests/providers/google/cloud/hooks/test_bigquery.py:        assert mock_insert.has_calls(
./tests/providers/google/cloud/hooks/test_pubsub.py:        publish_method.has_calls(calls)
./tests/providers/google/cloud/hooks/test_cloud_memorystore.py:        mock_get_conn.return_value.get_instance.has_calls(
./tests/providers/google/cloud/hooks/test_cloud_memorystore.py:        mock_get_conn.return_value.get_instance.has_calls(
./tests/providers/google/cloud/hooks/test_cloud_memorystore.py:        mock_get_conn.return_value.get_instance.has_calls(
./tests/providers/google/cloud/hooks/test_dataproc.py:        mock_get_job.has_calls(calls)
./tests/providers/google/cloud/hooks/test_dataproc.py:            mock_get_job.has_calls(calls)
./tests/providers/google/suite/operators/test_sheets.py:        mock_xcom.has_calls(calls)
./tests/providers/http/operators/test_http.py:            mock_info.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)

I don't think I have the time to fix all these in a short time frame, I haven't looked at these parts at all..

Actually, has_calls should simply create a new mock on mock_check_output ..

@potiuk
Copy link
Member

potiuk commented Dec 21, 2021

For some reason, has_calls is used instead of assert_has_calls. I couldn't find any documentation of has_calls, but it seems to do the same thing as assert_has_calls, just that it returns a boolean instead of doing an assertion on its own. (EDIT: I'm wrong, it just seems to create a new mock ad-hoc..)This means the affected tests don't actually assert anything, making them pass although they shouldn't.

UPS!

There are a couple of other places where has_calls is used:

(airflow-env) ➜  airflow git:(main) ✗ egrep -ir '[^_]has_calls' .
./tests/providers/google/common/hooks/test_base_google.py:        mock_check_output.has_calls(
./tests/providers/google/common/hooks/test_base_google.py:        mock_check_output.has_calls(
./tests/providers/google/cloud/transfers/test_sheets_to_gcs.py:        mock_sheet_hook.return_value.get_values.has_calls(calls)
./tests/providers/google/cloud/transfers/test_sheets_to_gcs.py:        mock_upload_data.has_calls(calls)
./tests/providers/google/cloud/hooks/test_bigquery.py:        mock_poll_job_complete.has_calls(mock.call(running_job_id), mock.call(running_job_id))
./tests/providers/google/cloud/hooks/test_bigquery.py:        mock_schema.has_calls([mock.call(x, "") for x in ["field_1", "field_2"]])
./tests/providers/google/cloud/hooks/test_bigquery.py:        assert mock_insert.has_calls(
./tests/providers/google/cloud/hooks/test_pubsub.py:        publish_method.has_calls(calls)
./tests/providers/google/cloud/hooks/test_cloud_memorystore.py:        mock_get_conn.return_value.get_instance.has_calls(
./tests/providers/google/cloud/hooks/test_cloud_memorystore.py:        mock_get_conn.return_value.get_instance.has_calls(
./tests/providers/google/cloud/hooks/test_cloud_memorystore.py:        mock_get_conn.return_value.get_instance.has_calls(
./tests/providers/google/cloud/hooks/test_dataproc.py:        mock_get_job.has_calls(calls)
./tests/providers/google/cloud/hooks/test_dataproc.py:            mock_get_job.has_calls(calls)
./tests/providers/google/suite/operators/test_sheets.py:        mock_xcom.has_calls(calls)
./tests/providers/http/operators/test_http.py:            mock_info.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)
./tests/providers/airbyte/hooks/test_airbyte.py:        assert mock_get_job.has_calls(calls)

AH COOL. We should fix them.

I don't think I have the time to fix all these in a short time frame, I haven't looked at these parts at all..

No worries, I will create an issue for that and we will fix it. Also might make sense to ban using "has_calls" in our tests in this case!

@uranusjr
Copy link
Member

cc @deedmitrij

@jobegrabber
Copy link
Contributor Author

No worries, I will create an issue for that and we will fix it. Also might make sense to ban using "has_calls" in our tests in this case!

Thanks! I don't think there is anything else to do on this specific PR, is there?

@kaxil kaxil merged commit 4233ebe into apache:main Dec 31, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 31, 2021

Awesome work, congrats on your first merged pull request!

@kaxil
Copy link
Member

kaxil commented Dec 31, 2021

Thanks for the PR, well done 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers okay to merge It's ok to merge this PR as it does not require more tests provider:google Google (including GCP) related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GKE Authentication not possible with user ADC and project ID set in either connection or gcloud config
4 participants