summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nova/crypto.py4
-rw-r--r--nova/tests/test_crypto.py4
2 files changed, 5 insertions, 3 deletions
diff --git a/nova/crypto.py b/nova/crypto.py
index cecd1846bc..c9f3030d48 100644
--- a/nova/crypto.py
+++ b/nova/crypto.py
@@ -274,7 +274,9 @@ def ssh_encrypt_text(ssh_public_key, text):
def revoke_cert(project_id, file_name):
"""Revoke a cert by file name."""
start = os.getcwd()
- if not os.chdir(ca_folder(project_id)):
+ try:
+ os.chdir(ca_folder(project_id))
+ except OSError:
raise exception.ProjectNotFound(project_id=project_id)
try:
# NOTE(vish): potential race condition here
diff --git a/nova/tests/test_crypto.py b/nova/tests/test_crypto.py
index b99f329a5c..392937f864 100644
--- a/nova/tests/test_crypto.py
+++ b/nova/tests/test_crypto.py
@@ -136,12 +136,12 @@ class RevokeCertsTest(test.TestCase):
@mock.patch.object(utils, 'execute',
side_effect=processutils.ProcessExecutionError)
- @mock.patch.object(os, 'chdir', return_value=True)
+ @mock.patch.object(os, 'chdir', return_value=None)
def test_revoke_cert_process_execution_error(self, *args, **kargs):
self.assertRaises(exception.RevokeCertFailure, crypto.revoke_cert,
2, 'test_file')
- @mock.patch.object(os, 'chdir', return_value=False)
+ @mock.patch.object(os, 'chdir', mock.Mock(side_effect=OSError))
def test_revoke_cert_project_not_found_chdir_fails(self, *args, **kargs):
self.assertRaises(exception.ProjectNotFound, crypto.revoke_cert,
2, 'test_file')