086cfcab7a698c708cb98020fb6e50e3c3acbf97
[armband.git] / patches / opnfv-fuel / 0003-mcp-salt-formulas-armband-Extend-libvirt_domain.patch
1 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2 : Copyright (c) 2018 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: Sun, 20 Aug 2017 22:41:26 +0200
11 Subject: [PATCH] mcp: salt-formulas: armband: Extend libvirt_domain
12
13 Add new state in armband salt formula that:
14 * extends salt's virt libvirt_domain.jinja template with support for:
15   - hw_firmware_type;
16   - virt_machine_model;
17   - cpu_model;
18   These will later be leveraged via salt virt formula with AArch64
19   specific values.
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`.
28
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.
31
32 [1] http://bootstrap.saltstack.com
33
34 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
35 ---
36  mcp/config/states/baremetal_init              |   1 +
37  .../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
42
43 diff --git a/mcp/config/states/baremetal_init b/mcp/config/states/baremetal_init
44 index 6a44b788..6f935445 100755
45 --- a/mcp/config/states/baremetal_init
46 +++ b/mcp/config/states/baremetal_init
47 @@ -31,6 +31,7 @@ wait_for 5.0 "salt -C 'kvm* or cmp*' state.apply opnfv.route_wrapper"
48  wait_for 5.0 "salt -C 'cmp*' state.apply linux.network"
49  wait_for 30.0 "salt -C 'kvm* or cmp*' test.ping"
50
51 +salt -C 'kvm*' state.apply armband.salt_minion
52  salt -C 'kvm* or cmp*' system.reboot
53  wait_for 90.0 "salt -C 'kvm* or cmp*' test.ping"
54
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
56 new file mode 100644
57 index 00000000..9e74c240
58 --- /dev/null
59 +++ b/mcp/salt-formulas/armband/files/salt-minion-aarch64-rollup.diff
60 @@ -0,0 +1,101 @@
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
64 +
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`.
68 +
69 +NOTE: This change will be leveraged by passing a custom DEB repo to
70 +the bootstrap script with `-R linux.enea.com/saltstack`.
71 +
72 +[1] http://bootstrap.saltstack.com
73 +
74 +Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
75 +---
76 +
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 !')
83 +
84 ++    # NOTE(armband): edit bootstrap script on the fly to allow AArch64
85 ++    script_content = script_content.replace('"amd64")', '"amd64"|"arm64")')
86 ++
87 +     # Get the path to the built-in deploy scripts directory
88 +     builtin_deploy_dir = os.path.join(
89 +         os.path.dirname(__file__),
90 +--
91 +
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
95 +
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
99 +for AArch64:
100 +- UEFI loader support (pflash);
101 +- custom machine model (e.g. 'virt-2.9'), since AArch64 defaults to
102 +  'integratorcp';
103 +- custom cpu model;
104 +
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
107 +reclass model.
108 +
109 +Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
110 +---
111 +
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
115 +@@ -3,11 +3,22 @@
116 +         <vcpu>{{ cpu }}</vcpu>
117 +         <memory unit='KiB'>{{ mem }}</memory>
118 +         <os>
119 ++                {% if custom_virt_machine %}
120 ++                <type machine='{{ virt_machine_model }}'>hvm</type>
121 ++                {% else %}
122 +                 <type>hvm</type>
123 ++                {% endif %}
124 ++                {% if os_loader_type == 'pflash' %}
125 ++                <loader readonly='yes' type='{{ os_loader_type }}'>{{ os_loader }}</loader>
126 ++                <nvram>{{ os_loader_nvram }}</nvram>
127 ++                {% endif %}
128 +                 {% for dev in boot_dev %}
129 +                 <boot dev='{{ dev }}' />
130 +                 {% endfor %}
131 +         </os>
132 ++        {% if cpu_mode == 'custom' %}
133 ++        <cpu mode='{{ cpu_model }}' check='none'/>
134 ++        {% endif %}
135 +         <devices>
136 +                 {% for diskname, disk in disks.items() %}
137 +                 <disk type='file' device='disk'>
138 +--
139 +
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
143 +
144 +Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
145 +---
146 +
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>
152 +     '''
153 +     dom = _get_domain(vm_)
154 +-    return dom.undefine() == 0
155 ++    try:
156 ++        return dom.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_NVRAM) == 0
157 ++    except libvirt.libvirtError:
158 ++        return dom.undefine() == 0
159 +
160 +
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
163 new file mode 100644
164 index 00000000..cc5c9242
165 --- /dev/null
166 +++ b/mcp/salt-formulas/armband/salt_minion.sls
167 @@ -0,0 +1,7 @@
168 +salt-minion-aarch64-rollup:
169 +  file.patch:
170 +  - name: /usr/lib/python2.7/dist-packages
171 +  - source: salt://armband/files/salt-minion-aarch64-rollup.diff
172 +  - hash: False
173 +  - options: '-p1'
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 -r - < /var/cache/salt/minion/files/base/armband/files/salt-minion-aarch64-rollup.diff'