diff options
-rw-r--r-- | meta/lib/oeqa/utils/network.py | 4 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/nfs.py | 39 |
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 | ||
5 | import socket | 5 | import socket |
6 | 6 | ||
7 | def get_free_port(): | 7 | def 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 | ||
2 | import os | ||
3 | import sys | ||
4 | import tempfile | ||
5 | import contextlib | ||
6 | import socket | ||
7 | from oeqa.utils.commands import bitbake, get_bb_var, Command | ||
8 | from oeqa.utils.network import get_free_port | ||
9 | |||
10 | @contextlib.contextmanager | ||
11 | def 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 | |||