Skip to content

Commit 6efd825

Browse files
committed
Create osl_python resource
This migrates and replaces what used to be in base::python. Signed-off-by: Lance Albertson <[email protected]>
1 parent 5270037 commit 6efd825

File tree

8 files changed

+151
-0
lines changed

8 files changed

+151
-0
lines changed

Berksfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ source 'https://supermarket.chef.io'
22

33
solver :ruby, :required
44

5+
cookbook 'osl-repos', git: '[email protected]:osuosl-cookbooks/osl-repos'
56
cookbook 'osl-resources-test', path: 'test/fixtures/cookbooks/osl-resources-test'
67

78
metadata

kitchen.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ suites:
4343
- name: osl_packagecloud_repo
4444
run_list:
4545
- recipe[osl-resources-test::osl_packagecloud_repo]
46+
- name: osl_python
47+
run_list:
48+
- recipe[osl-resources-test::osl_python]
4649
- name: osl_route
4750
excludes:
4851
- debian-11

libraries/helpers.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,56 @@ def osl_local_ipv6?
7878
local
7979
end
8080

81+
def osl_python_packages
82+
case node['platform_family']
83+
when 'rhel'
84+
case node['platform_version'].to_i
85+
when 8
86+
%w(
87+
python2
88+
python2-devel
89+
python2-pip
90+
python2-setuptools
91+
python2-virtualenv
92+
python3-pip
93+
python3-setuptools
94+
python3-virtualenv
95+
python36
96+
python36-devel
97+
)
98+
when 7
99+
%w(
100+
python
101+
python2-pip
102+
python3
103+
python3-devel
104+
python3-pip
105+
python3-setuptools
106+
python-devel
107+
python-setuptools
108+
python-virtualenv
109+
)
110+
end
111+
when 'debian'
112+
case node['platform_version'].to_i
113+
when 11
114+
%w(
115+
python3
116+
python3-dev
117+
python3-pip
118+
python3-setuptools
119+
python3-virtualenv
120+
python3-wheel
121+
python2-dev
122+
python-pip-whl
123+
python-setuptools
124+
virtualenv
125+
python-wheel-common
126+
)
127+
end
128+
end
129+
end
130+
81131
private
82132

83133
def osl_local_ip

metadata.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
version '1.2.4'
1010

1111
depends 'line'
12+
depends 'osl-repos'
1213

1314
supports 'centos', '~> 7.0'
1415
supports 'centos_stream', '~> 8.0'

resources/osl_python.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
resource_name :osl_python
2+
provides :osl_python
3+
unified_mode true
4+
5+
default_action :install
6+
7+
action :install do
8+
if platform_family?('rhel') && node['platform_version'].to_i < 8
9+
include_recipe 'osl-repos::epel'
10+
end
11+
12+
package 'install python packages' do
13+
package_name osl_python_packages
14+
end
15+
16+
# Debian 11 does not ship with pip2
17+
if platform_family?('debian')
18+
get_pip = ::File.join(Chef::Config[:file_cache_path], 'get-pip.py')
19+
20+
remote_file get_pip do
21+
source 'https://bootstrap.pypa.io/pip/2.7/get-pip.py'
22+
not_if { ::File.exist?('/usr/local/bin/pip2') }
23+
end
24+
25+
execute "python2 #{get_pip}" do
26+
creates '/usr/local/bin/pip2'
27+
end
28+
29+
link '/usr/bin/pip2' do
30+
to '/usr/local/bin/pip2'
31+
end
32+
end
33+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
osl_python 'default'
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
control 'osl_python' do
2+
title 'Verify python is configured'
3+
4+
os_family = os.family
5+
os_release = os.release.to_i
6+
7+
case os_family
8+
when 'redhat'
9+
case os_release
10+
when 8
11+
packages = %w(
12+
python2
13+
python2-devel
14+
python2-pip
15+
python2-setuptools
16+
python2-virtualenv
17+
python3-pip
18+
python3-setuptools
19+
python3-virtualenv
20+
python36
21+
python36-devel
22+
)
23+
when 7
24+
packages = %w(
25+
python
26+
python2-pip
27+
python3
28+
python3-devel
29+
python3-pip
30+
python3-setuptools
31+
python-devel
32+
python-setuptools
33+
python-virtualenv
34+
)
35+
end
36+
when 'debian'
37+
case os_release
38+
when 11
39+
packages = %w(
40+
python3
41+
python3-dev
42+
python3-pip
43+
python3-setuptools
44+
python3-virtualenv
45+
python3-wheel
46+
python2-dev
47+
python-pip-whl
48+
python-setuptools
49+
virtualenv
50+
python-wheel-common
51+
)
52+
end
53+
end
54+
55+
packages.each do |pkg|
56+
describe package pkg do
57+
it { should be_installed }
58+
end
59+
end
60+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
name: osl_python

0 commit comments

Comments
 (0)