Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def test_jail_fs_create_02():
    subprocess.check_output(
        ['focker', 'jail', 'remove', '--force', 'test-jail-fs-create-02'])
    name = jail_fs_create()
    zfs_tag(name, ['test-jail-fs-create-02'])
    assert zfs_exists(name)
    mountpoint = zfs_mountpoint(name)
    assert os.path.exists(mountpoint)
    with open(os.path.join(mountpoint, 'test.txt'), 'w') as f:
        f.write('test\n')
    assert os.path.exists(os.path.join(mountpoint, 'test.txt'))
    with open(os.path.join(mountpoint, 'test.txt'), 'r') as f:
        assert f.read() == 'test\n'
    subprocess.check_output(
        ['focker', 'jail', 'remove', 'test-jail-fs-create-02'])
    assert not zfs_exists(name)
    assert not os.path.exists(mountpoint)
Exemplo n.º 3
0
def test_command_volume_prune():
    subprocess.check_output(['focker', 'volume', 'remove', '--force', 'test-command-volume-prune'])
    subprocess.check_output(['focker', 'volume', 'create', '-t', 'test-command-volume-prune'])
    name, sha256 = zfs_find('test-command-volume-prune', focker_type='volume')
    mountpoint = zfs_mountpoint(name)
    subprocess.check_output(['focker', 'volume', 'untag', 'test-command-volume-prune'])
    args = lambda: 0
    command_volume_prune(args)
    assert not zfs_exists(name)
    assert not os.path.exists(mountpoint)
Exemplo n.º 4
0
def test_jail_fs_create_01():
    subprocess.check_output([
        'focker', 'image', 'remove', '--force', '-R', 'test-jail-fs-create-01'
    ])
    subprocess.check_output(
        ['focker', 'bootstrap', '--empty', '-t', 'test-jail-fs-create-01'])
    name = jail_fs_create('test-jail-fs-create-01')
    assert zfs_exists(name)
    mountpoint = zfs_mountpoint(name)
    assert os.path.exists(mountpoint)
    with open(os.path.join(mountpoint, 'test.txt'), 'w') as f:
        f.write('test\n')
    assert os.path.exists(os.path.join(mountpoint, 'test.txt'))
    with open(os.path.join(mountpoint, 'test.txt'), 'r') as f:
        assert f.read() == 'test\n'
    subprocess.check_output(
        ['focker', 'image', 'remove', '-R', 'test-jail-fs-create-01'])
    assert not zfs_exists(name)
    assert not os.path.exists(mountpoint)
Exemplo n.º 5
0
def test_command_volume_remove():
    subprocess.check_output(['focker', 'volume', 'remove', '--force', 'test-command-volume-remove'])
    subprocess.check_output(['focker', 'volume', 'create', '-t', 'test-command-volume-remove'])
    name, sha256 = zfs_find('test-command-volume-remove', focker_type='volume')
    mountpoint = zfs_mountpoint(name)
    args = lambda: 0
    args.references = ['test-command-volume-remove']
    args.force = False
    command_volume_remove(args)
    with pytest.raises(ValueError):
        zfs_find('test-command-volume-remove', focker_type='volume')
    with pytest.raises(ValueError):
        zfs_find(sha256, focker_type='volume')
    assert not os.path.exists(mountpoint)
    assert not zfs_exists(name)
Exemplo n.º 6
0
def test_command_image_remove():
    focker_unlock()
    subprocess.check_output([
        'focker', 'image', 'remove', '--force', '-R',
        'test-command-image-remove'
    ])
    subprocess.check_output(
        ['focker', 'bootstrap', '--empty', '-t', 'test-command-image-remove'])
    name, sha256 = zfs_find('test-command-image-remove', focker_type='image')
    mountpoint = zfs_mountpoint(name)
    args = lambda: 0
    args.reference = 'test-command-image-remove'
    args.force = False
    args.remove_dependents = False
    command_image_remove(args)
    with pytest.raises(ValueError):
        zfs_find('test-command-image-remove', focker_type='image')
    with pytest.raises(ValueError):
        zfs_find(sha256, focker_type='image')
    assert not os.path.exists(mountpoint)
    assert not zfs_exists(name)