Remove deprecated method from agent utils file
Commit I26b0a4d6105420a2c242b81a4cd58e0adef4cbec marked method replace_file as redundant. Functionality was moved to neutron.common.utils:replace_file Related-Bug: #1504477 Change-Id: I77f907bee20bf921d4127502c1ce8156425e158a
This commit is contained in:
parent
eccbbd113f
commit
25fdc2a9f9
|
@ -21,10 +21,8 @@ import pwd
|
|||
import shlex
|
||||
import socket
|
||||
import struct
|
||||
import tempfile
|
||||
import threading
|
||||
|
||||
import debtcollector
|
||||
import eventlet
|
||||
from eventlet.green import subprocess
|
||||
from eventlet import greenthread
|
||||
|
@ -162,24 +160,6 @@ def get_interface_mac(interface):
|
|||
for char in info[MAC_START:MAC_END]])[:-1]
|
||||
|
||||
|
||||
@debtcollector.removals.remove(message="Redundant in Mitaka release.")
|
||||
def replace_file(file_name, data, file_mode=0o644):
|
||||
"""Replaces the contents of file_name with data in a safe manner.
|
||||
|
||||
First write to a temp file and then rename. Since POSIX renames are
|
||||
atomic, the file is unlikely to be corrupted by competing writes.
|
||||
|
||||
We create the tempfile on the same device to ensure that it can be renamed.
|
||||
"""
|
||||
|
||||
base_dir = os.path.dirname(os.path.abspath(file_name))
|
||||
tmp_file = tempfile.NamedTemporaryFile('w+', dir=base_dir, delete=False)
|
||||
tmp_file.write(data)
|
||||
tmp_file.close()
|
||||
os.chmod(tmp_file.name, file_mode)
|
||||
os.rename(tmp_file.name, file_name)
|
||||
|
||||
|
||||
def find_child_pids(pid):
|
||||
"""Retrieve a list of the pids of child processes of the given pid."""
|
||||
|
||||
|
|
|
@ -182,35 +182,6 @@ class AgentUtilsGetInterfaceMAC(base.BaseTestCase):
|
|||
self.assertEqual(actual_val, expect_val)
|
||||
|
||||
|
||||
class AgentUtilsReplaceFile(base.BaseTestCase):
|
||||
def _test_replace_file_helper(self, explicit_perms=None):
|
||||
# make file to replace
|
||||
with mock.patch('tempfile.NamedTemporaryFile') as ntf:
|
||||
ntf.return_value.name = '/baz'
|
||||
with mock.patch('os.chmod') as chmod:
|
||||
with mock.patch('os.rename') as rename:
|
||||
if explicit_perms is None:
|
||||
expected_perms = 0o644
|
||||
utils.replace_file('/foo', 'bar')
|
||||
else:
|
||||
expected_perms = explicit_perms
|
||||
utils.replace_file('/foo', 'bar', explicit_perms)
|
||||
|
||||
expected = [mock.call('w+', dir='/', delete=False),
|
||||
mock.call().write('bar'),
|
||||
mock.call().close()]
|
||||
|
||||
ntf.assert_has_calls(expected)
|
||||
chmod.assert_called_once_with('/baz', expected_perms)
|
||||
rename.assert_called_once_with('/baz', '/foo')
|
||||
|
||||
def test_replace_file_with_default_perms(self):
|
||||
self._test_replace_file_helper()
|
||||
|
||||
def test_replace_file_with_0o600_perms(self):
|
||||
self._test_replace_file_helper(0o600)
|
||||
|
||||
|
||||
class TestFindChildPids(base.BaseTestCase):
|
||||
|
||||
def test_returns_empty_list_for_exit_code_1(self):
|
||||
|
|
Loading…
Reference in New Issue