Revert warning message in setup/gather_facts (#83427)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/83366/head
Abhijeet Kasurde 6 months ago committed by GitHub
parent cf265eb14d
commit 6e8a7ed327
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,2 +1,3 @@
---
bugfixes:
- setup/gather_facts will now warn and skip missing ``sysctl`` instead of being a fatal error.
- setup/gather_facts will skip missing ``sysctl`` instead of being a fatal error (https://github.com/ansible/ansible/pull/81297).

@ -1348,14 +1348,13 @@ class AnsibleModule(object):
# and we don't want to break modules unnecessarily
return None
def get_bin_path(self, arg, required=False, opt_dirs=None, warning=None):
def get_bin_path(self, arg, required=False, opt_dirs=None):
'''
Find system executable in PATH.
:param arg: The executable to find.
:param required: if the executable is not found and required is ``True``, fail_json
:param opt_dirs: optional list of directories to search in addition to ``PATH``
:param warning: optional message when arg not found, only works when required=False
:returns: if found return full path; otherwise return original arg, unless 'warning' then return None
:raises: Sysexit: if arg is not found and required=True (via fail_json)
'''
@ -1366,8 +1365,6 @@ class AnsibleModule(object):
except ValueError as e:
if required:
self.fail_json(msg=to_text(e))
elif warning is not None:
self.warn("Unable to find %s, %s" % (arg, warning))
return bin_path

@ -129,7 +129,7 @@ class AIXHardware(Hardware):
rc, out, err = self.module.run_command("/usr/sbin/lsattr -El sys0 -a fwversion")
data = out.split()
dmi_facts['firmware_version'] = data[1].strip('IBM,')
lsconf_path = self.module.get_bin_path("lsconf", warning="dmi facts skipped")
lsconf_path = self.module.get_bin_path("lsconf")
if lsconf_path:
rc, out, err = self.module.run_command(lsconf_path)
if rc == 0 and out:
@ -160,9 +160,8 @@ class AIXHardware(Hardware):
"""
vgs_facts = {}
warn = "vgs facts skipped"
lsvg_path = self.module.get_bin_path("lsvg", warning=warn)
xargs_path = self.module.get_bin_path("xargs", warning=warn)
lsvg_path = self.module.get_bin_path("lsvg")
xargs_path = self.module.get_bin_path("xargs")
cmd = "%s -o | %s %s -p" % (lsvg_path, xargs_path, lsvg_path)
if lsvg_path and xargs_path:
rc, out, err = self.module.run_command(cmd, use_unsafe_shell=True)
@ -195,7 +194,7 @@ class AIXHardware(Hardware):
# AIX does not have mtab but mount command is only source of info (or to use
# api calls to get same info)
mount_path = self.module.get_bin_path('mount', warning="skipping mount facts")
mount_path = self.module.get_bin_path('mount')
if mount_path:
rc, mount_out, err = self.module.run_command(mount_path)
if mount_out:
@ -234,9 +233,8 @@ class AIXHardware(Hardware):
device_facts = {}
device_facts['devices'] = {}
warn = 'device facts are skipped'
lsdev_cmd = self.module.get_bin_path('lsdev', warning=warn)
lsattr_cmd = self.module.get_bin_path('lsattr', warning=warn)
lsdev_cmd = self.module.get_bin_path('lsdev')
lsattr_cmd = self.module.get_bin_path('lsattr')
if lsdev_cmd and lsattr_cmd:
rc, out_lsdev, err = self.module.run_command(lsdev_cmd)

@ -95,10 +95,7 @@ class DarwinHardware(Hardware):
total_used = 0
page_size = 4096
vm_stat_command = self.module.get_bin_path(
'vm_stat',
warning='falling back to sysctl for memtotal_mb, default to 0 for memfree_mb'
)
vm_stat_command = self.module.get_bin_path('vm_stat')
if vm_stat_command is None:
return memory_facts
@ -136,7 +133,7 @@ class DarwinHardware(Hardware):
# On Darwin, the default format is annoying to parse.
# Use -b to get the raw value and decode it.
sysctl_cmd = self.module.get_bin_path('sysctl', warning='skipping uptime facts')
sysctl_cmd = self.module.get_bin_path('sysctl')
if not sysctl_cmd:
return {}

@ -304,7 +304,7 @@ class LinuxHardware(Hardware):
)
except AttributeError:
# In Python < 3.3, os.sched_getaffinity() is not available
nproc_cmd = self.module.get_bin_path('nproc', warning="skipping processor_nproc")
nproc_cmd = self.module.get_bin_path('nproc')
if nproc_cmd is not None:
rc, out, _err = self.module.run_command(nproc_cmd)
if rc == 0:
@ -391,10 +391,7 @@ class LinuxHardware(Hardware):
'product_version': 'system-version',
'system_vendor': 'system-manufacturer',
}
dmi_bin = self.module.get_bin_path(
'dmidecode',
warning="skipping dmi facts"
)
dmi_bin = self.module.get_bin_path('dmidecode')
if dmi_bin is None:
dmi_facts = dict.fromkeys(
DMI_DICT.keys(),
@ -865,10 +862,7 @@ class LinuxHardware(Hardware):
""" Get LVM Facts if running as root and lvm utils are available """
lvm_facts = {'lvm': 'N/A'}
vgs_cmd = self.module.get_bin_path(
'vgs',
warning="skipping LVM facts"
)
vgs_cmd = self.module.get_bin_path('vgs')
if vgs_cmd is None:
return lvm_facts

@ -161,10 +161,7 @@ class NetBSDHardware(Hardware):
def get_uptime_facts(self):
# On NetBSD, we need to call sysctl with -n to get this value as an int.
sysctl_cmd = self.module.get_bin_path(
'sysctl',
warning="skipping uptime facts"
)
sysctl_cmd = self.module.get_bin_path('sysctl')
if sysctl_cmd is None:
return {}

@ -112,10 +112,7 @@ class OpenBSDHardware(Hardware):
def get_uptime_facts(self):
# On openbsd, we need to call it with -n to get this value as an int.
sysctl_cmd = self.module.get_bin_path(
'sysctl',
warning="skipping uptime facts"
)
sysctl_cmd = self.module.get_bin_path('sysctl')
if sysctl_cmd is None:
return {}

@ -174,8 +174,7 @@ class SunOSHardware(Hardware):
prtdiag_path = self.module.get_bin_path(
"prtdiag",
opt_dirs=[platform_sbin],
warning="skipping dmi facts"
opt_dirs=[platform_sbin]
)
if prtdiag_path is None:
return dmi_facts

@ -31,10 +31,7 @@ class AIXNetwork(GenericBsdIfconfigNetwork):
def get_default_interfaces(self, route_path):
interface = dict(v4={}, v6={})
netstat_path = self.module.get_bin_path(
'netstat',
warning="skipping default interface facts"
)
netstat_path = self.module.get_bin_path('netstat')
if netstat_path is None:
return interface['v4'], interface['v6']

@ -47,10 +47,7 @@ class FcWwnInitiatorFactCollector(BaseFactCollector):
elif sys.platform.startswith('sunos'):
# on solaris 10 or solaris 11 should use `fcinfo hba-port`
# TBD (not implemented): on solaris 9 use `prtconf -pv`
cmd = module.get_bin_path(
'fcinfo',
warning="skipping fibre wwn initiator facts"
)
cmd = module.get_bin_path('fcinfo')
if cmd:
cmd = cmd + " hba-port"
rc, fcinfo_out, err = module.run_command(cmd)
@ -62,14 +59,8 @@ class FcWwnInitiatorFactCollector(BaseFactCollector):
data = line.split(' ')
fc_facts['fibre_channel_wwn'].append(data[-1].rstrip())
elif sys.platform.startswith('aix'):
cmd = module.get_bin_path(
'lsdev',
warning="skipping fibre wwn initiator facts"
)
lscfg_cmd = module.get_bin_path(
'lscfg',
warning="skipping fibre wwn initiator facts"
)
cmd = module.get_bin_path('lsdev')
lscfg_cmd = module.get_bin_path('lscfg')
if cmd and lscfg_cmd:
# get list of available fibre-channel devices (fcs)
cmd = cmd + " -Cc adapter -l fcs*"
@ -90,14 +81,10 @@ class FcWwnInitiatorFactCollector(BaseFactCollector):
data = line.split('.')
fc_facts['fibre_channel_wwn'].append(data[-1].rstrip())
elif sys.platform.startswith('hp-ux'):
cmd = module.get_bin_path(
'ioscan',
warning="skipping fibre wwn initiator facts"
)
cmd = module.get_bin_path('ioscan')
fcmsu_cmd = module.get_bin_path(
'fcmsutil',
opt_dirs=['/opt/fcms/bin'],
warning="skipping fibre wwn initiator facts"
)
# go ahead if we have both commands available
if cmd and fcmsu_cmd:

@ -34,18 +34,12 @@ class GenericBsdIfconfigNetwork(Network):
def populate(self, collected_facts=None):
network_facts = {}
ifconfig_path = self.module.get_bin_path(
'ifconfig',
warning="skipping network facts"
)
ifconfig_path = self.module.get_bin_path('ifconfig')
if ifconfig_path is None:
return network_facts
route_path = self.module.get_bin_path(
'route',
warning="skipping network facts"
)
route_path = self.module.get_bin_path('route')
if route_path is None:
return network_facts

@ -31,8 +31,7 @@ class HPUXNetwork(Network):
network_facts = {}
netstat_path = self.module.get_bin_path(
'netstat',
opt_dirs=['/usr/bin'],
warning="skipping network facts"
opt_dirs=['/usr/bin']
)
if netstat_path is None:
@ -52,8 +51,7 @@ class HPUXNetwork(Network):
default_interfaces = {}
netstat_path = self.module.get_bin_path(
'netstat',
opt_dirs=['/usr/bin'],
warning="skipping default interface facts"
opt_dirs=['/usr/bin']
)
if netstat_path is None:
@ -73,8 +71,7 @@ class HPUXNetwork(Network):
interfaces = {}
netstat_path = self.module.get_bin_path(
'netstat',
opt_dirs=['/usr/bin'],
warning="skipping default interface info facts"
opt_dirs=['/usr/bin']
)
if netstat_path is None:

@ -63,10 +63,7 @@ class HurdPfinetNetwork(Network):
def populate(self, collected_facts=None):
network_facts = {}
fsysopts_path = self.module.get_bin_path(
'fsysopts',
warning="skipping network facts"
)
fsysopts_path = self.module.get_bin_path('fsysopts')
if fsysopts_path is None:
return network_facts

@ -79,10 +79,7 @@ class IscsiInitiatorNetworkCollector(NetworkCollector):
iscsi_facts['iscsi_iqn'] = line.split('=', 1)[1]
break
elif sys.platform.startswith('aix'):
cmd = module.get_bin_path(
'lsattr',
warning="skipping iscsi initiator facts"
)
cmd = module.get_bin_path('lsattr')
if cmd is None:
return iscsi_facts
@ -95,8 +92,7 @@ class IscsiInitiatorNetworkCollector(NetworkCollector):
elif sys.platform.startswith('hp-ux'):
cmd = module.get_bin_path(
'iscsiutil',
opt_dirs=['/opt/iscsi/bin'],
warning="skipping iscsi initiator facts"
opt_dirs=['/opt/iscsi/bin']
)
if cmd is None:
return iscsi_facts

@ -24,13 +24,11 @@ class FacterFactCollector(BaseFactCollector):
def find_facter(self, module):
facter_path = module.get_bin_path(
'facter',
opt_dirs=['/opt/puppetlabs/bin'],
warning="falling back to cfacter to gather facter facts"
opt_dirs=['/opt/puppetlabs/bin']
)
cfacter_path = module.get_bin_path(
'cfacter',
opt_dirs=['/opt/puppetlabs/bin'],
warning="skipping facter facts"
opt_dirs=['/opt/puppetlabs/bin']
)
# Prefer to use cfacter if available

@ -37,8 +37,7 @@ class OhaiFactCollector(BaseFactCollector):
def find_ohai(self, module):
return module.get_bin_path(
'ohai',
warning="skipping ohai facts"
'ohai'
)
def run_ohai(self, module, ohai_path):

@ -23,7 +23,7 @@ from ansible.module_utils.common.text.converters import to_text
def get_sysctl(module, prefixes):
sysctl = dict()
sysctl_cmd = module.get_bin_path('sysctl', warning='skipping sysctl based facts')
sysctl_cmd = module.get_bin_path('sysctl')
if sysctl_cmd is not None:
cmd = [sysctl_cmd]

@ -1,19 +0,0 @@
# Copyright: Contributors to the Ansible project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
import json
import pytest
@pytest.mark.parametrize("stdin", [{}], indirect=["stdin"])
def test_get_bin_path_warning(am, capfd):
am.get_bin_path("non_existent_cmd", warning="skipping non_existent_cmd")
with pytest.raises(SystemExit):
am.exit_json()
out, dummy = capfd.readouterr()
expected_warning = ["Unable to find non_existent_cmd, skipping non_existent_cmd"]
assert json.loads(out)["warnings"] == expected_warning

@ -89,7 +89,7 @@ FCMSUTIL_OUT = """
"""
def mock_get_bin_path(cmd, required=False, opt_dirs=None, warning=None):
def mock_get_bin_path(cmd, required=False, opt_dirs=None):
cmds = {
'lsdev': '/usr/sbin/lsdev',
'lscfg': '/usr/sbin/lscfg',

@ -9,7 +9,7 @@ import pytest
from ansible.module_utils.facts.network import generic_bsd
def mock_get_bin_path(command, warning=None):
def mock_get_bin_path(command):
cmds = {
'ifconfig': 'fake/ifconfig',
'route': 'fake/route',

Loading…
Cancel
Save