diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-01-02 19:17:39 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-01-02 19:17:39 +0000 |
| commit | c66755f0edfe803653e5e278dc078a7a7e82b6e4 (patch) | |
| tree | ce1ea059e9390489d1ede9518292f77c6494a4e9 /nova/tests | |
| parent | 46b047fbcc9a4d2c54c74c46163d89f557e5898c (diff) | |
| parent | 2397c6b902174ef39bff5f9194a06f82c6746267 (diff) | |
Merge "Report failures to mount in localfs correctly."
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/virt/disk/test_api.py | 63 | ||||
| -rw-r--r-- | nova/tests/virt/disk/test_nbd.py | 24 |
2 files changed, 85 insertions, 2 deletions
diff --git a/nova/tests/virt/disk/test_api.py b/nova/tests/virt/disk/test_api.py new file mode 100644 index 000000000..95368a2c2 --- /dev/null +++ b/nova/tests/virt/disk/test_api.py @@ -0,0 +1,63 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 OpenStack LLC +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +import os +import tempfile + +import fixtures + +from nova.openstack.common import importutils +from nova import test +from nova.virt.disk import api + + +class APITestCase(test.TestCase): + + 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 + 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)) + + # 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( + 'nova.openstack.common.importutils.import_module', + fake_import_fails)) + + imgfile = tempfile.NamedTemporaryFile() + self.addCleanup(imgfile.close) + self.assertFalse(api.can_resize_fs(imgfile, 100, use_cow=True)) diff --git a/nova/tests/virt/disk/test_nbd.py b/nova/tests/virt/disk/test_nbd.py index 16003c9ac..59b0784d9 100644 --- a/nova/tests/virt/disk/test_nbd.py +++ b/nova/tests/virt/disk/test_nbd.py @@ -16,11 +16,12 @@ # under the License. -import fixtures import os +import tempfile -from nova import test +import fixtures +from nova import test from nova.virt.disk.mount import nbd ORIG_EXISTS = os.path.exists @@ -270,3 +271,22 @@ class NbdTestCase(test.TestCase): # No error logged, device consumed self.assertFalse(n.get_dev()) + + def test_do_mount_need_to_specify_fs_type(self): + # NOTE(mikal): Bug 1094373 saw a regression where we failed to + # communicate a failed mount properly. + def fake_trycmd(*args, **kwargs): + return '', 'broken' + self.useFixture(fixtures.MonkeyPatch('nova.utils.trycmd', fake_trycmd)) + + imgfile = tempfile.NamedTemporaryFile() + self.addCleanup(imgfile.close) + tempdir = self.useFixture(fixtures.TempDir()).path + mount = nbd.NbdMount(imgfile.name, tempdir) + + def fake_returns_true(*args, **kwargs): + return True + mount.get_dev = fake_returns_true + mount.map_dev = fake_returns_true + + self.assertFalse(mount.do_mount()) |
