From 5b35b18be6a04ed4dd69dc71e5fb436c212c15fc Mon Sep 17 00:00:00 2001 From: Sunny Kumar Date: Mon, 10 Jun 2019 15:16:48 +0530 Subject: tests: added cleanup for lock files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: useradd fails with: Cannot allocate memory useradd: cannot lock /etc/passwd; try again later. Solution: Lock files should get automatically removed once "usradd" or "groupadd" command finishes. But sometimes we encounter situations (bugs) where some of these files may not get properly unlocked after the execution of the command. In that case, when we execute useradd next time, it may show the error “cannot lock /etc/password” or “unable to lock group file”. So, to avoid any such errors, check for any lock files under /etc and remove those. updates: bz#1193929 Change-Id: If6456a271c2bc0717f768d7101a40ce44a9af3d7 Signed-off-by: Sunny Kumar --- tests/include.rc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests') diff --git a/tests/include.rc b/tests/include.rc index af78172fee2..ebe94b3fd11 100644 --- a/tests/include.rc +++ b/tests/include.rc @@ -552,6 +552,38 @@ function process_pids() { echo "${pids[@]}" } +## Lock files should get automatically removed once "usradd" or "groupadd" +## command finishes. But sometimes we encounter situations (bugs) where +## some of these files may not get properly unlocked after the execution of +## the command. In that case, when we execute useradd next time, it may show +## the error “cannot lock /etc/password” or “unable to lock group file”. +## So, to avoid any such errors, check for any lock files under /etc. +## and remove those. + +function remove_lock_files() +{ + if [ ! -f /etc/passwd.lock ]; + then + rm -rf /etc/passwd.lock; + fi + + if [ ! -f /etc/group.lock ]; + then + rm -rf /etc/group.lock; + fi + + if [ ! -f /etc/shadow.lock ]; + then + rm -rf /etc/shadow.lock; + fi + + if [ ! -f /etc/gshadow.lock ]; + then + rm -rf /etc/gshadow.lock; + fi +} + + function cleanup() { local end_time @@ -572,6 +604,9 @@ function cleanup() ;; esac + # Clean up lock files. + remove_lock_files + # Clean up all client mounts for m in `mount | grep fuse.glusterfs | awk '{print $3}'`; do umount $flag $m -- cgit