def test_command_volume_protect(monkeypatch): subprocess.check_output(['focker', 'volume', 'remove', '--force', 'test-command-volume-protect']) subprocess.check_output(['focker', 'volume', 'create', '-t', 'test-command-volume-protect']) args = lambda: 0 args.references = ['test-command-volume-protect'] command_volume_protect(args) name, sha256 = zfs_find('test-command-volume-protect', focker_type='volume') mountpoint = zfs_mountpoint(name) lst = zfs_parse_output(['zfs', 'get', '-H', 'focker:protect', name]) assert len(lst) == 1 assert lst[0][2] == 'on' with pytest.raises(RuntimeError): zfs_destroy(name) subprocess.check_output(['focker', 'volume', 'untag', 'test-command-volume-protect']) lst = zfs_parse_output(['zfs', 'get', '-H', 'focker:tags', name]) assert len(lst) == 1 assert lst[0][2] == '-' n_called = 0 def fake_run(*args, **kwargs): nonlocal n_called n_called += 1 return zfs_run(*args, **kwargs) monkeypatch.setattr(focker.zfs, 'zfs_run', fake_run) zfs_prune(focker_type='volume') assert not n_called == 1 with pytest.raises(subprocess.CalledProcessError): subprocess.check_output(['focker', 'volume', 'remove', sha256]) subprocess.check_output(['zfs', 'destroy', '-r', '-f', name]) assert not zfs_exists(name) assert not os.path.exists(mountpoint)
def test_command_volume_unprotect(): subprocess.check_output(['focker', 'volume', 'remove', '--force', 'test-command-volume-unprotect']) subprocess.check_output(['focker', 'volume', 'create', '-t', 'test-command-volume-unprotect']) subprocess.check_output(['focker', 'volume', 'protect', 'test-command-volume-unprotect']) name, _ = zfs_find('test-command-volume-unprotect', focker_type='volume') lst = zfs_parse_output(['zfs', 'get', '-H', 'focker:protect', name]) assert len(lst) == 1 assert lst[0][2] == 'on' args = lambda: 0 args.references = ['test-command-volume-unprotect'] command_volume_unprotect(args) lst = zfs_parse_output(['zfs', 'get', '-H', 'focker:protect', name]) assert len(lst) == 1 assert lst[0][2] == '-' subprocess.check_output(['focker', 'volume', 'remove', 'test-command-volume-unprotect'])
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, 'protect': True, '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,focker:protect', name]) assert zst[0][2] == '1G' assert zst[1][2] == 'on' assert zst[2][2] == 'on' subprocess.check_output(['zfs', 'destroy', '-r', '-f', name])
def test_command_volume_untag(): subprocess.check_output(['focker', 'volume', 'remove', '--force', 'test-command-volume-untag']) subprocess.check_output(['focker', 'volume', 'create', '-t', 'test-command-volume-untag', 'test-command-volume-untag-1', 'test-command-volume-untag-2']) name, sha256 = zfs_find('test-command-volume-untag', focker_type='volume') args = lambda: 0 args.tags = ['test-command-volume-untag-1', 'test-command-volume-untag-2'] command_volume_untag(args) tags = zfs_parse_output(['zfs', 'get', '-H', 'focker:tags', name]) tags = tags[0][2].split(',') assert tags == ['test-command-volume-untag'] with pytest.raises(ValueError): zfs_find('test-command-volume-untag-1', focker_type='volume') with pytest.raises(ValueError): zfs_find('test-command-image-untag-2', focker_type='volume') subprocess.check_output(['focker', 'volume', 'remove', 'test-command-volume-untag'])
def test_command_volume_set(): subprocess.check_output(['focker', 'volume', 'remove', '--force', 'test-command-volume-set']) subprocess.check_output(['focker', 'volume', 'create', '-t', 'test-command-volume-set']) name, sha256 = zfs_find('test-command-volume-set', focker_type='volume') args = lambda: 0 args.reference = 'test-command-volume-set' args.properties = ['rdonly=on', 'quota=1G'] command_volume_set(args) props = zfs_parse_output(['zfs', 'get', '-H', 'rdonly,quota', name]) assert len(props) == 2 for i in range(2): assert props[i][0] == name assert props[0][1] == 'readonly' assert props[1][1] == 'quota' assert props[0][2] == 'on' assert props[1][2] == '1G' subprocess.check_output(['focker', 'volume', 'remove', 'test-command-volume-set'])