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

Validate default_kernel global property on set #613

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

alimirjamali
Copy link
Contributor

@alimirjamali
Copy link
Contributor Author

Additional side notes:

I did not go to the extreme of doing it like how it is done in the QubesVM class. A simpler approach of just using the Kernel Pool is implemented. It is similar to how it is done in Qubes Manager.

@alimirjamali
Copy link
Contributor Author

alimirjamali commented Aug 18, 2024

Humm. The pylint complain is very well understandable:

qubes/app.py:1598:4: C0103: Method name "on_property_pre_set_default_kernel" doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern (invalid-name)

On the other hand, the failed test is confusing:

    return iter(self._pool.list_volumes())
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gitlab-runner/builds/QubesOS/qubes-core-admin/qubes/storage/kernels.py", line 216, in list_volumes
    for kernel_version in os.listdir(self.dir_path)]
                          ^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/qubes/vm-kernels'

p.s.: Oh. I see. TC_90_Qubes.setUp setting the default_kernel and everything else. This PR breaks all the unit tests.

It is not possible to cheat and reuse the test for qubesvm.py kernel setter. It is not implemented.

@alimirjamali alimirjamali force-pushed the Issue-8992 branch 3 times, most recently from f03a57e to b044b86 Compare August 18, 2024 02:12
@alimirjamali
Copy link
Contributor Author

The nice fact about the two last failed tests is that it shows that the code is actually working.

1st. test failed since /var/lib/qubes/vm-kernels directory did not exist.
2nd. test failed since /var/lib/qubes/vm-kernels/1.0 which was used by some unittest did not exist.

I guess there is no need for additional unit tests.

@alimirjamali
Copy link
Contributor Author

Fixing few remaining unit tests.

@alimirjamali alimirjamali force-pushed the Issue-8992 branch 5 times, most recently from 31daa6c to 4bec5ec Compare August 18, 2024 11:50
run-tests Outdated
@@ -19,6 +19,17 @@ if sudo --non-interactive "$name/ci/lvm-manage" setup-lvm vg$$/pool; then
CLEANUP_LVM=yes
fi

CLEANUP_KERNEL_POOL=
if [ ! -d "/var/lib/qubes/vm-kernels" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

This won't work when running tests in actual dom0 (vm-kernels dir exists, but "1.0" kernel doesn't).
Some of the tests patch qubes_kernels_base_dir, see for example test_260_kernelopts in qubes/tests/vm/qubesvm.py which should be safer approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Just recognized it. I will do the tests locally in order to avoid abusing the CI/CD servers and cluttering the logs. Will come back after I fix it properly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marmarek I finally managed to patch one of the major base classes (AdminAPITestCase). I believe that I can go forward and properly patch the rest.

I have a question regarding the CI/CD servers. Are they owned by Qubes project or they belong to Gitlab? I am trying to avoid using the online ones as much as possible and test the patches locally. But using the online ones are sometimes more convenient.

Copy link
Member

Choose a reason for hiding this comment

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

I have a question regarding the CI/CD servers. Are they owned by Qubes project or they belong to Gitlab? I am trying to avoid using the online ones as much as possible and test the patches locally. But using the online ones are sometimes more convenient.

We use our own runners, you can use them as much as you like :)

@alimirjamali
Copy link
Contributor Author

Nice. The tearDown function is purging /tmp/qubes-test-dir. So creating the /tmp/qubes-test-dir/vm-kernels/1.0/vmlinuz in the startup bash file is insufficient.

I am not going to abuse CI/CD server anymore. Reverting to local tests and will come back after I patched all unittests

@alimirjamali alimirjamali force-pushed the Issue-8992 branch 3 times, most recently from 386961c to 134e971 Compare August 18, 2024 15:10
@alimirjamali
Copy link
Contributor Author

The approach of patching the existing untitests to allow default_kernel checkup is wrong. Some of them break in different scenarios. The proper approach would be mocking on_property_pre_set_default_kernel in relevant unittest classes to ignore it. Then write a single unittest for on_property_pre_set_default_kernel scenario. I will do it tomorrow.

Copy link

codecov bot commented Aug 18, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 69.35%. Comparing base (a1a023b) to head (151010d).
Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
qubes/app.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #613      +/-   ##
==========================================
+ Coverage   69.32%   69.35%   +0.02%     
==========================================
  Files          58       58              
  Lines       11953    11958       +5     
==========================================
+ Hits         8286     8293       +7     
+ Misses       3667     3665       -2     
Flag Coverage Δ
unittests 69.35% <92.30%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alimirjamali
Copy link
Contributor Author

Ok. We have passed CI checks and Codecov is advising on the new Unittests. I should use the helper function for QubesVM as well and add the necessary unittests. Hopefully tomorrow

@alimirjamali alimirjamali force-pushed the Issue-8992 branch 2 times, most recently from 8b03df9 to 9991c35 Compare August 19, 2024 16:44
@alimirjamali
Copy link
Contributor Author

@marmarek This is ready for review

qubes/app.py Outdated Show resolved Hide resolved
@marmarek marmarek merged commit ae7aa11 into QubesOS:main Sep 26, 2024
4 checks passed
@alimirjamali alimirjamali deleted the Issue-8992 branch October 29, 2024 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"default-kernel" global property doesn't validate if the kernel exists
2 participants