mgr/nfs: test Export.validate(); several fixes

Signed-off-by: Sage Weil <sage@newdream.net>
This commit is contained in:
Sage Weil 2021-06-11 15:55:27 -04:00
parent 16c5cb62f7
commit 01a8d0ba3d
2 changed files with 30 additions and 8 deletions

View File

@ -385,14 +385,16 @@ class Export:
protocols = [protocols]
transports = export_block.values.get('transports')
if not isinstance(transports, list):
if isinstance(transports, str):
transports = [transports]
elif not transports:
transports = []
return cls(export_block.values['export_id'],
export_block.values['path'],
cluster_id,
export_block.values['pseudo'],
export_block.values['access_type'],
export_block.values.get('access_type', 'none'),
export_block.values.get('squash', 'no_root_squash'),
export_block.values.get('security_label', True),
protocols,
@ -453,7 +455,7 @@ class Export:
@staticmethod
def validate_access_type(access_type: str) -> None:
valid_access_types = ['rw', 'ro', 'none']
if access_type.lower() not in valid_access_types:
if not isinstance(access_type, str) or access_type.lower() not in valid_access_types:
raise NFSInvalidOperation(
f'{access_type} is invalid, valid access type are'
f'{valid_access_types}'
@ -466,7 +468,7 @@ class Export:
"rootidsquash", "all", "all_squash", "allsquash", "all_anomnymous",
"allanonymous", "no_root_squash", "none", "noidsquash",
]
if squash not in valid_squash_ls:
if squash.lower() not in valid_squash_ls:
raise NFSInvalidOperation(
f"squash {squash} not in valid list {valid_squash_ls}"
)
@ -494,8 +496,10 @@ class Export:
raise NFSInvalidOperation(f'{trans} is not a valid transport protocol')
for client in self.clients:
self.validate_squash(client.squash)
self.validate_access_type(client.access_type)
if client.squash:
self.validate_squash(client.squash)
if client.access_type:
self.validate_access_type(client.access_type)
if self.fsal.name == 'CEPH':
fs = cast(CephFSFSAL, self.fsal)

View File

@ -389,7 +389,7 @@ NFS_CORE_PARAM {
'pseudo': '/cephfs_a/',
'security_label': True,
'squash': 'no_root_squash',
'transports': [None]}
'transports': []}
export = [e for e in conf.exports['foo'] if e.export_id == 2][0]
ex_dict = export.to_dict()
@ -534,7 +534,25 @@ NFS_CORE_PARAM {
export2 = Export.from_dict(j['export_id'], j)
j2 = export2.to_dict()
assert j == j2
"""
@pytest.mark.parametrize(
"block",
[
export_1,
export_2,
]
)
def test_export_validate(self, block):
cluster_id = 'foo'
blocks = GaneshaConfParser(block).parse()
print(block)
export = Export.from_export_block(blocks[0], cluster_id)
print(export.__dict__)
nfs_mod = Module('nfs', '', '')
with mock.patch('nfs.export_utils.check_fs', return_value=True):
export.validate(nfs_mod)
"""
def test_update_export(self):
for cluster_id, info in self.clusters.items():
self._do_test_update_export(cluster_id, info['exports'])