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