Repository: RedHatInsights/insights-core

Issue:
Enhance parser "corosync_cmapctl"
The clear schedule event way is different on RHEL 7 and RHEL 8.
On RHEL 7, it is 
```
corosync-cmapctl -d runtime.schedmiss.timestamp && corosync-cmapctl -d runtime.schedmiss.delay
```
On RHEL 8, it is 
```
corosync-cmapctl -C schedmiss
```
So I'll enhance the parser to run it with some dependency.



Discussion:

Resolving patch:
diff --git a/insights/parsers/corosync_cmapctl.py b/insights/parsers/corosync_cmapctl.py
--- a/insights/parsers/corosync_cmapctl.py
+++ b/insights/parsers/corosync_cmapctl.py
@@ -44,10 +44,6 @@ class CorosyncCmapctl(CommandParser, dict):
     def __init__(self, context):
         super(CorosyncCmapctl, self).__init__(context, extra_bad_lines=['corosync-cmapctl: invalid option'])
 
-    def get_stats_schedmiss(self):
-        """ Return a dict of the stats.schedmiss info """
-        return dict((key, value) for key, value in self.items() if key.startswith('stats.schedmiss'))
-
     def parse_content(self, content):
         if not content:
             raise SkipException
diff --git a/insights/specs/default.py b/insights/specs/default.py
--- a/insights/specs/default.py
+++ b/insights/specs/default.py
@@ -29,7 +29,7 @@
 from insights.combiners.cloud_provider import CloudProvider
 from insights.combiners.satellite_version import SatelliteVersion
 from insights.combiners.services import Services
-from insights.components.rhel_version import IsRhel8
+from insights.components.rhel_version import IsRhel8, IsRhel7
 from insights.specs import Specs
 
 
@@ -199,12 +199,15 @@ def is_ceph_monitor(broker):
     cobbler_settings = first_file(["/etc/cobbler/settings", "/conf/cobbler/settings"])
     cobbler_modules_conf = first_file(["/etc/cobbler/modules.conf", "/conf/cobbler/modules.conf"])
     corosync = simple_file("/etc/sysconfig/corosync")
-    corosync_cmapctl = foreach_execute(
-        [
-            "/usr/sbin/corosync-cmapctl",
-            '/usr/sbin/corosync-cmapctl -m stats "stats.schedmiss."',
-            '/usr/sbin/corosync-cmapctl -C schedmiss'
-        ], "%s")
+
+    @datasource([IsRhel7, IsRhel8])
+    def corosync_cmapctl_cmd_list(broker):
+        if broker.get(IsRhel7):
+            return ["/usr/sbin/corosync-cmapctl", 'corosync-cmapctl -d runtime.schedmiss.timestamp', 'corosync-cmapctl -d runtime.schedmiss.delay']
+        if broker.get(IsRhel8):
+            return ["/usr/sbin/corosync-cmapctl", '/usr/sbin/corosync-cmapctl -m stats', '/usr/sbin/corosync-cmapctl -C schedmiss']
+        raise SkipComponent()
+    corosync_cmapctl = foreach_execute(corosync_cmapctl_cmd_list, "%s")
     corosync_conf = simple_file("/etc/corosync/corosync.conf")
     cpu_cores = glob_file("sys/devices/system/cpu/cpu[0-9]*/online")
     cpu_siblings = glob_file("sys/devices/system/cpu/cpu[0-9]*/topology/thread_siblings_list")


Test patch:
diff --git a/insights/parsers/tests/test_corosync_cmapctl.py b/insights/parsers/tests/test_corosync_cmapctl.py
--- a/insights/parsers/tests/test_corosync_cmapctl.py
+++ b/insights/parsers/tests/test_corosync_cmapctl.py
@@ -65,6 +65,20 @@
 stats.schedmiss.9.timestamp (u64) = 5106540630601
 """.strip()
 
+COROSYNC_CONTENT_6 = """
+config.totemconfig_reload_in_progress (u8) = 0
+internal_configuration.service.0.name (str) = corosync_cmap
+internal_configuration.service.0.ver (u32) = 0
+internal_configuration.service.1.name (str) = corosync_cfg
+internal_configuration.service.1.ver (u32) = 0
+internal_configuration.service.2.name (str) = corosync_cpg
+internal_configuration.service.2.ver (u32) = 0
+internal_configuration.service.3.name (str) = corosync_quorum
+internal_configuration.service.3.ver (u32) = 0
+runtime.schedmiss.delay (flt) = 2282.403320
+runtime.schedmiss.timestamp (u64) = 1589895874915
+""".strip()
+
 
 def test_corosync_doc_examples():
     env = {
@@ -76,11 +90,10 @@ def test_corosync_doc_examples():
 
 def test_state_schemiss():
     corodata = corosync_cmapctl.CorosyncCmapctl(context_wrap(COROSYNC_CONTENT_2, path='corosync-cmapctl_-m_stats_stats.schedmiss'))
-    schemiss_dict = corodata.get_stats_schedmiss()
-    assert 'stats.schedmiss.0.delay' in schemiss_dict
-    assert schemiss_dict['stats.schedmiss.0.delay'] == '2023.957031'
-    assert schemiss_dict['stats.schedmiss.0.timestamp'] == '5106558848098'
-    assert len(schemiss_dict) == 20
+    assert 'stats.schedmiss.0.delay' in corodata
+    assert corodata['stats.schedmiss.0.delay'] == '2023.957031'
+    assert corodata['stats.schedmiss.0.timestamp'] == '5106558848098'
+    assert len(corodata) == 20
 
 
 def test_exception():
@@ -90,3 +103,11 @@ def test_exception():
         corosync_cmapctl.CorosyncCmapctl(context_wrap(COROSYNC_CONTENT_4, path="corosync_cmpctl_-C"))
     with pytest.raises(ParseException):
         corosync_cmapctl.CorosyncCmapctl(context_wrap(COROSYNC_CONTENT_5, path="corosync_cmpctl"))
+
+
+def test_runtime_schemiss():
+    corodata = corosync_cmapctl.CorosyncCmapctl(context_wrap(COROSYNC_CONTENT_6, path='corosync-cmapctl'))
+    assert "runtime.schedmiss.delay" in corodata
+    assert corodata['runtime.schedmiss.delay'] == '2282.403320'
+    assert "runtime.schedmiss.timestamp" in corodata
+    assert corodata['runtime.schedmiss.timestamp'] == '1589895874915'