Skip to content

Commit

Permalink
feat(pip): add python pip binary to images, with tests
Browse files Browse the repository at this point in the history
As discussed in the #formulas channel in slack
Renamed attributes -> inputs in inspec as the former are being deprecated
  • Loading branch information
javierbertoli committed Jun 27, 2019
1 parent 7abcacb commit bdf7525
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
7 changes: 5 additions & 2 deletions salt-testing-docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"provisioners": [
{
"type": "shell-local",
"command": "echo version: \"'{{user `salt_ver` }}'\" > /tmp/packer-salt-attributes.yml"
"inline": [
"echo salt_version: \"'{{user `salt_ver` }}'\" > /tmp/packer-inspec-inputs.yml",
"echo py_version: \"'{{user `py_ver` }}'\" >> /tmp/packer-inspec-inputs.yml"
]
},
{
"type": "file",
Expand Down Expand Up @@ -52,7 +55,7 @@
{
"type": "inspec",
"profile": "test/integration",
"attributes": "/tmp/packer-salt-attributes.yml"
"attributes": "/tmp/packer-inspec-inputs.yml"
}
],
"post-processors": [
Expand Down
36 changes: 28 additions & 8 deletions scripts/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ COMMON_PKGS="udev git net-tools sudo curl"
case ${OS} in
debian|ubuntu)
D_PKGS="${COMMON_PKGS} locales procps openssh-server lsb-release"
if [ "${PY_VER}" = "3" ]; then
D_PKGS="${D_PKGS} python3-pip"
else
D_PKGS="${D_PKGS} python-pip"
fi

apt-get update && apt-get install -y ${D_PKGS}
# Use @vutny's suggestion in https://github.com/saltstack-formulas/postgres-formula/pull/269#issuecomment-492597286
Expand All @@ -35,34 +40,49 @@ case ${OS} in
dpkg-reconfigure -f noninteractive locales
;;
centos)
C_PKGS="${COMMON_PKGS} openssh-server openssh-clients which"

if [ "${PY_VER}" = "3" ]; then
C_PKGS="${C_PKGS} epel-release"
fi
C_PKGS="${COMMON_PKGS} openssh-server openssh-clients which epel-release"

yum -y update && yum -y install ${C_PKGS}

if [ "${PY_VER}" = "3" ]; then
if [ "${SALT_VER}" = "develop" ]; then
PY_PKGS="python34 python34-pip python34-devel openssl-devel gcc-g++ zeromq zeromq-devel"
# The bootstrapper script only installs python3.4 packages
# and searches for python3 binary, which does not exist on the python3.4 package
# and searches for *3 binaries, which do not exist on the python3.4 packages
ln -s /usr/bin/python3.4 /usr/bin/python3
ln -s /usr/bin/pip3.4 /usr/bin/pip3
else
PY_PKGS="python36"
PY_PKGS="python36 python36-pip"
fi
else # py2
if [ "${OS_VER}" = "7" ]; then
PY_PKGS="python2-pip"
else # centos6
PY_PKGS="python-pip"
fi
yum -y update && yum -y install ${PY_PKGS}
fi
yum -y update && yum -y install ${PY_PKGS}
;;
fedora)
F_PKGS="${COMMON_PKGS} openssh-server openssh-clients which"

if [ "${PY_VER}" = "3" ]; then
F_PKGS="${F_PKGS} python3-pip"
else
F_PKGS="${F_PKGS} python2-pip"
fi

dnf -y update && dnf -y install ${F_PKGS}
;;
opensuse*)
O_PKGS="${COMMON_PKGS} glibc-locale net-tools openssh which"

if [ "${PY_VER}" = "3" ]; then
O_PKGS="${O_PKGS} python3-pip"
else
O_PKGS="${O_PKGS} python-pip"
fi

if [ "${OS_VER}" = "15" ]; then
O_PKGS="${O_PKGS} net-tools-deprecated python-xml"
fi
Expand Down
11 changes: 11 additions & 0 deletions test/integration/controls/python.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version = input('py_version') == '3' ? '3' : ''

control 'python and python tools' do
title 'should match the desired version'

[ "python#{version}", "pip#{version}"].each do |c|
describe command(c) do
it { should exist }
end
end
end
2 changes: 1 addition & 1 deletion test/integration/controls/salt_pkgs.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = attribute('version') == 'develop' ? 'Fluorine' : attribute('version')
version = input('salt_version') == 'develop' ? 'Fluorine' : input('salt_version')

control 'salt call' do
title 'should be installed'
Expand Down
7 changes: 5 additions & 2 deletions test/integration/inspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ copyright_email: javier@netmanagers.com.ar
license: Apache-2.0
summary: Verify that the salt-{minion,call,solo} is pre-installed
version: 0.1.0
attributes:
- name: version
inputs:
- name: salt_version
type: string
required: true
- name: py_version
type: string
required: true

Expand Down

0 comments on commit bdf7525

Please sign in to comment.