Merge "Add options to apt-get install call"

This commit is contained in:
Zuul 2018-11-15 23:09:50 +00:00 committed by Gerrit Code Review
commit 9c2ca30001
3 changed files with 46 additions and 3 deletions

View File

@ -59,9 +59,25 @@ load_package_list_with_versions $(dpkg -l | awk 'NR>5 {print $2"="$3}')
{{- if hasKey .Values.conf "apt" }}
{{- if hasKey .Values.conf.apt "packages" }}
apt-get update
# Set all debconf selections up front
{{- range .Values.conf.apt.packages }}
if [[ "${CURRENT_PACKAGES[{{ .name | squote }}]+isset}" != "isset"{{- if .version }} || "${CURRENT_PACKAGES[{{ .name | squote }}]}" != {{ .version | squote }}{{- end }} ]]; then
apt-get install -y{{ if .repo }} -t {{ .repo | squote }}{{ end }} {{ .name | squote -}} {{- if .version }}={{ .version | squote }}{{ end }}
{{- $pkg_name := .name }}
{{- range .debconf }}
debconf-set-selections <<< "{{ $pkg_name }} {{ .question }} {{ .question_type }} {{ .answer }}"
{{- end }}
{{- end }}
# Run dpkg in case of interruption of previous dpkg operation
dpkg --configure -a
# Perform package installs
{{- range .Values.conf.apt.packages }}
{{- $pkg_name := .name }}
if [[ "${CURRENT_PACKAGES[{{ .name | squote }}]+isset}" != "isset"{{- if .version }} || "${CURRENT_PACKAGES[{{ .name | squote }}]}" != {{ .version }}{{- end }} ]]; then
# Run this in case some package installation was interrupted
DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold{{- if .repo }} -t {{ .repo }}{{ end }} {{ .name -}} {{- if .version }}={{ .version }}{{ end }}
INSTALLED_THIS_TIME="$INSTALLED_THIS_TIME {{ .name }}"
fi
REQUESTED_PACKAGES="$REQUESTED_PACKAGES {{ .name }}"
@ -80,6 +96,7 @@ if [ -f ${persist_path}/packages ]; then
TO_DELETE=$(comm -23 ${persist_path}/packages ${persist_path}/packages.requested)
TO_KEEP=$(echo "$TO_DELETE" | comm -23 ${persist_path}/packages -)
if [ ! -z "$TO_DELETE" ]; then
dpkg --configure -a
for pkg in "$TO_DELETE"; do
apt-get purge -y $pkg
done
@ -102,6 +119,7 @@ fi
######################################################
{{- if hasKey .Values.conf.apt "blacklistpkgs" }}
dpkg --configure -a
{{- range .Values.conf.apt.blacklistpkgs }}
{{- $package := . }}
apt-get remove --autoremove -y {{ $package | squote }}

View File

@ -158,6 +158,18 @@ Here is an example configuration for it::
version: <VERSION1>
- name: <PACKAGE2>
It is also possible to provide debconf settings for packages the following
way::
conf:
apt:
packages:
- name: openssh-server
debconf:
- question: openssh-server/permit-root-login
question_type: boolean
answer: false
Operations
----------

View File

@ -49,7 +49,7 @@ USERNAME4=userfour
USERNAME4_SUDO=false
APT_PACKAGE1=python-pbr
APT_VERSION1=1.8.0-4ubuntu1
APT_PACKAGE2=python-yaml
APT_PACKAGE2=mysql-server
APT_PACKAGE3=python-simplejson
APT_VERSION3=3.8.1-1ubuntu2
APT_PACKAGE4=less
@ -804,12 +804,25 @@ test_apt(){
apt:
packages:
- name: $APT_PACKAGE2
debconf:
- question: mysql-server/root_password
question_type: password
answer: rootpw
- question: mysql-server/root_password_again
question_type: password
answer: rootpw
- name: $APT_PACKAGE3
version: $APT_VERSION3" > "${overrides_yaml}"
install_base "--values=${overrides_yaml}"
get_container_status apt
_test_apt_package_version $APT_PACKAGE1 none
_test_apt_package_version $APT_PACKAGE2 any
# Each entry in passwords.dat contains question value in Name and Template
# field, so grepping root_password should return 4 lines
if [[ $(grep root_password /var/cache/debconf/passwords.dat | wc -l) != 4 ]]; then
echo "[FAIL] Package $APT_PACKAGE2 should have debconf values configured" >> "${TEST_RESULTS}"
return 1
fi
_test_apt_package_version $APT_PACKAGE3 $APT_VERSION3
echo '[SUCCESS] apt test2 passed successfully' >> "${TEST_RESULTS}"