forked from ansible/ansible
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor iscsi network facts module, remove external grep call, add u…
…nit test (ansible#55643) * remove external grep call and parse with python * use function for repeated code * use module.get_bin_path() for iscsiutil on HPUX * some code opt for HPUX * clean up non-module code, module being defined is a requirement for this code * import get_bin_path() directly and use without module prefix * Add integration tests for AIX and HP-UX * add changelog fragment * Apply suggestions from code review Co-Authored-By: mator <matorola@gmail.com> * Apply suggestions from code review #2 Co-Authored-By: Sam Doran <sdoran@redhat.com> * Remove strict requirement on executable to exist for get_bin_path() as it will allow facts gathering to continue without an error. Almost all other files under facts do not have "required=True" (except 2 files, which should be probably fixed). And check return value for get_bin_path() , before run attempt. * add check for AIX lsattr run_command return code
- Loading branch information
Showing
3 changed files
with
77 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- refactor iSCSI network facts for AIX and HP-UX, add unit test, remove external grep call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
test/units/module_utils/facts/network/test_iscsi_get_initiator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2019 Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
from ansible.module_utils.facts.network import iscsi | ||
from units.compat.mock import Mock, patch | ||
|
||
|
||
# AIX # lsattr -E -l iscsi0 | ||
LSATTR_OUTPUT = """ | ||
disc_filename /etc/iscsi/targets Configuration file False | ||
disc_policy file Discovery Policy True | ||
initiator_name iqn.localhost.hostid.7f000002 iSCSI Initiator Name True | ||
isns_srvnames auto iSNS Servers IP Addresses True | ||
isns_srvports iSNS Servers Port Numbers True | ||
max_targets 16 Maximum Targets Allowed True | ||
num_cmd_elems 200 Maximum number of commands to queue to driver True | ||
""" | ||
|
||
# HP-UX # iscsiutil -l | ||
ISCSIUTIL_OUTPUT = """ | ||
Initiator Name : iqn.2001-04.com.hp.stor:svcio | ||
Initiator Alias : | ||
Authentication Method : None | ||
CHAP Method : CHAP_UNI | ||
Initiator CHAP Name : | ||
CHAP Secret : | ||
NAS Hostname : | ||
NAS Secret : | ||
Radius Server Hostname : | ||
Header Digest : None,CRC32C (default) | ||
Data Digest : None,CRC32C (default) | ||
SLP Scope list for iSLPD : | ||
""" | ||
|
||
|
||
def test_get_iscsi_info(mocker): | ||
module = Mock() | ||
inst = iscsi.IscsiInitiatorNetworkCollector() | ||
|
||
mocker.patch('sys.platform', 'aix6') | ||
mocker.patch('ansible.module_utils.facts.network.iscsi.get_bin_path', return_value='/usr/sbin/lsattr') | ||
mocker.patch.object(module, 'run_command', return_value=(0, LSATTR_OUTPUT, '')) | ||
aix_iscsi_expected = {"iscsi_iqn": "iqn.localhost.hostid.7f000002"} | ||
assert aix_iscsi_expected == inst.collect(module=module) | ||
|
||
mocker.patch('sys.platform', 'hp-ux') | ||
mocker.patch('ansible.module_utils.facts.network.iscsi.get_bin_path', return_value='/opt/iscsi/bin/iscsiutil') | ||
mocker.patch.object(module, 'run_command', return_value=(0, ISCSIUTIL_OUTPUT, '')) | ||
hpux_iscsi_expected = {"iscsi_iqn": " iqn.2001-04.com.hp.stor:svcio"} | ||
assert hpux_iscsi_expected == inst.collect(module=module) |