From 25fdc2a9f9bdeacd91ab2f9317c5dff1d8ec5977 Mon Sep 17 00:00:00 2001 From: "Dariusz Smigiel (dasm)" Date: Tue, 22 Mar 2016 15:41:02 +0000 Subject: [PATCH] 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 --- neutron/agent/linux/utils.py | 20 -------------- neutron/tests/unit/agent/linux/test_utils.py | 29 -------------------- 2 files changed, 49 deletions(-) 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):