Merge "Verify the disk file exists before running qemu-img on it."
This commit is contained in:
		@@ -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()
 | 
			
		||||
 
 | 
			
		||||
@@ -2473,6 +2473,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, ''))
 | 
			
		||||
@@ -4073,8 +4076,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',
 | 
			
		||||
@@ -4098,7 +4103,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
 | 
			
		||||
@@ -4257,7 +4264,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')
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user