Exemple #1
0
    def test_extend_qcow_success(self):
        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)
        imgsize = 10
        device = "/dev/sdh"
        image = imgmodel.LocalFileImage(imgfile, imgmodel.FORMAT_QCOW2)

        self.flags(resize_fs_using_block_device=True)
        mounter = FakeMount.instance_for_format(image, None, None)
        mounter.device = device

        self.mox.StubOutWithMock(api, 'can_resize_image')
        self.mox.StubOutWithMock(utils, 'execute')
        self.mox.StubOutWithMock(api, 'is_image_extendable')
        self.mox.StubOutWithMock(mounter, 'get_dev')
        self.mox.StubOutWithMock(mounter, 'unget_dev')
        self.mox.StubOutWithMock(api, 'resize2fs')
        self.mox.StubOutWithMock(mount.Mount,
                                 'instance_for_format',
                                 use_mock_anything=True)

        api.can_resize_image(imgfile, imgsize).AndReturn(True)
        utils.execute('qemu-img', 'resize', imgfile, imgsize)
        api.is_image_extendable(image).AndReturn(True)
        mount.Mount.instance_for_format(image, None, None).AndReturn(mounter)
        mounter.get_dev().AndReturn(True)
        api.resize2fs(mounter.device, run_as_root=True, check_exit_code=[0])
        mounter.unget_dev()

        self.mox.ReplayAll()
        api.extend(image, imgsize)
Exemple #2
0
    def test_extend_qcow_success(self):
        imgfile = tempfile.NamedTemporaryFile()
        imgsize = 10
        device = "/dev/sdh"
        use_cow = True

        self.flags(resize_fs_using_block_device=True)
        mounter = FakeMount.instance_for_format(
            imgfile, None, None, 'qcow2')
        mounter.device = device

        self.mox.StubOutWithMock(api, 'can_resize_image')
        self.mox.StubOutWithMock(utils, 'execute')
        self.mox.StubOutWithMock(api, 'is_image_extendable')
        self.mox.StubOutWithMock(mounter, 'get_dev')
        self.mox.StubOutWithMock(mounter, 'unget_dev')
        self.mox.StubOutWithMock(api, 'resize2fs')
        self.mox.StubOutWithMock(mount.Mount, 'instance_for_format',
                                 use_mock_anything=True)

        api.can_resize_image(imgfile, imgsize).AndReturn(True)
        utils.execute('qemu-img', 'resize', imgfile, imgsize)
        api.is_image_extendable(imgfile, use_cow).AndReturn(True)
        mount.Mount.instance_for_format(
            imgfile, None, None, 'qcow2').AndReturn(mounter)
        mounter.get_dev().AndReturn(True)
        api.resize2fs(mounter.device, run_as_root=True, check_exit_code=[0])
        mounter.unget_dev()

        self.mox.ReplayAll()
        api.extend(imgfile, imgsize, use_cow=use_cow)
Exemple #3
0
    def test_extend_raw_success(self):
        imgfile = tempfile.NamedTemporaryFile()
        imgsize = 10
        use_cow = False

        self.mox.StubOutWithMock(api, 'can_resize_image')
        self.mox.StubOutWithMock(utils, 'execute')
        self.mox.StubOutWithMock(api, 'is_image_extendable')
        self.mox.StubOutWithMock(api, 'resize2fs')

        api.can_resize_image(imgfile, imgsize).AndReturn(True)
        utils.execute('qemu-img', 'resize', imgfile, imgsize)
        api.is_image_extendable(imgfile, use_cow).AndReturn(True)
        api.resize2fs(imgfile, run_as_root=False, check_exit_code=[0])

        self.mox.ReplayAll()
        api.extend(imgfile, imgsize, use_cow=use_cow)
Exemple #4
0
    def test_extend_raw_success(self):
        imgfile = tempfile.NamedTemporaryFile()
        imgsize = 10
        use_cow = False

        self.mox.StubOutWithMock(api, 'can_resize_image')
        self.mox.StubOutWithMock(utils, 'execute')
        self.mox.StubOutWithMock(api, 'is_image_extendable')
        self.mox.StubOutWithMock(api, 'resize2fs')

        api.can_resize_image(imgfile, imgsize).AndReturn(True)
        utils.execute('qemu-img', 'resize', imgfile, imgsize)
        api.is_image_extendable(imgfile, use_cow).AndReturn(True)
        api.resize2fs(imgfile, run_as_root=False, check_exit_code=[0])

        self.mox.ReplayAll()
        api.extend(imgfile, imgsize, use_cow=use_cow)
Exemple #5
0
    def test_is_image_extendable_raw(self):
        imgfile = tempfile.NamedTemporaryFile()

        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('e2label', imgfile)
        self.mox.ReplayAll()

        image = imgmodel.LocalFileImage(imgfile, imgmodel.FORMAT_RAW)
        self.addCleanup(imgfile.close)
        self.assertTrue(api.is_image_extendable(image))
Exemple #6
0
    def test_is_image_extendable_raw(self):
        imgfile = tempfile.NamedTemporaryFile()

        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('e2label', imgfile)
        self.mox.ReplayAll()

        image = imgmodel.LocalFileImage(imgfile, imgmodel.FORMAT_RAW)
        self.addCleanup(imgfile.close)
        self.assertTrue(api.is_image_extendable(image))
Exemple #7
0
    def test_can_resize_need_fs_type_specified(self):
        # Downstream-only skip
        # This test fails when libguestfs is available in the unit test
        # environment.
        # This can be trivially made to pass by passing imgfile.name instead of
        # imgfile to api.is_image_extendable. However, it needs a significant
        # rework to be meaningful. We're skipping it for the moment.
        self.skipTest("Fails when libguestfs is available")

        # NOTE(mikal): Bug 1094373 saw a regression where we failed to
        # treat a failure to mount as a failure to be able to resize the
        # filesystem
        def _fake_get_disk_size(path):
            return 10

        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.api.get_disk_size',
                                 _fake_get_disk_size))

        def fake_trycmd(*args, **kwargs):
            return '', 'broken'

        self.useFixture(fixtures.MonkeyPatch('nova.utils.trycmd', fake_trycmd))

        def fake_returns_true(*args, **kwargs):
            return True

        def fake_returns_nothing(*args, **kwargs):
            return ''

        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.mount.nbd.NbdMount.get_dev',
                                 fake_returns_true))
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.mount.nbd.NbdMount.map_dev',
                                 fake_returns_true))
        self.useFixture(
            fixtures.MonkeyPatch(
                'nova.virt.disk.vfs.localfs.VFSLocalFS.get_image_fs',
                fake_returns_nothing))

        # Force the use of localfs, which is what was used during the failure
        # reported in the bug
        def fake_import_fails(*args, **kwargs):
            raise Exception('Failed')

        self.useFixture(
            fixtures.MonkeyPatch('oslo.utils.import_module',
                                 fake_import_fails))

        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)
        self.assertFalse(api.is_image_extendable(imgfile, use_cow=True))
Exemple #8
0
    def test_can_resize_need_fs_type_specified(self):
        # Downstream-only skip
        # This test fails when libguestfs is available in the unit test
        # environment.
        # This can be trivially made to pass by passing imgfile.name instead of
        # imgfile to api.is_image_extendable. However, it needs a significant
        # rework to be meaningful. We're skipping it for the moment.
        self.skipTest("Fails when libguestfs is available")

        # NOTE(mikal): Bug 1094373 saw a regression where we failed to
        # treat a failure to mount as a failure to be able to resize the
        # filesystem
        def _fake_get_disk_size(path):
            return 10
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.disk.api.get_disk_size', _fake_get_disk_size))

        def fake_trycmd(*args, **kwargs):
            return '', 'broken'
        self.useFixture(fixtures.MonkeyPatch('nova.utils.trycmd', fake_trycmd))

        def fake_returns_true(*args, **kwargs):
            return True

        def fake_returns_nothing(*args, **kwargs):
            return ''
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.disk.mount.nbd.NbdMount.get_dev',
                fake_returns_true))
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.disk.mount.nbd.NbdMount.map_dev',
                fake_returns_true))
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.disk.vfs.localfs.VFSLocalFS.get_image_fs',
                fake_returns_nothing))

        # Force the use of localfs, which is what was used during the failure
        # reported in the bug
        def fake_import_fails(*args, **kwargs):
            raise Exception('Failed')
        self.useFixture(fixtures.MonkeyPatch(
                'oslo.utils.import_module',
                fake_import_fails))

        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)
        self.assertFalse(api.is_image_extendable(imgfile, use_cow=True))
Exemple #9
0
    def test_can_resize_need_fs_type_specified(self):
        # NOTE(mikal): Bug 1094373 saw a regression where we failed to
        # treat a failure to mount as a failure to be able to resize the
        # filesystem
        def _fake_get_disk_size(path):
            return 10

        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.api.get_disk_size',
                                 _fake_get_disk_size))

        def fake_trycmd(*args, **kwargs):
            return '', 'broken'

        self.useFixture(fixtures.MonkeyPatch('nova.utils.trycmd', fake_trycmd))

        def fake_returns_true(*args, **kwargs):
            return True

        def fake_returns_nothing(*args, **kwargs):
            return ''

        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.mount.nbd.NbdMount.get_dev',
                                 fake_returns_true))
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.mount.nbd.NbdMount.map_dev',
                                 fake_returns_true))
        self.useFixture(
            fixtures.MonkeyPatch(
                'nova.virt.disk.vfs.localfs.VFSLocalFS.get_image_fs',
                fake_returns_nothing))

        # Force the use of localfs, which is what was used during the failure
        # reported in the bug
        def fake_import_fails(*args, **kwargs):
            raise Exception('Failed')

        self.useFixture(
            fixtures.MonkeyPatch('oslo_utils.import_module',
                                 fake_import_fails))

        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)
        image = imgmodel.LocalFileImage(imgfile.name, imgmodel.FORMAT_QCOW2)
        self.assertFalse(api.is_image_extendable(image))
Exemple #10
0
    def test_can_resize_need_fs_type_specified(self):
        # NOTE(mikal): Bug 1094373 saw a regression where we failed to
        # treat a failure to mount as a failure to be able to resize the
        # filesystem
        def _fake_get_disk_size(path):
            return 10
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.disk.api.get_disk_size', _fake_get_disk_size))

        def fake_trycmd(*args, **kwargs):
            return '', 'broken'
        self.useFixture(fixtures.MonkeyPatch('nova.utils.trycmd', fake_trycmd))

        def fake_returns_true(*args, **kwargs):
            return True

        def fake_returns_nothing(*args, **kwargs):
            return ''
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.disk.mount.nbd.NbdMount.get_dev',
                fake_returns_true))
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.disk.mount.nbd.NbdMount.map_dev',
                fake_returns_true))
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.disk.vfs.localfs.VFSLocalFS.get_image_fs',
                fake_returns_nothing))

        # Force the use of localfs, which is what was used during the failure
        # reported in the bug
        def fake_import_fails(*args, **kwargs):
            raise Exception('Failed')
        self.useFixture(fixtures.MonkeyPatch(
                'oslo_utils.import_module',
                fake_import_fails))

        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)
        image = imgmodel.LocalFileImage(imgfile.name, imgmodel.FORMAT_QCOW2)
        self.assertFalse(api.is_image_extendable(image))
Exemple #11
0
 def test_is_image_extendable_raw(self, mock_exec):
     imgfile = tempfile.NamedTemporaryFile()
     image = imgmodel.LocalFileImage(imgfile, imgmodel.FORMAT_RAW)
     self.addCleanup(imgfile.close)
     self.assertTrue(api.is_image_extendable(image))
     mock_exec.assert_called_once_with('e2label', imgfile)
Exemple #12
0
 def test_can_resize_need_fs_type_specified(self, mock_image_fs):
     imgfile = tempfile.NamedTemporaryFile()
     self.addCleanup(imgfile.close)
     image = imgmodel.LocalFileImage(imgfile.name, imgmodel.FORMAT_QCOW2)
     self.assertFalse(api.is_image_extendable(image))
     self.assertTrue(mock_image_fs.called)
Exemple #13
0
 def test_is_image_extendable_raw(self, mock_exec):
     imgfile = tempfile.NamedTemporaryFile()
     image = imgmodel.LocalFileImage(imgfile, imgmodel.FORMAT_RAW)
     self.addCleanup(imgfile.close)
     self.assertTrue(api.is_image_extendable(image))
     mock_exec.assert_called_once_with('e2label', imgfile)
Exemple #14
0
 def test_can_resize_need_fs_type_specified(self, mock_image_fs):
     imgfile = tempfile.NamedTemporaryFile()
     self.addCleanup(imgfile.close)
     image = imgmodel.LocalFileImage(imgfile.name, imgmodel.FORMAT_QCOW2)
     self.assertFalse(api.is_image_extendable(image))
     self.assertTrue(mock_image_fs.called)