Skip to content

Commit

Permalink
AutoYaST: fix to allow NFS4 options (FATE#312242, bnc#457981)
Browse files Browse the repository at this point in the history
Backported from 29e91e5
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
  • Loading branch information
mvidner committed Jan 18, 2013
1 parent c6fd242 commit 8ccdfc0
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 48 deletions.
96 changes: 57 additions & 39 deletions src/modules/Nfs.ycp
Expand Up @@ -83,21 +83,26 @@
// list of created directories
list<string> created_dirs = [];

/**
* Set module data
* @param settings module settings
* @return void
*/
global define void Set(list<map> 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;
}

/**
Expand All @@ -108,40 +113,48 @@
* @return success
*/
global define boolean Import (list<map> settings) ``{
map global_options = $[];
// first the compat switch
if (haskey (settings[0]:$[], "enable_nfs4")) {
global_options = settings[0]:$[];
settings = remove(settings, 0);
}

list<map<string, any> > entries = (list<map<string, any> >) 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<string, any> 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;
}

Expand All @@ -158,7 +171,12 @@
"nfs_options":entry["mntops"]:""
]);
});
return entries;
map<string, any> options = $[
"enable_nfs4": nfs4_enabled,
"idmapd_domain": idmapd_domain
];
// FIXME: now the list is always nonempty; is that OK?
return prepend(entries, options);
}

/* ------------------------------------------------------------ */
Expand Down
24 changes: 20 additions & 4 deletions src/nfs.rnc
@@ -1,10 +1,26 @@
nfs =
element nfs {
LIST,
element nfs_entry {
# hack: the <nfs> 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
}*
}
11 changes: 9 additions & 2 deletions 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
56 changes: 53 additions & 3 deletions 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";

Expand All @@ -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));

// ---------
Expand All @@ -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"]:"");
}

0 comments on commit 8ccdfc0

Please sign in to comment.