From adb75cb5685579334c1deab0d17b40a47470249d Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Sun, 8 Jan 2017 00:17:32 -0800 Subject: [PATCH] heat: convert open to context manager Change-Id: I5ce6c77839f4104d305d66238bb2c6cbdc39a28c Signed-off-by: Ross Brattain --- yardstick/benchmark/contexts/heat.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py index 0b2fbdcd6..79b7472ff 100644 --- a/yardstick/benchmark/contexts/heat.py +++ b/yardstick/benchmark/contexts/heat.py @@ -94,9 +94,10 @@ class HeatContext(Context): rsa_key = paramiko.RSAKey.generate(bits=2048, progress_func=None) rsa_key.write_private_key_file(self.key_filename) - open(self.key_filename + ".pub", "w").write("%s %s\n" % - (rsa_key.get_name(), - rsa_key.get_base64())) + print("Writing %s ..." % self.key_filename) + with open(self.key_filename + ".pub", "w") as pubkey_file: + pubkey_file.write( + "%s %s\n" % (rsa_key.get_name(), rsa_key.get_base64())) del rsa_key @property -- 2.16.6