From 4af5fd172bd091dbc051c7c95808cbbfb1b645ea Mon Sep 17 00:00:00 2001
From: Matt Crees <mattc@stackhpc.com>
Date: Fri, 6 Jan 2023 15:58:25 +0000
Subject: [PATCH] Add command to run config validation

Adds the command ``kayobe overcloud service configuration validate`` to
run the ``oslo-config-validator`` on all hosts via Kolla-Ansible. The
output directory of the results is specified with the flag
``--output-dir``.

Change-Id: I5d5d16eeabe69e8659e33722165928df096b3559
---
 doc/source/administration/overcloud.rst       | 11 ++++++++
 kayobe/cli/commands.py                        | 28 +++++++++++++++++--
 ...un-config-validation-351df61eb6094d66.yaml |  5 ++++
 setup.cfg                                     |  3 ++
 4 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100644 releasenotes/notes/add-command-to-run-config-validation-351df61eb6094d66.yaml

diff --git a/doc/source/administration/overcloud.rst b/doc/source/administration/overcloud.rst
index 6be18083..38065923 100644
--- a/doc/source/administration/overcloud.rst
+++ b/doc/source/administration/overcloud.rst
@@ -218,6 +218,17 @@ specified directory, with one subdirectory per container. This command may be
 followed by ``kayobe overcloud service configuration save`` to gather the
 generated configuration to the Ansible control host.
 
+Validating Overcloud Service Configuration
+==========================================
+
+Issues can arise in Kolla Ansible deployments when incorrect options are used
+in configuration files. This is because OpenStack services will ignore unknown
+options. It is also important to keep on top of deprecated options that may be
+removed in the future. The ``oslo-config-validator`` can be used to check both
+of these. This command will run it on the OpenStack control plane services::
+
+    (kayobe) $ kayobe overcloud service configuration validate --output-dir /path/to/save/results
+
 Performing Database Backups
 ===========================
 
diff --git a/kayobe/cli/commands.py b/kayobe/cli/commands.py
index c44b642c..71ac2f5c 100644
--- a/kayobe/cli/commands.py
+++ b/kayobe/cli/commands.py
@@ -1320,7 +1320,7 @@ class OvercloudServiceConfigurationGenerate(KayobeAnsibleMixin,
     def get_parser(self, prog_name):
         parser = super(OvercloudServiceConfigurationGenerate,
                        self).get_parser(prog_name)
-        group = parser.add_argument_group("Service Configuration")
+        group = parser.add_argument_group("Service Configuration Generate")
         group.add_argument("--node-config-dir", required=True,
                            help="the directory to store the config files on "
                                 "the remote node (required)")
@@ -1346,6 +1346,30 @@ class OvercloudServiceConfigurationGenerate(KayobeAnsibleMixin,
                                          extra_vars=extra_vars)
 
 
+class OvercloudServiceConfigurationValidate(KayobeAnsibleMixin,
+                                            KollaAnsibleMixin, VaultMixin,
+                                            Command):
+    """Runs oslo config validator on the OpenStack control plane services."""
+
+    def get_parser(self, prog_name):
+        parser = super(OvercloudServiceConfigurationValidate,
+                       self).get_parser(prog_name)
+        group = parser.add_argument_group("Service Configuration Validate")
+        group.add_argument("--output-dir", required=True,
+                           help="the directory to store the results of running"
+                                "the config validator (required)")
+        return parser
+
+    def take_action(self, parsed_args):
+        self.app.LOG.debug("Validating overcloud service configuration")
+        extra_vars = {}
+        if parsed_args.output_dir:
+            extra_vars[
+                "service_config_validate_output_dir"] = parsed_args.output_dir
+        self.run_kolla_ansible_overcloud(parsed_args, "validate-config",
+                                         extra_vars=extra_vars)
+
+
 class OvercloudServiceConfigurationSave(KayobeAnsibleMixin, VaultMixin,
                                         Command):
     """Gather and save the overcloud service configuration files.
@@ -1359,7 +1383,7 @@ class OvercloudServiceConfigurationSave(KayobeAnsibleMixin, VaultMixin,
     def get_parser(self, prog_name):
         parser = super(OvercloudServiceConfigurationSave, self).get_parser(
             prog_name)
-        group = parser.add_argument_group("Service configuration")
+        group = parser.add_argument_group("Service Configuration Save")
         group.add_argument("--exclude",
                            help="optional comma-separated list of patterns "
                                 "matching filenames to exclude")
diff --git a/releasenotes/notes/add-command-to-run-config-validation-351df61eb6094d66.yaml b/releasenotes/notes/add-command-to-run-config-validation-351df61eb6094d66.yaml
new file mode 100644
index 00000000..5ea5e740
--- /dev/null
+++ b/releasenotes/notes/add-command-to-run-config-validation-351df61eb6094d66.yaml
@@ -0,0 +1,5 @@
+---
+features:
+  - |
+    Adds the command ``kayobe overcloud service configuration validate`` to run
+    the ``oslo-config-validator`` on all hosts via Kolla-Ansible.
diff --git a/setup.cfg b/setup.cfg
index 58126dbc..230c83dc 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -70,6 +70,7 @@ kayobe.cli=
     overcloud_provision = kayobe.cli.commands:OvercloudProvision
     overcloud_service_configuration_save = kayobe.cli.commands:OvercloudServiceConfigurationSave
     overcloud_service_configuration_generate = kayobe.cli.commands:OvercloudServiceConfigurationGenerate
+    overcloud_service_configuration_validate = kayobe.cli.commands:OvercloudServiceConfigurationValidate
     overcloud_service_deploy = kayobe.cli.commands:OvercloudServiceDeploy
     overcloud_service_deploy_containers = kayobe.cli.commands:OvercloudServiceDeployContainers
     overcloud_service_destroy = kayobe.cli.commands:OvercloudServiceDestroy
@@ -168,6 +169,8 @@ kayobe.cli.overcloud_service_configuration_save =
     hooks = kayobe.cli.commands:HookDispatcher
 kayobe.cli.overcloud_service_configuration_generate =
     hooks = kayobe.cli.commands:HookDispatcher
+kayobe.cli.overcloud_service_configuration_validate =
+    hooks = kayobe.cli.commands:HookDispatcher
 kayobe.cli.overcloud_service_deploy =
     hooks = kayobe.cli.commands:HookDispatcher
 kayobe.cli.overcloud_service_deploy_containers =
-- 
GitLab