Skip to content

Commit 5f107ee

Browse files
authored
Support NFS RDMA enabled key for nfs_global_settings module (#191)
1 parent 6c821fb commit 5f107ee

File tree

7 files changed

+115
-9
lines changed

7 files changed

+115
-9
lines changed

docs/modules/nfs_global_settings.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ Parameters
4545
Enable/Disable the rquota protocol.
4646

4747

48+
nfs_rdma_enabled (optional, bool, None)
49+
Enables or disables RDMA for NFS.
50+
51+
Supported on PowerScale 9.8 and later.
52+
53+
4854
nfsv3 (optional, dict, None)
4955
Enable/disable NFSv3 protocol.
5056

@@ -56,6 +62,8 @@ Parameters
5662
nfsv3_rdma_enabled (optional, bool, None)
5763
To enable/disable RDMA for NFSv3 protocol.
5864

65+
For PowerScale 9.8 :emphasis:`nfsv3\_rdma\_enabled` is not supported and :emphasis:`nfs\_rdma\_enabled` is used for both nfsv3 and nfsv4.
66+
5967

6068

6169
nfsv4 (optional, dict, None)
@@ -90,9 +98,9 @@ Parameters
9098
verify_ssl (True, bool, None)
9199
boolean variable to specify whether to validate SSL certificate or not.
92100

93-
\ :literal:`true`\ - indicates that the SSL certificate should be verified.
101+
:literal:`true` - indicates that the SSL certificate should be verified.
94102

95-
\ :literal:`false`\ - indicates that the SSL certificate should not be verified.
103+
:literal:`false` - indicates that the SSL certificate should not be verified.
96104

97105

98106
api_user (True, str, None)
@@ -110,7 +118,7 @@ Notes
110118
-----
111119

112120
.. note::
113-
- The \ :emphasis:`check\_mode`\ is supported.
121+
- The :emphasis:`check\_mode` is supported.
114122
- The modules present in this collection named as 'dellemc.powerscale' are built to support the Dell PowerScale storage platform.
115123

116124

@@ -144,6 +152,7 @@ Examples
144152
nfsv40_enabled: true
145153
nfsv41_enabled: true
146154
nfsv42_enabled: false
155+
nfs_rdma_enabled: true
147156
rpc_minthreads: 17
148157
rpc_maxthreads: 20
149158
rquota_enabled: true

plugins/modules/nfs_global_settings.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
description:
4242
- Enable/Disable the rquota protocol.
4343
type: bool
44+
nfs_rdma_enabled:
45+
description:
46+
- Enables or disables RDMA for NFS.
47+
- Supported on PowerScale 9.8 and later.
48+
type: bool
4449
nfsv3:
4550
description:
4651
- Enable/disable NFSv3 protocol.
@@ -53,6 +58,8 @@
5358
nfsv3_rdma_enabled:
5459
description:
5560
- To enable/disable RDMA for NFSv3 protocol.
61+
- For PowerScale 9.8 I(nfsv3_rdma_enabled) is not supported
62+
and I(nfs_rdma_enabled) is used for both nfsv3 and nfsv4.
5663
type: bool
5764
nfsv4:
5865
description:
@@ -102,6 +109,7 @@
102109
nfsv40_enabled: true
103110
nfsv41_enabled: true
104111
nfsv42_enabled: false
112+
nfs_rdma_enabled: true
105113
rpc_minthreads: 17
106114
rpc_maxthreads: 20
107115
rquota_enabled: true
@@ -197,12 +205,30 @@ def __init__(self):
197205

198206
self.api_client = utils.get_powerscale_connection(self.module.params)
199207
self.isi_sdk = utils.get_powerscale_sdk()
208+
self.array_version = f"{self.isi_sdk.major}.{self.isi_sdk.minor}"
209+
200210
LOG.info('Got python SDK instance for provisioning on PowerScale ')
201211
check_mode_msg = f'Check mode flag is {self.module.check_mode}'
202212
LOG.info(check_mode_msg)
203213

204214
self.protocol_api = self.isi_sdk.ProtocolsApi(self.api_client)
205215

216+
def validate_input(self):
217+
"""
218+
Validate the input parameters based on the array version.
219+
This method checks whether certain parameters are allowed based on the array version.
220+
If the array version is 9.8 or later, the nfsv3.nfsv3_rdma_enabled parameter is not allowed.
221+
If the array version is earlier than 9.8, the nfs_rdma_enabled parameter is not allowed.
222+
"""
223+
params = self.module.params
224+
225+
if utils.parse_version(self.array_version) < utils.parse_version("9.8"):
226+
if params.get("nfs_rdma_enabled") is not None:
227+
self.module.fail_json(msg="nfs_rdma_enabled is not allowed when array version is earlier than 9.8.")
228+
else:
229+
if params.get("nfsv3") and params.get("nfsv3").get("nfsv3_rdma_enabled") is not None:
230+
self.module.fail_json(msg="nfsv3.nfsv3_rdma_enabled is not allowed when array version is 9.8 or later.")
231+
206232
def get_nfs_global_settings_details(self):
207233
"""
208234
Get details of NFS global settings
@@ -249,14 +275,14 @@ def is_nfsv3v4_modify_required(self, settings_params, settings_details, modify_d
249275
nfsv4_keys = ["nfsv4_enabled", "nfsv40_enabled", "nfsv41_enabled", "nfsv42_enabled"]
250276
if settings_params["nfsv4"] is not None:
251277
for key in nfsv4_keys:
252-
if settings_params["nfsv4"][key] is not None and \
278+
if key in settings_params["nfsv4"] and settings_params["nfsv4"][key] is not None and \
253279
settings_details[key] != settings_params["nfsv4"][key]:
254280
modify_dict[key] = settings_params["nfsv4"][key]
255281

256282
nfsv3_keys = ["nfsv3_enabled", "nfsv3_rdma_enabled"]
257283
if settings_params["nfsv3"] is not None:
258284
for key in nfsv3_keys:
259-
if settings_params["nfsv3"][key] is not None and \
285+
if key in settings_params["nfsv3"] and settings_params["nfsv3"][key] is not None and \
260286
settings_details[key] != settings_params["nfsv3"][key]:
261287
modify_dict[key] = settings_params["nfsv3"][key]
262288

@@ -267,9 +293,9 @@ def is_nfs_global_modify_required(self, settings_params, settings_details):
267293
Check whether modification is required in NFS global settings
268294
"""
269295
modify_dict = {}
270-
keys = ["service", "rpc_maxthreads", "rpc_minthreads", "rquota_enabled"]
296+
keys = ["service", "rpc_maxthreads", "rpc_minthreads", "rquota_enabled", "nfs_rdma_enabled"]
271297
for key in keys:
272-
if settings_params[key] is not None and \
298+
if key in settings_params and settings_params[key] is not None and \
273299
settings_details[key] != settings_params[key]:
274300
modify_dict[key] = settings_params[key]
275301

@@ -284,6 +310,7 @@ def get_nfs_global_settings_parameters(self):
284310
service=dict(type='bool'), rpc_maxthreads=dict(type='int'),
285311
rpc_minthreads=dict(type='int'),
286312
rquota_enabled=dict(type='bool'),
313+
nfs_rdma_enabled=dict(type='bool'),
287314
nfsv3=dict(
288315
type='dict', options=dict(
289316
nfsv3_enabled=dict(type='bool'),
@@ -319,6 +346,7 @@ def handle(self, nfs_global_obj, nfs_global_params, nfs_global_details):
319346

320347
class NFSGlobalSettingsHandler:
321348
def handle(self, nfs_global_obj, nfs_global_params):
349+
nfs_global_obj.validate_input()
322350
nfs_global_details = nfs_global_obj.get_nfs_global_settings_details()
323351
NFSGlobalSettingsModifyHandler().handle(
324352
nfs_global_obj=nfs_global_obj, nfs_global_params=nfs_global_params,

tests/unit/plugins/__init__

Whitespace-only changes.

tests/unit/plugins/module_utils/mock_nfs_global_settings_api.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,35 @@ class MockNFSGlobalSettingsApi:
1414

1515
NFS_GLOBAL_COMMON_ARGS = {
1616
"onefs_host": "**.***.**.***",
17-
"nfsv3_enabled": None,
1817
"nfsv3": None,
1918
"nfsv4": None,
2019
"rpc_maxthreads": 20,
2120
"rpc_minthreads": 17,
2221
"rquota_enabled": None,
2322
"service": None
2423
}
24+
25+
NFS_GLOBAL_97_RDMA_ARGS = {
26+
"onefs_host": "**.***.**.**",
27+
"nfsv3": {"nfsv3_rdma_enabled": True},
28+
"nfsv4": None,
29+
"rpc_maxthreads": 20,
30+
"rpc_minthreads": 17,
31+
"rquota_enabled": None,
32+
"service": None
33+
}
34+
35+
NFS_GLOBAL_98_RDMA_ARGS = {
36+
"onefs_host": "**.***.**.**",
37+
"nfs_rdma_enabled": True,
38+
"nfsv3": None,
39+
"nfsv4": None,
40+
"rpc_maxthreads": 20,
41+
"rpc_minthreads": 17,
42+
"rquota_enabled": None,
43+
"service": None
44+
}
45+
2546
GET_NFS_GLOBAL_RESPONSE = {
2647
"nfsv3_enabled": False,
2748
"nfsv3_rdma_enabled": True,
@@ -35,9 +56,26 @@ class MockNFSGlobalSettingsApi:
3556
"service": True
3657
}
3758

59+
GET_NFS_GLOBAL_RESPONSE_RDMA_98 = {
60+
"nfsv3_enabled": False,
61+
"nfs_rdma_enabled": True,
62+
"nfsv40_enabled": True,
63+
"nfsv41_enabled": True,
64+
"nfsv42_enabled": False,
65+
"nfsv4_enabled": True,
66+
"rpc_maxthreads": 20,
67+
"rpc_minthreads": 17,
68+
"rquota_enabled": True,
69+
"service": True
70+
}
71+
3872
@staticmethod
3973
def get_nfs_global_settings_exception_response(response_type):
4074
if response_type == 'get_details_exception':
4175
return "Got error SDK Error message while getting NFS global setings details "
4276
elif response_type == 'update_exception':
4377
return "Modify NFS global settings failed with error: SDK Error message"
78+
elif response_type == 'rdma_exception':
79+
return "nfs_rdma_enabled is not allowed when array version is earlier than 9.8."
80+
elif response_type == 'rdma_v3_exception':
81+
return "nfsv3.nfsv3_rdma_enabled is not allowed when array version is 9.8 or later."

tests/unit/plugins/module_utils/shared_library/powerscale_unit_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def capture_fail_json_call(self, error_msg, module_handler=None, invoke_perform_
3737
self.powerscale_module_mock.perform_module_operation()
3838
self.powerscale_module_mock.module.fail_json.assert_called()
3939
call_args = self.powerscale_module_mock.module.fail_json.call_args.kwargs
40-
assert error_msg in call_args['msg']
40+
assert call_args['msg'] is not None and error_msg in call_args['msg']
4141

4242
def capture_fail_json_method(self, error_msg, module_mock, function_name, *args, **kwargs):
4343
with pytest.raises(SystemExit):

tests/unit/plugins/modules/__init__

Whitespace-only changes.

tests/unit/plugins/modules/test_nfs_global_settings.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import MockApiException
2323
from ansible_collections.dellemc.powerscale.tests.unit.plugins.module_utils.shared_library.powerscale_unit_base import \
2424
PowerScaleUnitBase
25+
from ansible_collections.dellemc.powerscale.tests.unit.plugins.module_utils.mock_sdk_response import (
26+
MockSDKResponse,
27+
)
2528

2629

2730
class TestNFSGlobalSettings(PowerScaleUnitBase):
@@ -35,18 +38,44 @@ def test_get_nfs_global_details(self, powerscale_module_mock):
3538
self.nfs_global_args.update({
3639
})
3740
powerscale_module_mock.module.params = self.nfs_global_args
41+
powerscale_module_mock.array_version = "9.7"
3842
NFSGlobalSettingsHandler().handle(powerscale_module_mock, powerscale_module_mock.module.params)
3943
powerscale_module_mock.protocol_api.get_nfs_settings_global.assert_called()
4044

4145
def test_get_nfs_global_details_exception(self, powerscale_module_mock):
4246
self.nfs_global_args.update({})
4347
powerscale_module_mock.module.params = self.nfs_global_args
48+
powerscale_module_mock.array_version = "9.7"
4449
powerscale_module_mock.protocol_api.get_nfs_settings_global = MagicMock(
4550
side_effect=MockApiException)
4651
self.capture_fail_json_call(
4752
MockNFSGlobalSettingsApi.get_nfs_global_settings_exception_response('get_details_exception'),
4853
NFSGlobalSettingsHandler)
4954

55+
def test_modify_nfs_rdma_97_exception(self, powerscale_module_mock):
56+
self.nfs_global_args.update(MockNFSGlobalSettingsApi.GET_NFS_GLOBAL_RESPONSE_RDMA_98)
57+
powerscale_module_mock.module.params = self.nfs_global_args
58+
powerscale_module_mock.array_version = "9.7"
59+
powerscale_module_mock.protocol_api.get_nfs_settings_global = MagicMock(
60+
return_value=MockSDKResponse(
61+
MockNFSGlobalSettingsApi.GET_NFS_GLOBAL_RESPONSE_RDMA_98
62+
))
63+
self.capture_fail_json_call(
64+
MockNFSGlobalSettingsApi.get_nfs_global_settings_exception_response('rdma_exception'),
65+
NFSGlobalSettingsHandler)
66+
67+
def test_modify_nfs_rdma_98_exception(self, powerscale_module_mock):
68+
self.nfs_global_args.update(MockNFSGlobalSettingsApi.NFS_GLOBAL_97_RDMA_ARGS)
69+
powerscale_module_mock.module.params = self.nfs_global_args
70+
powerscale_module_mock.array_version = "9.8"
71+
powerscale_module_mock.protocol_api.get_nfs_settings_global = MagicMock(
72+
return_value=MockSDKResponse(
73+
MockNFSGlobalSettingsApi.GET_NFS_GLOBAL_RESPONSE_RDMA_98
74+
))
75+
self.capture_fail_json_call(
76+
MockNFSGlobalSettingsApi.get_nfs_global_settings_exception_response('rdma_v3_exception'),
77+
NFSGlobalSettingsHandler)
78+
5079
def test_modify_nfs_global_response(self, powerscale_module_mock):
5180
self.nfs_global_args.update({
5281
"service": True,
@@ -59,6 +88,7 @@ def test_modify_nfs_global_response(self, powerscale_module_mock):
5988
}
6089
})
6190
powerscale_module_mock.module.params = self.nfs_global_args
91+
powerscale_module_mock.array_version = "9.7"
6292
powerscale_module_mock.get_nfs_global_settings_details = MagicMock(
6393
return_value=MockNFSGlobalSettingsApi.GET_NFS_GLOBAL_RESPONSE)
6494
NFSGlobalSettingsHandler().handle(powerscale_module_mock,
@@ -78,6 +108,7 @@ def test_modify_nfs_global_exception(self, powerscale_module_mock):
78108
}
79109
})
80110
powerscale_module_mock.module.params = self.nfs_global_args
111+
powerscale_module_mock.array_version = "9.7"
81112
powerscale_module_mock.get_nfs_global_settings_details = MagicMock(
82113
return_value=MockNFSGlobalSettingsApi.GET_NFS_GLOBAL_RESPONSE)
83114
powerscale_module_mock.protocol_api.update_nfs_settings_global = MagicMock(

0 commit comments

Comments
 (0)