Skip to content

Fix Support Assist Defect #193

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

Merged
merged 1 commit into from
Jun 20, 2025
Merged
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
32 changes: 27 additions & 5 deletions plugins/modules/support_assist.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,33 @@ def validate_gateway_connections(self, settings_details, connection_dict):
"""
Validate gateway connections
"""
if ('mode' in connection_dict and connection_dict['mode'] == 'gateway') or (
settings_details['connection']['mode'] == 'gateway'):
if ('gateway_endpoints' in connection_dict and connection_dict['gateway_endpoints'] == []) or (
settings_details['connection']['gateway_endpoints'] == []):
error_msg = "Gateway endpoints cannot be empty when the mode is gateway."
is_from_gateway_to_gateway = (
'mode' not in connection_dict
and settings_details['connection']['mode'] == 'gateway'
)
is_from_direct_to_gateway = (
'mode' in connection_dict
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about setting connection_dict['mode'] = settings_params['connection']['mode'] regardless of the difference, so we will not struggle with checking if 'mode' in connection_dict`

Another question, is it possible to omit mode in playbook?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, connection_dict reflects what has been modified to determine if changed flag need to be set to true. Updating it would affect the changed flag. For now, I suggest we keep this design and come up with a better way to detect the diff in the future.

and connection_dict['mode'] == 'gateway'
and settings_details['connection']['mode'] == 'direct'
)
is_dict_gateway_empty = (
'gateway_endpoints' in connection_dict
and connection_dict['gateway_endpoints'] == []
)
is_array_gateway_empty = (
'gateway_endpoints' not in connection_dict
and settings_details['connection']['gateway_endpoints'] == []
)

# Refined the verification logic to fix failures while adding gateway endpoints
# in certain scenarios (since ansible-powerscale 3.1.0 and powerscale 9.5.0)
if 'gateway_endpoints' in connection_dict or 'mode' in connection_dict:
if (is_from_gateway_to_gateway or is_from_direct_to_gateway) and (
is_dict_gateway_empty or is_array_gateway_empty
):
error_msg = (
"Gateway endpoints cannot be empty when the mode is gateway."
)
LOG.error(error_msg)
self.module.fail_json(msg=error_msg)

Expand Down
34 changes: 34 additions & 0 deletions tests/unit/plugins/module_utils/mock_support_assist_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,40 @@ class MockSupportAssistApi:
}
}

GET_SUPPORT_ASSIST_RESPONSE_DIRECT_MODE = {
"connection": {
"gateway_endpoints": [],
"mode": "direct",
"network_pools": [
{
"pool": "pool1",
"subnet": "subnet0"
}
]
},
"connection_state": "disabled",
"contact": {
"primary": {
"email": "[email protected]",
"first_name": "Eric",
"last_name": "Nam",
"phone": "1234567890"
},
"secondary": {
"email": "[email protected]",
"first_name": "Daniel",
"last_name": "Kang",
"phone": "1234567891"
}
},
"telemetry": {
"offline_collection_period": 60,
"telemetry_enabled": True,
"telemetry_persist": True,
"telemetry_threads": 10
}
}

@staticmethod
def get_support_assist_settings_exception_response(response_type):
if response_type == 'get_details_exception':
Expand Down
78 changes: 77 additions & 1 deletion tests/unit/plugins/modules/test_support_assist.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,69 @@ def test_modify_support_assist_exception(self, powerscale_module_mock):
MockSupportAssistApi.get_support_assist_settings_exception_response('update_exception'),
SupportAssistHandler)

def test_empty_gateway_endpoints_exception(self, powerscale_module_mock):
def test_modify_mode_from_gateway_to_direct(self, powerscale_module_mock):
self.support_assist_args.update(
{
"connection": {
"mode": "direct"
}
})
self.set_module_params(self.support_assist_args, {})
powerscale_module_mock.get_support_assist_details = MagicMock(
return_value=MockSupportAssistApi.GET_SUPPORT_ASSIST_RESPONSE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you revise the method name of the two test_modify_mode_to_direct, so it is obvious to know the purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated

SupportAssistHandler().handle(powerscale_module_mock,
powerscale_module_mock.module.params)
assert powerscale_module_mock.module.exit_json.call_args[1]['changed'] is True

def test_modify_mode_from_direct_to_direct(self, powerscale_module_mock):
self.support_assist_args.update(
{
"connection": {
"mode": "direct"
}
})
self.set_module_params(self.support_assist_args, {})
powerscale_module_mock.get_support_assist_details = MagicMock(
return_value=MockSupportAssistApi.GET_SUPPORT_ASSIST_RESPONSE_DIRECT_MODE)
SupportAssistHandler().handle(powerscale_module_mock,
powerscale_module_mock.module.params)
assert powerscale_module_mock.module.exit_json.call_args[1]['changed'] is True

def test_add_gateway_endpoints_from_gateway_to_direct(self, powerscale_module_mock):
self.support_assist_args.update(
{
"connection": {
"gateway_endpoints": [
{
"enabled": True,
"gateway_host": "XX.XX.XX.XX",
"gateway_port": 9443,
"priority": 2,
"use_proxy": False,
"validate_ssl": False,
"state": "present"
},
{
"enabled": True,
"gateway_host": "XX.XX.XX.XY",
"gateway_port": 9443,
"priority": 2,
"use_proxy": False,
"validate_ssl": False,
"state": "present"
}
],
"mode": "gateway"
}
})
self.set_module_params(self.support_assist_args, {})
powerscale_module_mock.get_support_assist_details = MagicMock(
return_value=MockSupportAssistApi.GET_SUPPORT_ASSIST_RESPONSE_DIRECT_MODE)
SupportAssistHandler().handle(powerscale_module_mock,
powerscale_module_mock.module.params)
assert powerscale_module_mock.module.exit_json.call_args[1]['changed'] is True

def test_empty_gateway_endpoints_exception_1(self, powerscale_module_mock):
self.support_assist_args.update(
{
"connection": {
Expand All @@ -256,6 +318,20 @@ def test_empty_gateway_endpoints_exception(self, powerscale_module_mock):
MockSupportAssistApi.get_support_assist_settings_exception_response('empty_gateway_exception'),
SupportAssistHandler)

def test_empty_gateway_endpoints_exception_2(self, powerscale_module_mock):
self.support_assist_args.update(
{
"connection": {
"mode": "gateway"
}
})
self.set_module_params(self.support_assist_args, {})
powerscale_module_mock.get_support_assist_details = MagicMock(
return_value=MockSupportAssistApi.GET_SUPPORT_ASSIST_RESPONSE_DIRECT_MODE)
self.capture_fail_json_call(
MockSupportAssistApi.get_support_assist_settings_exception_response('empty_gateway_exception'),
SupportAssistHandler)

def test_empty_network_pools_exception(self, powerscale_module_mock):
self.support_assist_args.update(
{
Expand Down