From 5fa6bc4d368e2c4d2ad9c96895726bf6facec6a3 Mon Sep 17 00:00:00 2001
From: Will Szumski <will@stackhpc.com>
Date: Mon, 29 Oct 2018 15:55:22 +0000
Subject: [PATCH] Automatically enable serial consoles on post configure

This functionality is controlled by the flag ironic_serial_console_autoenable,
which, when enabled, will configure serial consoles for each of the ironic
nodes during the `overcloud post configure` step. This was added to reduce the
number of kayobe commands that are needed to be run for a given deployment.

Change-Id: I7072e518c29387b964e4e25b08b4559f152d5ecf
Story: 2004192
Task: 29325
---
 ...etal-compute-serial-console-post-config.yml |  6 ++++++
 ansible/group_vars/all/ironic                  |  3 +++
 ansible/kolla-ansible.yml                      | 18 ++++++++++++++++++
 doc/source/administration/bare-metal.rst       |  8 ++++++++
 etc/kayobe/ironic.yml                          |  3 +++
 kayobe/cli/commands.py                         |  4 +++-
 kayobe/tests/unit/cli/test_commands.py         |  4 +++-
 ...ble-to-post-configure-c61704185c57783d.yaml |  6 ++++++
 8 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 ansible/baremetal-compute-serial-console-post-config.yml
 create mode 100644 releasenotes/notes/add-serial-console-enable-to-post-configure-c61704185c57783d.yaml

diff --git a/ansible/baremetal-compute-serial-console-post-config.yml b/ansible/baremetal-compute-serial-console-post-config.yml
new file mode 100644
index 00000000..0e2538cd
--- /dev/null
+++ b/ansible/baremetal-compute-serial-console-post-config.yml
@@ -0,0 +1,6 @@
+---
+# This is a wrapper around baremetal-compute-serial-console which only runs the playbook when
+# ironic_serial_console_autoenable is set to true.
+
+- import_playbook: baremetal-compute-serial-console.yml
+  when: ironic_serial_console_autoenable | bool
\ No newline at end of file
diff --git a/ansible/group_vars/all/ironic b/ansible/group_vars/all/ironic
index f70d24cc..beb99a43 100644
--- a/ansible/group_vars/all/ironic
+++ b/ansible/group_vars/all/ironic
@@ -131,6 +131,9 @@ kolla_ironic_pxe_append_params: >
 ###############################################################################
 # Ironic Node Configuration
 
+# Whether or not to enable the serial consoles on post configure
+ironic_serial_console_autoenable: false
+
 # This defines the start of the range of TCP ports to used for the IPMI socat
 # serial consoles
 ironic_serial_console_tcp_pool_start: 30000
diff --git a/ansible/kolla-ansible.yml b/ansible/kolla-ansible.yml
index 4be1751b..e470a6c4 100644
--- a/ansible/kolla-ansible.yml
+++ b/ansible/kolla-ansible.yml
@@ -171,6 +171,24 @@
       set_fact:
         kolla_api_interface: "{{ kolla_bifrost_network_interface }}"
 
+- name: Validate configuration options for kolla-ansible
+  hosts: localhost
+  tags:
+    - kolla-ansible
+    - config-validation
+  tasks:
+    - name: Validate serial console configuration
+      block:
+        - name: Check ipmitool-socat is in enabled in kolla_ironic_enabled_console_interfaces
+          fail:
+            msg: >
+              kolla_ironic_enabled_console_interfaces must contain ipmitool-socat if you set
+              ironic_serial_console_autoenable to true
+          when:
+            - kolla_ironic_enabled_console_interfaces is defined
+            - "'ipmitool-socat' not in kolla_ironic_enabled_console_interfaces"
+      when: ironic_serial_console_autoenable | bool
+
 - name: Ensure Kolla Ansible is configured
   hosts: localhost
   tags:
diff --git a/doc/source/administration/bare-metal.rst b/doc/source/administration/bare-metal.rst
index 6bdd79fa..2d806945 100644
--- a/doc/source/administration/bare-metal.rst
+++ b/doc/source/administration/bare-metal.rst
@@ -131,3 +131,11 @@ You can optionally limit the nodes targeted by setting
 
 which should take the form of an `ansible host pattern
 <https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html>`_.
+
+Serial console auto-enable
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+To enable the serial consoles automatically on ``kayobe overcloud post configure``, you can set
+``ironic_serial_console_autoenable`` in ``etc/kayobe/ironic.yml``::
+
+    ironic_serial_console_autoenable: true
diff --git a/etc/kayobe/ironic.yml b/etc/kayobe/ironic.yml
index 4c0a0e42..4bfdbe1a 100644
--- a/etc/kayobe/ironic.yml
+++ b/etc/kayobe/ironic.yml
@@ -106,6 +106,9 @@
 ###############################################################################
 # Ironic Node Configuration
 
+# Whether or not to enable the serial consoles on post configure
+#ironic_serial_console_autoenable:
+
 # This defines the start of the range of TCP ports to used for the IPMI socat
 # serial consoles
 #ironic_serial_console_tcp_pool_start:
diff --git a/kayobe/cli/commands.py b/kayobe/cli/commands.py
index 4596af69..0aac9834 100644
--- a/kayobe/cli/commands.py
+++ b/kayobe/cli/commands.py
@@ -1257,6 +1257,7 @@ class OvercloudPostConfigure(KayobeAnsibleMixin, VaultMixin, Command):
       inspector service.
     * Register a provisioning network with glance.
     * Configure Grafana for control plane.
+    * Configure serial consoles for the ironic nodes
     """
 
     def take_action(self, parsed_args):
@@ -1264,7 +1265,8 @@ class OvercloudPostConfigure(KayobeAnsibleMixin, VaultMixin, Command):
         playbooks = _build_playbook_list(
             "overcloud-ipa-images", "overcloud-introspection-rules",
             "overcloud-introspection-rules-dell-lldp-workaround",
-            "provision-net", "overcloud-grafana-configure")
+            "provision-net", "overcloud-grafana-configure",
+            "baremetal-compute-serial-console-post-config")
         self.run_kayobe_playbooks(parsed_args, playbooks)
 
 
diff --git a/kayobe/tests/unit/cli/test_commands.py b/kayobe/tests/unit/cli/test_commands.py
index c3d45635..a7454538 100644
--- a/kayobe/tests/unit/cli/test_commands.py
+++ b/kayobe/tests/unit/cli/test_commands.py
@@ -1283,7 +1283,9 @@ class TestCase(unittest.TestCase):
                     utils.get_data_files_path("ansible", "overcloud-introspection-rules-dell-lldp-workaround.yml"),  # noqa
                     utils.get_data_files_path("ansible", "provision-net.yml"),
                     utils.get_data_files_path(
-                        "ansible", "overcloud-grafana-configure.yml")
+                        "ansible", "overcloud-grafana-configure.yml"),
+                    utils.get_data_files_path(
+                        "ansible", "baremetal-compute-serial-console-post-config.yml"),  # noqa
                 ],
             ),
         ]
diff --git a/releasenotes/notes/add-serial-console-enable-to-post-configure-c61704185c57783d.yaml b/releasenotes/notes/add-serial-console-enable-to-post-configure-c61704185c57783d.yaml
new file mode 100644
index 00000000..df0d8e9f
--- /dev/null
+++ b/releasenotes/notes/add-serial-console-enable-to-post-configure-c61704185c57783d.yaml
@@ -0,0 +1,6 @@
+---
+features:
+  - |
+    Added the ability to configure baremetal serial consoles during the
+    post configure step. This is controlled via ``ironic_serial_console_autoenable``
+    in ``etc/kayobe/ironic.yml``.
-- 
GitLab