1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

lxc_container: use tempfile.TemporaryDirectory (#11323)

* lxc_container: use tempfile.TemporaryDirectory

* add changelog frag

* typo
This commit is contained in:
Alexei Znamensky 2025-12-25 20:18:19 +13:00 committed by GitHub
parent 99b9680ea2
commit ec6b7bf91c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 65 additions and 70 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- lxc_container - use ``tempfile.TemporaryDirectory()`` instead of ``mkdtemp()`` (https://github.com/ansible-collections/community.general/pull/11323).

View file

@ -409,9 +409,7 @@ lxc_container:
"""
import os
import os.path
import re
import shutil
import subprocess
import tempfile
import time
@ -1351,9 +1349,7 @@ class LxcContainerManagement:
* Clean up
"""
# Create a temp dir
temp_dir = tempfile.mkdtemp()
with tempfile.TemporaryDirectory() as temp_dir:
# Set the name of the working dir, temp + container_name
work_dir = os.path.join(temp_dir, self.container_name)
@ -1425,9 +1421,6 @@ class LxcContainerManagement:
else:
self.container.start()
# Remove tmpdir
shutil.rmtree(temp_dir)
def check_count(self, count, method):
if count > 1:
self.failure(