summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/tests/create_keypairs_tests.py
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-07-27 10:27:14 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-07-27 10:27:14 -0600
commitca276f452540f68c08cb3df9049e9e7876364dac (patch)
treece26c5fb721f10402669bf761c4e69317d3f3eca /snaps/openstack/tests/create_keypairs_tests.py
parentfdcd5600bade294ae2a2207ef01da92f22f64327 (diff)
Ensure library and tests close all necessary resources.
The SNAPS-OO library and tests had left open files, ssh, and scp connections. These have all now been wrapped with try/finally blocks. JIRA: SNAPS-152 Change-Id: I43e09978b5c075bd78ff3279c0799556b8758878 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/tests/create_keypairs_tests.py')
-rw-r--r--snaps/openstack/tests/create_keypairs_tests.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/snaps/openstack/tests/create_keypairs_tests.py b/snaps/openstack/tests/create_keypairs_tests.py
index 0b35095..7b75d05 100644
--- a/snaps/openstack/tests/create_keypairs_tests.py
+++ b/snaps/openstack/tests/create_keypairs_tests.py
@@ -285,9 +285,15 @@ class CreateKeypairsTests(OSIntegrationTestCase):
self.keypair_creator.get_keypair())
self.assertEqual(self.keypair_creator.get_keypair(), keypair)
- file_key = open(os.path.expanduser(self.pub_file_path)).read()
- self.assertEqual(self.keypair_creator.get_keypair().public_key,
- file_key)
+ pub_file = None
+ try:
+ pub_file = open(os.path.expanduser(self.pub_file_path))
+ file_key = pub_file.read()
+ self.assertEqual(self.keypair_creator.get_keypair().public_key,
+ file_key)
+ finally:
+ if pub_file:
+ pub_file.close()
def test_create_keypair_save_both(self):
"""
@@ -305,7 +311,16 @@ class CreateKeypairsTests(OSIntegrationTestCase):
self.keypair_creator.get_keypair())
self.assertEqual(self.keypair_creator.get_keypair(), keypair)
- file_key = open(os.path.expanduser(self.pub_file_path)).read()
+ pub_file = None
+ try:
+ pub_file = open(os.path.expanduser(self.pub_file_path))
+ file_key = pub_file.read()
+ self.assertEqual(self.keypair_creator.get_keypair().public_key,
+ file_key)
+ finally:
+ if pub_file:
+ pub_file.close()
+
self.assertEqual(self.keypair_creator.get_keypair().public_key,
file_key)
@@ -328,7 +343,16 @@ class CreateKeypairsTests(OSIntegrationTestCase):
self.keypair_creator.get_keypair())
self.assertEqual(self.keypair_creator.get_keypair(), keypair)
- file_key = open(os.path.expanduser(self.pub_file_path)).read()
+ pub_file = None
+ try:
+ pub_file = open(os.path.expanduser(self.pub_file_path))
+ file_key = pub_file.read()
+ self.assertEqual(self.keypair_creator.get_keypair().public_key,
+ file_key)
+ finally:
+ if pub_file:
+ pub_file.close()
+
self.assertEqual(self.keypair_creator.get_keypair().public_key,
file_key)