diff options
author | Michael Still <mikal@stillhq.com> | 2019-04-01 08:27:01 +0000 |
---|---|---|
committer | Michael Still <mikal@stillhq.com> | 2019-04-04 20:44:01 +0000 |
commit | 504099e4e2bdd3fcda661d53956c303af88e8dfb (patch) | |
tree | d2c7bd2969e1a879a5a3c229c5e4a520edeab8bc /nova | |
parent | 82c79ceac30d7b97d68c2d71bdd0aae8c7038811 (diff) | |
download | nova-504099e4e2bdd3fcda661d53956c303af88e8dfb.tar.gz |
Add test coverage for nova.privsep.qemu.
Now that we have a fixture that makes this easier, pay down some
technical debt.
Change-Id: I74491ecce3527fe375d219f5c6bc87123f796c44
Diffstat (limited to 'nova')
-rw-r--r-- | nova/privsep/qemu.py | 2 | ||||
-rw-r--r-- | nova/tests/unit/privsep/test_qemu.py | 54 |
2 files changed, 56 insertions, 0 deletions
diff --git a/nova/privsep/qemu.py b/nova/privsep/qemu.py index 8c22d689cb..5880fb1775 100644 --- a/nova/privsep/qemu.py +++ b/nova/privsep/qemu.py @@ -55,6 +55,8 @@ def unprivileged_convert_image(source, dest, in_format, out_format, # just like 'writethrough', calls fsync(2)|fdatasync(2), which # ensures to safely write the data to the physical disk. + # NOTE(mikal): there is an assumption here that the source and destination + # are in the instances_path. Is that worth enforcing? if nova.privsep.utils.supports_direct_io(instances_path): cache_mode = 'none' else: diff --git a/nova/tests/unit/privsep/test_qemu.py b/nova/tests/unit/privsep/test_qemu.py new file mode 100644 index 0000000000..5fbc178983 --- /dev/null +++ b/nova/tests/unit/privsep/test_qemu.py @@ -0,0 +1,54 @@ +# Copyright 2019 Aptira Pty Ltd +# 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 mock + +import nova.privsep.qemu +from nova import test +from nova.tests import fixtures + + +class QemuTestCase(test.NoDBTestCase): + """Test qemu related utility methods.""" + + def setUp(self): + super(QemuTestCase, self).setUp() + self.useFixture(fixtures.PrivsepFixture()) + + @mock.patch('oslo_concurrency.processutils.execute') + @mock.patch('nova.privsep.utils.supports_direct_io') + def _test_convert_image(self, meth, mock_supports_direct_io, mock_execute): + mock_supports_direct_io.return_value = True + meth('/fake/source', '/fake/destination', 'informat', 'outformat', + '/fake/instances/path', compress=True) + mock_execute.assert_called_with( + 'qemu-img', 'convert', '-t', 'none', '-O', 'outformat', + '-f', 'informat', '-c', '/fake/source', '/fake/destination') + + mock_supports_direct_io.reset_mock() + mock_execute.reset_mock() + + mock_supports_direct_io.return_value = False + meth('/fake/source', '/fake/destination', 'informat', 'outformat', + '/fake/instances/path', compress=True) + mock_execute.assert_called_with( + 'qemu-img', 'convert', '-t', 'writeback', '-O', 'outformat', + '-f', 'informat', '-c', '/fake/source', '/fake/destination') + + def test_convert_image(self): + self._test_convert_image(nova.privsep.qemu.convert_image) + + def test_convert_image_unprivileged(self): + self._test_convert_image(nova.privsep.qemu.unprivileged_convert_image) |