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

Modernize scripts in bin/ #2679

Merged
merged 15 commits into from
Mar 7, 2024
Merged

Modernize scripts in bin/ #2679

merged 15 commits into from
Mar 7, 2024

Conversation

hmpf
Copy link
Contributor

@hmpf hmpf commented Sep 8, 2023

Closes #2676

@hmpf hmpf requested a review from lunkwill42 September 8, 2023 07:16
@github-actions
Copy link

github-actions bot commented Sep 8, 2023

Test results

     12 files       12 suites   11m 9s ⏱️
3 320 tests 3 320 ✔️ 0 💤 0
9 435 runs  9 435 ✔️ 0 💤 0

Results for commit 7dbda65.

♻️ This comment has been updated with latest results.

@hmpf hmpf force-pushed the modernize-scripts branch 2 times, most recently from 34f9aa7 to 88f57c7 Compare November 17, 2023 12:28
@hmpf hmpf changed the title Modernize scripts in bin/ (not done!) Modernize scripts in bin/ Nov 17, 2023
@hmpf
Copy link
Contributor Author

hmpf commented Nov 17, 2023

This had to be too easy. What did I miss?

@hmpf hmpf marked this pull request as ready for review November 17, 2023 12:29
@hmpf hmpf self-assigned this Nov 20, 2023
Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

As you write, this seemed too easy. There's still some work left, but it's beautiful so far :-)

Yes, moving the scripts is easy, but finding all the references to them, and tests for them is more difficult. In particular, you have some failing tests that look for the binaries under their old names (not the generated tests).

We don't have proper tests that test for consistency when it comes to cron jobs, for example. See all crontab snippets in this directory:

https://github.com/Uninett/nav/tree/d0f3a5bf9c34dec29c6d67da6c8004e28b332f1d/python/nav/etc/cron.d

Also see daemon config in this file:

https://github.com/Uninett/nav/blob/d0f3a5bf9c34dec29c6d67da6c8004e28b332f1d/python/nav/etc/daemons.yml

An extensive search in the codebase for any of the script names that originally ended in .py would be wise.

python/nav/bin/sortedstats_cacher.py Outdated Show resolved Hide resolved
@hmpf
Copy link
Contributor Author

hmpf commented Nov 20, 2023

Tests for bin/pping.py and bin/smsd updated. main() made importable in bin/ipdevpolld.

Cron-files and daemon.yml updated.

After running ag '\W\w+\.py\W' --ignore "*.js" in order to find all references to py-files, i only found such references to bin-scripts in docstrings and comments. Changed those as well, in their own commit.

@hmpf hmpf requested a review from lunkwill42 November 20, 2023 11:45
@hmpf hmpf force-pushed the modernize-scripts branch from 9588f5a to 983bf4d Compare November 20, 2023 13:39
@lunkwill42 lunkwill42 closed this Nov 20, 2023
@lunkwill42 lunkwill42 reopened this Nov 20, 2023
@lunkwill42 lunkwill42 changed the base branch from master to 5.7.x November 21, 2023 07:34
@lunkwill42 lunkwill42 changed the base branch from 5.7.x to master November 21, 2023 07:34
@hmpf hmpf force-pushed the modernize-scripts branch 2 times, most recently from 0db1c96 to ba8d9ee Compare November 21, 2023 11:14
Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

Can't put my finger on anything but the failing tests for now. Sudo issues, I assume.

Get the tests running, and I'll approve :)

@hmpf hmpf force-pushed the modernize-scripts branch 3 times, most recently from 8e9e806 to ba05910 Compare November 21, 2023 12:57
@hmpf
Copy link
Contributor Author

hmpf commented Nov 22, 2023

The tests are all green when running locally with the test docker setup. I can't seem to make them green on gihub.

What is currently happening is that each script is executed in situ, with hardcoded paths to ./python/nav/bin. It might be that a better solution is testing them in their installed position or via the fact that they are entrypoints in pyproject.toml. Maybe via something like https://github.com/kvas-it/pytest-console-scripts.

@hmpf hmpf marked this pull request as draft November 22, 2023 07:37
@hmpf
Copy link
Contributor Author

hmpf commented Nov 22, 2023

@hmpf hmpf force-pushed the modernize-scripts branch from 6b0b038 to a708cad Compare January 3, 2024 10:58
@hmpf hmpf force-pushed the modernize-scripts branch 2 times, most recently from 26cddf9 to e8be647 Compare February 20, 2024 11:29
@lunkwill42
Copy link
Member

I was able to reproduce the GitHub issue locally by adding sudo to the tests/docker/Dockerfile image. But then, by looking at what actually changed in this PR, there is no big magic needed to get the tests to work. The installed pping executable is no longer named pping.py, it's named just pping. The only needed change is to remove the .py.

The failing tests are more or less designed to run the installed version of the executable, which is the only "sane" way to ensure sudo-to-root knows how to run it using the correct python interpreter and environment. As a nice "bonus", you also get to verify that the installation of the executable pping shim as defined in pyproject.toml works.

Copy link

codecov bot commented Feb 29, 2024

Codecov Report

Attention: Patch coverage is 81.63265% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 56.69%. Comparing base (3c4f8bd) to head (49f747f).

❗ Current head 49f747f differs from pull request most recent head 300d891. Consider uploading reports for the commit 300d891 to get more accurate results

Files Patch % Lines
python/nav/bin/radiusparser.py 0.00% 7 Missing ⚠️
python/nav/bin/collect_active_ip.py 90.00% 1 Missing ⚠️
python/nav/bin/servicemon.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2679      +/-   ##
==========================================
- Coverage   57.18%   56.69%   -0.49%     
==========================================
  Files         568      602      +34     
  Lines       41301    43971    +2670     
==========================================
+ Hits        23617    24931    +1314     
- Misses      17684    19040    +1356     

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

@hmpf hmpf force-pushed the modernize-scripts branch 2 times, most recently from 5e60889 to 5531f5a Compare March 1, 2024 12:15
@hmpf hmpf marked this pull request as ready for review March 1, 2024 12:18
@hmpf hmpf force-pushed the modernize-scripts branch 3 times, most recently from 6afb01d to 2e6abf5 Compare March 4, 2024 12:48
Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

Looks good to me! Glad to get it done!

My last addition is an entry to the release notes, as this change may require action from users on an upgrade.

hmpf and others added 13 commits March 7, 2024 10:03
Not all scripts had a sufficiently pure main()-function.

Also, remove bindir-magic from setup.py.
This makes it possible for all the other scripts to find nav itself.
It will still be installed in a bin-dir as "nav".
All scripts installed via entrypoints needs to have an importable
callable. This script lacked that.
This makes sudo available in the Docker-based test environment, in order
to make the environment slightly more similar to GitHub Actions (which
doesn't feature gosu).  With sudo it is easier to locally reproduce
sudo-related problems observed on GitHub actions.
@hmpf hmpf force-pushed the modernize-scripts branch from 31d4805 to 7dbda65 Compare March 7, 2024 09:03
@hmpf hmpf merged commit f92920c into Uninett:master Mar 7, 2024
8 checks passed
@hmpf hmpf deleted the modernize-scripts branch March 7, 2024 09:37
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.

Move script installation from setuptools/setup.py to pyproject.toml
3 participants