Skip to content

Commit f5058f4

Browse files
committed
Support --workdir-root in the tmt clean images command (#3426)
1 parent 7501a7b commit f5058f4

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

docs/releases.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
======================
66

77

8+
tmt-1.41.0
9+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10+
11+
Add the ``--workdir-root`` option for the ``tmt clean images``
12+
command so that users can specify the directory they want.
13+
14+
815
tmt-1.40.0
916
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1017

tmt/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3952,7 +3952,8 @@ def images(self) -> bool:
39523952
successful = True
39533953
for method in tmt.steps.provision.ProvisionPlugin.methods():
39543954
# FIXME: ignore[union-attr]: https://github.com/teemtee/tmt/issues/1599
3955-
if not method.class_.clean_images(self, self.is_dry_run): # type: ignore[union-attr]
3955+
if not method.class_.clean_images( # type: ignore[union-attr]
3956+
self, self.is_dry_run, self.workdir_root):
39563957
successful = False
39573958
return successful
39583959

tmt/cli/_root.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,9 +1700,10 @@ def clean_guests(
17001700
# inference. See Context and ContextObjects above.
17011701
@clean.command(name='images') # type: ignore[arg-type]
17021702
@pass_context
1703+
@workdir_root_options
17031704
@verbosity_options
17041705
@dry_options
1705-
def clean_images(context: Context, **kwargs: Any) -> None:
1706+
def clean_images(context: Context, _workdir_root: Optional[str], **kwargs: Any) -> None:
17061707
"""
17071708
Remove images of supported provision methods.
17081709
@@ -1714,12 +1715,17 @@ def clean_images(context: Context, **kwargs: Any) -> None:
17141715
# cleaned, similarly to guests.
17151716
assert context.obj.clean_logger is not None # narrow type
17161717

1718+
workdir_root = Path(_workdir_root) if _workdir_root is not None else None
1719+
if workdir_root and not workdir_root.exists():
1720+
raise tmt.utils.GeneralError(f"Path '{workdir_root}' doesn't exist.")
1721+
17171722
clean_obj = tmt.Clean(
17181723
logger=context.obj.clean_logger
17191724
.descend(logger_name='clean-images', extra_shift=0)
17201725
.apply_verbosity_options(**kwargs),
17211726
parent=context.obj.clean,
1722-
cli_invocation=CliInvocation.from_context(context))
1727+
cli_invocation=CliInvocation.from_context(context),
1728+
workdir_root=effective_workdir_root(workdir_root))
17231729
context.obj.clean_partials["images"].append(clean_obj.images)
17241730

17251731
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tmt/steps/provision/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,7 @@ def options(cls, how: Optional[str] = None) -> list[tmt.options.ClickOptionDecor
23682368
return super().options(how) + cls._guest_class.options(how)
23692369

23702370
@classmethod
2371-
def clean_images(cls, clean: 'tmt.base.Clean', dry: bool) -> bool:
2371+
def clean_images(cls, clean: 'tmt.base.Clean', dry: bool, workdir_root: Path) -> bool:
23722372
""" Remove the images of one particular plugin """
23732373
return True
23742374

tmt/steps/provision/testcloud.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,15 +1220,17 @@ def _print_local_images(self) -> None:
12201220
click.echo(f"{TESTCLOUD_IMAGES / filename}")
12211221

12221222
@classmethod
1223-
def clean_images(cls, clean: 'tmt.base.Clean', dry: bool) -> bool:
1223+
def clean_images(cls, clean: 'tmt.base.Clean', dry: bool, workdir_root: Path) -> bool:
12241224
""" Remove the testcloud images """
1225+
testcloud_images = workdir_root / 'testcloud/images'
1226+
12251227
clean.info('testcloud', shift=1, color='green')
1226-
if not TESTCLOUD_IMAGES.exists():
1228+
if not testcloud_images.exists():
12271229
clean.warn(
1228-
f"Directory '{TESTCLOUD_IMAGES}' does not exist.", shift=2)
1230+
f"Directory '{testcloud_images}' does not exist.", shift=2)
12291231
return True
12301232
successful = True
1231-
for image in TESTCLOUD_IMAGES.iterdir():
1233+
for image in testcloud_images.iterdir():
12321234
if dry:
12331235
clean.verbose(f"Would remove '{image}'.", shift=2)
12341236
else:

0 commit comments

Comments
 (0)