Skip to content

Conversation

@amoghrajesh
Copy link
Contributor

Seems that pytest will walk up looking for other conftest.py files beyond the tests/charts repo due to which the helm chart tests require DB init to be done which should not be the case. The tests inside tests finds the nearest _clear_db fixture and continues to use it. We should not use that conftest fixture for helm chart tests.
So likely then #28631 had side-effect of trying to clear db where it was not initialized

This PR moves the helm charts tests outside tests/charts to test-charts. Tested using the steps:

  1. Created a new env
  2. Ran the command
    pip install -e ."[devel]" --constraint https://raw.githubusercontent.com/apache/airflow/constraints-main/constraints-source-providers-3.8.txt
  3. Ran the tests in test-charts and we are good 👍! Did not have to init any DB at all

^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
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 newsfragments.

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

Loooks good - pending static checks fixes. Thanks for taking care of it :). Good idea with adding docstrings.

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

Ah. Forgot it. Few more things are needed:

  • .dockerignore -> it should be added to not be excluded when Docker image is built (see !tests, !kubernetes_tests). Probably also adding !docker_tests is a good idea. We do not run docker tests in breeze usually, but having them in CI image would be nice.

  • you also need to add it to VOLUMES_FOR_SELECTED_MOUNTS in docker_command_utils.py in breeze - this way the folder will be also mounted when you run breeze command from local sources and you will be able to run the tests with latest sources when you are inside of breeze. Once you add it there, pre-commit will automatically update it in other places.

  • probably helm_tests is a better name after looking theere - it will be following the convention we already have there (docker_tests, kubernetes_tests)

@amoghrajesh
Copy link
Contributor Author

All these points are valid. Making the changes to accommodate them

@amoghrajesh amoghrajesh requested a review from potiuk July 6, 2023 09:34
@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

All these points are valid. Making the changes to accommodate them

still some "test-charts" in there.

@amoghrajesh
Copy link
Contributor Author

Woops. Looks like the IDE didnt catch it all. Made them manually

@amoghrajesh amoghrajesh changed the title Migrating helm chart tests to test-charts to prevent test DB init Migrating helm chart tests to helm_tests to prevent test DB init Jul 6, 2023
@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

Looks good - only static checks need to be fixed

@amoghrajesh
Copy link
Contributor Author

Not sure what the failure is. doesn't look related to the changes in this PR

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

Ah... I look at the checks and I was surprised, I have not seen Helm tests running. This

One more thing in selective checks (in breeze) we detect if Helm tests should be run:

        FileGroupForCi.HELM_FILES: [
            r"^chart",
            r"^airflow/kubernetes",
            r"^tests/kubernetes",
            r"^tests/charts",
        ],

@amoghrajesh
Copy link
Contributor Author

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

There is one unnerving thing here as well - for some reason (and I have no idea why yet) I cannot see the "Unit tests: Helm" running in this PR. I will take a look after you fix all the static checks (and please rebase to latest main as well).

@amoghrajesh
Copy link
Contributor Author

Let me rebase and let the CI run once. I am not sure what is failing in the static checks. It is not so clear from logs

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

Not sure what the failure is. doesn't look related to the changes in this PR

Look at the output of it. It says exactly what it is - and prints you the command tat you should run to fix it. It's about changed breeze commmands that need regeneration of embedded Breeze images.

@amoghrajesh
Copy link
Contributor Author

Thought that was a false alarm. Checking it

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

Screenshot 2023-07-06 at 13 33 56

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

Ah.. Looking at the generated image, there is one more problem:

https://github.com/apache/airflow/blob/main/dev/breeze/src/airflow_breeze/global_constants.py#L123

This is why you had this "static check" failures. The image generation should not be needed, but there is one more place where "tests" / "charts" was used and now the list of allowed packages is wrong.

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

You can switch to "swipe" view for the image generated and you will see what happened.

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

BTW. It would also be great to filter out the __pycache__ folder from https://github.com/apache/airflow/blob/main/dev/breeze/src/airflow_breeze/global_constants.py#L123 - for some reason you had it in your environment, and we should filter it out then.

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

They are failing because of the __pycache__. Look at --helm-test-package help output:

image

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

For some reason, in your environment there is __pycache__ folder in the "helm-tests" folder - just filter it out in the place where it is generated (that's the lines I pointed out to you)

@amoghrajesh
Copy link
Contributor Author

Oh, thanks for explaining so patiently. I could not see the folder because it was a hidden one! Silly me

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

Now.... Coming back to unit tests that faik .. There seems to be coming from that chang. For example the first one determines the folder where chart is - this way:

chart_dir = Path(__file__).parents[3] / "chart"

And after the tests were moved from the "tests/charts" to "helm-tests" - this is no longer working - because instead of looking for chart in "/opt/airflow/chart", it looks in "/opt/chart".

So I think you need to also take a look at those tests that are failling and fix similar cases.

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

BTW. And yeah, those are all (except pycache problems I kind of expected to see in this PR, so this is not really strange or unexpected :)

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

Oh, thanks for explaining so patiently. I could not see the folder because it was a hidden one! Silly me

Not a problem, I think there is a value in doing it, as you will learn quite a bit more on how things work in Airflow CI/Breeze/tests etc. - I know well things that are obvious to me as I worked on it for quite some time, aren't necessary obvious to others. I think the important thing is that YOU do not loose the patience, and will go through all that with open approach accepting that there are completely new things coming up that you have to learn about and where this "simple" PR will take quite some time to complete, and that things will be looking wrong at times. There are quite a few moving pieces here that make the whole system works - the fact that you have breeze where you can run it all manually, local venv, but also CI that uses breeze and reproducible enviroment make it much more complex (but not complicated) I think. Complex in the sense that there are multiple pieces of puzzle that work together and each has a role, but every single one is simple (once you know the role, and know that it is there at all).

@amoghrajesh
Copy link
Contributor Author

Thanks for the detailed mentoring, @potiuk
You have been very helpful and now I know quite some areas confidently in airflow :)

@amoghrajesh
Copy link
Contributor Author

Hopefully we should get a green CI now. I have run the tests in the whole module. All looks good 👍🏽
Will also rebase to main so that any unknowns don't show up.

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

🤞

@potiuk
Copy link
Member

potiuk commented Jul 6, 2023

1 test left it seems :)

@amoghrajesh
Copy link
Contributor Author

@potiuk I think we are done with it now. Hopefully this time it will :)

@amoghrajesh
Copy link
Contributor Author

Clean build finally, @potiuk 🙂

@pytest.fixture(scope="class", autouse=True)
def isolate_chart(request):
chart_dir = Path(__file__).parents[3] / "chart"
chart_dir = Path(__file__).parents[3] / "airflow" / "chart"
Copy link
Member

@potiuk potiuk Jul 6, 2023

Choose a reason for hiding this comment

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

Suggested change
chart_dir = Path(__file__).parents[3] / "airflow" / "chart"
chart_dir = Path(__file__).parents[2] / "chart"

This is how it should be. Having "airflow" hard-coded, you assume that that Airflow has been checked out as "airflow" directory, which does not necessarily needs to be true. This would cause subtle problems that could be very difficult to fix when you will be running the tests in loca environment.

You can easily checkout airflow with a different "folder" name or even create a work-tree if you work on different branches in the same directory where you keep several different versions of airflow checked out.

For example I have:

code
       | - airflow -> here I mostly work on main
       | - airflow-copy -> here I mostly work on v2-6-test branch or similar

The airflow-copy is a worktree of the "airflow" repoository - which means that I have one git repository but I can have different branches of the same repo checked out in different folders.

If you do parents[3] / "airflow" / "chart", what will happen is that when I run tests in "airflow-copy", it will copy chart from the "airflow" folder, which might be an old tag or branch. That would be extremely difficult test failure to trace in those cases.

Copy link
Member

Choose a reason for hiding this comment

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

(Also in other places)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point. Thanks for the explanation. I will make the changes :)

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

The "chart" directory deterrmining needs to be fixed (see comment)

@amoghrajesh amoghrajesh requested a review from potiuk July 7, 2023 05:46
@amoghrajesh
Copy link
Contributor Author

@potiuk has any new hook been added to check for re2 library over re? The static checks fail with the error..

Use re2 over re....................................................................Failed
- hook id: check-usage-of-re2-over-re
- exit code: 1

helm_tests/airflow_aux/test_pod_template_file.py:19:import re
helm_tests/other/test_redis.py:19:import re
``

@potiuk
Copy link
Member

potiuk commented Jul 7, 2023

🎉 🎉

@potiuk potiuk merged commit 907aeeb into apache:main Jul 7, 2023
syedahsn pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Jul 11, 2023
…che#32394)



---------

Co-authored-by: Amogh Desai <adesai@adesai-MBP16.local>
@ephraimbuddy ephraimbuddy added the changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) label Aug 2, 2023
@ephraimbuddy ephraimbuddy added this to the Airflow 2.7.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev-tools changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants