@@ -15,9 +15,10 @@ def command_bootstrap(args): | |||||
name = find_prefix(poolname + '/focker/images/', sha256) | name = find_prefix(poolname + '/focker/images/', sha256) | ||||
subprocess.check_output(['zfs', 'create', '-o', 'focker:sha256=' + sha256, name]) | subprocess.check_output(['zfs', 'create', '-o', 'focker:sha256=' + sha256, name]) | ||||
zfs_tag(name, tags) | 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') | |||||
if not args.dry_run: | |||||
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', 'set', 'rdonly=on', name]) | ||||
subprocess.check_output(['zfs', 'snapshot', name + '@1']) | subprocess.check_output(['zfs', 'snapshot', name + '@1']) |
@@ -79,6 +79,7 @@ def create_parser(): | |||||
parser = ListForwarder([subparsers_top.add_parser(cmd) for cmd in ['bootstrap', 'boot', 'bs']]) | parser = ListForwarder([subparsers_top.add_parser(cmd) for cmd in ['bootstrap', 'boot', 'bs']]) | ||||
parser.set_defaults(func=command_bootstrap) | parser.set_defaults(func=command_bootstrap) | ||||
parser.add_argument('--tags', '-t', type=str, nargs='+', default=None) | parser.add_argument('--tags', '-t', type=str, nargs='+', default=None) | ||||
parser.add_argument('--dry-run', '-d', action='store_true') | |||||
# image | # image | ||||
subparsers = ListForwarder([ subparsers_top.add_parser(cmd).add_subparsers(dest='L2_command') \ | subparsers = ListForwarder([ subparsers_top.add_parser(cmd).add_subparsers(dest='L2_command') \ | ||||
@@ -1,13 +1,17 @@ | |||||
import subprocess | import subprocess | ||||
from focker.zfs import * | from focker.zfs import * | ||||
import re | import re | ||||
import os | |||||
def test_bootstrap(): | def test_bootstrap(): | ||||
subprocess.run(['focker', 'image', 'remove', '--force', 'test-focker-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]) | |||||
subprocess.run(['focker', 'bootstrap', '--dry-run', '--tags', 'test-focker-bootstrap']) | |||||
name, sha256 = zfs_find('test-focker-bootstrap', focker_type='image') | |||||
basename = os.path.basename(name) | |||||
assert len(basename) >= 7 | |||||
assert re.search('[a-f]', basename[:7]) | |||||
assert len(sha256) == 64 | assert len(sha256) == 64 | ||||
assert name == sha256[:len(name)] | |||||
assert basename == sha256[:len(basename)] | |||||
assert zfs_exists_snapshot_sha256(sha256) | |||||
subprocess.check_output(['zfs', 'destroy', '-r', '-f', name]) |