Skip to content

Fix bootstrapping python::pyvenv when Python is not installed #716

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

Merged
merged 2 commits into from
Apr 28, 2025

Conversation

smortex
Copy link
Member

@smortex smortex commented Apr 24, 2025

When python is not installed, a catalog with a python::pyvenv resource should compile and apply successfully.

Instead it currently cause a catalog compilation error:

   Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, The function 'split' was called with arguments it does not accept. It expects one of:
    (String str, String pattern)
      rejected: parameter 'str' expects a String value, got Undef
    (String str, Regexp pattern)
      rejected: parameter 'str' expects a String value, got Undef
    (String str, Type[Regexp] pattern)
      rejected: parameter 'str' expects a String value, got Undef
    (Sensitive[String] sensitive, String pattern)
      rejected: parameter 'sensitive' expects a Sensitive[String] value, got Undef
    (Sensitive[String] sensitive, Regexp pattern)
      rejected: parameter 'sensitive' expects a Sensitive[String] value, got Undef
    (Sensitive[String] sensitive, Type[Regexp] pattern)
      rejected: parameter 'sensitive' expects a Sensitive[String] value, got Undef (file: /etc/puppetlabs/code/environments/production/modules/python/manifests/pyvenv.pp, line: 48, column: 34) (file: /etc/puppetlabs/code/environments/production/modules/taiga/manifests/back/install.pp, line: 15) on node debian12-64-puppet7.example.com

@smortex smortex changed the title Add a unit test to illustrate the pyvenv bootstrap issue Fix bootstrapping pyvenv when python is not installed Apr 24, 2025
This module that manage python needs python to be installed in order to
work properly under certain conditions.

When python is not installed on a node, the python_version fact does not
have a value.  When using `python::pyvenv` on such a system without a
specific version set, a call of the split() function on this unde value
cause an error te be raised:

```
   Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, The function 'split' was called with arguments it does not accept. It expects one of:
    (String str, String pattern)
      rejected: parameter 'str' expects a String value, got Undef
    (String str, Regexp pattern)
      rejected: parameter 'str' expects a String value, got Undef
    (String str, Type[Regexp] pattern)
      rejected: parameter 'str' expects a String value, got Undef
    (Sensitive[String] sensitive, String pattern)
      rejected: parameter 'sensitive' expects a Sensitive[String] value, got Undef
    (Sensitive[String] sensitive, Regexp pattern)
      rejected: parameter 'sensitive' expects a Sensitive[String] value, got Undef
    (Sensitive[String] sensitive, Type[Regexp] pattern)
      rejected: parameter 'sensitive' expects a Sensitive[String] value, got Undef (file: /etc/puppetlabs/code/environments/production/modules/python/manifests/pyvenv.pp, line: 48, column: 34) (file: /etc/puppetlabs/code/environments/production/modules/taiga/manifests/back/install.pp, line: 15) on node debian12-64-puppet7.example.com
```
@smortex smortex force-pushed the fix-pyvenv-bootstraping branch from e117ac1 to 81daea2 Compare April 24, 2025 21:20
When Python is not installed, the python_version fact is undef, but we
need to know which version of Python is going to be installed by the
module in order to use the proper command invocation for building
virtual envs.

This issue only occurs when the user use the system version of Python,
so add the default version of Python for supported operating systems
into Hiera and use that as a fallback when the version of Python is
unknown.
@@ -0,0 +1 @@
python::default_system_version: "3.11"
Copy link
Member Author

Choose a reason for hiding this comment

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

For the common file, the choice of 3.11 was arbitrary. We really only want a default for systems missing in Hiera data (e.g. operating systems not listed as supported). For example the test suite mocks Debian 6, and we do not want to add support for this in Hiera 🙃

@smortex smortex added the bug Something isn't working label Apr 24, 2025
@smortex smortex changed the title Fix bootstrapping pyvenv when python is not installed Fix bootstrapping python::pyvenv when Python is not installed Apr 24, 2025
@smortex
Copy link
Member Author

smortex commented Apr 24, 2025

This fix the issue I am facing:

https://github.com/opus-codium/puppet-taiga/actions/runs/14652911906?pr=78

Ready for review!

@smortex smortex marked this pull request as ready for review April 24, 2025 22:44
Copy link
Member

@kenyon kenyon left a comment

Choose a reason for hiding this comment

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

Nice, this reminds me of what I was talking about in voxpupuli/puppet-puppetboard#403. We have essentially duplicated your system-version work here in the puppetboard hiera data: https://github.com/voxpupuli/puppet-puppetboard/tree/88d2e9a038ae9da14344d422397f6708df2ba9b4/data/os

@smortex
Copy link
Member Author

smortex commented Apr 25, 2025

Nice, this reminds me of what I was talking about in voxpupuli/puppet-puppetboard#403. We have essentially duplicated your system-version work here in the puppetboard hiera data: voxpupuli/puppet-puppetboard@88d2e9a/data/os

Interesting.

  1. It allows to compare versions and I only see a difference for RedHat 8 (3.6 vs 3.8). I found 3.6 here but maybe it was updated in later 8.x RedHat versions? It looks like 3.6 is the last version where the module behavior change, so the impact should be negligible I think 🤷.
  2. If I understand correctly, this should allow to simplify the puppet-puppetboard module when this is merged, right?

@kenyon
Copy link
Member

kenyon commented Apr 25, 2025

Yes, seems like modules using python, like puppet-puppetboard, should be able to depend on the default system Python version provided by puppet-python.

Not sure about the RHEL 8 Python 3 version.

@smortex
Copy link
Member Author

smortex commented Apr 28, 2025

Fine, let's merge this, make a new release and allow to simplify consumer ports!

@smortex smortex merged commit 1ee9a64 into master Apr 28, 2025
28 checks passed
@smortex smortex deleted the fix-pyvenv-bootstraping branch April 28, 2025 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants