diff --git a/neutron/agent/linux/utils.py b/neutron/agent/linux/utils.py index 3166f1163f3..c38b66f757d 100644 --- a/neutron/agent/linux/utils.py +++ b/neutron/agent/linux/utils.py @@ -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.""" diff --git a/neutron/tests/unit/agent/linux/test_utils.py b/neutron/tests/unit/agent/linux/test_utils.py index 7a53ee4dfe8..c93bc097249 100644 --- a/neutron/tests/unit/agent/linux/test_utils.py +++ b/neutron/tests/unit/agent/linux/test_utils.py @@ -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):