diff options
author | jichenjc <jichenjc@cn.ibm.com> | 2015-02-06 02:59:48 +0800 |
---|---|---|
committer | jichenjc <jichenjc@cn.ibm.com> | 2015-02-09 15:13:52 +0800 |
commit | 767c461a7f977b910cc8779687dcef4412f57ff8 (patch) | |
tree | 08d5a9348d6290baeb4f370a0195121f0ae5107d /nova/tests/unit/test_crypto.py | |
parent | 2495849456555a897750fc5fbbc1842630c25ae9 (diff) | |
download | nova-767c461a7f977b910cc8779687dcef4412f57ff8.tar.gz |
CWD is incorrectly set if exceptions are thrown
The call to utils.execute ends up in /opt/stack/nova/nova/utils.py which
ultimately calls processutils.execute() in the oslo_concurrency module.
If there's an error when executing the command which calls an bash script
then an exception ProcessExecutionError will be raised.
This patch adds a finally statement to ensure the dir will be switched back
to its original one.
Closes-Bug: #1414530
Change-Id: Ie4e95999795d349a5897f7a180e34187485bd8f1
Diffstat (limited to 'nova/tests/unit/test_crypto.py')
-rw-r--r-- | nova/tests/unit/test_crypto.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/nova/tests/unit/test_crypto.py b/nova/tests/unit/test_crypto.py index 6872eb7096..2d4eac4d9a 100644 --- a/nova/tests/unit/test_crypto.py +++ b/nova/tests/unit/test_crypto.py @@ -69,6 +69,16 @@ class X509Test(test.TestCase): dec = crypto.decrypt_text(project_id, enc) self.assertEqual(text, dec) + @mock.patch.object(utils, 'execute', + side_effect=processutils.ProcessExecutionError) + def test_ensure_ca_filesystem_chdir(self, *args, **kargs): + with utils.tempdir() as tmpdir: + self.flags(ca_path=tmpdir) + start = os.getcwd() + self.assertRaises(processutils.ProcessExecutionError, + crypto.ensure_ca_filesystem) + self.assertEqual(start, os.getcwd()) + class RevokeCertsTest(test.TestCase): |