summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils
diff options
context:
space:
mode:
authorNathan Rossi <nathan@nathanrossi.com>2019-08-28 05:06:29 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-08-28 16:44:09 +0100
commit98e52739716f82d8a5f62035ee0b9c44588f8039 (patch)
treea13712b30de7d08401d4abad0a1980ae034826f2 /meta/lib/oeqa/utils
parentb88477d0690822fd7a5fa599afccb5a3b7969660 (diff)
downloadpoky-98e52739716f82d8a5f62035ee0b9c44588f8039.tar.gz
oeqa/utils/nfs: Add unfs_server function to setup a userspace NFS server
Add a nfs module into oeqa utils. This module provides unfs_server which allows a test case to build unfs3-native and setup the unfs server on a target directory of the host. This directory is then shared and can be mounted by the host or a target device attached to the host (e.g. qemu via tap or slirp). The nfs server is setup over UDP and automatically assigns user privileged ports. The function provides the UDP ports for the server as part of a returned python contextmanager which handles cleanup of the server process on completion or exception. Also add a 'udp' arg to get_free_port to get a free UDP port. Note: unfs3 still requires the host to have rpcbind or portmap running. (From OE-Core rev: c754fd85be85ad0a381b642365eca17cea8eb627) Signed-off-by: Nathan Rossi <nathan@nathanrossi.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r--meta/lib/oeqa/utils/network.py4
-rw-r--r--meta/lib/oeqa/utils/nfs.py39
2 files changed, 41 insertions, 2 deletions
diff --git a/meta/lib/oeqa/utils/network.py b/meta/lib/oeqa/utils/network.py
index 59cbbc4f1b..59d01723a1 100644
--- a/meta/lib/oeqa/utils/network.py
+++ b/meta/lib/oeqa/utils/network.py
@@ -4,8 +4,8 @@
4 4
5import socket 5import socket
6 6
7def get_free_port(): 7def get_free_port(udp = False):
8 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 8 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM if not udp else socket.SOCK_DGRAM)
9 s.bind(('', 0)) 9 s.bind(('', 0))
10 addr = s.getsockname() 10 addr = s.getsockname()
11 s.close() 11 s.close()
diff --git a/meta/lib/oeqa/utils/nfs.py b/meta/lib/oeqa/utils/nfs.py
new file mode 100644
index 0000000000..a37686c914
--- /dev/null
+++ b/meta/lib/oeqa/utils/nfs.py
@@ -0,0 +1,39 @@
1# SPDX-License-Identifier: MIT
2import os
3import sys
4import tempfile
5import contextlib
6import socket
7from oeqa.utils.commands import bitbake, get_bb_var, Command
8from oeqa.utils.network import get_free_port
9
10@contextlib.contextmanager
11def unfs_server(directory, logger = None):
12 unfs_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "unfs3-native")
13 if not os.path.exists(os.path.join(unfs_sysroot, "usr", "bin", "unfsd")):
14 # build native tool
15 bitbake("unfs3-native -c addto_recipe_sysroot")
16
17 exports = None
18 cmd = None
19 try:
20 # create the exports file
21 with tempfile.NamedTemporaryFile(delete = False) as exports:
22 exports.write("{0} (rw,no_root_squash,no_all_squash,insecure)\n".format(directory).encode())
23
24 # find some ports for the server
25 nfsport, mountport = get_free_port(udp = True), get_free_port(udp = True)
26
27 nenv = dict(os.environ)
28 nenv['PATH'] = "{0}/sbin:{0}/usr/sbin:{0}/usr/bin:".format(unfs_sysroot) + nenv.get('PATH', '')
29 cmd = Command(["unfsd", "-d", "-p", "-N", "-e", exports.name, "-n", str(nfsport), "-m", str(mountport)],
30 bg = True, env = nenv, output_log = logger)
31 cmd.run()
32 yield nfsport, mountport
33 finally:
34 if cmd is not None:
35 cmd.stop()
36 if exports is not None:
37 # clean up exports file
38 os.unlink(exports.name)
39