Skip to content

Commit

Permalink
add support for nfs dumps with non root user
Browse files Browse the repository at this point in the history
Signed-off-by: Mahesh Kumar G <[email protected]>
  • Loading branch information
mahi657 committed May 15, 2024
1 parent 417e57e commit b746f14
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions testcases/PowerNVDump.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def setUp(self):
try: self.mem_resource = conf.args.mem_resource
except AttributeError:
self.mem_resource = 2048
self.dump_server_user = conf.args.dump_server_user if 'dump_server_user' in conf.args else 'root'
self.dump_server_ip = conf.args.dump_server_ip if 'dump_server_ip' in conf.args else ''
self.dump_server_pw = conf.args.dump_server_pw if 'dump_server_pw' in conf.args else ''
self.dump_path = conf.args.dump_path if 'dump_path' in conf.args else ''
Expand Down Expand Up @@ -147,7 +148,7 @@ def setup_test(self, dump_place="local"):
"ls -l /var/crash | grep '^d'| awk '{print $9}'")
if dump_place == "net":
self.crash_content = self.c.run_command(
"ssh -i %s root@%s \"ls -l %s | grep '^d'\" | awk '{print $9}'" % (self.rsa_path, self.dump_server_ip, self.dump_path))
"ssh -i %s %s@%s \"ls -l %s | grep '^d'\" | awk '{print $9}'" % (self.rsa_path, self.dump_server_user, self.dump_server_ip, self.dump_path))
log.debug("crash content is %s" % (self.crash_content))

def setup_pwdless_auth(self):
Expand All @@ -169,13 +170,14 @@ def setup_pwdless_auth(self):
self.c.run_command(
"ssh-keygen -q -t rsa -f %s -P ''" % self.rsa_path)
self.c.run_command("chmod 400 %s" % self.rsa_path)
self.c.run_command("sshpass -p %s ssh-copy-id -o \"StrictHostKeyChecking no\" -i %s root@%s" %
(self.dump_server_pw, self.rsa_path, self.dump_server_ip))
self.c.run_command("sshpass -p %s ssh-copy-id -o \"StrictHostKeyChecking no\" -i %s %s@%s" %
(self.dump_server_pw, self.rsa_path, self.dump_server_user, self.dump_server_ip))
except CommandFailed:
self.fail(
"Failed to create/copy ssh key file")
pwd_less = self.c.run_command(
"ssh -i %s -o \"StrictHostKeyChecking no\" -o \"NumberOfPasswordPrompts=0\" %s \"echo\"" % (self.rsa_path, self.dump_server_ip))
"ssh -i %s -o \"StrictHostKeyChecking no\" -o \"NumberOfPasswordPrompts=0\" %s@%s \"echo\"" % (self.rsa_path, self.dump_server_user, self.dump_server_ip))

def is_fadump_param_enabled(self):
'''
Expand Down Expand Up @@ -253,7 +255,7 @@ def verify_dump_file(self, boot_type=BootType.NORMAL, dump_place="local"):
"ls -l /var/crash | grep '^d'| awk '{print $9}'")
if dump_place == "net":
crash_content_after = self.c.run_command(
"ssh root@%s -i %s \"ls -l %s | grep '^d'\" | awk '{print $9}'" % (self.dump_server_ip, self.rsa_path, self.dump_path))
"ssh %s@%s -i %s \"ls -l %s | grep '^d'\" | awk '{print $9}'" % (self.dump_server_user, self.dump_server_ip, self.rsa_path, self.dump_path))
self.crash_content = list(
set(crash_content_after) - set(self.crash_content))
if self.distro == "sles":
Expand All @@ -262,32 +264,42 @@ def verify_dump_file(self, boot_type=BootType.NORMAL, dump_place="local"):
self.crash_content = list(filter(lambda x: re.search('\d{4}-\d{2}-\d{2}-\d{2}:\d{2}', x), self.crash_content))
if len(self.crash_content):
if dump_place == "net":
self.c.run_command('scp -i %s -r root@%s:/%s/%s /var/crash/' %
(self.rsa_path, self.dump_server_ip, self.dump_path, self.crash_content[0]), timeout=1200)
#if user is not root, cannot copy/list vmcore files due to permission issue, because the owner of vmcore dir will be root.
if self.dump_server_user == 'root':
self.c.run_command('scp -i %s -r %s@%s:/%s/%s /var/crash/' %
(self.rsa_path, self.dump_server_user, self.dump_server_ip, self.dump_path, self.crash_content[0]), timeout=1200)
if self.distro == "ubuntu":
self.c.run_command("ls /var/crash/%s/dump*" %
self.crash_content[0])
else:
res = self.c.run_command("ls /var/crash/%s/vmcore*" %
self.crash_content[0])
paths = res[0].split()
file_names = [os.path.basename(path) for path in paths]
# Check if vmcore-dmesg-incomplete.txt is present in file_names
if "vmcore-dmesg-incomplete.txt" in file_names:
raise OpTestError("kdump failed to create vmcore file")
if self.dump_server_user != 'root':
res = self.c.run_command("ssh %s@%s -i %s ls %s/%s/vmcore*" %
(self.dump_server_user, self.dump_server_ip, self.rsa_path, self.dump_path, self.crash_content[0]))
else:
filtered_files = [f for f in file_names if f.startswith("vmcore") and not f == "vmcore-dmesg.txt"]
if filtered_files:
log.debug("vmcore file %s exists in crash dir" % filtered_files)
else:
res = self.c.run_command("ls /var/crash/%s/vmcore*" %
self.crash_content[0])
paths = res[0].split()
file_names = [os.path.basename(path) for path in paths]
# Check if vmcore-dmesg-incomplete.txt is present in file_names
if "vmcore-dmesg-incomplete.txt" in file_names:
raise OpTestError("kdump failed to create vmcore file")
else:
filtered_files = [f for f in file_names if f.startswith("vmcore") and not f == "vmcore-dmesg.txt"]
if filtered_files:
log.debug("vmcore file %s exists in crash dir" % filtered_files)
else:
raise OpTestError("kdump failed to create vmcore file")
if boot_type == BootType.MPIPL:
self.c.run_command("ls /var/crash/%s/opalcore*" %
self.crash_content[0])
else:
msg = "Dump directory not created"
raise OpTestError(msg)
self.c.run_command("rm -rf /var/crash/%s; sync" % self.crash_content[0])
if self.dump_server_user != 'root':
#cannot delete with normal user since dump dir is owned by root
pass
else:
self.c.run_command("rm -rf /var/crash/%s; sync" % self.crash_content[0])

def verify_fadump_reg(self):
'''
Expand Down

0 comments on commit b746f14

Please sign in to comment.