From 8ccdfc05464fe39e6344e2498cbbe21c5369692e Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Fri, 18 Jan 2013 14:56:33 +0100 Subject: [PATCH] AutoYaST: fix to allow NFS4 options (FATE#312242, bnc#457981) Backported from 29e91e5e406e7ef9647810b92b462c478d46a9c9 BUT! changed the schema to keep compatibility with SLE11-SP2. Nfs.ycp: removing a public function Nfs::Set which is not used anywhere else. Namely not in - autoyast2 - yast2-backup - yast2-installation - yast2-nfs-client - yast2-nfs-server --- src/modules/Nfs.ycp | 96 +++++++++++++++++++++--------------- src/nfs.rnc | 24 +++++++-- testsuite/tests/autoyast.out | 11 ++++- testsuite/tests/autoyast.ycp | 56 +++++++++++++++++++-- 4 files changed, 139 insertions(+), 48 deletions(-) diff --git a/src/modules/Nfs.ycp b/src/modules/Nfs.ycp index e540433..28fe00b 100644 --- a/src/modules/Nfs.ycp +++ b/src/modules/Nfs.ycp @@ -83,21 +83,26 @@ // list of created directories list created_dirs = []; - /** - * Set module data - * @param settings module settings - * @return void - */ - global define void Set(list settings) ``{ - nfs_entries = maplist(map entry, settings, ``{ - return($[ - "spec":entry["server_path"]:"", - "file":entry["mount_point"]:"", - "vfstype":entry["vfstype"]:"", - "mntops":entry["nfs_options"]:"" - ]); - }); - return; + boolean ReadNfs4() { + return SCR::Read(.sysconfig.nfs.NFS4_SUPPORT) == "yes"; + } + + string ReadIdmapd() { + return (string) SCR::Read(.etc.idmapd_conf, "Domain"); + } + + + define boolean validate_ay_nfs_entry(map entry) { + boolean missing = false; + foreach (string k, ["server_path", "mount_point", "nfs_options"], + { + if (! haskey (entry, k)) + { + y2error ("Missing at Import: '%1'.", k); + missing = true; + } + }); + return !missing; } /** @@ -108,40 +113,48 @@ * @return success */ global define boolean Import (list settings) ``{ + map global_options = $[]; + // first the compat switch + if (haskey (settings[0]:$[], "enable_nfs4")) { + global_options = settings[0]:$[]; + settings = remove(settings, 0); + } + + list > entries = (list >) settings; + // ... - boolean missing = false; - settings = maplist(map s,settings,``{ - foreach (string k, ["server_path", "mount_point", "nfs_options"], ``{ - if (! haskey (s, k)) - { - y2error ("Missing at Import: '%1'.", k); - missing = true; - } - }); + if (find(map e, entries, ``(! validate_ay_nfs_entry(e)) ) != nil) { + return false; + } + entries = maplist(map e, entries, { //Backwards compatibility: with FaTE#302031, we support nfsv4 mounts //thus we need to keep info on nfs version (v3 vs. v4) //But older AY profiles might not contain this element //so let's assume nfsv3 in that case (#395850) - if ( !haskey(s, "vfstype") ) + if ( !haskey(e, "vfstype") ) { - s["vfstype"] = "nfs"; - } else { - if (s["vfstype"]:"nfs" == "nfs4") - { - nfs4_enabled = true; - } + e["vfstype"] = "nfs"; } - return s; - + return e; }); - if (missing) - { - return false; - } + nfs4_enabled = global_options["enable_nfs4"]:ReadNfs4(); + idmapd_domain = global_options["idmapd_domain"]:ReadIdmapd(); + + nfs_entries = maplist(map entry, entries, { + // vfstype can override a missing enable_nfs4 + if (entry["vfstype"]:"" == "nfs4") { + nfs4_enabled = true; + } + return($[ + "spec":entry["server_path"]:"", + "file":entry["mount_point"]:"", + "vfstype":entry["vfstype"]:"", + "mntops":entry["nfs_options"]:"" + ]); + }); - Set(settings); return true; } @@ -158,7 +171,12 @@ "nfs_options":entry["mntops"]:"" ]); }); - return entries; + map options = $[ + "enable_nfs4": nfs4_enabled, + "idmapd_domain": idmapd_domain + ]; + // FIXME: now the list is always nonempty; is that OK? + return prepend(entries, options); } /* ------------------------------------------------------------ */ diff --git a/src/nfs.rnc b/src/nfs.rnc index 20ce1f7..3491a2a 100644 --- a/src/nfs.rnc +++ b/src/nfs.rnc @@ -1,10 +1,26 @@ -nfs = - element nfs { - LIST, - element nfs_entry { +# hack: the list is heterogeneous, +# with an optional first entry which carries the global options +# bnc#... + +nfs_global_options_content = ( + element enable_nfs4 { BOOLEAN }? & + element idmapd_domain { text }? +) + +nfs_entry_content = ( element server_path { text } & element mount_point { text } & element vfstype {text}? & element nfs_options { text } +) + +nfs = + element nfs { + LIST, + element nfs_entry { + nfs_global_options_content + }? , + element nfs_entry { + nfs_entry_content }* } diff --git a/testsuite/tests/autoyast.out b/testsuite/tests/autoyast.out index 550f0b6..c2409c8 100644 --- a/testsuite/tests/autoyast.out +++ b/testsuite/tests/autoyast.out @@ -1,9 +1,16 @@ -Read .target.tmpdir nil -Log Failed to set temporary directory: nil +Read .target.tmpdir "/tmp" Dump Nfs::Import Dump - basic, SLE11-SP2 +Read .sysconfig.nfs.NFS4_SUPPORT "no" +Read .etc.idmapd_conf "Domain" "localdomain" +Return true Dump -- and Export Dump - empty +Read .sysconfig.nfs.NFS4_SUPPORT "no" +Read .etc.idmapd_conf "Domain" "localdomain" +Return true Dump - invalid, missing basic data Log Missing at Import: 'mount_point'. Log Missing at Import: 'nfs_options'. +Dump - basic, SLE11-SP3 +Dump -- and Export diff --git a/testsuite/tests/autoyast.ycp b/testsuite/tests/autoyast.ycp index 596e49f..b6010ce 100644 --- a/testsuite/tests/autoyast.ycp +++ b/testsuite/tests/autoyast.ycp @@ -1,5 +1,25 @@ { include "testsuite.ycp"; + map I_READ = $[ + "target" : $[ + "tmpdir" : "/tmp", + ], + ]; + map I_WRITE = $[]; + map I_EXEC = $[]; + TESTSUITE_INIT ([I_READ, I_WRITE, I_EXEC], nil); + + map READ = $[ + "etc": $[ + "idmapd_conf" : "localdomain", + ], + "sysconfig": $[ + "nfs" : $[ + "NFS4_SUPPORT": "no", + ], + ], + ]; + import "Nfs"; import "Assert"; @@ -12,20 +32,26 @@ "nfs_options": "defaults" ]; - Nfs::Import([ entry1 ]); + TEST (``( + Nfs::Import([ entry1 ]) + ), [READ, $[], $[]], nil); Assert::Equal(1, size(Nfs::nfs_entries)); Assert::Equal("data.example.com:/mirror", Nfs::nfs_entries[0, "spec"]:""); DUMP("-- and Export"); list e = Nfs::Export(); - Assert::Equal(1, size(e)); + Assert::Equal(2, size(e)); + Assert::Equal(true, haskey(e[0]:$[], "enable_nfs4")); + Assert::Equal(true, haskey(e[0]:$[], "idmapd_domain")); Assert::Equal("data.example.com:/mirror", e[1, "server_path"]:""); Assert::Equal("/mirror", e[1, "mount_point"]:""); Assert::Equal("defaults", e[1, "nfs_options"]:""); // --------- DUMP("- empty"); - Nfs::Import([]); + TEST (``( + Nfs::Import([]) + ), [READ, $[], $[]], nil); Assert::Equal(0, size(Nfs::nfs_entries)); // --------- @@ -36,4 +62,28 @@ Nfs::Import([ entry_invalid ]); Assert::Equal(0, size(Nfs::nfs_entries)); + + // --------- + DUMP("- basic, SLE11-SP3"); + map global_options = $[ + "enable_nfs4": true, + "idmapd_domain": "example.com" + ]; + Nfs::Import([ + global_options, + entry1 + ]); + Assert::Equal(true, Nfs::nfs4_enabled); + Assert::Equal("example.com", Nfs::idmapd_domain); + Assert::Equal(1, size(Nfs::nfs_entries)); + Assert::Equal("data.example.com:/mirror", Nfs::nfs_entries[0, "spec"]:""); + + DUMP("-- and Export"); + e = Nfs::Export(); + Assert::Equal(2, size(e)); + Assert::Equal(true, e[0, "enable_nfs4"]:false); + Assert::Equal("example.com", e[0, "idmapd_domain"]:""); + Assert::Equal("data.example.com:/mirror", e[1, "server_path"]:""); + Assert::Equal("/mirror", e[1, "mount_point"]:""); + Assert::Equal("defaults", e[1, "nfs_options"]:""); }