IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
소스 검색

Stop jails at the beginning of focker compose.

master
부모
커밋
defcfed708
2개의 변경된 파일55개의 추가작업 그리고 0개의 파일을 삭제
  1. +13
    -0
      focker/compose.py
  2. +42
    -0
      tests/test_compose.py

+ 13
- 0
focker/compose.py 파일 보기

@@ -17,6 +17,7 @@ from .zfs import AmbiguousValueError, \
from .jail import jail_fs_create, \
jail_create, \
jail_remove, \
jail_stop, \
backup_file, \
quote
from .misc import random_sha256_hexdigest, \
@@ -154,6 +155,16 @@ def build_jails(spec):
setup_dependencies(spec, generated_names)
def stop_jails(spec):
for jailname, _ in spec.items():
try:
name, _ = zfs_find(jailname, focker_type='jail')
except ValueError:
continue
print('Stopping:', jailname)
jail_stop(zfs_mountpoint(name))
def command_compose_build(args):
if not os.path.exists(args.filename):
raise ValueError('File not found: ' + args.filename)
@@ -161,6 +172,8 @@ def command_compose_build(args):
print('path:', path)
with open(args.filename, 'r') as f:
spec = yaml.safe_load(f)
if 'jails' in spec:
stop_jails(spec['jails'])
if 'exec.prebuild' in spec:
exec_prebuild(spec['exec.prebuild'], path)
if 'volumes' in spec:


+ 42
- 0
tests/test_compose.py 파일 보기

@@ -5,6 +5,7 @@ from focker.compose import exec_hook, \
build_images, \
setup_dependencies, \
build_jails, \
stop_jails, \
command_compose_build
import focker.compose
from tempfile import TemporaryDirectory
@@ -262,6 +263,47 @@ def test_build_jails():
conf.write('/etc/jail.conf')
def test_stop_jails_01(monkeypatch):
spec = {
'foobar': {}
}
def mock_zfs_find(name, focker_type):
assert name == 'foobar'
assert focker_type == 'jail'
return 'baf', None
def mock_zfs_mountpoint(name):
assert name == 'baf'
return '/beef'
def mock_jail_stop(path):
assert path == '/beef'
monkeypatch.setattr(focker.compose, 'zfs_find', mock_zfs_find)
monkeypatch.setattr(focker.compose, 'zfs_mountpoint', mock_zfs_mountpoint)
monkeypatch.setattr(focker.compose, 'jail_stop', mock_jail_stop)
stop_jails(spec)
def test_stop_jails_02(monkeypatch):
spec = {
'foobar': {}
}
def mock_zfs_find(name, focker_type):
assert name == 'foobar'
assert focker_type == 'jail'
raise ValueError('Not found')
def mock_zfs_mountpoint(name):
mock_zfs_mountpoint.called = True
mock_zfs_mountpoint.called = False
def mock_jail_stop(path):
mock_jail_stop.called = True
mock_jail_stop.called = False
monkeypatch.setattr(focker.compose, 'zfs_find', mock_zfs_find)
monkeypatch.setattr(focker.compose, 'zfs_mountpoint', mock_zfs_mountpoint)
monkeypatch.setattr(focker.compose, 'jail_stop', mock_jail_stop)
stop_jails(spec)
assert not mock_zfs_mountpoint.called
assert not mock_jail_stop.called
def test_command_compose_build(monkeypatch):
with TemporaryDirectory() as d:
with open(os.path.join(d, 'focker-compose.yml'), 'w') as f:


불러오는 중...
취소
저장