From 404ffc9b62775df76782091368f10483b31553d6 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Sat, 30 May 2020 08:47:46 +0200 Subject: [PATCH] Change bootstrap switch name --dry-run to --empty. --- focker/bootstrap.py | 2 +- focker/focker.py | 2 +- tests/test_bootstrap.py | 24 ++++++++++++++++++++++-- tests/test_compose.py | 4 ++-- tests/test_focker.py | 4 ++-- tests/test_image.py | 16 ++++++++-------- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/focker/bootstrap.py b/focker/bootstrap.py index bb79077..58c5400 100644 --- a/focker/bootstrap.py +++ b/focker/bootstrap.py @@ -15,7 +15,7 @@ def command_bootstrap(args): name = find_prefix(poolname + '/focker/images/', sha256) subprocess.check_output(['zfs', 'create', '-o', 'focker:sha256=' + sha256, name]) zfs_tag(name, tags) - if not args.dry_run: + if not args.empty: res = subprocess.run(['bsdinstall', 'jail', zfs_mountpoint(name)]) if res.returncode != 0: zfs_run(['zfs', 'destroy', '-r', '-f', name]) diff --git a/focker/focker.py b/focker/focker.py index f335316..7b3af25 100644 --- a/focker/focker.py +++ b/focker/focker.py @@ -79,7 +79,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) - parser.add_argument('--dry-run', '-d', action='store_true') + parser.add_argument('--empty', '-e', action='store_true') # image subparsers = ListForwarder([ subparsers_top.add_parser(cmd).add_subparsers(dest='L2_command') \ diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index a35c71c..5e546e3 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -2,11 +2,31 @@ import subprocess from focker.zfs import * import re import os +from focker.bootstrap import command_bootstrap +from focker.misc import focker_unlock -def test_bootstrap(): +def test_bootstrap_01(): subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-focker-bootstrap']) - subprocess.check_output(['focker', 'bootstrap', '--dry-run', '--tags', 'test-focker-bootstrap']) + subprocess.check_output(['focker', 'bootstrap', '--empty', '--tags', 'test-focker-bootstrap']) + name, sha256 = zfs_find('test-focker-bootstrap', focker_type='image') + basename = os.path.basename(name) + assert 7 <= len(basename) <= 64 + assert re.search('[a-f]', basename[:7]) + assert len(sha256) == 64 + assert basename == sha256[:len(basename)] + assert zfs_exists_snapshot_sha256(sha256) + assert zfs_parse_output(['zfs', 'get', '-H', 'rdonly', name])[0][2] == 'on' + subprocess.check_output(['zfs', 'destroy', '-r', '-f', name]) + + +def test_bootstrap_02(): + subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-focker-bootstrap']) + args = lambda: 0 + args.empty = True + args.tags = ['test-focker-bootstrap'] + command_bootstrap(args) + focker_unlock() name, sha256 = zfs_find('test-focker-bootstrap', focker_type='image') basename = os.path.basename(name) assert 7 <= len(basename) <= 64 diff --git a/tests/test_compose.py b/tests/test_compose.py index 7313389..07f6962 100644 --- a/tests/test_compose.py +++ b/tests/test_compose.py @@ -142,7 +142,7 @@ def test_build_volumes(): def test_build_images(): subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-focker-bootstrap']) - subprocess.check_output(['focker', 'bootstrap', '--dry-run', '--tags', 'test-focker-bootstrap']) + subprocess.check_output(['focker', 'bootstrap', '--empty', '--tags', 'test-focker-bootstrap']) subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-build-images']) with TemporaryDirectory() as d: with open(os.path.join(d, 'Fockerfile'), 'w') as f: @@ -216,7 +216,7 @@ def test_build_jails(): 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']) + subprocess.check_output(['focker', 'bootstrap', '--empty', '-t', 'test-focker-bootstrap']) spec = { 'test-build-jails-A': { 'image': 'test-focker-bootstrap', diff --git a/tests/test_focker.py b/tests/test_focker.py index 949465c..fdfcd29 100644 --- a/tests/test_focker.py +++ b/tests/test_focker.py @@ -8,10 +8,10 @@ import pytest def test_parser_bootstrap(): parser = create_parser() - args = parser.parse_args(['bootstrap', '--dry-run', '--tags', 'a', 'b', 'c']) + args = parser.parse_args(['bootstrap', '--empty', '--tags', 'a', 'b', 'c']) assert args.func == command_bootstrap assert args.tags == ['a', 'b', 'c'] - assert args.dry_run + assert args.empty def test_parser_image(): diff --git a/tests/test_image.py b/tests/test_image.py index 4769571..6758e0d 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -47,7 +47,7 @@ def test_validate_spec_04(): def test_build_squeeze(monkeypatch): focker_unlock() subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-build-squeeze-base']) - subprocess.check_output(['focker', 'bootstrap', '--dry-run', '-t', 'test-build-squeeze-base']) + subprocess.check_output(['focker', 'bootstrap', '--empty', '-t', 'test-build-squeeze-base']) spec = dict(base='test-build-squeeze-base', steps=[ dict(copy=['/etc/localtime', '/etc/localtime']), dict(copy=['/etc/hosts', '/etc/hosts']) @@ -73,7 +73,7 @@ def test_build_squeeze(monkeypatch): def test_build(monkeypatch): focker_unlock() subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-build-squeeze-base']) - subprocess.check_output(['focker', 'bootstrap', '--dry-run', '-t', 'test-build-squeeze-base']) + subprocess.check_output(['focker', 'bootstrap', '--empty', '-t', 'test-build-squeeze-base']) spec = dict(base='test-build-squeeze-base', steps=[ dict(copy=['/etc/localtime', '/etc/localtime']), dict(copy=['/etc/hosts', '/etc/hosts']) @@ -105,7 +105,7 @@ def test_build(monkeypatch): def test_command_image_build(): focker_unlock() subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-command-image-build-base']) - subprocess.check_output(['focker', 'bootstrap', '--dry-run', '-t', 'test-command-image-build-base']) + subprocess.check_output(['focker', 'bootstrap', '--empty', '-t', 'test-command-image-build-base']) with TemporaryDirectory() as d: args = lambda: 0 @@ -132,7 +132,7 @@ def test_command_image_build(): def test_command_image_tag(): focker_unlock() subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-command-image-tag']) - subprocess.check_output(['focker', 'bootstrap', '--dry-run', '-t', 'test-command-image-tag']) + subprocess.check_output(['focker', 'bootstrap', '--empty', '-t', 'test-command-image-tag']) name_1, sha256_1 = zfs_find('test-command-image-tag', focker_type='image') args = lambda: 0 args.reference = sha256_1 @@ -153,7 +153,7 @@ def test_command_image_tag(): def test_command_image_untag(): focker_unlock() subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-command-image-untag']) - subprocess.check_output(['focker', 'bootstrap', '--dry-run', '-t', 'test-command-image-untag', 'test-command-image-untag-1', 'test-command-image-untag-2']) + subprocess.check_output(['focker', 'bootstrap', '--empty', '-t', 'test-command-image-untag', 'test-command-image-untag-1', 'test-command-image-untag-2']) name, sha256 = zfs_find('test-command-image-untag', focker_type='image') args = lambda: 0 args.tags = ['test-command-image-untag-1', 'test-command-image-untag-2'] @@ -171,7 +171,7 @@ def test_command_image_untag(): def test_command_image_list(monkeypatch): focker_unlock() subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-command-image-list']) - subprocess.check_output(['focker', 'bootstrap', '--dry-run', '-t', 'test-command-image-list', 'test-command-image-list-1', 'test-command-image-list-2']) + subprocess.check_output(['focker', 'bootstrap', '--empty', '-t', 'test-command-image-list', 'test-command-image-list-1', 'test-command-image-list-2']) name, sha256 = zfs_find('test-command-image-list', focker_type='image') args = lambda: 0 args.tagged_only = True @@ -199,7 +199,7 @@ def test_command_image_list(monkeypatch): def test_command_image_prune(): focker_unlock() subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-command-image-prune']) - subprocess.check_output(['focker', 'bootstrap', '--dry-run', '-t', 'test-command-image-prune']) + subprocess.check_output(['focker', 'bootstrap', '--empty', '-t', 'test-command-image-prune']) name, sha256 = zfs_find('test-command-image-prune', focker_type='image') mountpoint = zfs_mountpoint(name) subprocess.check_output(['focker', 'image', 'untag', 'test-command-image-prune']) @@ -215,7 +215,7 @@ def test_command_image_prune(): def test_command_image_remove(): focker_unlock() subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-command-image-remove']) - subprocess.check_output(['focker', 'bootstrap', '--dry-run', '-t', '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