diff options
author | spisarski <s.pisarski@cablelabs.com> | 2017-07-27 10:27:14 -0600 |
---|---|---|
committer | spisarski <s.pisarski@cablelabs.com> | 2017-07-27 10:27:14 -0600 |
commit | ca276f452540f68c08cb3df9049e9e7876364dac (patch) | |
tree | ce26c5fb721f10402669bf761c4e69317d3f3eca /snaps/provisioning/tests | |
parent | fdcd5600bade294ae2a2207ef01da92f22f64327 (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/provisioning/tests')
-rw-r--r-- | snaps/provisioning/tests/ansible_utils_tests.py | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/snaps/provisioning/tests/ansible_utils_tests.py b/snaps/provisioning/tests/ansible_utils_tests.py index 203ba33..da056b2 100644 --- a/snaps/provisioning/tests/ansible_utils_tests.py +++ b/snaps/provisioning/tests/ansible_utils_tests.py @@ -239,9 +239,14 @@ class AnsibleProvisioningTests(OSIntegrationTestCase): ssh_client = self.inst_creator.ssh_client() self.assertIsNotNone(ssh_client) - out = ssh_client.exec_command('pwd')[1].channel.in_buffer.read(1024) - self.assertIsNotNone(out) - self.assertGreater(len(out), 1) + + try: + out = ssh_client.exec_command('pwd')[1].channel.in_buffer.read( + 1024) + self.assertIsNotNone(out) + self.assertGreater(len(out), 1) + finally: + ssh_client.close() # Need to use the first floating IP as subsequent ones are currently # broken with Apex CO @@ -257,14 +262,25 @@ class AnsibleProvisioningTests(OSIntegrationTestCase): ssh = ansible_utils.ssh_client(ip, user, priv_key, self.os_creds.proxy_settings) self.assertIsNotNone(ssh) - scp = SCPClient(ssh.get_transport()) - scp.get('~/hello.txt', self.test_file_local_path) + + try: + scp = SCPClient(ssh.get_transport()) + scp.get('~/hello.txt', self.test_file_local_path) + finally: + scp.close() + ssh.close() self.assertTrue(os.path.isfile(self.test_file_local_path)) - with open(self.test_file_local_path) as f: - file_contents = f.readline() - self.assertEqual('Hello World!', file_contents) + test_file = None + + try: + with open(self.test_file_local_path) as test_file: + file_contents = test_file.readline() + self.assertEqual('Hello World!', file_contents) + finally: + if test_file: + test_file.close() def test_apply_template_playbook(self): """ @@ -310,11 +326,21 @@ class AnsibleProvisioningTests(OSIntegrationTestCase): ssh = ansible_utils.ssh_client(ip, user, priv_key, self.os_creds.proxy_settings) self.assertIsNotNone(ssh) - scp = SCPClient(ssh.get_transport()) - scp.get('/tmp/hello.txt', self.test_file_local_path) + + try: + scp = SCPClient(ssh.get_transport()) + scp.get('/tmp/hello.txt', self.test_file_local_path) + finally: + scp.close() + ssh.close() self.assertTrue(os.path.isfile(self.test_file_local_path)) - with open(self.test_file_local_path) as f: - file_contents = f.readline() - self.assertEqual('Hello Foo!', file_contents) + test_file = None + try: + with open(self.test_file_local_path) as test_file: + file_contents = test_file.readline() + self.assertEqual('Hello Foo!', file_contents) + finally: + if test_file: + test_file.close() |