nova/nova/tests/unit/privsep/test_fs.py
Michael Still 38469b81a9 Start moving users of parted to privsep.
This isn't all calls, but a step along the way. Note that I moved
a xenapi unit test to being the first unit test for privsep directly.
I'm not sure if I love this way of testing (having the "meat" of
the method undecorated and having a wrapper), but I've been unable
to come up with a way to mock away the entrypoint wrapper.

Change-Id: I35d4e7c6c43cbcbc1549aa28796ff97f447a4b03
blueprint: hurrah-for-privsep
2018-01-22 21:37:53 +00:00

35 lines
1.3 KiB
Python

# Copyright 2013 OpenStack Foundation
# 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.fs
from nova import test
class PrivsepFilesystemHelpersTestCase(test.NoDBTestCase):
@mock.patch('oslo_concurrency.processutils.execute')
def test_list_partitions(self, 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")
self.assertEqual(2, len(partitions))
self.assertEqual((1, 2, 10, "ext3", "", "boot"), partitions[0])
self.assertEqual((2, 20, 10, "", "bob", ""), partitions[1])