Skip to content

Commit 0c89fca

Browse files
committed
add support for nfs dumps with non root user
1 parent 417e57e commit 0c89fca

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

testcases/PowerNVDump.py

+30-18
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def setUp(self):
115115
try: self.mem_resource = conf.args.mem_resource
116116
except AttributeError:
117117
self.mem_resource = 2048
118+
self.dump_server_user = conf.args.dump_server_user if 'dump_server_user' in conf.args else 'root'
118119
self.dump_server_ip = conf.args.dump_server_ip if 'dump_server_ip' in conf.args else ''
119120
self.dump_server_pw = conf.args.dump_server_pw if 'dump_server_pw' in conf.args else ''
120121
self.dump_path = conf.args.dump_path if 'dump_path' in conf.args else ''
@@ -147,7 +148,7 @@ def setup_test(self, dump_place="local"):
147148
"ls -l /var/crash | grep '^d'| awk '{print $9}'")
148149
if dump_place == "net":
149150
self.crash_content = self.c.run_command(
150-
"ssh -i %s root@%s \"ls -l %s | grep '^d'\" | awk '{print $9}'" % (self.rsa_path, self.dump_server_ip, self.dump_path))
151+
"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))
151152
log.debug("crash content is %s" % (self.crash_content))
152153

153154
def setup_pwdless_auth(self):
@@ -169,13 +170,14 @@ def setup_pwdless_auth(self):
169170
self.c.run_command(
170171
"ssh-keygen -q -t rsa -f %s -P ''" % self.rsa_path)
171172
self.c.run_command("chmod 400 %s" % self.rsa_path)
172-
self.c.run_command("sshpass -p %s ssh-copy-id -o \"StrictHostKeyChecking no\" -i %s root@%s" %
173173
(self.dump_server_pw, self.rsa_path, self.dump_server_ip))
174+
self.c.run_command("sshpass -p %s ssh-copy-id -o \"StrictHostKeyChecking no\" -i %s %s@%s" %
175+
(self.dump_server_pw, self.rsa_path, self.dump_server_user, self.dump_server_ip))
174176
except CommandFailed:
175177
self.fail(
176178
"Failed to create/copy ssh key file")
177179
pwd_less = self.c.run_command(
178-
"ssh -i %s -o \"StrictHostKeyChecking no\" -o \"NumberOfPasswordPrompts=0\" %s \"echo\"" % (self.rsa_path, self.dump_server_ip))
180+
"ssh -i %s -o \"StrictHostKeyChecking no\" -o \"NumberOfPasswordPrompts=0\" %s@%s \"echo\"" % (self.rsa_path, self.dump_server_user, self.dump_server_ip))
179181

180182
def is_fadump_param_enabled(self):
181183
'''
@@ -253,7 +255,7 @@ def verify_dump_file(self, boot_type=BootType.NORMAL, dump_place="local"):
253255
"ls -l /var/crash | grep '^d'| awk '{print $9}'")
254256
if dump_place == "net":
255257
crash_content_after = self.c.run_command(
256-
"ssh root@%s -i %s \"ls -l %s | grep '^d'\" | awk '{print $9}'" % (self.dump_server_ip, self.rsa_path, self.dump_path))
258+
"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))
257259
self.crash_content = list(
258260
set(crash_content_after) - set(self.crash_content))
259261
if self.distro == "sles":
@@ -262,32 +264,42 @@ def verify_dump_file(self, boot_type=BootType.NORMAL, dump_place="local"):
262264
self.crash_content = list(filter(lambda x: re.search('\d{4}-\d{2}-\d{2}-\d{2}:\d{2}', x), self.crash_content))
263265
if len(self.crash_content):
264266
if dump_place == "net":
265-
self.c.run_command('scp -i %s -r root@%s:/%s/%s /var/crash/' %
266-
(self.rsa_path, self.dump_server_ip, self.dump_path, self.crash_content[0]), timeout=1200)
267+
#if user is not root, cannot copy/list vmcore files due to permission issue, because the owner of vmcore dir will be root.
268+
if self.dump_server_user == 'root':
269+
self.c.run_command('scp -i %s -r %s@%s:/%s/%s /var/crash/' %
270+
(self.rsa_path, self.dump_server_user, self.dump_server_ip, self.dump_path, self.crash_content[0]), timeout=1200)
267271
if self.distro == "ubuntu":
268272
self.c.run_command("ls /var/crash/%s/dump*" %
269273
self.crash_content[0])
270274
else:
271-
res = self.c.run_command("ls /var/crash/%s/vmcore*" %
272-
self.crash_content[0])
273-
paths = res[0].split()
274-
file_names = [os.path.basename(path) for path in paths]
275-
# Check if vmcore-dmesg-incomplete.txt is present in file_names
276-
if "vmcore-dmesg-incomplete.txt" in file_names:
277-
raise OpTestError("kdump failed to create vmcore file")
275+
if self.dump_server_user != 'root':
276+
res = self.c.run_command("ssh %s@%s -i %s ls %s/%s/vmcore*" %
277+
(self.dump_server_user, self.dump_server_ip, self.rsa_path, self.dump_path, self.crash_content[0]))
278278
else:
279-
filtered_files = [f for f in file_names if f.startswith("vmcore") and not f == "vmcore-dmesg.txt"]
280-
if filtered_files:
281-
log.debug("vmcore file %s exists in crash dir" % filtered_files)
282-
else:
279+
res = self.c.run_command("ls /var/crash/%s/vmcore*" %
280+
self.crash_content[0])
281+
paths = res[0].split()
282+
file_names = [os.path.basename(path) for path in paths]
283+
# Check if vmcore-dmesg-incomplete.txt is present in file_names
284+
if "vmcore-dmesg-incomplete.txt" in file_names:
283285
raise OpTestError("kdump failed to create vmcore file")
286+
else:
287+
filtered_files = [f for f in file_names if f.startswith("vmcore") and not f == "vmcore-dmesg.txt"]
288+
if filtered_files:
289+
log.debug("vmcore file %s exists in crash dir" % filtered_files)
290+
else:
291+
raise OpTestError("kdump failed to create vmcore file")
284292
if boot_type == BootType.MPIPL:
285293
self.c.run_command("ls /var/crash/%s/opalcore*" %
286294
self.crash_content[0])
287295
else:
288296
msg = "Dump directory not created"
289297
raise OpTestError(msg)
290-
self.c.run_command("rm -rf /var/crash/%s; sync" % self.crash_content[0])
298+
if self.dump_server_user != 'root':
299+
#cannot delete with normal user since dump dir is owned by root
300+
pass
301+
else:
302+
self.c.run_command("rm -rf /var/crash/%s; sync" % self.crash_content[0])
291303

292304
def verify_fadump_reg(self):
293305
'''

0 commit comments

Comments
 (0)