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:
parent
99b9680ea2
commit
ec6b7bf91c
2 changed files with 65 additions and 70 deletions
2
changelogs/fragments/11323-lxc-container-tempdir.yml
Normal file
2
changelogs/fragments/11323-lxc-container-tempdir.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- lxc_container - use ``tempfile.TemporaryDirectory()`` instead of ``mkdtemp()`` (https://github.com/ansible-collections/community.general/pull/11323).
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue