From 9d81ad6423bba3fbbf04c3a837b725d55ca4f05a Mon Sep 17 00:00:00 2001 From: Jasper Lievisse Adriaanse Date: Tue, 1 Nov 2016 10:29:07 +0100 Subject: [PATCH] Rework how OpenBSD processor facts are resolved (cherry picked from commit c17dad0def2fa86733c07610189e94486e056203) --- lib/ansible/module_utils/facts.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 0f6d1e70bce..2229251755e 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -1574,7 +1574,6 @@ class OpenBSDHardware(Hardware): - devices """ platform = 'OpenBSD' - DMESG_BOOT = '/var/run/dmesg.boot' def populate(self): self.sysctl = self.get_sysctl() @@ -1632,19 +1631,19 @@ class OpenBSDHardware(Hardware): def get_processor_facts(self): processor = [] - dmesg_boot = get_file_content(OpenBSDHardware.DMESG_BOOT) - if not dmesg_boot: - rc, dmesg_boot, err = self.module.run_command("/sbin/dmesg") - i = 0 - for line in dmesg_boot.splitlines(): - if line.split(' ', 1)[0] == 'cpu%i:' % i: - processor.append(line.split(' ', 1)[1]) - i = i + 1 - processor_count = i + for i in range(int(self.sysctl['hw.ncpu'])): + processor.append(self.sysctl['hw.model']) + self.facts['processor'] = processor - self.facts['processor_count'] = processor_count - # I found no way to figure out the number of Cores per CPU in OpenBSD - self.facts['processor_cores'] = 'NA' + # The following is partly a lie because there is no reliable way to + # determine the number of physical CPUs in the system. We can only + # query the number of logical CPUs, which hides the number of cores. + # On amd64/i386 we could try to inspect the smt/core/package lines in + # dmesg, however even those have proven to be unreliable. + # So take a shortcut and report the logical number of processors in + # 'processor_count' and 'processor_cores' and leave it at that. + self.facts['processor_count'] = self.sysctl['hw.ncpu'] + self.facts['processor_cores'] = self.sysctl['hw.ncpu'] def get_device_facts(self): devices = []