Skip to content

Prefer Hiera data to params.pp #652

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions REFERENCE.md
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@

* `python::config`: Optionally installs the gunicorn service
* `python::install`: Installs core python packages
* `python::params`: The python Module default configuration settings.

### Defined types

@@ -81,8 +80,8 @@ The following parameters are available in the `python` class:
* [`manage_python_package`](#-python--manage_python_package)
* [`manage_venv_package`](#-python--manage_venv_package)
* [`manage_pip_package`](#-python--manage_pip_package)
* [`venv`](#-python--venv)
* [`gunicorn_package_name`](#-python--gunicorn_package_name)
* [`venv`](#-python--venv)
* [`python_pips`](#-python--python_pips)
* [`python_pyvenvs`](#-python--python_pyvenvs)
* [`python_requirements`](#-python--python_requirements)
@@ -112,8 +111,6 @@ Allowed values:
- 3/3.3/... means you are going to install the python3/python3.3/...
package, if available on your osfamily.

Default value: `$facts['os']['family'] ? { 'Archlinux' => 'system', default => '3'`

##### <a name="-python--pip"></a>`pip`

Data type: `Python::Package::Ensure`
@@ -160,8 +157,6 @@ Data type: `Boolean`

to determine if the epel class is used.

Default value: `$python::params::use_epel`

##### <a name="-python--manage_scl"></a>`manage_scl`

Data type: `Boolean`
@@ -198,31 +193,25 @@ Data type: `Boolean`

manage the state for package venv

Default value: `$python::params::manage_venv_package`

##### <a name="-python--manage_pip_package"></a>`manage_pip_package`

Data type: `Boolean`

manage the state for package pip

Default value: `$python::params::manage_pip_package`

##### <a name="-python--venv"></a>`venv`

Data type: `Python::Package::Ensure`
##### <a name="-python--gunicorn_package_name"></a>`gunicorn_package_name`

Data type: `String[1]`


Default value: `'absent'`

##### <a name="-python--gunicorn_package_name"></a>`gunicorn_package_name`
##### <a name="-python--venv"></a>`venv`

Data type: `String[1]`
Data type: `Python::Package::Ensure`



Default value: `$python::params::gunicorn_package_name`
Default value: `'absent'`

##### <a name="-python--python_pips"></a>`python_pips`

@@ -301,6 +290,7 @@ The following parameters are available in the `python::pip::bootstrap` class:
* [`version`](#-python--pip--bootstrap--version)
* [`manage_python`](#-python--pip--bootstrap--manage_python)
* [`http_proxy`](#-python--pip--bootstrap--http_proxy)
* [`pip_lookup_path`](#-python--pip--bootstrap--pip_lookup_path)
* [`exec_provider`](#-python--pip--bootstrap--exec_provider)

##### <a name="-python--pip--bootstrap--version"></a>`version`
@@ -327,6 +317,12 @@ Proxy server to use for outbound connections.

Default value: `undef`

##### <a name="-python--pip--bootstrap--pip_lookup_path"></a>`pip_lookup_path`

Data type: `Array[String[1]]`



##### <a name="-python--pip--bootstrap--exec_provider"></a>`exec_provider`

Data type: `String[1]`
@@ -753,11 +749,11 @@ Default value: `'root'`

##### <a name="-python--pip--group"></a>`group`

Data type: `Optional[String[1]]`
Data type: `String[1]`

The group of the virtualenv being manipulated.

Default value: `getvar('python::params::group')`
Default value: `lookup('python::pip::group')`

##### <a name="-python--pip--index"></a>`index`

11 changes: 11 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
python::version: '3'
Copy link
Member

Choose a reason for hiding this comment

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

can you please keep the data in the init.pp instead common.yaml? That enables puppet-strings to pick it up and document it in the REFERENCE.md.

Copy link
Member

Choose a reason for hiding this comment

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

at https://voxpupuli.org/docs/reviewing_pr/, we have:

Are hiera yaml files added for data-in-modules? Ensure that the data is compatible with hiera 5. Static data that is equal across every supported operating system must stay in the init.pp, it shouldn’t be moved to a common.yaml due to puppet-strings issue #250.

Copy link
Member Author

Choose a reason for hiding this comment

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

These parameters in common.yaml have overrides in other data/**/*.yaml and should be os-dependent. They where previously documented as:

Default value: `$python::params::<foo>`

this line is not shown anymore. If we put the value in init.pp instead of common.yaml, wrong default values would be documented for some operating systems.

python::use_epel: true
python::gunicorn_package_name: 'gunicorn'
python::manage_pip_package: true
python::manage_venv_package: true
python::pip::group: 'root'
Copy link
Member Author

Choose a reason for hiding this comment

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

Kudos to who can tell me what is wrong here: the default value is not catch by Automatic Parameter Lookup in spec/defines/pip_spec.rb. Setting an explicit value in the test suite or a default value in manifests/pip.pp for the $group parameter workaround the issue, but I don't get why it is not working as expected.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, setting values for sub-classes of python is unusual (and maybe not supported?) but I would like to avoid breaking backwards compatibility in this PR.

python::pip::bootstrap::pip_lookup_path:
- /bin
- /usr/bin
- /usr/local/bin
7 changes: 7 additions & 0 deletions data/os/AIX.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
python::pip::group: 'system'
python::pip::bootstrap::pip_lookup_path:
- /bin
- /usr/bin
- /usr/local/bin
- /opt/freeware/bin/
4 changes: 4 additions & 0 deletions data/os/Archlinux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
python::version: 'system'
python::manage_pip_package: false
python::manage_venv_package: false
3 changes: 3 additions & 0 deletions data/os/RedHat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
python::use_epel: true
python::gunicorn_package_name: 'python-gunicorn'
2 changes: 2 additions & 0 deletions data/os/RedHat/CentOS/8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
python::gunicorn_package_name: 'python3-gunicorn'
2 changes: 2 additions & 0 deletions data/os/RedHat/Fedora.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
python::use_epel: false
2 changes: 2 additions & 0 deletions data/os/RedHat/RedHat/8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
python::gunicorn_package_name: 'python3-gunicorn'
19 changes: 19 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
version: 5

defaults:
datadir: 'data'
data_hash: 'yaml_data'

hierarchy:
- name: 'family/name/major'
path: 'os/%{facts.os.family}/%{facts.os.name}/%{facts.os.release.major}.yaml'

- name: 'family/name'
path: 'os/%{facts.os.family}/%{facts.os.name}.yaml'

- name: 'family'
path: 'os/%{facts.os.family}.yaml'

- name: 'common'
path: 'common.yaml'
12 changes: 6 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -37,29 +37,29 @@
# }
#
class python (
Python::Version $version,
Boolean $manage_venv_package,
Boolean $manage_pip_package,
String[1] $gunicorn_package_name,
Boolean $use_epel,
Python::Package::Ensure $ensure = 'present',
Python::Version $version = $facts['os']['family'] ? { 'Archlinux' => 'system', default => '3' },
Python::Package::Ensure $pip = 'present',
Python::Package::Ensure $dev = 'absent',
Python::Package::Ensure $venv = 'absent',
Python::Package::Ensure $gunicorn = 'absent',
Boolean $manage_gunicorn = true,
Boolean $manage_python_package = true,
Boolean $manage_venv_package = $python::params::manage_venv_package,
Boolean $manage_pip_package = $python::params::manage_pip_package,
String[1] $gunicorn_package_name = $python::params::gunicorn_package_name,
Optional[Python::Provider] $provider = undef,
Hash $python_pips = {},
Hash $python_pyvenvs = {},
Hash $python_requirements = {},
Hash $python_dotfiles = {},
Boolean $use_epel = $python::params::use_epel,
Boolean $rhscl_use_public_repository = true,
Stdlib::Httpurl $anaconda_installer_url = 'https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh',
Stdlib::Absolutepath $anaconda_install_path = '/opt/python',
Boolean $manage_scl = true,
Optional[Python::Umask] $umask = undef,
) inherits python::params {
) {
$exec_prefix = $provider ? {
'scl' => "/usr/bin/scl enable ${version} -- ",
'rhscl' => "/usr/bin/scl enable ${version} -- ",
44 changes: 0 additions & 44 deletions manifests/params.pp

This file was deleted.

2 changes: 1 addition & 1 deletion manifests/pip.pp
Original file line number Diff line number Diff line change
@@ -49,13 +49,13 @@
# }
#
define python::pip (
String[1] $group = lookup('python::pip::group'), # lint:ignore:lookup_in_parameter
String[1] $pkgname = $name,
Variant[Enum[present, absent, latest], String[1]] $ensure = present,
Variant[Enum['system'], Stdlib::Absolutepath] $virtualenv = 'system',
String[1] $pip_provider = 'pip',
Variant[Boolean, String] $url = false,
String[1] $owner = 'root',
Optional[String[1]] $group = getvar('python::params::group'),
Optional[Python::Umask] $umask = undef,
Variant[Boolean,String[1]] $index = false,
Variant[Boolean,String[1]] $extra_index = false,
7 changes: 4 additions & 3 deletions manifests/pip/bootstrap.pp
Original file line number Diff line number Diff line change
@@ -10,11 +10,12 @@
# }
#
class python::pip::bootstrap (
Array[String[1]] $pip_lookup_path,
Enum['pip', 'pip3'] $version = 'pip',
Variant[Boolean, String] $manage_python = false,
Optional[Stdlib::HTTPUrl] $http_proxy = undef,
String[1] $exec_provider = 'shell',
) inherits python::params {
) {
if $manage_python {
include python
} else {
@@ -36,7 +37,7 @@
command => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python3',
environment => $environ,
unless => 'which pip3',
path => $python::params::pip_lookup_path,
path => $pip_lookup_path,
require => Package['python3'],
provider => $exec_provider,
}
@@ -53,7 +54,7 @@
command => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python',
environment => $environ,
unless => 'which pip',
path => $python::params::pip_lookup_path,
path => $pip_lookup_path,
require => Package['python'],
provider => $exec_provider,
}
1 change: 0 additions & 1 deletion spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
context 'with defaults' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('python::install') }
it { is_expected.to contain_class('python::params') }
it { is_expected.to contain_class('python::config') }
it { is_expected.to contain_package('python') }

3 changes: 0 additions & 3 deletions spec/default_module_facts.yml

This file was deleted.

1 change: 0 additions & 1 deletion spec/defines/requirements_spec.rb
Original file line number Diff line number Diff line change
@@ -47,7 +47,6 @@
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('python::config') }
it { is_expected.to contain_class('python::install') }
it { is_expected.to contain_class('python::params') }
it { is_expected.to contain_class('python') }
it { is_expected.to contain_exec('python_requirements/requirements.txt') }

6 changes: 0 additions & 6 deletions spec/spec.opts

This file was deleted.