From a008f3e9fcb183038b45dd631dff9befcd87aa97 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Tue, 26 May 2020 09:13:54 +0200 Subject: [PATCH] Add test for build_volumes. --- tests/test_compose.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/test_compose.py b/tests/test_compose.py index c4e925f..ef26b4f 100644 --- a/tests/test_compose.py +++ b/tests/test_compose.py @@ -1,6 +1,7 @@ from focker.compose import exec_hook, \ exec_prebuild, \ - exec_postbuild + exec_postbuild, \ + build_volumes from tempfile import TemporaryDirectory import os import pytest @@ -9,6 +10,11 @@ from focker.misc import focker_lock, \ focker_unlock import inspect import ast +import stat +from focker.zfs import zfs_find, \ + zfs_mountpoint, \ + zfs_parse_output +import subprocess def test_exec_hook_01(): @@ -93,3 +99,33 @@ def test_exec_prebuild(): def test_exec_postbuild(): _test_simple_forward(exec_postbuild) + + +def test_build_volumes(): + subprocess.check_output(['focker', 'volume', 'remove', '--force', 'test-build-volumes']) + err = False + try: + name, _ = zfs_find('test-build-volumes', focker_type='volume') + except: + err = True + assert err + spec = { + 'test-build-volumes': { + 'chown': '65534:65534', + 'chmod': 0o123, + 'zfs': { + 'quota': '1G', + 'readonly': 'on' + } + } + } + build_volumes(spec) + name, _ = zfs_find('test-build-volumes', focker_type='volume') + st = os.stat(zfs_mountpoint(name)) + assert st.st_uid == 65534 + assert st.st_gid == 65534 + assert ('%o' % st.st_mode)[-3:] == '123' + zst = zfs_parse_output(['zfs', 'get', '-H', 'quota,readonly', name]) + assert zst[0][2] == '1G' + assert zst[1][2] == 'on' + subprocess.check_output(['zfs', 'destroy', '-r', '-f', name])