MCPcopy
hub / github.com/saltstack/salt / cleanup

Function cleanup

tools/testsuite/container_test.py:312–402  ·  view source on GitHub ↗

Clean up artifacts and/or containers. Examples: * Clean up artifacts only: tools ts container-test cleanup --artifacts * Remove containers matching pattern: tools ts container-test cleanup --containers 'salt-test-*' * Clean up everything: too

(
    ctx: Context,
    artifacts: bool = False,
    containers: str = None,
)

Source from the content-addressed store, hash-verified

310 },
311)
312def cleanup(
313 ctx: Context,
314 artifacts: bool = False,
315 containers: str = None,
316):
317 """
318 Clean up artifacts and/or containers.
319
320 Examples:
321
322 * Clean up artifacts only:
323
324 tools ts container-test cleanup --artifacts
325
326 * Remove containers matching pattern:
327
328 tools ts container-test cleanup --containers 'salt-test-*'
329
330 * Clean up everything:
331
332 tools ts container-test cleanup --artifacts --containers 'salt-test-*'
333 """
334 if not artifacts and not containers:
335 ctx.error("Specify --artifacts and/or --containers")
336 ctx.exit(1)
337
338 if artifacts:
339 ctx.info("Cleaning up artifacts...")
340
341 # Remove artifacts directory
342 artifacts_path = tools.utils.REPO_ROOT / "artifacts"
343 if artifacts_path.exists():
344 shutil.rmtree(artifacts_path)
345 ctx.info(f" ✓ Removed {artifacts_path}")
346
347 # Remove nox artifacts
348 for pattern in ["nox-*.zip", "nox.*.tar.*"]:
349 for path in tools.utils.REPO_ROOT.glob(pattern):
350 path.unlink()
351 ctx.info(f" ✓ Removed {path.name}")
352
353 ctx.info("✓ Artifacts cleaned up")
354
355 if containers:
356 if not check_docker(ctx):
357 ctx.exit(1)
358
359 ctx.info(f"Finding containers matching: {containers}")
360
361 # List matching containers
362 ret = ctx.run(
363 "docker",
364 "ps",
365 "-a",
366 "--filter",
367 f"name={containers}",
368 "--format",
369 "{{.Names}}",

Callers

nothing calls this directly

Calls 7

check_dockerFunction · 0.85
exitMethod · 0.80
unlinkMethod · 0.80
errorMethod · 0.45
infoMethod · 0.45
existsMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected