Support configurable Zaqar backends
[apex-tripleo-heat-templates.git] / extraconfig / pre_network / host_config_and_reboot.yaml
1 heat_template_version: pike
2
3 description: >
4   All configurations which require reboot should be initiated via PreNetworkConfig. After
5   this configuration is completed, the corresponding node will be rebooted.
6
7 parameters:
8   server:
9     type: string
10   RoleParameters:
11     type: json
12     description: Role Specific parameters
13     default: {}
14   ServiceNames:
15     type: comma_delimited_list
16     default: []
17   IsolCpusList:
18     default: "0"
19     description: List of cores to be isolated by tuned
20     type: string
21     constraints:
22       - allowed_pattern: "[0-9,-]+"
23   OvsEnableDpdk:
24     default: false
25     description: Whether or not to configure enable DPDK in OVS
26     type: boolean
27   OvsDpdkCoreList:
28     description: >
29       List of cores to be used for DPDK lcore threads.  Note, these threads
30       are used by the OVS control path for validator and handling functions.
31     type: string
32     constraints:
33       - allowed_pattern: "[0-9,-]*"
34     default: ""
35   OvsDpdkMemoryChannels:
36     description: Number of memory channels per socket to be used for DPDK
37     type: string
38     constraints:
39       - allowed_pattern: "[0-9]*"
40     default: ""
41   OvsDpdkSocketMemory:
42     default: ""
43     description: >
44       Sets the amount of hugepage memory to assign per NUMA node. It is
45       recommended to use the socket closest to the PCIe slot used for the
46       desired DPDK NIC.  The format should be in "<socket 0 mem>, <socket 1
47       mem>, <socket n mem>", where the value is specified in MB.  For example:
48       "1024,0".
49     type: string
50   OvsDpdkDriverType:
51     default: "vfio-pci"
52     description: >
53       DPDK Driver type. Ensure the Overcloud NIC to be used for DPDK supports
54       this UIO/PMD driver.
55     type: string
56   OvsPmdCoreList:
57     description: >
58       A list or range of CPU cores for PMD threads to be pinned to.  Note, NIC
59       location to cores on socket, number of hyper-threaded logical cores, and
60       desired number of PMD threads can all play a role in configuring this
61       setting.  These cores should be on the same socket where
62       OvsDpdkSocketMemory is assigned.  If using hyperthreading then specify
63       both logical cores that would equal the physical core. Also, specifying
64       more than one core will trigger multiple PMD threads to be spawned which
65       may improve dataplane performance.
66     constraints:
67       - allowed_pattern: "[0-9,-]*"
68     type: string
69     default: ""
70   # DEPRECATED: the following options are deprecated and are currently maintained
71   # for backwards compatibility. They will be removed in the Queens cycle.
72   HostCpusList:
73     description: List of cores to be used for host process
74     type: string
75     constraints:
76       - allowed_pattern: "[0-9,-]+"
77     default: '0'
78   NeutronDpdkCoreList:
79     description: List of cores to be used for DPDK Poll Mode Driver
80     type: string
81     constraints:
82       - allowed_pattern: "[0-9,-]*"
83     default: ''
84   NeutronDpdkMemoryChannels:
85     description: Number of memory channels to be used for DPDK
86     type: string
87     constraints:
88       - allowed_pattern: "[0-9]*"
89     default: ''
90   NeutronDpdkSocketMemory:
91     default: ''
92     description: Memory allocated for each socket
93     type: string
94   NeutronDpdkDriverType:
95     default: "vfio-pci"
96     description: DPDK Driver type
97     type: string
98   deployment_actions:
99     default: ['CREATE', 'UPDATE']
100     type: comma_delimited_list
101     description: >
102       List of stack actions that will trigger any deployments in this
103       templates. The actions will be an empty list of the server is in the
104       toplevel DeploymentServerBlacklist parameter's value.
105
106 conditions:
107   is_host_config_required: {not: {equals: [{get_param: [RoleParameters, KernelArgs]}, ""]}}
108   # YAQL is enabled in conditions with https://review.openstack.org/#/c/467506/
109   is_dpdk_config_required:
110     or:
111       - yaql:
112         expression: $.data.service_names.contains('neutron_ovs_dpdk_agent')
113         data:
114           service_names: {get_param: ServiceNames}
115       - {get_param: OvsEnableDpdk}
116       - {get_param: [RoleParameters, OvsEnableDpdk]}
117   is_reboot_config_required:
118     or:
119       - is_host_config_required
120       - is_dpdk_config_required
121   l_cores_empty: {equals: [{get_param: OvsDpdkCoreList}, '']}
122   pmd_cores_empty: {equals: [{get_param: OvsPmdCoreList}, '']}
123   mem_channels_empty: {equals: [{get_param: OvsDpdkMemoryChannels}, '']}
124   socket_mem_empty: {equals: [{get_param: OvsDpdkSocketMemory}, '']}
125   driver_not_set: {equals: [{get_param: OvsDpdkDriverType}, 'vfio-pci']}
126   isol_cpus_empty: {equals: [{get_param: IsolCpusList}, '0']}
127   deployment_actions_empty:
128     equals:
129       - {get_param: deployment_actions}
130       - []
131
132 resources:
133   RoleParametersValue:
134     type: OS::Heat::Value
135     properties:
136       type: json
137       value:
138         map_replace:
139           - map_replace:
140             - IsolCpusList: IsolCpusList
141               OvsDpdkCoreList: OvsDpdkCoreList
142               OvsDpdkMemoryChannels: OvsDpdkMemoryChannels
143               OvsDpdkSocketMemory: OvsDpdkSocketMemory
144               OvsDpdkDriverType: OvsDpdkDriverType
145               OvsPmdCoreList: OvsDpdkCoreList
146             - values: {get_param: [RoleParameters]}
147           - values:
148               IsolCpusList: {if: [isol_cpus_empty, {get_param: HostCpusList}, {get_param: IsolCpusList}]}
149               OvsDpdkCoreList: {if: [l_cores_empty, {get_param: HostCpusList}, {get_param: OvsDpdkCoreList}]}
150               OvsDpdkMemoryChannels: {if: [mem_channels_empty, {get_param: NeutronDpdkMemoryChannels}, {get_param: OvsDpdkMemoryChannels}]}
151               OvsDpdkSocketMemory: {if: [socket_mem_empty, {get_param: NeutronDpdkSocketMemory}, {get_param: OvsDpdkSocketMemory}]}
152               OvsDpdkDriverType: {if: [driver_not_set, {get_param: NeutronDpdkDriverType}, {get_param: OvsDpdkDriverType}]}
153               OvsPmdCoreList: {if: [pmd_cores_empty, {get_param: NeutronDpdkCoreList}, {get_param: OvsPmdCoreList}]}
154
155   HostParametersConfig:
156     type: OS::Heat::SoftwareConfig
157     condition: is_host_config_required
158     properties:
159       group: ansible
160       inputs:
161         - name: _KERNEL_ARGS_
162         - name: _TUNED_PROFILE_NAME_
163         - name: _TUNED_CORES_
164       outputs:
165         - name: result
166       config:
167         get_file: ansible_host_config.yaml
168
169   HostParametersDeployment:
170     type: OS::Heat::SoftwareDeployment
171     condition: is_host_config_required
172     properties:
173       name: HostParametersDeployment
174       server:  {get_param: server}
175       config: {get_resource: HostParametersConfig}
176       actions:
177         if:
178           - deployment_actions_empty
179           - []
180           - ['CREATE'] # Only do this on CREATE
181       input_values:
182         _KERNEL_ARGS_: {get_param: [RoleParameters, KernelArgs]}
183         _TUNED_PROFILE_NAME_: {get_param: [RoleParameters, TunedProfileName]}
184         _TUNED_CORES_: {get_param: [RoleParameters, IsolCpusList]}
185
186   EnableDpdkConfig:
187     type: OS::Heat::SoftwareConfig
188     condition: is_dpdk_config_required
189     properties:
190       group: script
191       config:
192         str_replace:
193           template: |
194             #!/bin/bash
195             set -x
196
197             # OvS Permission issue temporary workaround
198             # https://bugzilla.redhat.com/show_bug.cgi?id=1459436
199             # Actual solution from openvswitch - https://mail.openvswitch.org/pipermail/ovs-dev/2017-June/333423.html
200             ovs_service_path="/usr/lib/systemd/system/ovs-vswitchd.service"
201
202             if grep -q 'RuntimeDirectoryMode' $ovs_service_path; then
203                 sed -i 's/RuntimeDirectoryMode=.*/RuntimeDirectoryMode=0775/' $ovs_service_path
204             else
205                 echo "RuntimeDirectoryMode=0775" >> $ovs_service_path
206             fi
207
208             if ! grep -Fxq "Group=qemu" $ovs_service_path ; then
209               echo "Group=qemu" >> $ovs_service_path
210             fi
211
212             if ! grep -Fxq "UMask=0002" $ovs_service_path ; then
213               echo "UMask=0002" >> $ovs_service_path
214             fi
215
216             ovs_ctl_path='/usr/share/openvswitch/scripts/ovs-ctl'
217             if ! grep -q "umask 0002 \&\& start_daemon \"\$OVS_VSWITCHD_PRIORITY\"" $ovs_ctl_path ; then
218               sed -i 's/start_daemon \"\$OVS_VSWITCHD_PRIORITY\"/umask 0002 \&\& start_daemon \"$OVS_VSWITCHD_PRIORITY\"/' $ovs_ctl_path
219             fi
220
221
222             # DO NOT use --detailed-exitcodes
223             puppet apply --logdest console \
224               --modulepath /etc/puppet/modules:/opt/stack/puppet-modules:/usr/share/openstack-puppet/modules \
225               -e '
226                 class {"vswitch::dpdk":
227                   host_core_list  => "$HOST_CORES",
228                   pmd_core_list   => "$PMD_CORES",
229                   memory_channels => "$MEMORY_CHANNELS",
230                   socket_mem      => "$SOCKET_MEMORY",
231                 }
232               '
233           params:
234             $HOST_CORES: {get_attr: [RoleParametersValue, value, OvsDpdkCoreList]}
235             $PMD_CORES: {get_attr: [RoleParametersValue, value, OvsPmdCoreList]}
236             $MEMORY_CHANNELS: {get_attr: [RoleParametersValue, value, OvsDpdkMemoryChannels]}
237             $SOCKET_MEMORY: {get_attr: [RoleParametersValue, value, OvsDpdkSocketMemory]}
238
239   EnableDpdkDeployment:
240     type: OS::Heat::SoftwareDeployment
241     condition: is_dpdk_config_required
242     properties:
243       name: EnableDpdkDeployment
244       server:  {get_param: server}
245       config: {get_resource: EnableDpdkConfig}
246       actions: ['CREATE'] # Only do this on CREATE
247
248   RebootConfig:
249     type: OS::Heat::SoftwareConfig
250     condition: is_reboot_config_required
251     properties:
252       group: script
253       config: |
254         #!/bin/bash
255         # Stop os-collect-config to avoid any race collecting another
256         # deployment before reboot happens
257         systemctl stop os-collect-config.service
258         /sbin/reboot
259
260   RebootDeployment:
261     type: OS::Heat::SoftwareDeployment
262     depends_on: HostParametersDeployment
263     condition: is_reboot_config_required
264     properties:
265       name: RebootDeployment
266       server:  {get_param: server}
267       config: {get_resource: RebootConfig}
268       actions:
269         if:
270           - deployment_actions_empty
271           - []
272           - ['CREATE'] # Only do this on CREATE
273       signal_transport: NO_SIGNAL
274
275 outputs:
276   result:
277     condition: is_host_config_required
278     value:
279       get_attr: [HostParametersDeployment, result]
280   stdout:
281     condition: is_host_config_required
282     value:
283       get_attr: [HostParametersDeployment, deploy_stdout]
284   stderr:
285     condition: is_host_config_required
286     value:
287       get_attr: [HostParametersDeployment, deploy_stderr]
288   status_code:
289     condition: is_host_config_required
290     value:
291       get_attr: [HostParametersDeployment, deploy_status_code]