[facts] add hpux fc info, refactor aix and solaris code (#57406)

* correctly parse device from string
* check for command presence before running them
* check for command presence and return code for solaris and aix as well
* add changelog
This commit is contained in:
Anatoly Pugachev 2021-04-28 17:17:19 +03:00 committed by GitHub
parent 7b03ebf939
commit 04e57d28e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 31 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- facts - add fiber channel facts for HP-UX (https://github.com/ansible/ansible/pull/57406)

View file

@ -49,24 +49,26 @@ class FcWwnInitiatorFactCollector(BaseFactCollector):
TBD (not implemented): on solaris 9 use `prtconf -pv`
"""
cmd = module.get_bin_path('fcinfo')
if cmd:
cmd = cmd + " hba-port"
rc, fcinfo_out, err = module.run_command(cmd)
"""
# fcinfo hba-port | grep "Port WWN"
HBA Port WWN: 10000090fa1658de
"""
if fcinfo_out:
if rc == 0 and fcinfo_out:
for line in fcinfo_out.splitlines():
if 'Port WWN' in line:
data = line.split(' ')
fc_facts['fibre_channel_wwn'].append(data[-1].rstrip())
elif sys.platform.startswith('aix'):
# get list of available fibre-channel devices (fcs)
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*"
rc, lsdev_out, err = module.run_command(cmd)
if lsdev_out:
lscfg_cmd = module.get_bin_path('lscfg')
if rc == 0 and lsdev_out:
for line in lsdev_out.splitlines():
# if device is available (not in defined state), get its WWN
if 'Available' in line:
@ -76,8 +78,32 @@ class FcWwnInitiatorFactCollector(BaseFactCollector):
# example output
# lscfg -vpl fcs3 | grep "Network Address"
# Network Address.............10000090FA551509
if rc == 0 and lscfg_out:
for line in lscfg_out.splitlines():
if 'Network Address' in line:
data = line.split('.')
fc_facts['fibre_channel_wwn'].append(data[-1].rstrip())
elif sys.platform.startswith('hp-ux'):
cmd = module.get_bin_path('ioscan')
fcmsu_cmd = module.get_bin_path('fcmsutil', opt_dirs=['/opt/fcms/bin'])
# go ahead if we have both commands available
if cmd and fcmsu_cmd:
# ioscan / get list of available fibre-channel devices (fcd)
cmd = cmd + " -fnC FC"
rc, ioscan_out, err = module.run_command(cmd)
if rc == 0 and ioscan_out:
for line in ioscan_out.splitlines():
line = line.strip()
if '/dev/fcd' in line:
dev = line.split(' ')
# get device information
cmd = fcmsu_cmd + " %s" % dev[0]
rc, fcmsutil_out, err = module.run_command(cmd)
# lookup the following line
# N_Port Port World Wide Name = 0x50060b00006975ec
if rc == 0 and fcmsutil_out:
for line in fcmsutil_out.splitlines():
if 'N_Port Port World Wide Name' in line:
data = line.split('=')
fc_facts['fibre_channel_wwn'].append(data[-1].strip())
return fc_facts

View file

@ -54,8 +54,43 @@ HBA Port WWN: 10000090fa1658de
NPIV Not Supported
"""
IOSCAN_OUT = """
Class I H/W Path Driver S/W State H/W Type Description
==================================================================
fc 0 2/0/10/1/0 fcd CLAIMED INTERFACE HP AB379-60101 4Gb Dual Port PCI/PCI-X Fibre Channel Adapter (FC Port 1)
/dev/fcd0
"""
def mock_get_bin_path(cmd, required=False):
FCMSUTIL_OUT = """
Vendor ID is = 0x1077
Device ID is = 0x2422
PCI Sub-system Vendor ID is = 0x103C
PCI Sub-system ID is = 0x12D7
PCI Mode = PCI-X 133 MHz
ISP Code version = 5.4.0
ISP Chip version = 3
Topology = PTTOPT_FABRIC
Link Speed = 4Gb
Local N_Port_id is = 0x010300
Previous N_Port_id is = None
N_Port Node World Wide Name = 0x50060b00006975ed
N_Port Port World Wide Name = 0x50060b00006975ec
Switch Port World Wide Name = 0x200300051e046c0f
Switch Node World Wide Name = 0x100000051e046c0f
N_Port Symbolic Port Name = server1_fcd0
N_Port Symbolic Node Name = server1_HP-UX_B.11.31
Driver state = ONLINE
Hardware Path is = 2/0/10/1/0
Maximum Frame Size = 2048
Driver-Firmware Dump Available = NO
Driver-Firmware Dump Timestamp = N/A
TYPE = PFC
NPIV Supported = YES
Driver Version = @(#) fcd B.11.31.1103 Dec 6 2010
"""
def mock_get_bin_path(cmd, required=False, opt_dirs=None):
result = None
if cmd == 'lsdev':
result = '/usr/sbin/lsdev'
@ -63,6 +98,10 @@ def mock_get_bin_path(cmd, required=False):
result = '/usr/sbin/lscfg'
elif cmd == 'fcinfo':
result = '/usr/sbin/fcinfo'
elif cmd == 'ioscan':
result = '/usr/bin/ioscan'
elif cmd == 'fcmsutil':
result = '/opt/fcms/bin/fcmsutil'
return result
@ -74,6 +113,10 @@ def mock_run_command(cmd):
result = LSCFG_OUTPUT
elif 'fcinfo' in cmd:
result = FCINFO_OUTPUT
elif 'ioscan' in cmd:
result = IOSCAN_OUT
elif 'fcmsutil' in cmd:
result = FCMSUTIL_OUT
else:
rc = 1
result = 'Error'
@ -87,7 +130,7 @@ def test_get_fc_wwn_info(mocker):
mocker.patch.object(module, 'get_bin_path', side_effect=mock_get_bin_path)
mocker.patch.object(module, 'run_command', side_effect=mock_run_command)
d = {'aix6': ['10000090FA551508'], 'sunos5': ['10000090fa1658de']}
d = {'aix6': ['10000090FA551508'], 'sunos5': ['10000090fa1658de'], 'hp-ux11': ['0x50060b00006975ec']}
for key, value in d.items():
mocker.patch('sys.platform', key)
wwn_expected = {"fibre_channel_wwn": value}