maas: curtin: Fix generic kernel dep purge
[fuel.git] / mcp / patches / salt-formula-maas / 0006-curtin-Add-Bionic-support.patch
1 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2 : Copyright (c) 2019 Mirantis Inc., Enea AB and others.
3 :
4 : All rights reserved. This program and the accompanying materials
5 : are made available under the terms of the Apache License, Version 2.0
6 : which accompanies this distribution, and is available at
7 : http://www.apache.org/licenses/LICENSE-2.0
8 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
9 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
10 Date: Wed, 16 Oct 2019 15:02:39 +0200
11 Subject: [PATCH] curtin: Add Bionic support
12
13 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
14 ---
15  .../curtin_userdata_amd64_generic_bionic      | 83 +++++++++++++++++++
16  .../curtin_userdata_arm64_generic_bionic      | 78 +++++++++++++++++
17  maas/region.sls                               | 24 ++++++
18  3 files changed, 185 insertions(+)
19  create mode 100644 maas/files/curtin_userdata_amd64_generic_bionic
20  create mode 100644 maas/files/curtin_userdata_arm64_generic_bionic
21
22 diff --git a/maas/files/curtin_userdata_amd64_generic_bionic b/maas/files/curtin_userdata_amd64_generic_bionic
23 new file mode 100644
24 index 0000000..c28721a
25 --- /dev/null
26 +++ b/maas/files/curtin_userdata_amd64_generic_bionic
27 @@ -0,0 +1,83 @@
28 +{%- from "maas/map.jinja" import cluster with context %}
29 +{%- raw %}
30 +#cloud-config
31 +debconf_selections:
32 + maas: |
33 +  {{for line in str(curtin_preseed).splitlines()}}
34 +  {{line}}
35 +  {{endfor}}
36 +{{if third_party_drivers and driver}}
37 +early_commands:
38 +  {{py: key_string = ''.join(['\\x%x' % x for x in map(ord, driver['key_binary'])])}}
39 +  driver_00_get_key: /bin/echo -en '{{key_string}}' > /tmp/maas-{{driver['package']}}.gpg
40 +  driver_01_add_key: ["apt-key", "add", "/tmp/maas-{{driver['package']}}.gpg"]
41 +  driver_02_add: ["add-apt-repository", "-y", "deb {{driver['repository']}} {{node.get_distro_series()}} main"]
42 +  driver_03_update_install: ["sh", "-c", "apt-get update --quiet && apt-get --assume-yes install {{driver['package']}}"]
43 +  driver_04_load: ["sh", "-c", "depmod && modprobe {{driver['module']}}"]
44 +{{endif}}
45 +late_commands:
46 +  maas: [wget, '--no-proxy', {{node_disable_pxe_url|escape.json}}, '--post-data', {{node_disable_pxe_data|escape.json}}, '-O', '/dev/null']
47 +{% endraw %}
48 +
49 +{%- if cluster.get('saltstack_repo_key', False) %}
50 +  {% set salt_repo_key = salt['hashutil.base64_b64encode'](cluster.saltstack_repo_key) %}
51 +  apt_00_set_gpg: ["curtin", "in-target", "--", "sh", "-c", "echo '{{salt_repo_key}}' | base64 -d | apt-key add -"]
52 +{%- endif %}
53 +{% if cluster.saltstack_repo_bionic.startswith('deb') %}
54 +  {%- set saltstack_repo = cluster.saltstack_repo_bionic -%}
55 +{%- else %}
56 +  {%- set saltstack_repo = 'deb [arch=amd64] ' + cluster.saltstack_repo_bionic -%}
57 +{%- endif %}
58 +
59 +  apt_01_set_repo: ["curtin", "in-target", "--", "sh", "-c", "echo '{{ saltstack_repo }}' >> /etc/apt/sources.list.d/mcp_saltstack.list"]
60 +  apt_03_update: ["curtin", "in-target", "--", "apt-get", "update"]
61 +{%- if salt['pillar.get']('maas:cluster:curtin_vars:amd64:bionic:extra_pkgs:enabled')|default(false) %}
62 +  {% for pkg in pillar.maas.cluster.curtin_vars.amd64.bionic.extra_pkgs.pkgs -%}
63 +  apt_04_install_pkgs_{{ loop.index }}: ["curtin", "in-target", "--", "apt-get", "-y", "install", "{{ pkg }}"]
64 +  {% endfor %}
65 +{%- endif %}
66 +{%- if salt['pillar.get']('maas:cluster:curtin_vars:amd64:bionic:kernel_package:enabled')|default(false)  %}
67 +  apt_05_kernel_old_absent: ["curtin", "in-target", "--", "sh", "-c", "dpkg -l '*linux-generic-*[0-9]*' '*linux-image-*[0-9]*' '*linux-headers-*[0-9]*' '*linux-image-extra-*[0-9]*' '*linux-modules-extra-*[0-9]*' 'linux-generic' 'linux-image-generic' 'linux-headers-generic' 2>/dev/null | grep -E '^ii' | awk '{print $2}' | grep -v '{{ pillar.maas.cluster.curtin_vars.amd64.bionic.kernel_package.value.split('-')[2:-1] | join('-') }}' | xargs dpkg --purge --force-depends"]
68 +{%- endif %}
69 +  salt_01_install: ["curtin", "in-target", "--", "apt-get", "-y", "install", "salt-minion", "ifupdown", "cloud-init", "dnsmasq"]
70 +  salt_02_hostname_set: ["curtin", "in-target", "--", "echo", "{% raw %}{{node.hostname}}{% endraw %}.{{pillar.linux.system.domain}}"]
71 +  salt_03_hostname_get: ["curtin", "in-target", "--", "sh", "-c", "echo 'id: {% raw %}{{node.hostname}}{% endraw %}.{{pillar.linux.system.domain}}' >> /etc/salt/minion.d/minion.conf"]
72 +  salt_04_master: ["curtin", "in-target", "--", "sh", "-c", "echo 'master: {{ salt_master_ip }}' >> /etc/salt/minion.d/minion.conf"]
73 +  salt_05_max_event_size: ["curtin", "in-target", "--", "sh", "-c", "echo 'max_event_size: 100000000' >> /etc/salt/minion.d/minion.conf"]
74 +  salt_06_acceptance_wait_time_max: ["curtin", "in-target", "--", "sh", "-c", "echo 'acceptance_wait_time_max: 60' >> /etc/salt/minion.d/minion.conf"]
75 +  salt_07_acceptance_wait_time: ["curtin", "in-target", "--", "sh", "-c", "echo 'acceptance_wait_time: 10' >> /etc/salt/minion.d/minion.conf"]
76 +  salt_08_random_reauth_delay: ["curtin", "in-target", "--", "sh", "-c", "echo 'random_reauth_delay: 270' >> /etc/salt/minion.d/minion.conf"]
77 +  salt_09_recon_default: ["curtin", "in-target", "--", "sh", "-c", "echo 'recon_default: 1000' >> /etc/salt/minion.d/minion.conf"]
78 +  salt_10_recon_max: ["curtin", "in-target", "--", "sh", "-c", "echo 'recon_max: 60000' >> /etc/salt/minion.d/minion.conf"]
79 +  salt_11_recon_randomize: ["curtin", "in-target", "--", "sh", "-c", "echo 'recon_randomize: True' >> /etc/salt/minion.d/minion.conf"]
80 +  salt_12_auth_timeout: ["curtin", "in-target", "--", "sh", "-c", "echo 'auth_timeout: 60' >> /etc/salt/minion.d/minion.conf"]
81 +
82 +  salt_20_bionic_nplan_stop: ["curtin", "in-target", "--", "systemctl", "stop", "systemd-networkd.socket", "systemd-networkd", "networkd-dispatcher", "systemd-networkd-wait-online", "systemd-resolved"]
83 +  salt_21_bionic_nplan_disable: ["curtin", "in-target", "--", "systemctl", "disable", "systemd-networkd.socket", "systemd-networkd", "networkd-dispatcher", "systemd-networkd-wait-online", "systemd-resolved"]
84 +  salt_22_bionic_nplan_mask: ["curtin", "in-target", "--", "systemctl", "mask", "systemd-networkd.socket", "systemd-networkd", "networkd-dispatcher", "systemd-networkd-wait-online", "systemd-resolved"]
85 +  salt_23_bionic_nplan_purge: ["curtin", "in-target", "--", "apt", "--assume-yes", "purge", "nplan", "netplan.io"]
86 +  salt_24_bionic_interfaces: ["curtin", "in-target", "--", "sh", "-c", "echo 'source /etc/network/interfaces.d/*' >> /etc/network/interfaces"]
87 +  salt_25_bionic_networking_unmask: ["curtin", "in-target", "--", "systemctl", "unmask", "networking.service"]
88 +  salt_26_bionic_networking_enable: ["curtin", "in-target", "--", "systemctl", "enable", "networking.service"]
89 +  salt_27_bionic_networking_start: ["curtin", "in-target", "--", "systemctl", "start", "networking.service"]
90 +
91 +{%- if salt['pillar.get']('maas:cluster:curtin_vars:amd64:bionic:kernel_package:enabled')|default(false)  %}
92 +kernel:
93 +  package: {{ pillar.maas.cluster.curtin_vars.amd64.bionic.kernel_package.value }}
94 +{%- endif %}
95 +
96 +{% raw %}
97 +{{if third_party_drivers and driver}}
98 +  driver_00_key_get: curtin in-target -- sh -c "/bin/echo -en '{{key_string}}' > /tmp/maas-{{driver['package']}}.gpg"
99 +  driver_02_key_add: ["curtin", "in-target", "--", "apt-key", "add", "/tmp/maas-{{driver['package']}}.gpg"]
100 +  driver_03_add: ["curtin", "in-target", "--", "add-apt-repository", "-y", "deb {{driver['repository']}} {{node.get_distro_series()}} main"]
101 +  driver_04_update_install: ["curtin", "in-target", "--", "apt-get", "update", "--quiet"]
102 +  driver_05_install: ["curtin", "in-target", "--", "apt-get", "-y", "install", "{{driver['package']}}"]
103 +  driver_06_depmod: ["curtin", "in-target", "--", "depmod"]
104 +  driver_07_update_initramfs: ["curtin", "in-target", "--", "update-initramfs", "-u"]
105 +{{endif}}
106 +{% endraw %}
107 +
108 +{#
109 +# vim: ft=jinja
110 +#}
111 diff --git a/maas/files/curtin_userdata_arm64_generic_bionic b/maas/files/curtin_userdata_arm64_generic_bionic
112 new file mode 100644
113 index 0000000..d14388a
114 --- /dev/null
115 +++ b/maas/files/curtin_userdata_arm64_generic_bionic
116 @@ -0,0 +1,78 @@
117 +{%- from "maas/map.jinja" import cluster with context %}
118 +{% raw %}
119 +#cloud-config
120 +debconf_selections:
121 + maas: |
122 +  {{for line in str(curtin_preseed).splitlines()}}
123 +  {{line}}
124 +  {{endfor}}
125 +{{if third_party_drivers and driver}}
126 +early_commands:
127 +  {{py: key_string = ''.join(['\\x%x' % x for x in map(ord, driver['key_binary'])])}}
128 +  driver_00_get_key: /bin/echo -en '{{key_string}}' > /tmp/maas-{{driver['package']}}.gpg
129 +  driver_01_add_key: ["apt-key", "add", "/tmp/maas-{{driver['package']}}.gpg"]
130 +  driver_02_add: ["add-apt-repository", "-y", "deb {{driver['repository']}} {{node.get_distro_series()}} main"]
131 +  driver_03_update_install: ["sh", "-c", "apt-get update --quiet && apt-get --assume-yes install {{driver['package']}}"]
132 +  driver_04_load: ["sh", "-c", "depmod && modprobe {{driver['module']}}"]
133 +{{endif}}
134 +late_commands:
135 +  maas: [wget, '--no-proxy', {{node_disable_pxe_url|escape.json}}, '--post-data', {{node_disable_pxe_data|escape.json}}, '-O', '/dev/null']
136 +{% endraw %}
137 +{%- if cluster.get('saltstack_repo_key', False) %}
138 +  {% set salt_repo_key = salt['hashutil.base64_b64encode'](cluster.saltstack_repo_key) %}
139 +  apt_00_set_gpg: ["curtin", "in-target", "--", "sh", "-c", "echo '{{salt_repo_key}}' | base64 -d | apt-key add -"]
140 +{%- endif %}
141 +{% if cluster.saltstack_repo_bionic.startswith('deb') %}
142 +  {%- set saltstack_repo = cluster.saltstack_repo_bionic -%}
143 +{%- else %}
144 +  {%- set saltstack_repo = 'deb [arch=amd64] ' + cluster.saltstack_repo_bionic -%}
145 +{%- endif %}
146 +{#- NOTE: Re-use amd64 repos on arm64 since most packages are arch independent #}
147 +  apt_01_set_repo: ["curtin", "in-target", "--", "sh", "-c", "echo '{{ saltstack_repo }}' >> /etc/apt/sources.list.d/mcp_saltstack.list"]
148 +  apt_03_update: ["curtin", "in-target", "--", "apt-get", "update"]
149 +{%- if salt['pillar.get']('maas:cluster:curtin_vars:arm64:bionic:extra_pkgs:enabled')|default(false) %}
150 +  {% for pkg in pillar.maas.cluster.curtin_vars.arm64.bionic.extra_pkgs.pkgs -%}
151 +  apt_04_install_pkgs_{{ loop.index }}: ["curtin", "in-target", "--", "apt-get", "-y", "install", "{{ pkg }}"]
152 +  {% endfor %}
153 +{%- endif %}
154 +{%- if salt['pillar.get']('maas:cluster:curtin_vars:arm64:bionic:kernel_package:enabled')|default(false)  %}
155 +  apt_05_kernel_old_absent: ["curtin", "in-target", "--", "sh", "-c", "dpkg -l '*linux-generic-*[0-9]*' '*linux-image-*[0-9]*' '*linux-headers-*[0-9]*' '*linux-image-extra-*[0-9]*' '*linux-modules-extra-*[0-9]*' 'linux-generic' 'linux-image-generic' 'linux-headers-generic' 2>/dev/null | grep -E '^ii' | awk '{print $2}' | grep -v '{{ pillar.maas.cluster.curtin_vars.arm64.bionic.kernel_package.value.split('-')[2:-1] | join('-') }}' | xargs dpkg --purge --force-depends"]
156 +{%- endif %}
157 +  salt_01_install: ["curtin", "in-target", "--", "apt-get", "-y", "install", "salt-minion", "python-futures", "ifupdown", "cloud-init", "dnsmasq"]
158 +  salt_02_hostname_set: ["curtin", "in-target", "--", "echo", "{% raw %}{{node.hostname}}{% endraw %}.{{pillar.linux.system.domain}}"]
159 +  salt_03_hostname_get: ["curtin", "in-target", "--", "sh", "-c", "echo 'id: {% raw %}{{node.hostname}}{% endraw %}.{{pillar.linux.system.domain}}' >> /etc/salt/minion.d/minion.conf"]
160 +  salt_04_master: ["curtin", "in-target", "--", "sh", "-c", "echo 'master: {{ salt_master_ip }}' >> /etc/salt/minion.d/minion.conf"]
161 +  salt_05_max_event_size: ["curtin", "in-target", "--", "sh", "-c", "echo 'max_event_size: 100000000' >> /etc/salt/minion.d/minion.conf"]
162 +  salt_06_acceptance_wait_time_max: ["curtin", "in-target", "--", "sh", "-c", "echo 'acceptance_wait_time_max: 60' >> /etc/salt/minion.d/minion.conf"]
163 +  salt_07_acceptance_wait_time: ["curtin", "in-target", "--", "sh", "-c", "echo 'acceptance_wait_time: 10' >> /etc/salt/minion.d/minion.conf"]
164 +  salt_08_random_reauth_delay: ["curtin", "in-target", "--", "sh", "-c", "echo 'random_reauth_delay: 270' >> /etc/salt/minion.d/minion.conf"]
165 +  salt_09_recon_default: ["curtin", "in-target", "--", "sh", "-c", "echo 'recon_default: 1000' >> /etc/salt/minion.d/minion.conf"]
166 +  salt_10_recon_max: ["curtin", "in-target", "--", "sh", "-c", "echo 'recon_max: 60000' >> /etc/salt/minion.d/minion.conf"]
167 +  salt_11_recon_randomize: ["curtin", "in-target", "--", "sh", "-c", "echo 'recon_randomize: True' >> /etc/salt/minion.d/minion.conf"]
168 +  salt_12_auth_timeout: ["curtin", "in-target", "--", "sh", "-c", "echo 'auth_timeout: 60' >> /etc/salt/minion.d/minion.conf"]
169 +
170 +  salt_20_bionic_nplan_stop: ["curtin", "in-target", "--", "systemctl", "stop", "systemd-networkd.socket", "systemd-networkd", "networkd-dispatcher", "systemd-networkd-wait-online", "systemd-resolved"]
171 +  salt_21_bionic_nplan_disable: ["curtin", "in-target", "--", "systemctl", "disable", "systemd-networkd.socket", "systemd-networkd", "networkd-dispatcher", "systemd-networkd-wait-online", "systemd-resolved"]
172 +  salt_22_bionic_nplan_mask: ["curtin", "in-target", "--", "systemctl", "mask", "systemd-networkd.socket", "systemd-networkd", "networkd-dispatcher", "systemd-networkd-wait-online", "systemd-resolved"]
173 +  salt_23_bionic_nplan_purge: ["curtin", "in-target", "--", "apt", "--assume-yes", "purge", "nplan", "netplan.io"]
174 +  salt_24_bionic_interfaces: ["curtin", "in-target", "--", "sh", "-c", "echo 'source /etc/network/interfaces.d/*' >> /etc/network/interfaces"]
175 +  salt_25_bionic_networking_unmask: ["curtin", "in-target", "--", "systemctl", "unmask", "networking.service"]
176 +  salt_26_bionic_networking_enable: ["curtin", "in-target", "--", "systemctl", "enable", "networking.service"]
177 +  salt_27_bionic_networking_start: ["curtin", "in-target", "--", "systemctl", "start", "networking.service"]
178 +
179 +{%- if salt['pillar.get']('maas:cluster:curtin_vars:arm64:bionic:kernel_package:enabled')|default(false)  %}
180 +kernel:
181 +  package: {{ pillar.maas.cluster.curtin_vars.arm64.bionic.kernel_package.value }}
182 +{%- endif %}
183 +
184 +{% raw %}
185 +{{if third_party_drivers and driver}}
186 +  driver_00_key_get: curtin in-target -- sh -c "/bin/echo -en '{{key_string}}' > /tmp/maas-{{driver['package']}}.gpg"
187 +  driver_02_key_add: ["curtin", "in-target", "--", "apt-key", "add", "/tmp/maas-{{driver['package']}}.gpg"]
188 +  driver_03_add: ["curtin", "in-target", "--", "add-apt-repository", "-y", "deb {{driver['repository']}} {{node.get_distro_series()}} main"]
189 +  driver_04_update_install: ["curtin", "in-target", "--", "apt-get", "update", "--quiet"]
190 +  driver_05_install: ["curtin", "in-target", "--", "apt-get", "-y", "install", "{{driver['package']}}"]
191 +  driver_06_depmod: ["curtin", "in-target", "--", "depmod"]
192 +  driver_07_update_initramfs: ["curtin", "in-target", "--", "update-initramfs", "-u"]
193 +{{endif}}
194 +{% endraw %}
195 diff --git a/maas/region.sls b/maas/region.sls
196 index 52fb952..ca876ee 100644
197 --- a/maas/region.sls
198 +++ b/maas/region.sls
199 @@ -138,6 +138,30 @@ maas_apache_headers:
200    - require:
201      - pkg: maas_region_packages
202
203 +/etc/maas/preseeds/curtin_userdata_amd64_generic_bionic:
204 +  file.managed:
205 +  - source: salt://maas/files/curtin_userdata_amd64_generic_bionic
206 +  - template: jinja
207 +  - user: root
208 +  - group: root
209 +  - mode: 644
210 +  - context:
211 +      salt_master_ip: {{ region.salt_master_ip }}
212 +  - require:
213 +    - pkg: maas_region_packages
214 +
215 +/etc/maas/preseeds/curtin_userdata_arm64_generic_bionic:
216 +  file.managed:
217 +  - source: salt://maas/files/curtin_userdata_arm64_generic_bionic
218 +  - template: jinja
219 +  - user: root
220 +  - group: root
221 +  - mode: 644
222 +  - context:
223 +      salt_master_ip: {{ region.salt_master_ip }}
224 +  - require:
225 +    - pkg: maas_region_packages
226 +
227  Configure /root/.pgpass for MAAS:
228    file.managed:
229    - name: /root/.pgpass