diff options
author | Michael Still <mikal@stillhq.com> | 2019-03-29 04:09:40 +0000 |
---|---|---|
committer | Michael Still <mikal@stillhq.com> | 2019-04-04 20:42:43 +0000 |
commit | f389773f5255051f2f1cff4d0b0a08eafc0ac147 (patch) | |
tree | 88e2c7f5b2318473ec577ec47b3295666d61b6cf /nova/tests/unit/privsep | |
parent | 7b28861444af4ad498cd5db969a0051d2b384d88 (diff) | |
download | nova-f389773f5255051f2f1cff4d0b0a08eafc0ac147.tar.gz |
Improve test coverage of nova.privsep.fs, continued.
Using the new PrivsepFixture, improve test coverage of filesystem
utilities. This finishes off coverage for this file.
Change-Id: I4af57ced168cf285cd3872d20dc2a369b3ac2e14
Diffstat (limited to 'nova/tests/unit/privsep')
-rw-r--r-- | nova/tests/unit/privsep/test_fs.py | 83 |
1 files changed, 81 insertions, 2 deletions
diff --git a/nova/tests/unit/privsep/test_fs.py b/nova/tests/unit/privsep/test_fs.py index 1486869094..53748bb181 100644 --- a/nova/tests/unit/privsep/test_fs.py +++ b/nova/tests/unit/privsep/test_fs.py @@ -150,18 +150,97 @@ class PrivsepFilesystemHelpersTestCase(test.NoDBTestCase): check_exit_code=[0, 2]) @mock.patch('oslo_concurrency.processutils.execute') - def test_list_partitions(self, mock_execute): + def test_privileged_e2fsck(self, mock_execute): + nova.privsep.fs.e2fsck('/path/nosuch') + mock_execute.assert_called_with('e2fsck', '-fp', '/path/nosuch', + check_exit_code=[0, 1, 2]) + + @mock.patch('oslo_concurrency.processutils.execute') + def test_privileged_e2fsck_with_flags(self, mock_execute): + nova.privsep.fs.e2fsck('/path/nosuch', flags='festive') + mock_execute.assert_called_with('e2fsck', 'festive', '/path/nosuch', + check_exit_code=[0, 1, 2]) + + @mock.patch('oslo_concurrency.processutils.execute') + def test_unprivileged_e2fsck(self, mock_execute): + nova.privsep.fs.unprivileged_e2fsck('/path/nosuch') + mock_execute.assert_called_with('e2fsck', '-fp', '/path/nosuch', + check_exit_code=[0, 1, 2]) + + @mock.patch('oslo_concurrency.processutils.execute') + def test_unprivileged_e2fsck_with_flags(self, mock_execute): + nova.privsep.fs.unprivileged_e2fsck('/path/nosuch', flags='festive') + mock_execute.assert_called_with('e2fsck', 'festive', '/path/nosuch', + check_exit_code=[0, 1, 2]) + + @mock.patch('oslo_concurrency.processutils.execute') + def test_privileged_resize2fs(self, mock_execute): + nova.privsep.fs.resize2fs('/path/nosuch', [0, 1, 2]) + mock_execute.assert_called_with('resize2fs', '/path/nosuch', + check_exit_code=[0, 1, 2]) + + @mock.patch('oslo_concurrency.processutils.execute') + def test_privileged_resize2fs_with_size(self, mock_execute): + nova.privsep.fs.resize2fs('/path/nosuch', [0, 1, 2], 1024) + mock_execute.assert_called_with('resize2fs', '/path/nosuch', 1024, + check_exit_code=[0, 1, 2]) + + @mock.patch('oslo_concurrency.processutils.execute') + def test_unprivileged_resize2fs(self, mock_execute): + nova.privsep.fs.unprivileged_resize2fs('/path/nosuch', [0, 1, 2]) + mock_execute.assert_called_with('resize2fs', '/path/nosuch', + check_exit_code=[0, 1, 2]) + + @mock.patch('oslo_concurrency.processutils.execute') + def test_unprivileged_resize2fs_with_size(self, mock_execute): + nova.privsep.fs.unprivileged_resize2fs('/path/nosuch', [0, 1, 2], 1024) + mock_execute.assert_called_with('resize2fs', '/path/nosuch', 1024, + check_exit_code=[0, 1, 2]) + + @mock.patch('oslo_concurrency.processutils.execute') + def test_create_partition_table(self, mock_execute): + nova.privsep.fs.create_partition_table('/dev/nosuch', 'style') + mock_execute.assert_called_with('parted', '--script', '/dev/nosuch', + 'mklabel', 'style', + check_exit_code=True) + + @mock.patch('oslo_concurrency.processutils.execute') + def test_create_partition(self, mock_execute): + nova.privsep.fs.create_partition('/dev/nosuch', 'style', 0, 100) + mock_execute.assert_called_with('parted', '--script', '/dev/nosuch', + '--', 'mkpart', 'style', 0, 100, + check_exit_code=True) + + @mock.patch('oslo_concurrency.processutils.execute') + def _test_list_partitions(self, meth, mock_execute): parted_return = "BYT;\n...\n" parted_return += "1:2s:11s:10s:ext3::boot;\n" parted_return += "2:20s:11s:10s::bob:;\n" mock_execute.return_value = (parted_return, None) - partitions = nova.privsep.fs.unprivileged_list_partitions("abc") + partitions = meth("abc") self.assertEqual(2, len(partitions)) self.assertEqual((1, 2, 10, "ext3", "", "boot"), partitions[0]) self.assertEqual((2, 20, 10, "", "bob", ""), partitions[1]) + def test_privileged_list_partitions(self): + self._test_list_partitions(nova.privsep.fs.list_partitions) + + def test_unprivileged_list_partitions(self): + self._test_list_partitions( + nova.privsep.fs.unprivileged_list_partitions) + + @mock.patch('oslo_concurrency.processutils.execute') + def test_resize_partition(self, mock_execute): + nova.privsep.fs.resize_partition('/dev/nosuch', 0, 100, True) + mock_execute.assert_has_calls([ + mock.call('parted', '--script', '/dev/nosuch', 'rm', '1'), + mock.call('parted', '--script', '/dev/nosuch', 'mkpart', + 'primary', '0s', '100s'), + mock.call('parted', '--script', '/dev/nosuch', + 'set', '1', 'boot', 'on')]) + class MkfsTestCase(test.NoDBTestCase): @mock.patch('oslo_concurrency.processutils.execute') |