You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ramitkataria (via GitHub)" <gi...@apache.org> on 2025/04/26 00:44:09 UTC

[PR] Refactor connection creation in system tests to use REST API instead [airflow]

ramitkataria opened a new pull request, #49804:
URL: https://github.com/apache/airflow/pull/49804

   Since direct DB access is not permitted in Airflow 3 due to Task SDK, the these system tests were failing during connection creation when run with Task SDK. This refactors the tests so they use REST API to create the connection.
   
   Also added a helper method to make REST API calls for tests without having to manually create the request.
   
   I've tested the `create_connection` task and confirmed it does create the connection.
   
   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #49804:
URL: https://github.com/apache/airflow/pull/49804#discussion_r2067049730


##########
providers/amazon/tests/system/amazon/aws/example_google_api_youtube_to_s3.py:
##########
@@ -73,28 +72,34 @@
 YOUTUBE_VIDEO_FIELDS = "items(id,snippet(description,publishedAt,tags,title))"
 
 SECRET_ARN_KEY = "SECRET_ARN"
+API_SERVER_URL_KEY = "ECS_example_google_api_youtube_to_s3_ExecutionApiServerUrl"

Review Comment:
   Interesting, you sure yyou tested with this change: #49599? That's literally the goal of this PR :) To automatically include a token in the request if this config is on



##########
providers/amazon/tests/system/amazon/aws/example_google_api_youtube_to_s3.py:
##########
@@ -73,28 +72,34 @@
 YOUTUBE_VIDEO_FIELDS = "items(id,snippet(description,publishedAt,tags,title))"
 
 SECRET_ARN_KEY = "SECRET_ARN"
+API_SERVER_URL_KEY = "ECS_example_google_api_youtube_to_s3_ExecutionApiServerUrl"

Review Comment:
   Interesting, you sure you tested with this change: #49599? That's literally the goal of this PR :) To automatically include a token in the request if this config is on



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #49804:
URL: https://github.com/apache/airflow/pull/49804#discussion_r2067069484


##########
devel-common/src/tests_common/test_utils/api_client_helpers.py:
##########
@@ -49,3 +56,24 @@ def generate_access_token(username: str, password: str, host: str) -> str:
 
     assert access_token, f"Failed to get JWT token from redirect url {url} with status code {login_response}"
     return access_token
+
+
+def make_authenticated_rest_api_request(
+    path: str,
+    method: str,
+    body: dict | None = None,
+    api_username: str = "admin",
+    api_password: str = "admin",
+    api_server_url: str | None = None,
+):
+    if not api_server_url:
+        api_server_url = conf.get("api", "base_url", fallback="http://localhost:8080")
+    api_server_url = api_server_url.rstrip("/")
+    token = generate_access_token(api_username, api_password, api_server_url)

Review Comment:
   Nice :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #49804:
URL: https://github.com/apache/airflow/pull/49804#issuecomment-2831899637

   We might eventually replace it with with python client - but I think it's good enough  for now  cc: @VladaZakharova @kosteev  ?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #49804:
URL: https://github.com/apache/airflow/pull/49804#discussion_r2067049730


##########
providers/amazon/tests/system/amazon/aws/example_google_api_youtube_to_s3.py:
##########
@@ -73,28 +72,34 @@
 YOUTUBE_VIDEO_FIELDS = "items(id,snippet(description,publishedAt,tags,title))"
 
 SECRET_ARN_KEY = "SECRET_ARN"
+API_SERVER_URL_KEY = "ECS_example_google_api_youtube_to_s3_ExecutionApiServerUrl"

Review Comment:
   Interesting, you sure you tested with this change: #49599? That's literally the goal of this PR :) To automatically include a token in the request if this config is on



##########
devel-common/src/tests_common/test_utils/api_client_helpers.py:
##########
@@ -49,3 +56,24 @@ def generate_access_token(username: str, password: str, host: str) -> str:
 
     assert access_token, f"Failed to get JWT token from redirect url {url} with status code {login_response}"
     return access_token
+
+
+def make_authenticated_rest_api_request(
+    path: str,
+    method: str,
+    body: dict | None = None,
+    api_username: str = "admin",
+    api_password: str = "admin",
+    api_server_url: str | None = None,
+):
+    if not api_server_url:
+        api_server_url = conf.get("api", "base_url", fallback="http://localhost:8080")
+    api_server_url = api_server_url.rstrip("/")
+    token = generate_access_token(api_username, api_password, api_server_url)

Review Comment:
   Interesting, you sure you tested with this change: #49599? That's literally the goal of this PR :) To automatically include a token in the request if this config is on



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on code in PR #49804:
URL: https://github.com/apache/airflow/pull/49804#discussion_r2064151939


##########
providers/amazon/tests/system/amazon/aws/example_google_api_youtube_to_s3.py:
##########
@@ -73,28 +72,34 @@
 YOUTUBE_VIDEO_FIELDS = "items(id,snippet(description,publishedAt,tags,title))"
 
 SECRET_ARN_KEY = "SECRET_ARN"
+API_SERVER_URL_KEY = "ECS_example_google_api_youtube_to_s3_ExecutionApiServerUrl"

Review Comment:
   Yupp, you're correct, this will not work. I assume it was working because of the fallback to localhost.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #49804:
URL: https://github.com/apache/airflow/pull/49804#issuecomment-2843521790

   @ramitkataria -> Generelly when in doubt - rebase and check if it still fails. `Always Be Rebased` is the motto you should use. That helps to see if the issue is resolved  without involving maintainers - they migth or might not know about some current or even new failures. You are 20 commits behind already.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas merged PR #49804:
URL: https://github.com/apache/airflow/pull/49804


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #49804:
URL: https://github.com/apache/airflow/pull/49804#discussion_r2067050752


##########
providers/amazon/tests/system/amazon/aws/example_google_api_youtube_to_s3.py:
##########
@@ -73,28 +72,34 @@
 YOUTUBE_VIDEO_FIELDS = "items(id,snippet(description,publishedAt,tags,title))"
 
 SECRET_ARN_KEY = "SECRET_ARN"
+API_SERVER_URL_KEY = "ECS_example_google_api_youtube_to_s3_ExecutionApiServerUrl"

Review Comment:
   Much better :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #49804:
URL: https://github.com/apache/airflow/pull/49804#discussion_r2063306481


##########
providers/amazon/tests/system/amazon/aws/example_google_api_youtube_to_s3.py:
##########
@@ -73,28 +72,34 @@
 YOUTUBE_VIDEO_FIELDS = "items(id,snippet(description,publishedAt,tags,title))"
 
 SECRET_ARN_KEY = "SECRET_ARN"
+API_SERVER_URL_KEY = "ECS_example_google_api_youtube_to_s3_ExecutionApiServerUrl"

Review Comment:
   I am not sure this is valid and I wonder how it could work. We might want to talk about it with @o-nikolas but I think we should:
   - save the execution api endpoint in the same SSM parameter used to stored system test external parameters. Use the same key across all system test, e.g. `API_SERVER_URL`
   - Update this line to `API_SERVER_URL_KEY = "API_SERVER_URL"`



##########
devel-common/src/tests_common/test_utils/api_client_helpers.py:
##########
@@ -49,3 +56,24 @@ def generate_access_token(username: str, password: str, host: str) -> str:
 
     assert access_token, f"Failed to get JWT token from redirect url {url} with status code {login_response}"
     return access_token
+
+
+def make_authenticated_rest_api_request(
+    path: str,
+    method: str,
+    body: dict | None = None,
+    api_username: str = "admin",
+    api_password: str = "admin",
+    api_server_url: str | None = None,
+):
+    if not api_server_url:
+        api_server_url = conf.get("api", "base_url", fallback="http://localhost:8080")
+    api_server_url = api_server_url.rstrip("/")
+    token = generate_access_token(api_username, api_password, api_server_url)

Review Comment:
   As mentioned in Slack, we might want to set `export AIRFLOW__CORE__SIMPLE_AUTH_MANAGER_ALL_ADMINS="True"` in AWS CI and call the Airflow API with no credentials. That would simplify things



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #49804:
URL: https://github.com/apache/airflow/pull/49804#discussion_r2067192686


##########
devel-common/src/tests_common/test_utils/api_client_helpers.py:
##########
@@ -66,9 +66,9 @@ def make_authenticated_rest_api_request(
     password: str = "admin",
 ):
     api_server_url = conf.get("api", "base_url", fallback="http://localhost:8080").rstrip("/")
-    auth_required = not conf.get("core", "simple_auth_manager_all_admins", fallback=False)
+    skip_auth = conf.get("core", "simple_auth_manager_all_admins", fallback="False") == "True"

Review Comment:
   ```suggestion
       skip_auth = conf.getboolean("core", "simple_auth_manager_all_admins", fallback=False)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "ramitkataria (via GitHub)" <gi...@apache.org>.
ramitkataria commented on code in PR #49804:
URL: https://github.com/apache/airflow/pull/49804#discussion_r2067044313


##########
devel-common/src/tests_common/test_utils/api_client_helpers.py:
##########
@@ -49,3 +56,24 @@ def generate_access_token(username: str, password: str, host: str) -> str:
 
     assert access_token, f"Failed to get JWT token from redirect url {url} with status code {login_response}"
     return access_token
+
+
+def make_authenticated_rest_api_request(
+    path: str,
+    method: str,
+    body: dict | None = None,
+    api_username: str = "admin",
+    api_password: str = "admin",
+    api_server_url: str | None = None,
+):
+    if not api_server_url:
+        api_server_url = conf.get("api", "base_url", fallback="http://localhost:8080")
+    api_server_url = api_server_url.rstrip("/")
+    token = generate_access_token(api_username, api_password, api_server_url)

Review Comment:
   I tried this but it still needs a valid token. I think it just makes all users admin but you still have to login and use the token



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "ramitkataria (via GitHub)" <gi...@apache.org>.
ramitkataria commented on PR #49804:
URL: https://github.com/apache/airflow/pull/49804#issuecomment-2843235304

   > BTW. The errors are unrelated - one of them random, one of them being fixed in main.
   
   Is error occurring right now the one being fixed in main? Otherwise I was thinking of moving the import statement to be inside the function


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #49804:
URL: https://github.com/apache/airflow/pull/49804#issuecomment-2831900054

   BTW. The errors are unrelated - one of them random, one of them being fixed in main.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "ramitkataria (via GitHub)" <gi...@apache.org>.
ramitkataria commented on code in PR #49804:
URL: https://github.com/apache/airflow/pull/49804#discussion_r2067041835


##########
providers/amazon/tests/system/amazon/aws/example_google_api_youtube_to_s3.py:
##########
@@ -73,28 +72,34 @@
 YOUTUBE_VIDEO_FIELDS = "items(id,snippet(description,publishedAt,tags,title))"
 
 SECRET_ARN_KEY = "SECRET_ARN"
+API_SERVER_URL_KEY = "ECS_example_google_api_youtube_to_s3_ExecutionApiServerUrl"

Review Comment:
   Yep, I incorrectly assumed how `SystemTestContextBuilder` fetched from SSM but after our discussion offline, I've removed setting the URL as a param to the function and will just be using API configuration's `base_url`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor connection creation in system tests to use REST API instead [airflow]

Posted by "ramitkataria (via GitHub)" <gi...@apache.org>.
ramitkataria commented on code in PR #49804:
URL: https://github.com/apache/airflow/pull/49804#discussion_r2067066348


##########
devel-common/src/tests_common/test_utils/api_client_helpers.py:
##########
@@ -49,3 +56,24 @@ def generate_access_token(username: str, password: str, host: str) -> str:
 
     assert access_token, f"Failed to get JWT token from redirect url {url} with status code {login_response}"
     return access_token
+
+
+def make_authenticated_rest_api_request(
+    path: str,
+    method: str,
+    body: dict | None = None,
+    api_username: str = "admin",
+    api_password: str = "admin",
+    api_server_url: str | None = None,
+):
+    if not api_server_url:
+        api_server_url = conf.get("api", "base_url", fallback="http://localhost:8080")
+    api_server_url = api_server_url.rstrip("/")
+    token = generate_access_token(api_username, api_password, api_server_url)

Review Comment:
   Ohh I just tried removing the header completely instead of sending an empty token and it worked!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org