aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2022-04-20 11:19:30 -0400
committerJake Hunsaker <jhunsake@redhat.com>2022-05-09 11:21:16 -0400
commit8aec430fd27785aa85a6e677151a2bb76da244dc (patch)
treef6b857846f1794b68ea0e244c4b3092bb4cddee3
parent9b10abcdd4aaa41e2549438d5bc52ece86dcb21f (diff)
downloadsos-8aec430fd27785aa85a6e677151a2bb76da244dc.tar.gz
[collect] Add cluster profile for RHOSP
Adds a cluster profile for Red Hat OpenStack Platform to identify controller and (optionally) compute nodes to collect sos reports from. Note that this adds a dependency on pyyaml to sos. This should be considered a weak dependency by downstreams. As such, it is added as a 'Recommends' in `sos.spec`. pip does not have the concept of 'weak dependencies', and so is added as a regular requirement in `setup.py`. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--.cirrus.yml2
-rw-r--r--requirements.txt1
-rw-r--r--setup.py2
-rw-r--r--sos.spec1
-rw-r--r--sos/collector/clusters/openstack.py68
5 files changed, 72 insertions, 2 deletions
diff --git a/.cirrus.yml b/.cirrus.yml
index 1592b5a3..8517fc47 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -121,7 +121,7 @@ report_stageone_task:
dnf -y remove sos
dnf -y install python3-pip ethtool
fi
- setup_script: &setup 'pip3 install avocado-framework==94.0 python-magic'
+ setup_script: &setup 'pip3 install avocado-framework==94.0 python-magic pyyaml'
# run the unittests separately as they require a different PYTHONPATH in
# order for the imports to work properly under avocado
unittest_script: PYTHONPATH=. avocado run tests/unittests/
diff --git a/requirements.txt b/requirements.txt
index 4c387efe..c6ba1162 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,3 +3,4 @@ coverage>=4.0.3
Sphinx>=1.3.5
pexpect>=4.0.0
python_magic>=0.4.20
+pyyaml
diff --git a/setup.py b/setup.py
index 5c1fa318..2a70802d 100644
--- a/setup.py
+++ b/setup.py
@@ -107,7 +107,7 @@ setup(
],
cmdclass=cmdclass,
command_options=command_options,
- requires=['pexpect', 'python_magic']
+ requires=['pexpect', 'python_magic', 'pyyaml']
)
diff --git a/sos.spec b/sos.spec
index 02a97e43..8ae23d5a 100644
--- a/sos.spec
+++ b/sos.spec
@@ -17,6 +17,7 @@ Requires: tar
Requires: xz
Requires: python3-pexpect
Requires: python3-magic
+Recommends: python3-pyyaml
Obsoletes: sos-collector <= 1.9
%description
diff --git a/sos/collector/clusters/openstack.py b/sos/collector/clusters/openstack.py
new file mode 100644
index 00000000..a5e0aad9
--- /dev/null
+++ b/sos/collector/clusters/openstack.py
@@ -0,0 +1,68 @@
+# Copyright Red Hat 2022, Jake Hunsaker <jhunsake@redhat.com>
+
+# This file is part of the sos project: https://github.com/sosreport/sos
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# version 2 of the GNU General Public License.
+#
+# See the LICENSE file in the source distribution for further information.
+
+import yaml
+
+from sos.collector.clusters import Cluster
+
+INVENTORY = "/var/lib/mistral/overcloud/tripleo-ansible-inventory.yaml"
+
+
+class rhosp(Cluster):
+ """
+ This cluster profile is for use with Red Hat OpenStack Platform
+ environments.
+
+ Different types of nodes may be enumerated by toggling the various profile
+ options such as Controllers and Compute nodes. By default, only Controller
+ nodes are enumerated.
+
+ Node enumeration is done by inspecting the ansible inventory file used for
+ deployment of the environment. This is canonically located at
+ /var/lib/mistral/overcloud/tripleo-ansible-inventory.yaml. Similarly, the
+ presence of this file on the primary node is what triggers the automatic
+ enablement of this profile.
+
+ Special consideration should be taken for where `sos collect` is being run
+ from, in that the hostnames of the enumerated nodes must be resolveable
+ from that system - not just from the primary node from which those nodes
+ are discovered. If this is not possible, consider enabling the `use-ip`
+ cluster option to instead have this profile source the IP addresses of the
+ nodes in question.
+ """
+
+ cluster_name = 'Red Hat OpenStack Platform'
+ option_list = [
+ ('use-ip', False, 'use IP addresses instead of hostnames to connect'),
+ ('controller', True, 'collect reports from controller nodes'),
+ ('compute', False, 'collect reports from compute nodes')
+ ]
+
+ def check_enabled(self):
+ return self.primary.file_exists(INVENTORY, need_root=True)
+
+ def get_nodes(self):
+ _nodes = []
+ _addr_field = ('external_ip' if self.get_option('use-ip') else
+ 'ctlplane_hostname')
+ try:
+ _inv = yaml.safe_load(self.primary.read_file(INVENTORY))
+ except Exception as err:
+ self.log_info("Error parsing yaml: %s" % err)
+ raise Exception("Could not parse yaml for node addresses")
+ try:
+ for _t in ['Controller', 'Compute']:
+ # fields are titled in the yaml, but our opts are lowercase
+ if self.get_option(_t.lower()):
+ for host in _inv[_t]['hosts'].keys():
+ _nodes.append(_inv[_t]['hosts'][host][_addr_field])
+ except Exception as err:
+ self.log_error("Error getting %s host addresses: %s" % (_t, err))
+ return _nodes