diff options
Diffstat (limited to 'src/cephadm/tests/test_cephadm.py')
-rw-r--r-- | src/cephadm/tests/test_cephadm.py | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index f27b9bcd362..bbaaf2d39f8 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1,5 +1,6 @@ # type: ignore +import contextlib import copy import errno import json @@ -38,6 +39,13 @@ def get_ceph_conf( mon_host = {mon_host} ''' +@contextlib.contextmanager +def bootstrap_test_ctx(*args, **kwargs): + with with_cephadm_ctx(*args, **kwargs) as ctx: + ctx.no_cleanup_on_failure = True + yield ctx + + class TestCephAdm(object): @mock.patch('cephadm.logger') @@ -1432,13 +1440,13 @@ class TestBootstrap(object): '--config', conf_file, ) - with with_cephadm_ctx(cmd) as ctx: + with bootstrap_test_ctx(cmd) as ctx: msg = r'No such file or directory' with pytest.raises(_cephadm.Error, match=msg): _cephadm.command_bootstrap(ctx) cephadm_fs.create_file(conf_file) - with with_cephadm_ctx(cmd) as ctx: + with bootstrap_test_ctx(cmd) as ctx: retval = _cephadm.command_bootstrap(ctx) assert retval == 0 @@ -1446,7 +1454,7 @@ class TestBootstrap(object): funkypatch.patch('cephadmlib.systemd.call') cmd = self._get_cmd() - with with_cephadm_ctx(cmd) as ctx: + with bootstrap_test_ctx(cmd) as ctx: msg = r'must specify --mon-ip or --mon-addrv' with pytest.raises(_cephadm.Error, match=msg): _cephadm.command_bootstrap(ctx) @@ -1455,13 +1463,13 @@ class TestBootstrap(object): funkypatch.patch('cephadmlib.systemd.call') cmd = self._get_cmd('--mon-ip', '192.168.1.1') - with with_cephadm_ctx(cmd, list_networks={}) as ctx: + with bootstrap_test_ctx(cmd, list_networks={}) as ctx: msg = r'--skip-mon-network' with pytest.raises(_cephadm.Error, match=msg): _cephadm.command_bootstrap(ctx) cmd += ['--skip-mon-network'] - with with_cephadm_ctx(cmd, list_networks={}) as ctx: + with bootstrap_test_ctx(cmd, list_networks={}) as ctx: retval = _cephadm.command_bootstrap(ctx) assert retval == 0 @@ -1540,12 +1548,12 @@ class TestBootstrap(object): cmd = self._get_cmd('--mon-ip', mon_ip) if not result: - with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx: + with bootstrap_test_ctx(cmd, list_networks=list_networks) as ctx: msg = r'--skip-mon-network' with pytest.raises(_cephadm.Error, match=msg): _cephadm.command_bootstrap(ctx) else: - with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx: + with bootstrap_test_ctx(cmd, list_networks=list_networks) as ctx: retval = _cephadm.command_bootstrap(ctx) assert retval == 0 @@ -1604,11 +1612,11 @@ class TestBootstrap(object): cmd = self._get_cmd('--mon-addrv', mon_addrv) if err: - with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx: + with bootstrap_test_ctx(cmd, list_networks=list_networks) as ctx: with pytest.raises(_cephadm.Error, match=err): _cephadm.command_bootstrap(ctx) else: - with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx: + with bootstrap_test_ctx(cmd, list_networks=list_networks) as ctx: retval = _cephadm.command_bootstrap(ctx) assert retval == 0 @@ -1621,13 +1629,13 @@ class TestBootstrap(object): '--skip-mon-network', ) - with with_cephadm_ctx(cmd, hostname=hostname) as ctx: + with bootstrap_test_ctx(cmd, hostname=hostname) as ctx: msg = r'--allow-fqdn-hostname' with pytest.raises(_cephadm.Error, match=msg): _cephadm.command_bootstrap(ctx) cmd += ['--allow-fqdn-hostname'] - with with_cephadm_ctx(cmd, hostname=hostname) as ctx: + with bootstrap_test_ctx(cmd, hostname=hostname) as ctx: retval = _cephadm.command_bootstrap(ctx) assert retval == 0 @@ -1646,7 +1654,7 @@ class TestBootstrap(object): '--fsid', fsid, ) - with with_cephadm_ctx(cmd) as ctx: + with bootstrap_test_ctx(cmd) as ctx: if err: with pytest.raises(_cephadm.Error, match=err): _cephadm.command_bootstrap(ctx) @@ -1661,7 +1669,7 @@ class TestShell(object): fsid = '00000000-0000-0000-0000-0000deadbeef' cmd = ['shell', '--fsid', fsid] - with with_cephadm_ctx(cmd) as ctx: + with bootstrap_test_ctx(cmd) as ctx: retval = _cephadm.command_shell(ctx) assert retval == 0 assert ctx.fsid == fsid |