Skip to content

Commit 6739a68

Browse files
cephadm: do not trigger rollback in bootstrap unit tests
Add a context manager that wraps the normal mock ctx context manager - this one disables bootstrap rollback by default. Use it in the tests that call command_bootstrap. The unit tests are older than the boostrap rollback behavior and therefore don't need it. However, this was not previously a problem. In python 3.12 (or 3.11?) changes to the shutil module prevent shutil.rmtree from working properly with the fake file system that cephadm tests rely upon heavily. Part of an effort to get ceph tox environments passing on Python 3.12. Signed-off-by: John Mulligan <[email protected]>
1 parent 9fbbdf7 commit 6739a68

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/cephadm/tests/test_cephadm.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# type: ignore
22

3+
import contextlib
34
import copy
45
import errno
56
import json
@@ -38,6 +39,13 @@ def get_ceph_conf(
3839
mon_host = {mon_host}
3940
'''
4041

42+
@contextlib.contextmanager
43+
def bootstrap_test_ctx(*args, **kwargs):
44+
with with_cephadm_ctx(*args, **kwargs) as ctx:
45+
ctx.no_cleanup_on_failure = True
46+
yield ctx
47+
48+
4149
class TestCephAdm(object):
4250

4351
@mock.patch('cephadm.logger')
@@ -1432,21 +1440,21 @@ def test_config(self, cephadm_fs, funkypatch):
14321440
'--config', conf_file,
14331441
)
14341442

1435-
with with_cephadm_ctx(cmd) as ctx:
1443+
with bootstrap_test_ctx(cmd) as ctx:
14361444
msg = r'No such file or directory'
14371445
with pytest.raises(_cephadm.Error, match=msg):
14381446
_cephadm.command_bootstrap(ctx)
14391447

14401448
cephadm_fs.create_file(conf_file)
1441-
with with_cephadm_ctx(cmd) as ctx:
1449+
with bootstrap_test_ctx(cmd) as ctx:
14421450
retval = _cephadm.command_bootstrap(ctx)
14431451
assert retval == 0
14441452

14451453
def test_no_mon_addr(self, cephadm_fs, funkypatch):
14461454
funkypatch.patch('cephadmlib.systemd.call')
14471455

14481456
cmd = self._get_cmd()
1449-
with with_cephadm_ctx(cmd) as ctx:
1457+
with bootstrap_test_ctx(cmd) as ctx:
14501458
msg = r'must specify --mon-ip or --mon-addrv'
14511459
with pytest.raises(_cephadm.Error, match=msg):
14521460
_cephadm.command_bootstrap(ctx)
@@ -1455,13 +1463,13 @@ def test_skip_mon_network(self, cephadm_fs, funkypatch):
14551463
funkypatch.patch('cephadmlib.systemd.call')
14561464
cmd = self._get_cmd('--mon-ip', '192.168.1.1')
14571465

1458-
with with_cephadm_ctx(cmd, list_networks={}) as ctx:
1466+
with bootstrap_test_ctx(cmd, list_networks={}) as ctx:
14591467
msg = r'--skip-mon-network'
14601468
with pytest.raises(_cephadm.Error, match=msg):
14611469
_cephadm.command_bootstrap(ctx)
14621470

14631471
cmd += ['--skip-mon-network']
1464-
with with_cephadm_ctx(cmd, list_networks={}) as ctx:
1472+
with bootstrap_test_ctx(cmd, list_networks={}) as ctx:
14651473
retval = _cephadm.command_bootstrap(ctx)
14661474
assert retval == 0
14671475

@@ -1540,12 +1548,12 @@ def test_mon_ip(self, mon_ip, list_networks, result, cephadm_fs, funkypatch):
15401548

15411549
cmd = self._get_cmd('--mon-ip', mon_ip)
15421550
if not result:
1543-
with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx:
1551+
with bootstrap_test_ctx(cmd, list_networks=list_networks) as ctx:
15441552
msg = r'--skip-mon-network'
15451553
with pytest.raises(_cephadm.Error, match=msg):
15461554
_cephadm.command_bootstrap(ctx)
15471555
else:
1548-
with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx:
1556+
with bootstrap_test_ctx(cmd, list_networks=list_networks) as ctx:
15491557
retval = _cephadm.command_bootstrap(ctx)
15501558
assert retval == 0
15511559

@@ -1604,11 +1612,11 @@ def test_mon_addrv(self, mon_addrv, list_networks, err, cephadm_fs, funkypatch):
16041612

16051613
cmd = self._get_cmd('--mon-addrv', mon_addrv)
16061614
if err:
1607-
with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx:
1615+
with bootstrap_test_ctx(cmd, list_networks=list_networks) as ctx:
16081616
with pytest.raises(_cephadm.Error, match=err):
16091617
_cephadm.command_bootstrap(ctx)
16101618
else:
1611-
with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx:
1619+
with bootstrap_test_ctx(cmd, list_networks=list_networks) as ctx:
16121620
retval = _cephadm.command_bootstrap(ctx)
16131621
assert retval == 0
16141622

@@ -1621,13 +1629,13 @@ def test_allow_fqdn_hostname(self, cephadm_fs, funkypatch):
16211629
'--skip-mon-network',
16221630
)
16231631

1624-
with with_cephadm_ctx(cmd, hostname=hostname) as ctx:
1632+
with bootstrap_test_ctx(cmd, hostname=hostname) as ctx:
16251633
msg = r'--allow-fqdn-hostname'
16261634
with pytest.raises(_cephadm.Error, match=msg):
16271635
_cephadm.command_bootstrap(ctx)
16281636

16291637
cmd += ['--allow-fqdn-hostname']
1630-
with with_cephadm_ctx(cmd, hostname=hostname) as ctx:
1638+
with bootstrap_test_ctx(cmd, hostname=hostname) as ctx:
16311639
retval = _cephadm.command_bootstrap(ctx)
16321640
assert retval == 0
16331641

@@ -1646,7 +1654,7 @@ def test_fsid(self, fsid, err, cephadm_fs, funkypatch):
16461654
'--fsid', fsid,
16471655
)
16481656

1649-
with with_cephadm_ctx(cmd) as ctx:
1657+
with bootstrap_test_ctx(cmd) as ctx:
16501658
if err:
16511659
with pytest.raises(_cephadm.Error, match=err):
16521660
_cephadm.command_bootstrap(ctx)
@@ -1661,7 +1669,7 @@ def test_fsid(self, cephadm_fs):
16611669
fsid = '00000000-0000-0000-0000-0000deadbeef'
16621670

16631671
cmd = ['shell', '--fsid', fsid]
1664-
with with_cephadm_ctx(cmd) as ctx:
1672+
with bootstrap_test_ctx(cmd) as ctx:
16651673
retval = _cephadm.command_shell(ctx)
16661674
assert retval == 0
16671675
assert ctx.fsid == fsid

0 commit comments

Comments
 (0)