summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Still <mikal@stillhq.com>2012-12-24 09:51:19 +1100
committerMichael Still <mikal@stillhq.com>2012-12-25 07:56:30 +1100
commit1b7cea76abde83e9f937e33b56d54fa885f2a0b9 (patch)
tree11f09b5c20ffdec8d99b585f98d5758663014c16
parenta52af4aee14447bed1b9acf8dbd8b25f4e5c7100 (diff)
Verify the disk file exists before running qemu-img on it.
Should resolve bug 955788, although it is a little hard to tell because the bug is so old. Change-Id: Ic0c47f4b6181f56a98cf58d4ebe2cc926d06d524
-rw-r--r--nova/tests/test_image_utils.py20
-rw-r--r--nova/tests/test_libvirt.py11
-rw-r--r--nova/tests/test_libvirt_utils.py4
-rw-r--r--nova/virt/images.py3
4 files changed, 38 insertions, 0 deletions
diff --git a/nova/tests/test_image_utils.py b/nova/tests/test_image_utils.py
index 9c040f2e1..a9768f821 100644
--- a/nova/tests/test_image_utils.py
+++ b/nova/tests/test_image_utils.py
@@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import os
+
from nova import test
from nova import utils
@@ -41,7 +43,9 @@ disk size: 96K
'format': f,
'path': path,
})
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
+ os.path.exists(path).AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((output, ''))
self.mox.ReplayAll()
@@ -60,7 +64,9 @@ disk size: 96K
output = template_output % ({
'path': path,
})
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
+ os.path.exists(path).AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((output, ''))
self.mox.ReplayAll()
@@ -84,7 +90,9 @@ disk size: 96K
'vsize_b': i,
'path': path,
})
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
+ os.path.exists(path).AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((output, ''))
self.mox.ReplayAll()
@@ -96,7 +104,9 @@ disk size: 96K
'vsize_b': i,
'path': path,
})
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
+ os.path.exists(path).AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((output, ''))
self.mox.ReplayAll()
@@ -113,7 +123,9 @@ cluster_size: 65536
disk size: 96K
blah BLAH: bb
"""
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
+ os.path.exists(path).AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((example_output, ''))
self.mox.ReplayAll()
@@ -133,7 +145,9 @@ cluster_size: 65536
disk size: 963434
backing file: /var/lib/nova/a328c7998805951a_2
"""
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
+ os.path.exists(path).AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((example_output, ''))
self.mox.ReplayAll()
@@ -158,7 +172,9 @@ ID TAG VM SIZE DATE VM CLOCK
1 d9a9784a500742a7bb95627bb3aace38 0 2012-08-20 10:52:46 00:00:00.000
backing file: /var/lib/nova/a328c7998805951a_2 (actual path: /b/3a988059e51a_2)
"""
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
+ os.path.exists(path).AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((example_output, ''))
self.mox.ReplayAll()
@@ -184,7 +200,9 @@ ID TAG VM SIZE DATE VM CLOCK
4 d9a9784a500742a7bb95627bb3aace38 0 2012-08-20 10:52:46 00:00:00.000
junk stuff: bbb
"""
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
+ os.path.exists(path).AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((example_output, ''))
self.mox.ReplayAll()
@@ -206,7 +224,9 @@ ID TAG VM SIZE DATE VM CLOCK
3 d9a9784a500742a7bb95627bb3aace38 0 2012-08-20 10:52:46 00:00:00.000
4 d9a9784a500742a7bb95627bb3aace38 0 2012-08-20 10:52:46 00:00:00.000
"""
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
+ os.path.exists(path).AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((example_output, ''))
self.mox.ReplayAll()
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index 6e941cb45..e4466fdf3 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -2366,6 +2366,9 @@ class LibvirtConnTestCase(test.TestCase):
"cluster_size: 2097152\n"
"backing file: /test/dummy (actual path: /backing/file)\n")
+ self.mox.StubOutWithMock(os.path, "exists")
+ os.path.exists('/test/disk.local').AndReturn(True)
+
self.mox.StubOutWithMock(utils, "execute")
utils.execute('env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
'/test/disk.local').AndReturn((ret, ''))
@@ -3866,8 +3869,10 @@ class LibvirtUtilsTestCase(test.TestCase):
libvirt_utils.create_image('qcow2', '/some/stuff', '1234567891234')
def test_create_cow_image(self):
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
rval = ('', '')
+ os.path.exists('/some/path').AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', '/some/path').AndReturn(rval)
utils.execute('qemu-img', 'create', '-f', 'qcow2',
@@ -3891,7 +3896,9 @@ class LibvirtUtilsTestCase(test.TestCase):
self.assertEquals(result, expected_result)
def test_get_disk_size(self):
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
+ os.path.exists('/some/path').AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
'/some/path').AndReturn(('''image: 00000001
file format: raw
@@ -4050,7 +4057,11 @@ disk size: 4.4M''', ''))
"backing file: /foo/bar/baz\n"
"...: ...\n"), ''
+ def return_true(*args, **kwargs):
+ return True
+
self.stubs.Set(utils, 'execute', fake_execute)
+ self.stubs.Set(os.path, 'exists', return_true)
out = libvirt_utils.get_disk_backing_file('')
self.assertEqual(out, 'baz')
diff --git a/nova/tests/test_libvirt_utils.py b/nova/tests/test_libvirt_utils.py
index 89410390b..60f0682a8 100644
--- a/nova/tests/test_libvirt_utils.py
+++ b/nova/tests/test_libvirt_utils.py
@@ -15,6 +15,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import os
+
from nova import test
from nova import utils
from nova.virt.libvirt import utils as libvirt_utils
@@ -30,7 +32,9 @@ cluster_size: 65536
disk size: 96K
blah BLAH: bb
"""
+ self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(utils, 'execute')
+ os.path.exists(path).AndReturn(True)
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((example_output, ''))
self.mox.ReplayAll()
diff --git a/nova/virt/images.py b/nova/virt/images.py
index 514c8755f..244b33ab7 100644
--- a/nova/virt/images.py
+++ b/nova/virt/images.py
@@ -176,6 +176,9 @@ class QemuImgInfo(object):
def qemu_img_info(path):
"""Return a object containing the parsed output from qemu-img info."""
+ if not os.path.exists(path):
+ return QemuImgInfo()
+
out, err = utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path)
return QemuImgInfo(out)