diff options
author | 2017-08-07 14:55:23 +0300 | |
---|---|---|
committer | 2017-08-07 14:55:23 +0300 | |
commit | a6fafab946b126f6f15f47032aa467ef81a64ae8 (patch) | |
tree | afa0fc091dfa92843a7384b32792b4bd2e2171b6 /app/monitoring/setup | |
parent | 02151ebd22bc9b453d971003bcdf882413b1be2d (diff) |
use tempfile.TempDirectory instead of /tmp
Change-Id: I408097ebd5f40a7f5ee5f1cc44e2a93410c0c7cc
Signed-off-by: Yaron Yogev <yaronyogev@gmail.com>
Diffstat (limited to 'app/monitoring/setup')
-rw-r--r-- | app/monitoring/setup/monitoring_handler.py | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/app/monitoring/setup/monitoring_handler.py b/app/monitoring/setup/monitoring_handler.py index f041264..a1ff864 100644 --- a/app/monitoring/setup/monitoring_handler.py +++ b/app/monitoring/setup/monitoring_handler.py @@ -18,6 +18,7 @@ import copy import pymongo import shutil import stat +import tempfile from boltons.iterutils import remap from discover.configuration import Configuration @@ -35,7 +36,6 @@ class MonitoringHandler(MongoAccess, CliAccess, BinaryConverter): PRODUCTION_CONFIG_DIR = '/etc/sensu/conf.d' APP_SCRIPTS_FOLDER = 'monitoring/checks' REMOTE_SCRIPTS_FOLDER = '/etc/sensu/plugins' - TMP_SSL_FOLDER = '/tmp/monitoring_ssl_files' provision_levels = { 'none': 0, @@ -334,11 +334,11 @@ class MonitoringHandler(MongoAccess, CliAccess, BinaryConverter): def deploy_ssl_files(self, hosts: list): monitoring_server = self.env_monitoring_config['server_ip'] gateway_host = SshConn.get_gateway_host(hosts[0]) - self.make_directory(self.TMP_SSL_FOLDER) + temp_dir = tempfile.TemporaryDirectory() for file_path in self.fetch_ssl_files: # copy SSL files from the monitoring server file_name = os.path.basename(file_path) - local_path = os.path.join(self.TMP_SSL_FOLDER, file_name) + local_path = os.path.join(temp_dir.name, file_name) self.get_file(monitoring_server, file_path, local_path) # first copy the files to the gateway self.write_to_remote_host(gateway_host, local_path, @@ -346,12 +346,6 @@ class MonitoringHandler(MongoAccess, CliAccess, BinaryConverter): ssl_path = os.path.commonprefix(self.fetch_ssl_files) for host in hosts: self.copy_from_gateway_to_host(host, ssl_path, ssl_path) - # remove files from temporary folder - for file_path in self.fetch_ssl_files: - tmp_path = os.path.join(self.TMP_SSL_FOLDER, - os.path.basename(file_path)) - if os.path.exists(tmp_path): - os.remove(tmp_path) # remove files from temporary folder def deploy_scripts_to_host(self, host_details): host = host_details['host'] |