Baremetal/utils should not log certain exceptions
unlink_without_raise was logging exceptions when it failed to unlink a file, which is confusing since it is often called on non-existing files. create_link_without_raise was also logging exceptions when it failed to create a symlink. This patch corrects this behaviour; both functions now explicitly check for the type of error they expect, and then suppress that. If another type of OSError is encountered, a warning is logged. This patch also adds unit tests for both functions. fixes bug 1097931. Change-Id: Ie36f59dce34a6c67765770c5f968c003003acc88
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import errno
|
||||
import os
|
||||
|
||||
from nova.openstack.common import log as logging
|
||||
@@ -43,8 +44,11 @@ def inject_into_image(image, key, net, metadata, admin_password,
|
||||
def unlink_without_raise(path):
|
||||
try:
|
||||
os.unlink(path)
|
||||
except OSError:
|
||||
LOG.exception(_("Failed to unlink %s") % path)
|
||||
except OSError, e:
|
||||
if e.errno == errno.ENOENT:
|
||||
return
|
||||
else:
|
||||
LOG.warn(_("Failed to unlink %(path)s, error: %(e)s") % locals())
|
||||
|
||||
|
||||
def write_to_file(path, contents):
|
||||
@@ -55,9 +59,12 @@ def write_to_file(path, contents):
|
||||
def create_link_without_raise(source, link):
|
||||
try:
|
||||
os.symlink(source, link)
|
||||
except OSError:
|
||||
LOG.exception(_("Failed to create symlink from %(source)s to %(link)s")
|
||||
% locals())
|
||||
except OSError, e:
|
||||
if e.errno == errno.EEXIST:
|
||||
return
|
||||
else:
|
||||
LOG.warn(_("Failed to create symlink from %(source)s to %(link)s"
|
||||
", error: %(e)s") % locals())
|
||||
|
||||
|
||||
def random_alnum(count):
|
||||
|
||||
Reference in New Issue
Block a user