Navigation Menu

Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Fix leaking tempfile handles
Browse files Browse the repository at this point in the history
  • Loading branch information
labisso committed Oct 29, 2012
1 parent 52047e0 commit 757ff33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion epuharness/fixture.py
@@ -1,3 +1,4 @@
import os
import tempfile import tempfile
from socket import timeout from socket import timeout


Expand Down Expand Up @@ -105,7 +106,8 @@ def make_fake_libcloud_site(self):
Also creates an instance of the MockEC2NodeDriver for convenience Also creates an instance of the MockEC2NodeDriver for convenience
""" """
from epu.mocklibcloud import MockEC2NodeDriver from epu.mocklibcloud import MockEC2NodeDriver
_, self.fake_libcloud_db = tempfile.mkstemp() fh, self.fake_libcloud_db = tempfile.mkstemp()
os.close(fh)
site_name = 'ec2-fake' site_name = 'ec2-fake'
fake_site = { fake_site = {
'name': site_name, 'name': site_name,
Expand Down
8 changes: 8 additions & 0 deletions epuharness/harness.py
Expand Up @@ -236,6 +236,7 @@ def _build_phantom_authz_file(self, users):
pw_file_contents += "%s\n%s\n" % (user.get('user', ''), user.get('password', '')) pw_file_contents += "%s\n%s\n" % (user.get('user', ''), user.get('password', ''))


(os_handle, pw_filename) = tempfile.mkstemp() (os_handle, pw_filename) = tempfile.mkstemp()
os.close(os_handle)
with open(pw_filename, "w") as pw_f: with open(pw_filename, "w") as pw_f:
pw_f.write(pw_file_contents) pw_f.write(pw_file_contents)


Expand Down Expand Up @@ -269,6 +270,7 @@ def _build_phantom_config(self, name, exchange, config, authz_file, logfile=None
config_yaml = yaml.dump(merged_config) config_yaml = yaml.dump(merged_config)


(os_handle, config_filename) = tempfile.mkstemp(suffix='.yml') (os_handle, config_filename) = tempfile.mkstemp(suffix='.yml')
os.close(os_handle)
with open(config_filename, "w") as config_f: with open(config_filename, "w") as config_f:
config_f.write(config_yaml) config_f.write(config_yaml)


Expand Down Expand Up @@ -340,6 +342,7 @@ def _build_epum_config(self, name, exchange, config, logfile=None, instance=None
config_yaml = yaml.dump(merged_config) config_yaml = yaml.dump(merged_config)


(os_handle, config_filename) = tempfile.mkstemp(suffix='.yml') (os_handle, config_filename) = tempfile.mkstemp(suffix='.yml')
os.close(os_handle)
with open(config_filename, "w") as config_f: with open(config_filename, "w") as config_f:
config_f.write(config_yaml) config_f.write(config_yaml)


Expand Down Expand Up @@ -415,6 +418,7 @@ def _build_provisioner_config(self, name, exchange, config, logfile=None, instan
config_yaml = yaml.dump(merged_config) config_yaml = yaml.dump(merged_config)


(os_handle, config_filename) = tempfile.mkstemp(suffix='.yml') (os_handle, config_filename) = tempfile.mkstemp(suffix='.yml')
os.close(os_handle)
with open(config_filename, "w") as config_f: with open(config_filename, "w") as config_f:
config_f.write(config_yaml) config_f.write(config_yaml)


Expand Down Expand Up @@ -485,6 +489,7 @@ def _build_dtrs_config(self, name, exchange, config, logfile=None, instance=None
config_yaml = yaml.dump(merged_config) config_yaml = yaml.dump(merged_config)


(os_handle, config_filename) = tempfile.mkstemp(suffix='.yml') (os_handle, config_filename) = tempfile.mkstemp(suffix='.yml')
os.close(os_handle)
with open(config_filename, "w") as config_f: with open(config_filename, "w") as config_f:
config_f.write(config_yaml) config_f.write(config_yaml)


Expand Down Expand Up @@ -565,6 +570,7 @@ def _build_process_dispatcher_config(self, exchange, name, config,
config_yaml = yaml.dump(merged_config) config_yaml = yaml.dump(merged_config)


(os_handle, config_filename) = tempfile.mkstemp(prefix="%s_" % name, suffix='.yml') (os_handle, config_filename) = tempfile.mkstemp(prefix="%s_" % name, suffix='.yml')
os.close(os_handle)
with open(config_filename, "w") as config_f: with open(config_filename, "w") as config_f:
config_f.write(config_yaml) config_f.write(config_yaml)


Expand Down Expand Up @@ -680,6 +686,7 @@ def _build_eeagent_config(self, exchange, name, process_dispatcher,
config_yaml = yaml.dump(config) config_yaml = yaml.dump(config)


(os_handle, config_filename) = tempfile.mkstemp(suffix='.yml') (os_handle, config_filename) = tempfile.mkstemp(suffix='.yml')
os.close(os_handle)
with open(config_filename, "w") as config_f: with open(config_filename, "w") as config_f:
config_f.write(config_yaml) config_f.write(config_yaml)


Expand Down Expand Up @@ -817,6 +824,7 @@ def _start_rel(self, name=None, module=None, cls=None, config=None,
rel_yaml = yaml.dump(rel) rel_yaml = yaml.dump(rel)


(os_handle, rel_filename) = tempfile.mkstemp(suffix='.yml') (os_handle, rel_filename) = tempfile.mkstemp(suffix='.yml')
os.close(os_handle)
with open(rel_filename, "w") as rel_f: with open(rel_filename, "w") as rel_f:
rel_f.write(rel_yaml) rel_f.write(rel_yaml)


Expand Down

0 comments on commit 757ff33

Please sign in to comment.