Temporary directory is not cleaned up in cdist-web #146

Closed
opened 2021-11-20 15:20:12 +00:00 by ungleich-gitea · 4 comments

Created by: pcoder

from cdist.integration import configure_hosts_simple
import cdist
import tempfile

def my_configure_host(hosts):
    return_value = True
    with tempfile.NamedTemporaryFile() as tmp_manifest:
        tmp_manifest.writelines([b'__cdist_marker'])
        try:
            configure_hosts_simple(hosts,
                                   tmp_manifest.name,
                                   verbose=cdist.argparse.VERBOSE_TRACE)
        except Exception as cdist_exception:
            logger.error(cdist_exception)
            return_value = False
    return return_value
    
my_configure_host(['my_host'])

Everytime I run my_configure_host one or more new temporary directories are created in /tmp and they don't get cleaned up on completion of the script.

However, if I run the same manifest using cdist config -vv my_host, the temporary directory is cleaned up perfectly.

*Created by: pcoder* ``` from cdist.integration import configure_hosts_simple import cdist import tempfile def my_configure_host(hosts): return_value = True with tempfile.NamedTemporaryFile() as tmp_manifest: tmp_manifest.writelines([b'__cdist_marker']) try: configure_hosts_simple(hosts, tmp_manifest.name, verbose=cdist.argparse.VERBOSE_TRACE) except Exception as cdist_exception: logger.error(cdist_exception) return_value = False return return_value my_configure_host(['my_host']) ``` Everytime I run `my_configure_host` one or more new temporary directories are created in /tmp and they don't get cleaned up on completion of the script. However, if I run the same manifest using `cdist config -vv my_host`, the temporary directory is cleaned up perfectly.
Author
Owner

Created by: pcoder

Thanks @darko-poljak for the quick fix. That works like a charm 👍

*Created by: pcoder* Thanks @darko-poljak for the quick fix. That works like a charm 👍
Author
Owner

Created by: darko-poljak

@pcoder Can you git pull and try again? I made a fix.

*Created by: darko-poljak* @pcoder Can you git pull and try again? I made a fix.
Author
Owner

Created by: pcoder

Yes @darko-poljak and this commit 08bc38dd0f

*Created by: pcoder* Yes @darko-poljak and this commit 08bc38dd0fc85e88b65d3068827346686a1e20f0
Author
Owner

Created by: darko-poljak

@pcoder Are you using ungleich/master?

*Created by: darko-poljak* @pcoder Are you using ungleich/master?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ungleich-public/cdist#146
No description provided.