Improve nfs-server to support multiple shares and options

With this we aim at making the nfs-server element capable of
deploying an arbitrary number of shares and to define for each
a list of clients allowed and the respective export options.

Change-Id: Ib056885c94c3bc475ed0e84237c83414795fc8e0
This commit is contained in:
Giulio Fidente 2014-10-03 15:38:01 +02:00
parent 797453e3f8
commit cd6ed180e3
8 changed files with 72 additions and 17 deletions

View File

@ -10,5 +10,5 @@ Configuration
# a list of nfs shares, each item in the list should be an nfs
# share address. (e.g 192.0.2.5:/mnt/state/var/lib/nfs_share)
**NOTE:** make sure to use the 'nfs-client' element when building the
compute nodes too.
**NOTE:** if backing Cinder with NFS remember to use the 'nfs-client'
element on the compute nodes as they will have to mount the NFS share too.

View File

@ -2,4 +2,4 @@
set -eux
set -o pipefail
install-packages -m nfs-client nfs_utils_package
install-packages -m nfs-client nfs_client_package

View File

@ -1,16 +1,16 @@
{
"family": {
"redhat": {
"nfs_utils_package": "nfs-utils"
"nfs_client_package": "nfs-utils"
},
"debian": {
"nfs_utils_package": "nfs-common"
"nfs_client_package": "nfs-client"
},
"suse": {
"nfs_utils_package": "nfs-client"
"nfs_client_package": "nfs-client"
}
},
"default": {
"nfs_utils_package": "nfs-utils"
"nfs_client_package": "nfs-utils"
}
}

View File

@ -1,9 +1,28 @@
##nfs-server
Installs and configures NFS server services.
This element installs and configures nfs services for testing the
cinder nfs backend in an environment where no nfs services are
present (i.e. CI)
When added to an image this element will, depending on the
config data, create a number of NFS shares and export them to
the given list of clients with respective options.
When added to an image, this element creates a directory at
/mnt/state/var/lib/nfs and shares it to each node on the
overcloud.
Shares are created in /mnt/state/var/lib/nfs
Configuration
-------------
nfs_server:
shares:
- name: share_name
clients:
- machine: machine_allowed
options: rw,async,no_root_squash
**NOTE**:
* `share_name` should be a valid POSIX dirname, special chars, spaces or
use of quotes is not supported
* share dir created on filesystem will be owned by root/root with mode 0770
* `machine` is required, defines the list of allowed clients, can be repeated
* `options` can be omitted the following are used: rw,async,no_root_squash

View File

@ -1,4 +1,4 @@
#!/bin/bash
set -eu
install-packages nfs-kernel-server
install-packages -m nfs-server nfs_server_package

View File

@ -1,3 +1,3 @@
{{#nfs_server.shares}}
/mnt/state/var/lib/nfs {{.}}(rw,async,no_root_squash)
/mnt/state/var/lib/nfs/{{name}}{{#clients}} {{machine}}({{#options}}{{.}}{{/options}}{{^options}}rw,async,no_root_squash{{/options}}){{/clients}}
{{/nfs_server.shares}}

View File

@ -1,7 +1,27 @@
#!/bin/bash
set -eu
[ -d /mnt/state/var/lib/nfs ] || install -d -m 0770 -o root -g root /mnt/state/var/lib/nfs
# We want to create a dir for each export in /etc/exports and
# allow valid POSIX paths only.
for share in $(grep -oE '^/[a-zA-Z0-9._-/]+' /etc/exports); do
[ -d "$share" ] || install -d -m 0770 -o root -g root "$share"
done
# Yet exports(5) allows for # comments; unquoted paths without spaces;
# unquoted paths with octal ascii sequences; double-quoted paths with spaces.
# Parsing all formats correctly requires usage of some non trivial
# code, which we decided to avoid for now.
# Shall we decide to support that, the following code should do (thanks lxsli).
#
#CODE='import ast, os.path, re, sys
#lines = sys.stdin.readlines()
#matchers = [re.match("\"([^\"]+)\"|(\\S+)", line) for line in lines if not re.search("^\s*#", line)]
#lines = [m.group(1) or m.group(2) for m in matchers]
#paths = [ast.literal_eval("\"%s\"" % line) for line in lines]
#paths = [path for path in paths if not os.path.isdir(path)]
#print "\n".join(paths),'
#cat /etc/exports | python -c "$CODE" | xargs -i install -d -m 0770 -o root -g root "{}
os-svc-enable -n nfs-server
os-svc-restart -n nfs-server
exportfs -a -r -v

View File

@ -0,0 +1,16 @@
{
"family": {
"redhat": {
"nfs_server_package": "nfs-utils"
},
"debian": {
"nfs_server_package": "nfs-server"
},
"suse": {
"nfs_server_package": "nfs-kernel-server"
}
},
"default": {
"nfs_server_package": "nfs-utils"
}
}