Browse Source

Add options to apt-get install call

This change also adds an apt-get update call and a possibility to
provide debconf options that might be needed for some packages.
In case of dpkg interruptions dpkg --configure -a is added to
try to handle the failures.

Change-Id: Ib1f9a412bc544b4f7754634740fb04569bae6d34
Vladyslav Drok 5 months ago
parent
commit
da532c32aa

+ 20
- 2
divingbell/templates/bin/_apt.sh.tpl View File

@@ -59,9 +59,25 @@ load_package_list_with_versions $(dpkg -l | awk 'NR>5 {print $2"="$3}')
59 59
 
60 60
 {{- if hasKey .Values.conf "apt" }}
61 61
 {{- if hasKey .Values.conf.apt "packages" }}
62
+apt-get update
63
+
64
+# Set all debconf selections up front
65
+{{- range .Values.conf.apt.packages }}
66
+{{- $pkg_name := .name }}
67
+{{- range .debconf }}
68
+    debconf-set-selections <<< "{{ $pkg_name }} {{ .question }} {{ .question_type }} {{ .answer }}"
69
+{{- end }}
70
+{{- end }}
71
+
72
+# Run dpkg in case of interruption of previous dpkg operation
73
+dpkg --configure -a
74
+
75
+# Perform package installs
62 76
 {{- range .Values.conf.apt.packages }}
63
-if [[ "${CURRENT_PACKAGES[{{ .name | squote }}]+isset}" != "isset"{{- if .version }} || "${CURRENT_PACKAGES[{{ .name | squote }}]}" != {{ .version | squote }}{{- end }} ]]; then
64
-    apt-get install -y{{ if .repo }} -t {{ .repo | squote }}{{ end }} {{ .name | squote -}} {{- if .version }}={{ .version | squote }}{{ end }}
77
+{{- $pkg_name := .name }}
78
+if [[ "${CURRENT_PACKAGES[{{ .name | squote }}]+isset}" != "isset"{{- if .version }} || "${CURRENT_PACKAGES[{{ .name | squote }}]}" != {{ .version }}{{- end }} ]]; then
79
+    # Run this in case some package installation was interrupted
80
+    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 }}
65 81
     INSTALLED_THIS_TIME="$INSTALLED_THIS_TIME {{ .name }}"
66 82
 fi
67 83
 REQUESTED_PACKAGES="$REQUESTED_PACKAGES {{ .name }}"
@@ -80,6 +96,7 @@ if [ -f ${persist_path}/packages ]; then
80 96
     TO_DELETE=$(comm -23 ${persist_path}/packages ${persist_path}/packages.requested)
81 97
     TO_KEEP=$(echo "$TO_DELETE" | comm -23 ${persist_path}/packages -)
82 98
     if [ ! -z "$TO_DELETE" ]; then
99
+        dpkg --configure -a
83 100
         for pkg in "$TO_DELETE"; do
84 101
             apt-get purge -y $pkg
85 102
         done
@@ -102,6 +119,7 @@ fi
102 119
 ######################################################
103 120
 
104 121
 {{- if hasKey .Values.conf.apt "blacklistpkgs" }}
122
+dpkg --configure -a
105 123
 {{- range .Values.conf.apt.blacklistpkgs }}
106 124
   {{- $package := . }}
107 125
   apt-get remove --autoremove -y {{ $package | squote }}

+ 12
- 0
doc/source/index.rst View File

@@ -158,6 +158,18 @@ Here is an example configuration for it::
158 158
           version: <VERSION1>
159 159
         - name: <PACKAGE2>
160 160
 
161
+It is also possible to provide debconf settings for packages the following
162
+way::
163
+
164
+    conf:
165
+      apt:
166
+        packages:
167
+        - name: openssh-server
168
+          debconf:
169
+          - question: openssh-server/permit-root-login
170
+            question_type: boolean
171
+            answer: false
172
+
161 173
 Operations
162 174
 ----------
163 175
 

+ 14
- 1
tools/gate/scripts/020-test-divingbell.sh View File

@@ -49,7 +49,7 @@ USERNAME4=userfour
49 49
 USERNAME4_SUDO=false
50 50
 APT_PACKAGE1=python-pbr
51 51
 APT_VERSION1=1.8.0-4ubuntu1
52
-APT_PACKAGE2=python-yaml
52
+APT_PACKAGE2=mysql-server
53 53
 APT_PACKAGE3=python-simplejson
54 54
 APT_VERSION3=3.8.1-1ubuntu2
55 55
 APT_PACKAGE4=less
@@ -804,12 +804,25 @@ test_apt(){
804 804
   apt:
805 805
     packages:
806 806
     - name: $APT_PACKAGE2
807
+      debconf:
808
+      - question: mysql-server/root_password
809
+        question_type: password
810
+        answer: rootpw
811
+      - question: mysql-server/root_password_again
812
+        question_type: password
813
+        answer: rootpw
807 814
     - name: $APT_PACKAGE3
808 815
       version: $APT_VERSION3" > "${overrides_yaml}"
809 816
   install_base "--values=${overrides_yaml}"
810 817
   get_container_status apt
811 818
   _test_apt_package_version $APT_PACKAGE1 none
812 819
   _test_apt_package_version $APT_PACKAGE2 any
820
+  # Each entry in passwords.dat contains question value in Name and Template
821
+  # field, so grepping root_password should return 4 lines
822
+  if [[ $(grep root_password /var/cache/debconf/passwords.dat | wc -l) != 4 ]]; then
823
+    echo "[FAIL] Package $APT_PACKAGE2 should have debconf values configured" >> "${TEST_RESULTS}"
824
+    return 1
825
+  fi
813 826
   _test_apt_package_version $APT_PACKAGE3 $APT_VERSION3
814 827
   echo '[SUCCESS] apt test2 passed successfully' >> "${TEST_RESULTS}"
815 828
 

Loading…
Cancel
Save