1 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2 : Copyright (c) 2017 Enea AB and others.
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: Sun, 20 Aug 2017 22:41:26 +0200
11 Subject: [PATCH] mcp: salt-formulas: armband: Extend libvirt_domain
13 Add new state in armband salt formula that:
14 * extends salt's virt libvirt_domain.jinja template with support for:
18 These will later be leveraged via salt virt formula with AArch64
20 * to ensure compatibilty of `virt.purge` with NVRAM-enabled domains
21 at undefine time, pass down the proper flag to libvirt from virt.py.
22 * re-enable AArch64 bootstrap
23 Recent changes in salt bootstrap script from [1] whitelist a
24 fixed pool of known architectures. Add "arm64" to that list on the
25 fly, as part of `config.gather_bootstrap_script`.
26 NOTE: This change will be leveraged by passing a custom DEB repo to
27 the bootstrap script with `-R linux.enea.com/saltstack`.
29 NOTE: After running this new state, salt-minion should be restarted
30 to pick up the changes, so we'll run it before rebooting kvm nodes.
32 [1] http://bootstrap.saltstack.com
34 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
36 mcp/config/states/virtual_control_plane | 1 +
37 .../armband/files/salt-minion-aarch64-rollup.diff | 101 +++++++++++++++++++++
38 mcp/salt-formulas/armband/salt_minion.sls | 7 ++
39 3 files changed, 109 insertions(+)
40 create mode 100644 mcp/salt-formulas/armband/files/salt-minion-aarch64-rollup.diff
41 create mode 100644 mcp/salt-formulas/armband/salt_minion.sls
43 diff --git a/mcp/config/states/virtual_control_plane b/mcp/config/states/virtual_control_plane
44 index 99fb517..88a4488 100755
45 --- a/mcp/config/states/virtual_control_plane
46 +++ b/mcp/config/states/virtual_control_plane
47 @@ -40,6 +40,7 @@ salt -C 'kvm*' pkg.install bridge-utils
48 salt -C 'kvm*' state.apply linux.network
49 salt -C 'cmp*' state.apply linux.system
50 salt -C 'cmp*' state.apply linux.network || true
51 +salt -C 'kvm*' state.apply armband.salt_minion || true
52 salt -C 'kvm* or cmp*' system.reboot
53 wait_for 90 "! salt -C 'kvm* or cmp*' test.ping | " \
54 "tee /dev/stderr | grep -Fq 'Not connected'"
55 diff --git a/mcp/salt-formulas/armband/files/salt-minion-aarch64-rollup.diff b/mcp/salt-formulas/armband/files/salt-minion-aarch64-rollup.diff
57 index 0000000..9e74c24
59 +++ b/mcp/salt-formulas/armband/files/salt-minion-aarch64-rollup.diff
61 +From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
62 +Date: Sun Aug 20 18:18:53 2017 +0200
63 +Subject: [PATCH] cloud.py: Allow AArch64 arch in salt bootstrap
65 +Recent changes in salt bootstrap script from [1] whitelist a
66 +fixed pool of known architectures. Add "arm64" to that list on the
67 +fly, as part of `config.gather_bootstrap_script`.
69 +NOTE: This change will be leveraged by passing a custom DEB repo to
70 +the bootstrap script with `-R linux.enea.com/saltstack`.
72 +[1] http://bootstrap.saltstack.com
74 +Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
77 +diff --git a/salt/utils/cloud.py b/salt/utils/cloud.py
78 +--- a/salt/utils/cloud.py
79 ++++ b/salt/utils/cloud.py
80 +@@ -2772,6 +2772,9 @@
81 + if not script_content:
82 + raise ValueError('No content in bootstrap script !')
84 ++ # NOTE(armband): edit bootstrap script on the fly to allow AArch64
85 ++ script_content = script_content.replace('"amd64")', '"amd64"|"arm64")')
87 + # Get the path to the built-in deploy scripts directory
88 + builtin_deploy_dir = os.path.join(
89 + os.path.dirname(__file__),
92 +From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
93 +Date: Sun Aug 20 18:18:53 2017 +0200
94 +Subject: [PATCH] libvirt_domain.jinja: Add AArch64 support
96 +Salt virt state relies on a Jinja template to create a libvirt
97 +XML definition for each new VM.
98 +This template needs to be extended with a few specific options
100 +- UEFI loader support (pflash);
101 +- custom machine model (e.g. 'virt-2.9'), since AArch64 defaults to
105 +Allow all these to be parametrized from the salt virt formula,
106 +which we will also adapt to allow the params to be passed via our
109 +Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
112 +diff --git a/salt/templates/virt/libvirt_domain.jinja b/salt/templates/virt/libvirt_domain.jinja
113 +--- a/salt/templates/virt/libvirt_domain.jinja
114 ++++ b/salt/templates/virt/libvirt_domain.jinja
116 + <vcpu>{{ cpu }}</vcpu>
117 + <memory unit='KiB'>{{ mem }}</memory>
119 ++ {% if custom_virt_machine %}
120 ++ <type machine='{{ virt_machine_model }}'>hvm</type>
124 ++ {% if os_loader_type == 'pflash' %}
125 ++ <loader readonly='yes' type='{{ os_loader_type }}'>{{ os_loader }}</loader>
126 ++ <nvram>{{ os_loader_nvram }}</nvram>
128 + {% for dev in boot_dev %}
129 + <boot dev='{{ dev }}' />
132 ++ {% if cpu_mode == 'custom' %}
133 ++ <cpu mode='{{ cpu_model }}' check='none'/>
136 + {% for diskname, disk in disks.items() %}
137 + <disk type='file' device='disk'>
140 +From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
141 +Date: Sun Nov 19 02:18:53 2017 +0200
142 +Subject: [PATCH] virt.py: undefine: NVRAM flag support
144 +Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
147 +diff --git a/salt/modules/virt.py b/salt/modules/virt.py
148 +--- a/salt/modules/virt.py
149 ++++ b/salt/modules/virt.py
150 +@@ -1523,7 +1523,10 @@
151 + salt '*' virt.undefine <domain>
153 + dom = _get_domain(vm_)
154 +- return dom.undefine() == 0
156 ++ return dom.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_NVRAM) == 0
157 ++ except libvirt.libvirtError:
158 ++ return dom.undefine() == 0
161 + def purge(vm_, dirs=False):
162 diff --git a/mcp/salt-formulas/armband/salt_minion.sls b/mcp/salt-formulas/armband/salt_minion.sls
164 index 0000000..9cce636
166 +++ b/mcp/salt-formulas/armband/salt_minion.sls
168 +salt-minion-aarch64-rollup:
170 + - name: /usr/lib/python2.7/dist-packages
171 + - source: salt://armband/files/salt-minion-aarch64-rollup.diff
174 + - unless: 'test -f /var/cache/salt/minion/files/base/armband/files/salt-minion-aarch64-rollup.diff && cd /usr/lib/python2.7/dist-packages && patch -p1 -R --dry-run /var/cache/salt/minion/files/base/armband/files/salt-minion-aarch64-rollup.diff'