From cd82803dc4bad1d85e59f42ee394167bf7729533 Mon Sep 17 00:00:00 2001 From: Philip Guyton Date: Thu, 14 Nov 2024 18:46:44 +0000 Subject: [PATCH] NFS exports restored as read-only #2912 Fix translation of DB dump derived config-save field names to NFS export create API field names. Affects Web-UI surfaced NFS export config of: - Access type ('Writable'/'Read only') - Response type ('async'/'sync') for NFS exports created via a config restore process. Note that we maintain DB dump derived config-save field names in the generated API calls (ignored currently), to enable future API field name alignment to DB model field names. At which point the additional fields added here to the API payload would themselves become redundant and up for deprecation, and in the change-over period ignored. --- .../storageadmin/views/config_backup.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/rockstor/storageadmin/views/config_backup.py b/src/rockstor/storageadmin/views/config_backup.py index 1c8e76154..6b73a4c9d 100644 --- a/src/rockstor/storageadmin/views/config_backup.py +++ b/src/rockstor/storageadmin/views/config_backup.py @@ -119,6 +119,11 @@ def restore_samba_exports(ml: list): def restore_nfs_exports(ml: list): + """ + Parses storageadmin model list from config-backup DB dump. + Assumes Share mount-point is Share name. + @param ml: Model list (storageadmin) + """ logger.info("Started restoring NFS exports.") exports = [] export_groups = {} @@ -127,13 +132,21 @@ def restore_nfs_exports(ml: list): if m["model"] == "storageadmin.nfsexport": exports.append(m["fields"]) elif m["model"] == "storageadmin.nfsexportgroup": + logger.debug(f"Processing nfsexportgroup = {m}") m["fields"]["pk"] = m["pk"] - export_groups[m["pk"]] = m["fields"] + # Derive API field names & structure from nfsexportgroup DB dump field names: + nfse_api_fields: dict = m["fields"] + # Maintaining "editable" and "syncable" enables future API sync to DB model. + if "editable" in nfse_api_fields: # 'mod_choice' from 'editable' + nfse_api_fields["mod_choice"] = nfse_api_fields["editable"] + if "syncable" in nfse_api_fields: # 'sync_choice' from 'syncable' + nfse_api_fields["sync_choice"] = nfse_api_fields["syncable"] + export_groups[m["pk"]] = nfse_api_fields elif m["model"] == "storageadmin.advancednfsexport": adv_exports["entries"].append(m["fields"]["export_str"]) for e in exports: if len(e["mount"].split("/")) != 3: - logger.info("skipping nfs export with mount: {}".format(e["mount"])) + logger.info(f"skipping nfs export with mount: {e['mount']}") continue e["shares"] = [e["mount"].split("/")[2]] payload = dict(export_groups[e["export_group"]], **e)