示例#1
0
    def test_disk_size(self):
        path = "/myhome/disk.config"
        template_output = """image: %(path)s
file format: raw
virtual size: %(v_size)s (%(vsize_b)s bytes)
cluster_size: 65536
disk size: 96K
"""
        for i in range(0, 128):
            bytes = i * 65336
            kbytes = bytes / 1024
            mbytes = kbytes / 1024
            output = template_output % ({"v_size": "%sM" % (mbytes), "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()
            d_size = libvirt_utils.get_disk_size(path)
            self.assertEqual(i, d_size)
            self.mox.UnsetStubs()
            output = template_output % ({"v_size": "%sK" % (kbytes), "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()
            d_size = libvirt_utils.get_disk_size(path)
            self.assertEqual(i, d_size)
            self.mox.UnsetStubs()
示例#2
0
文件: imagebackend.py 项目: nati/nova
 def create_lvm_image(base, size):
     base_size = libvirt_utils.get_disk_size(base)
     resize = size > base_size
     size = size if resize else base_size
     libvirt_utils.create_lvm_image(self.vg, self.lv, size, sparse=self.sparse)
     cmd = ("dd", "if=%s" % base, "of=%s" % self.path, "bs=4M")
     utils.execute(*cmd, run_as_root=True)
     if resize:
         disk.resize2fs(self.path)
 def _test_disk_size(self, mock_execute, path, expected_size):
     d_size = libvirt_utils.get_disk_size(path)
     self.assertEqual(expected_size, d_size)
     mock_execute.assert_called_once_with('env',
                                          'LC_ALL=C',
                                          'LANG=C',
                                          'qemu-img',
                                          'info',
                                          path,
                                          prlimit=images.QEMU_IMG_LIMITS)
示例#4
0
 def _test_disk_size(self, mock_execute, path, expected_size):
     d_size = libvirt_utils.get_disk_size(path)
     self.assertEqual(expected_size, d_size)
     mock_execute.assert_called_once_with(
         'env',
         'LC_ALL=C',
         'LANG=C',
         'qemu-img',
         'info',
         path,
         # PF9: add run_as_root
         run_as_root=True)
示例#5
0
    def test_disk_size(self):
        path = '/myhome/disk.config'
        template_output = """image: %(path)s
file format: raw
virtual size: %(v_size)s (%(vsize_b)s bytes)
cluster_size: 65536
disk size: 96K
"""
        for i in range(0, 128):
            bytes = i * 65336
            kbytes = bytes / 1024
            mbytes = kbytes / 1024
            output = template_output % ({
                'v_size': "%sM" % (mbytes),
                '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()
            d_size = libvirt_utils.get_disk_size(path)
            self.assertEqual(i, d_size)
            self.mox.UnsetStubs()
            output = template_output % ({
                'v_size': "%sK" % (kbytes),
                '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()
            d_size = libvirt_utils.get_disk_size(path)
            self.assertEqual(i, d_size)
            self.mox.UnsetStubs()
示例#6
0
    def test_disk_size(self):
        path = '/myhome/disk.config'
        template_output = """image: %(path)s
file format: raw
virtual size: %(v_size)s (%(vsize_b)s bytes)
cluster_size: 65536
disk size: 96K
"""
        for i in range(0, 128):
            bytes = i * 65336
            kbytes = bytes / 1024
            mbytes = kbytes / 1024
            output = template_output % ({
                'v_size': "%sM" % (mbytes),
                '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()
            d_size = libvirt_utils.get_disk_size(path)
            self.assertEqual(i, d_size)
            self.mox.UnsetStubs()
            output = template_output % ({
                'v_size': "%sK" % (kbytes),
                '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()
            d_size = libvirt_utils.get_disk_size(path)
            self.assertEqual(i, d_size)
            self.mox.UnsetStubs()
示例#7
0
 def _test_disk_size(self, mock_execute, path, expected_size):
     d_size = libvirt_utils.get_disk_size(path)
     self.assertEqual(expected_size, d_size)
     mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C',
                                          'qemu-img', 'info', path)
示例#8
0
 def _test_disk_size(self, mock_execute, path, expected_size):
     d_size = libvirt_utils.get_disk_size(path)
     self.assertEqual(expected_size, d_size)
     mock_execute.assert_called_once_with("env", "LC_ALL=C", "LANG=C", "qemu-img", "info", path)