Unhardcode console params

Allow to set console params on conductor by using the
following pillar ironic:conductor:console

Change-Id: I35d80ea63265b8ea07da933d5aa5ee3cf172cfc5
Related-Prod: PROD-26131
diff --git a/README.rst b/README.rst
index 6502a63..4d76b85 100644
--- a/README.rst
+++ b/README.rst
@@ -194,6 +194,26 @@
             strategy: ENCRYPT
             secret_key: secret
 
+
+Enable serial console for Baremetal Nodes
+-----------------------------------------
+
+.. code-block:: yaml
+
+  ironic:
+    conductor:
+      console:
+        terminal: shellinaboxd
+        terminal_cert_dir: /tmp/ca
+        terminal_timeout: 10
+        subprocess_checking_interval: 1
+        subprocess_timeout: 10
+        socat_address: 127.0.0.1
+
+You can read more info about it here:
+  https://docs.openstack.org/ironic/pike/admin/console.html#node-serial-console
+
+
 Ensure nodes are in target state (available).
 Starting from 1.11 API microversion newly-created node is moved to `enroll`
 state. To move it to available the following client pillar might be used:
diff --git a/ironic/conductor.sls b/ironic/conductor.sls
index 032c34a..40b1e05 100644
--- a/ironic/conductor.sls
+++ b/ironic/conductor.sls
@@ -10,6 +10,15 @@
   - require_in:
     - sls: ironic._common
 
+{%- if conductor.get('console', {}).get('enabled') %}
+ironic_console_packages:
+  pkg.installed:
+  - names: {{ conductor.console_pkgs }}
+  - install_recommends: False
+  - require_in:
+    - {{ conductor.service }}
+{%- endif %}
+
 {{ conductor.service }}:
   service.running:
     - enable: true
diff --git a/ironic/files/pike/ironic.conf b/ironic/files/pike/ironic.conf
index 5350c1a..3083ce9 100644
--- a/ironic/files/pike/ironic.conf
+++ b/ironic/files/pike/ironic.conf
@@ -1313,25 +1313,45 @@
 
 # Path to serial console terminal program. Used only by Shell
 # In A Box console. (string value)
+{%- if conductor.get('console', {}).terminal is defined %}
+terminal = {{ conductor.console.terminal }}
+{%- else %}
 #terminal = shellinaboxd
+{%- endif %}
 
 # Directory containing the terminal SSL cert (PEM) for serial
 # console access. Used only by Shell In A Box console. (string
 # value)
+{%- if conductor.get('console', {}).terminal_cert_dir is defined %}
+terminal_cert_dir = {{ conductor.console.terminal_cert_dir }}
+{%- else %}
 #terminal_cert_dir = <None>
+{%- endif %}
 
 # Directory for holding terminal pid files. If not specified,
 # the temporary directory will be used. (string value)
+{%- if conductor.get('console', {}).terminal_pid_dir is defined %}
+terminal_pid_dir = {{ conductor.console.terminal_pid_dir }}
+{%- else %}
 #terminal_pid_dir = <None>
+{%- endif %}
 
 # Time interval (in seconds) for checking the status of
 # console subprocess. (integer value)
 #subprocess_checking_interval = 1
+{%- if conductor.get('console', {}).subprocess_checking_interval is defined %}
+subprocess_checking_interval = {{ conductor.console.subprocess_checking_interval }}
+{%- else %}
+#subprocess_checking_interval = 1
+{%- endif %}
 
 # Time (in seconds) to wait for the console subprocess to
 # start. (integer value)
+{%- if conductor.get('console', {}).subprocess_timeout is defined %}
+subprocess_timeout = {{ conductor.console.subprocess_timeout }}
+{%- else %}
 #subprocess_timeout = 10
-
+{%- endif %}
 
 [cors]
 
@@ -3818,7 +3838,11 @@
 
 # Additional append parameters for baremetal PXE boot. (string
 # value)
+{%- if conductor.pxe_append_params is defined %}
+pxe_append_params = {{ conductor.pxe_append_params }}
+{%- else %}
 #pxe_append_params = nofb nomodeset vga=normal
+{%- endif %}
 
 # Default file system format for ephemeral partition, if one
 # is created. (string value)
diff --git a/ironic/files/queens/ironic.conf b/ironic/files/queens/ironic.conf
index 668e9c1..c302819 100644
--- a/ironic/files/queens/ironic.conf
+++ b/ironic/files/queens/ironic.conf
@@ -1210,34 +1210,62 @@
 
 # Path to serial console terminal program. Used only by Shell
 # In A Box console. (string value)
+{%- if conductor.get('console', {}).terminal is defined %}
+terminal = {{ conductor.console.terminal }}
+{%- else %}
 #terminal = shellinaboxd
+{%- endif %}
 
 # Directory containing the terminal SSL cert (PEM) for serial
 # console access. Used only by Shell In A Box console. (string
 # value)
+{%- if conductor.get('console', {}).terminal_cert_dir is defined %}
+terminal_cert_dir = {{ conductor.console.terminal_cert_dir }}
+{%- else %}
 #terminal_cert_dir = <None>
+{%- endif %}
 
 # Directory for holding terminal pid files. If not specified,
 # the temporary directory will be used. (string value)
+{%- if conductor.get('console', {}).terminal_pid_dir is defined %}
+terminal_pid_dir = {{ conductor.console.terminal_pid_dir }}
+{%- else %}
 #terminal_pid_dir = <None>
+{%- endif %}
 
 # Timeout (in seconds) for the terminal session to be closed
 # on inactivity. Set to 0 to disable timeout. Used only by
 # Socat console. (integer value)
 # Minimum value: 0
+{%- if conductor.get('console', {}).terminal_timeout is defined %}
+terminal_timeout = {{ conductor.console.terminal_timeout }}
+{%- else %}
 #terminal_timeout = 600
+{%- endif %}
 
 # Time interval (in seconds) for checking the status of
 # console subprocess. (integer value)
+{%- if conductor.get('console', {}).subprocess_checking_interval is defined %}
+subprocess_checking_interval = {{ conductor.console.subprocess_checking_interval }}
+{%- else %}
 #subprocess_checking_interval = 1
+{%- endif %}
 
 # Time (in seconds) to wait for the console subprocess to
 # start. (integer value)
+{%- if conductor.get('console', {}).subprocess_timeout is defined %}
+subprocess_timeout = {{ conductor.console.subprocess_timeout }}
+{%- else %}
 #subprocess_timeout = 10
+{%- endif %}
 
 # IP address of Socat service running on the host of ironic
 # conductor. Used only by Socat console. (IP address value)
+{%- if conductor.get('console', {}).socat_address is defined %}
+socat_address = {{ conductor.console.socat_address }}
+{%- else %}
 #socat_address = $my_ip
+{%- endif %}
 
 
 [cors]
@@ -2337,7 +2365,11 @@
 
 # Additional append parameters for baremetal PXE boot. (string
 # value)
+{%- if conductor.pxe_append_params is defined %}
+pxe_append_params = {{ conductor.pxe_append_params }}
+{%- else %}
 #pxe_append_params = nofb nomodeset vga=normal
+{%- endif %}
 
 # Default file system format for ephemeral partition, if one
 # is created. (string value)
diff --git a/ironic/map.jinja b/ironic/map.jinja
index ff55015..3ccd06d 100644
--- a/ironic/map.jinja
+++ b/ironic/map.jinja
@@ -28,6 +28,7 @@
     'Debian': {
         'pkgs': ['ipmitool', 'ironic-conductor', 'tftpd-hpa', 'syslinux-common', 'pxelinux', 'ipxe'],
         'uefi_pkgs': ['grub-efi-amd64-signed', 'shim-signed'],
+        'console_pkgs': ['shellinabox', 'socat'],
         'pxelinux_path': '/usr/lib/PXELINUX',
         'syslinux_files': ['chain.c32', 'libcom32.c32', 'libutil.c32', 'ldlinux.c32'],
         'syslinux_path': '/usr/lib/syslinux/modules/bios',
@@ -50,6 +51,7 @@
     'RedHat': {
         'pkgs': ['ipmitool', 'ironic-conductor', 'tftp-server', 'syslinux-extlinux', 'ipxe-bootimgs'],
         'uefi_pkgs': ['grub2-efi', 'shim'],
+        'console_pkgs': ['shellinabox', 'socat'],
         'pxelinux_path': '/usr/share/syslinux',
         'syslinux_files': ['chain.c32'],
         'syslinux_path': '/usr/share/syslinux',
diff --git a/tests/pillar/conductor_single.sls b/tests/pillar/conductor_single.sls
index 616e456..4c86486 100644
--- a/tests/pillar/conductor_single.sls
+++ b/tests/pillar/conductor_single.sls
@@ -20,6 +20,14 @@
     identity:
       engine: 'noauth'
     http_root: '/var/www/httproot'
+    console:
+      terminal: shellinaboxd
+      terminal_cert_dir: /tmp/ca
+      terminal_timeout: 10
+      subprocess_checking_interval: 1
+      subprocess_timeout: 10
+      socat_address: 127.0.0.1
+    pxe_append_params: nofb nomodeset vga=normal
   tftpd_hpa:
     server:
       bind: