From bdf752546be1b21e58d3870826d9fb430a7e42be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20B=C3=A9rtoli?= Date: Thu, 27 Jun 2019 17:43:55 -0300 Subject: [PATCH] feat(pip): add python pip binary to images, with tests As discussed in the #formulas channel in slack Renamed attributes -> inputs in inspec as the former are being deprecated --- salt-testing-docker.json | 7 +++-- scripts/prepare.sh | 36 ++++++++++++++++++++------ test/integration/controls/python.rb | 11 ++++++++ test/integration/controls/salt_pkgs.rb | 2 +- test/integration/inspec.yml | 7 +++-- 5 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 test/integration/controls/python.rb diff --git a/salt-testing-docker.json b/salt-testing-docker.json index a828dbd..c5dc773 100644 --- a/salt-testing-docker.json +++ b/salt-testing-docker.json @@ -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", @@ -52,7 +55,7 @@ { "type": "inspec", "profile": "test/integration", - "attributes": "/tmp/packer-salt-attributes.yml" + "attributes": "/tmp/packer-inspec-inputs.yml" } ], "post-processors": [ diff --git a/scripts/prepare.sh b/scripts/prepare.sh index fc028a0..a6af597 100755 --- a/scripts/prepare.sh +++ b/scripts/prepare.sh @@ -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 @@ -35,11 +40,7 @@ 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} @@ -47,22 +48,41 @@ case ${OS} in 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 diff --git a/test/integration/controls/python.rb b/test/integration/controls/python.rb new file mode 100644 index 0000000..bb5f183 --- /dev/null +++ b/test/integration/controls/python.rb @@ -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 diff --git a/test/integration/controls/salt_pkgs.rb b/test/integration/controls/salt_pkgs.rb index 554ed37..80aec66 100644 --- a/test/integration/controls/salt_pkgs.rb +++ b/test/integration/controls/salt_pkgs.rb @@ -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' diff --git a/test/integration/inspec.yml b/test/integration/inspec.yml index 120aa97..762b78d 100644 --- a/test/integration/inspec.yml +++ b/test/integration/inspec.yml @@ -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