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!
Przeglądaj źródła

Add test for build_images().

master
rodzic
commit
48b9e6264b
3 zmienionych plików z 56 dodań i 2 usunięć
  1. +1
    -0
      focker/focker.py
  2. +8
    -1
      focker/jail.py
  3. +47
    -1
      tests/test_compose.py

+ 1
- 0
focker/focker.py Wyświetl plik

@@ -139,6 +139,7 @@ def create_parser():
parser = ListForwarder([subparsers.add_parser(cmd) for cmd in ['remove', 'rem', 'rm', 'r']])
parser.set_defaults(func=command_jail_remove)
parser.add_argument('reference', type=str)
parser.add_argument('--force', '-f', action='store_true')
parser = ListForwarder([subparsers.add_parser(cmd) for cmd in ['exec', 'exe', 'e']])
parser.set_defaults(func=command_jail_exec)


+ 8
- 1
focker/jail.py Wyświetl plik

@@ -235,7 +235,14 @@ def command_jail_stop(args):
def command_jail_remove(args):
name, _ = zfs_find(args.reference, focker_type='jail')
try:
name, _ = zfs_find(args.reference, focker_type='jail')
except AmbiguousValueError:
raise
except ValueError:
if args.force:
return
raise
path = zfs_mountpoint(name)
jail_remove(path)


+ 47
- 1
tests/test_compose.py Wyświetl plik

@@ -3,7 +3,8 @@ from focker.compose import exec_hook, \
exec_postbuild, \
build_volumes, \
build_images, \
setup_dependencies
setup_dependencies, \
build_jails
from tempfile import TemporaryDirectory
import os
import pytest
@@ -200,3 +201,48 @@ def test_setup_dependencies():
del conf['test-setup-dependencies-B']
del conf['test-setup-dependencies-C']
conf.write('/etc/jail.conf')
def test_build_jails():
backup_file('/etc/jail.conf')
conf = jailconf.load('/etc/jail.conf')
for k in list(conf.keys()):
if conf[k]['host.hostname'].strip('\'"') in ['test-build-jails-A', 'test-build-jails-B']:
del conf[k]
conf.write('/etc/jail.conf')
subprocess.check_output(['focker', 'jail', 'remove', '--force', 'test-build-jails-A'])
subprocess.check_output(['focker', 'jail', 'remove', '--force', 'test-build-jails-B'])
subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-focker-bootstrap'])
subprocess.check_output(['focker', 'bootstrap', '--dry-run', '-t', 'test-focker-bootstrap'])
spec = {
'test-build-jails-A': {
'image': 'test-focker-bootstrap',
'exec.start': 'test-exec-start',
'exec.stop': 'test-exec-stop',
'ip4.addr': 'test-ip4-addr',
'interface': 'test-interface',
'host.hostname': 'test-build-jails-A'
}
}
spec['test-build-jails-B'] = spec['test-build-jails-A'].copy()
spec['test-build-jails-B']['host.hostname'] = 'test-build-jails-B'
build_jails(spec)
conf = jailconf.load('/etc/jail.conf')
print(conf.values())
blocks = list(filter(lambda a: a['host.hostname'].strip('"\'') in [ 'test-build-jails-A',
'test-build-jails-B' ], conf.values()))
print(blocks)
assert len(blocks) == 2
assert blocks[0]['host.hostname'] != blocks[1]['host.hostname']
for b in blocks:
name, _ = zfs_find(b['host.hostname'].strip('\'"'), focker_type='jail')
mountpoint = zfs_mountpoint(name)
assert b['path'] == mountpoint
assert b['exec.start'].strip('\'"') == 'test-exec-start'
assert b['exec.stop'].strip('\'"') == 'test-exec-stop'
assert b['ip4.addr'].strip('\'"') == 'test-ip4-addr'
assert b['interface'].strip('\'"') == 'test-interface'
subprocess.check_output(['focker', 'jail', 'remove', '--force', 'test-build-jails-A'])
subprocess.check_output(['focker', 'jail', 'remove', '--force', 'test-build-jails-B'])
subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-focker-bootstrap'])
conf.write('/etc/jail.conf')

Ładowanie…
Anuluj
Zapisz