heat_template_version: wallaby

description: Host config and reboot service which configures Kernel Args and reboot

parameters:
  RoleNetIpMap:
    default: {}
    type: json
  ServiceData:
    default: {}
    description: Dictionary packing service data
    type: json
  ServiceNetMap:
    default: {}
    description: Mapping of service_name -> network name. Typically set
                 via parameter_defaults in the resource registry. Use
                 parameter_merge_strategies to merge it with the defaults.
    type: json
  RoleName:
    default: ''
    description: Role name on which the service is applied
    type: string
  RoleParameters:
    default: {}
    description: Parameters specific to the role
    type: json
  EndpointMap:
    default: {}
    description: Mapping of service endpoint -> protocol. Typically set
                 via parameter_defaults in the resource registry.
    type: json
  KernelArgs:
    default: ""
    type: string
    description: Kernel Args to apply to the host
    tags:
      - role_specific
  KernelArgsDeferReboot:
    default: false
    type: boolean
    description: >
      When enabled, nodes will not get rebooted automatically by tripleo-kernel
      if KernelArgs have been changed. Operators will have to manually reboot
      nodes after the deployment or update process is completed.

      Leaving this enabled during a scale-up operation will prevent reboot on
      new nodes. This might cause deployment errors as the KernelArgs will not
      be applied.
    tags:
      - role_specific
  TunedProfileName:
    default: 'throughput-performance'
    type: string
    description: Tuned Profile to apply to the host
    tags:
      - role_specific
  IsolCpusList:
    default: ""
    type: string
    description: >
      List of logical CPU ids whic need to be isolated from the host processes.
      This input is provided to the tuned profile cpu-partitioning to configure
      systemd and repin interrupts (IRQ repinning).
    tags:
      - role_specific
  NodeRebootWaitTimeout:
    default: 900
    type: number
    description: Timeout in seconds to specify the wait time for ansible node reboot

resources:
  RoleParametersValue:
    type: OS::Heat::Value
    properties:
      type: json
      value:
        map_replace:
          - map_replace:
            - tuned_profile: TunedProfileName
              isolated_cores: IsolCpusList
              kernel_args: KernelArgs
              kernel_args_defer_reboot: KernelArgsDeferReboot
            - values: {get_param: [RoleParameters]}
          - values:
              TunedProfileName: {get_param: TunedProfileName}
              IsolCpusList: {get_param: IsolCpusList}
              KernelArgs: {get_param: KernelArgs}
              KernelArgsDeferReboot: {get_param: KernelArgsDeferReboot}

outputs:
  role_data:
    description: Role data for the Host Config Service
    value:
      service_name: boot_params_service
      deploy_steps_tasks:
        # TODO(skramaja): Tasks of Tuned TripleO service can be used here
        # But the configuration in that service has to be moved from host_prep_tasks to step 0 of deploy_step_tasks
        - name: Configure tuned before reboot
          when: step|int == 0
          include_role:
            name: tuned
          vars:
            tuned_profile: {get_attr: [RoleParametersValue, value, tuned_profile]}
            tuned_isolated_cores: {get_attr: [RoleParametersValue, value, isolated_cores]}
        - name: Configure kernel args and reboot
          when: step|int == 0
          include_role:
            name: tripleo_kernel
            tasks_from: kernelargs.yml
          vars:
            tripleo_kernel_args: {get_attr: [RoleParametersValue, value, kernel_args]}
            tripleo_kernel_defer_reboot: {get_attr: [RoleParametersValue, value, kernel_args_defer_reboot]}
            tripleo_kernel_reboot_timeout: {get_param: NodeRebootWaitTimeout}
      upgrade_tasks:
        - name: upgrade prepare for leapp to align kernel arg shortcommings in leapp
          tags:
            - never
            - system_upgrade
            - system_upgrade_prepare
          when:
            - step|int == 3
            - upgrade_leapp_enabled
          block:
            - name: fix grub entries to have name start with GRUB_
              replace:
                path: '/etc/default/grub'
                regexp: '^(TRIPLEO_HEAT_TEMPLATE_KERNEL_ARGS)(.*)'
                replace: 'GRUB_\1\2'
            - name: fix grub entries in append statement
              replace:
                path: '/etc/default/grub'
                regexp: '(.*){(TRIPLEO_HEAT_TEMPLATE_KERNEL_ARGS)}(.*)'
                replace: '\1{GRUB_\2}\3'