diff options
author | jichenjc <jichenjc@cn.ibm.com> | 2017-08-19 05:48:30 +0800 |
---|---|---|
committer | Matt Riedemann <mriedem.os@gmail.com> | 2017-10-20 16:46:15 -0400 |
commit | cb565d9baddf8799e36f5b37df4a365baf8d4cd4 (patch) | |
tree | 8cb5dfd9e35bb9b58a3a1a24b4f812d8a4ab3553 /nova/virt/hyperv/pathutils.py | |
parent | ae4b5d0147cb3e345bf57034221e9c8fedf3cad2 (diff) | |
download | nova-cb565d9baddf8799e36f5b37df4a365baf8d4cd4.tar.gz |
propagate OSError to MigrationPreCheckError
OSError will lead instance to ERROR state, change to
MigrationPreCheckError will make the instance status not changed.
Also, modify some test cases to make unit test easier
Closes-Bug: 1694636
Change-Id: I3286c32ca205ffd2d5d1aaab88cc96699476e410
Diffstat (limited to 'nova/virt/hyperv/pathutils.py')
-rw-r--r-- | nova/virt/hyperv/pathutils.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/nova/virt/hyperv/pathutils.py b/nova/virt/hyperv/pathutils.py index a6ad7aa4a7..f05799f2ec 100644 --- a/nova/virt/hyperv/pathutils.py +++ b/nova/virt/hyperv/pathutils.py @@ -14,6 +14,7 @@ # under the License. import os +import six import tempfile import time @@ -181,11 +182,15 @@ class PathUtils(pathutils.PathUtils): LOG.debug("Checking if %(src_dir)s and %(dest_dir)s point " "to the same location.", dict(src_dir=src_dir, dest_dir=dest_dir)) - with tempfile.NamedTemporaryFile(dir=dest_dir) as tmp_file: - src_path = os.path.join(src_dir, - os.path.basename(tmp_file.name)) - shared_storage = os.path.exists(src_path) + try: + with tempfile.NamedTemporaryFile(dir=dest_dir) as tmp_file: + src_path = os.path.join(src_dir, + os.path.basename(tmp_file.name)) + shared_storage = os.path.exists(src_path) + except OSError as e: + raise exception.FileNotFound(six.text_type(e)) + return shared_storage def check_remote_instances_dir_shared(self, dest): |