Fix missed chown call
When privsep'ing chown calls, this one was missed. Fix that. I think this entire method should go away, but it will break at least one of out tree driver. I'm talking to the powervm guys about a way forward there. Change-Id: I8a9bda36728896e60b13c32afda0a7130664cb7b Closes-Bug: #1716718
This commit is contained in:
parent
f01bda973a
commit
39c2cceb75
|
@ -145,16 +145,13 @@ class GenericUtilsTestCase(test.NoDBTestCase):
|
|||
self.assertTrue([c for c in password
|
||||
if c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'])
|
||||
|
||||
def test_temporary_chown(self):
|
||||
def fake_execute(*args, **kwargs):
|
||||
if args[0] == 'chown':
|
||||
fake_execute.uid = args[1]
|
||||
self.stub_out('nova.utils.execute', fake_execute)
|
||||
|
||||
@mock.patch('nova.privsep.dac_admin.chown')
|
||||
def test_temporary_chown(self, mock_chown):
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
with utils.temporary_chown(f.name, owner_uid=2):
|
||||
self.assertEqual(fake_execute.uid, 2)
|
||||
self.assertEqual(fake_execute.uid, os.getuid())
|
||||
mock_chown.assert_called_once_with(f.name, uid=2)
|
||||
mock_chown.reset_mock()
|
||||
mock_chown.assert_called_once_with(f.name, uid=os.getuid())
|
||||
|
||||
def test_get_shortened_ipv6(self):
|
||||
self.assertEqual("abcd:ef01:2345:6789:abcd:ef01:c0a8:fefe",
|
||||
|
|
|
@ -637,6 +637,10 @@ def generate_mac_address():
|
|||
return ':'.join(map(lambda x: "%02x" % x, mac))
|
||||
|
||||
|
||||
# NOTE(mikal): I really wanted this code to go away, but I can't find a way
|
||||
# to implement what the callers of this method want with privsep. Basically,
|
||||
# if we could hand off either a file descriptor or a file like object then
|
||||
# we could make this go away.
|
||||
@contextlib.contextmanager
|
||||
def temporary_chown(path, owner_uid=None):
|
||||
"""Temporarily chown a path.
|
||||
|
@ -649,12 +653,12 @@ def temporary_chown(path, owner_uid=None):
|
|||
orig_uid = os.stat(path).st_uid
|
||||
|
||||
if orig_uid != owner_uid:
|
||||
execute('chown', owner_uid, path, run_as_root=True)
|
||||
nova.privsep.dac_admin.chown(path, uid=owner_uid)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
if orig_uid != owner_uid:
|
||||
execute('chown', orig_uid, path, run_as_root=True)
|
||||
nova.privsep.dac_admin.chown(path, uid=orig_uid)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
Loading…
Reference in New Issue