Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve coverage for host, host group, port, por group, job #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output
__pycache__/
*.log
19 changes: 19 additions & 0 deletions tests/unit/plugins/module_utils/mock_host_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,22 @@ def get_initiator_exception_response(response_type):
return "Adding initiators ['100xx111xxxxxxxx'] to host test_host failed with error "
elif response_type == 'remove_initiators_from_host':
return "Removing initiators ['100xx000xxxxxxxx'] from host test_host failed with error "
if response_type == 'get_initiators_alias':
return "Retrieving initiator details based on alias 100xx000xxxxxxxx/200xx000xxxxxxxx failed with error 0"
if response_type == 'invalid_initiator':
return "Initiator invalid_initiator is invalid"

@staticmethod
def get_host_exception_response(response_type):
if response_type == 'modify_host':
return "Renaming of host test_host failed with error "
if response_type == 'delete_host':
return "Delete host test_host failed with error "
if response_type == 'create_host':
return "Create host test_host failed with error "
if response_type == 'create_host_new_name':
return "Invalid argument 'new_name' while creating a host"
if response_type == 'create_host_init_absent':
return "Incorrect initiator_state specified for Create host functionality"
if response_type == 'rename_host_empty_name':
return "Please provide valid host name."
59 changes: 59 additions & 0 deletions tests/unit/plugins/module_utils/mock_hostgroup_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright: (c) 2022-2025, Dell Technologies

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

"""
Mock Host Group Api for Host Group Test module on PowerMax
"""

from __future__ import (absolute_import, division, print_function)

__metaclass__ = type


class MockHostGroupApi:
HOST_GROUP_COMMON_ARGS = {
"state": "present",
"host_state": None,
"hostgroup_name": "test_hostgroup",
"hosts": None,
"host_flags": None,
"host_type": None,
"new_name": None
}

HOST_GROUP_RESPONSE = {
"num_of_hosts": 1,
"num_of_initiators": 1,
"enabled_flags": "",
"num_of_masking_views": 0,
"disabled_flags": "",
"host": [
{
"initiator": [
"1000000000000001"
],
"hostId": "test_hg_host"
}
],
"port_flags_override": False,
"type": "Fibre",
"consistent_lun": False,
"hostGroupId": "test_hostgroup"
}

@staticmethod
def get_error_message(response_type, hostgroup_name=None):
error_msg = {"empty_hostgroup_name": "hostgroup_name is mandatory parameter. Please provide valid host group name.",
"get_hostgroup_exception": f"Got error while getting details of host group {hostgroup_name}",
"create_host_exception": f"Create host group {hostgroup_name} failed with error",
"get_host_exception_while_creation": f"Create host group {hostgroup_name} failed as the host ansible_test_host does not exist",
"add_host_exception": f"Adding host ['ansible_test_host'] to host group {hostgroup_name} failed with error",
"remove_host_exception": f"Removing host ['test_hg_host'] from host group {hostgroup_name} failed with error",
"invalid_new_name_arg": "Invalid argument 'new_name' while creating a host",
"rename_exception": f"Renaming of host group {hostgroup_name} failed with error",
"delete_hostgroup_exception": f"Delete host group {hostgroup_name} failed with error",
"remove_host_during_creation": "Incorrect host_state specified for Create hostgroup functionality",
"rename_same_name": "Please provide valid hostgroup name",
"modify_host_flag_exception": f"Modify host group {hostgroup_name} failed with error"}
return error_msg[response_type]
25 changes: 25 additions & 0 deletions tests/unit/plugins/module_utils/mock_job_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright: (c) 2022-2025, Dell Technologies

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

"""
Mock Job Api for Job Test module on PowerMax
"""

from __future__ import (absolute_import, division, print_function)

__metaclass__ = type


class MockJobApi:
JOB_COMMON_ARGS = {
"job_id": "100000000"
}

@staticmethod
def get_error_message(response_type, job_id=None):
error_msg = {"invalid_job_id": f"Invalid job_id: {job_id}",
"get_job_by_id_exception": f"Get Job details for job_id {job_id} failed with error ",
"exit_exception": "Failed to close unisphere connection with error: SDK Error message",
"get_no_job_detail": f"Failed to find the job with specified job_id: {job_id}"}
return error_msg[response_type]
24 changes: 24 additions & 0 deletions tests/unit/plugins/module_utils/mock_port_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright: (c) 2022-2025, Dell Technologies

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

"""
Mock Port Api for Port Test module on PowerMax
"""

from __future__ import (absolute_import, division, print_function)

__metaclass__ = type


class MockPortApi:
PORT_COMMON_ARGS = {
"gateway_host": "**.***.**.***",
"serial_no": None,
}

@staticmethod
def get_error_message(response_type, director_id=None, port_id=None):
error_msg = {"get_port_exception": f"Failed to get details of port {director_id}:{port_id} with error",
"missing_mandatory_args": "Director ID and Port ID is mandatory for listing port information"}
return error_msg[response_type]
48 changes: 48 additions & 0 deletions tests/unit/plugins/module_utils/mock_portgroup_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright: (c) 2022-2025, Dell Technologies

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

"""
Mock Port Group Api for Port Group Test module on PowerMax
"""

from __future__ import absolute_import, division, print_function

__metaclass__ = type


class MockPortGroupApi:
PORT_GROUP_COMMON_ARGS = {
"state": "present",
"portgroup_name": "test_portgroup",
"new_name": None,
"port_state": None,
"ports": None,
"port_group_protocol": None,
}

PORT_GROUP_RESPONSE = {
"portGroupId": "test_portgroup",
"symmetrixPortKey": [
{"directorId": "FA-2D", "portId": "5"},
{"directorId": "FA-2D", "portId": "7"},
],
"num_of_masking_views": 0,
"type": "Fibre",
"num_of_ports": 2,
}

@staticmethod
def get_error_message(response_type, portgroup_name=None):
error_msg = {
"invalid_port_state": "Create port group test_portgroup failed; "
"error Invalid port_state: Ports can only be added while creating portgroup",
"create_portgroup_exception": f"Create port group {portgroup_name} failed; error",
"portgroup_empty_new_name": "Please provide new name for the port group",
"delete_portgroup_exception": f"Delete port group {portgroup_name} failed.",
"rename_portgroup_exception": f"Modify port group {portgroup_name} failed with error .",
"add_port_exception": "Add port {'director_id': 'FA-1D', 'port_id': '10'} to port group test_portgroup failed with error .",
"remove_port_exception": "Remove port {'director_id': 'FA-2D', 'port_id': '5'} "
"from port group test_portgroup failed with error .",
}
return error_msg[response_type]
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
__metaclass__ = type
import pytest
from mock.mock import MagicMock
from ansible_collections.dellemc.powermax.tests.unit.plugins.module_utils.mock_api_exception \
import MockApiException
from ansible_collections.dellemc.powermax.tests.unit.plugins.module_utils.shared_library. \
fail_json import FailJsonException, fail_json

Expand All @@ -19,8 +17,6 @@ class PowerMaxUnitBase:

@pytest.fixture
def powermax_module_mock(self, mocker, module_object):
exception_class_path = 'ansible_collections.dellemc.powermax.plugins.module_utils.storage.dell.utils.ApiException'
mocker.patch(exception_class_path, new=MockApiException)
powermax_module_mock = module_object()
powermax_module_mock.module = MagicMock()
powermax_module_mock.module.fail_json = fail_json
Expand Down
Loading
Loading