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!
Explorar el Código

Start adding tests.

master
Stanislaw Adaszewski hace 4 años
padre
commit
e7fd55938d
Se han modificado 5 ficheros con 30 adiciones y 4 borrados
  1. +1
    -0
      .gitignore
  2. +2
    -1
      focker/bootstrap.py
  3. +2
    -0
      focker/focker.py
  4. +12
    -3
      focker/image.py
  5. +13
    -0
      tests/test_bootstrap.py

+ 1
- 0
.gitignore Ver fichero

@@ -6,3 +6,4 @@ __pycache__
/mymailmap
/*.shar
/example/gitea/x
.pytest_cache/

+ 2
- 1
focker/bootstrap.py Ver fichero

@@ -9,7 +9,7 @@ from .zfs import zfs_poolname, \
def command_bootstrap(args):
version = subprocess.check_output(['freebsd-version']).decode('utf-8')
print('FreeBSD version:', version)
tags = [ 'freebsd-' + version.split('-')[0], 'freebsd-latest' ]
tags = args.tags or [ 'freebsd-' + version.split('-')[0], 'freebsd-latest' ]
sha256 = hashlib.sha256(('FreeBSD ' + version).encode('utf-8')).hexdigest()
poolname = zfs_poolname()
name = find_prefix(poolname + '/focker/images/', sha256)
@@ -17,6 +17,7 @@ def command_bootstrap(args):
zfs_tag(name, tags)
res = subprocess.run(['bsdinstall', 'jail', zfs_mountpoint(name)])
if res.returncode != 0:
zfs_run(['zfs', 'destroy', '-r', '-f', name])
raise ValueError('bsdinstall failed')
subprocess.check_output(['zfs', 'set', 'rdonly=on', name])
subprocess.check_output(['zfs', 'snapshot', name + '@1'])

+ 2
- 0
focker/focker.py Ver fichero

@@ -78,6 +78,7 @@ def create_parser():
parser = ListForwarder([subparsers_top.add_parser(cmd) for cmd in ['bootstrap', 'boot', 'bs']])
parser.set_defaults(func=command_bootstrap)
parser.add_argument('--tags', '-t', type=str, nargs='+', default=None)
# image
subparsers = ListForwarder([ subparsers_top.add_parser(cmd).add_subparsers(dest='L2_command') \
@@ -111,6 +112,7 @@ def create_parser():
parser.add_argument('reference', type=str)
# parser.add_argument('--remove-children', '-r', action='store_true')
parser.add_argument('--remove-dependents', '-R', action='store_true')
parser.add_argument('--force', '-f', action='store_true')
# jail
subparsers = ListForwarder([ subparsers_top.add_parser(cmd).add_subparsers(dest='L2_command') \


+ 12
- 3
focker/image.py Ver fichero

@@ -162,8 +162,15 @@ def command_image_prune(args):
def command_image_remove(args):
snap, snap_sha256 = zfs_find(args.reference, focker_type='image',
zfs_type='snapshot')
try:
snap, snap_sha256 = zfs_find(args.reference, focker_type='image',
zfs_type='snapshot')
except AmbiguousValueError:
raise
except ValueError:
if args.force:
return
raise
ds = snap.split('@')[0]
command = ['zfs', 'destroy', '-r', '-f']
#if args.remove_children:
@@ -171,5 +178,7 @@ def command_image_remove(args):
if args.remove_dependents:
command.append('-R')
command.append(ds)
subprocess.run(command)
res = subprocess.run(command)
if res.returncode != 0:
raise RuntimeError('zfs destroy failed')
# zfs_run(['zfs', 'destroy', ds])

+ 13
- 0
tests/test_bootstrap.py Ver fichero

@@ -0,0 +1,13 @@
import subprocess
from focker.zfs import *
import re
def test_bootstrap():
subprocess.run(['focker', 'image', 'remove', '--force', 'test-focker-bootstrap'])
subprocess.run(['focker', 'bootstrap', '--tags', 'test-focker-bootstrap'])
name, sha256 = zfs_find('test-focker-bootstrap', focker_type='volume')
assert len(name) >= 7
assert re.search('[a-f]', name[:7])
assert len(sha256) == 64
assert name == sha256[:len(name)]

Cargando…
Cancelar
Guardar