oeqa/runtime: improve some test cases
cover oeqa/runtime: improve some test cases
Yi Zhao (3):
oeqa/runtime/smart: fix hardcoded root directory oeqa/runtime/logrotate: fix hardcoded root directory oeqa/runtime/parselogs: escape special character for grep
meta/lib/oeqa/runtime/logrotate.py | 8 ++++---- meta/lib/oeqa/runtime/parselogs.py | 6 ++++-- meta/lib/oeqa/runtime/smart.py | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/3 oeqa/runtime/smart: fix hardcoded root directory
Use $HOME instead of /home/root in case user changes the default root directory by ROOT_HOME
--- meta/lib/oeqa/runtime/smart.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
meta/lib/oeqa/runtime/smart.py +2 -2
@@ -147,7 +147,7 @@ class SmartRepoTest(SmartTest): for i in output.split("\n"): if ("rpmsys" != str(i)) and ("myrpmdir" != str(i)): self.smart('channel --disable '+str(i)) - self.target.run('cd /home/root') + self.target.run('cd $HOME') self.smart('install psplash') for i in output.split("\n"): if ("rpmsys" != str(i)) and ("myrpmdir" != str(i)):
@@ -172,4 +172,4 @@ class SmartRepoTest(SmartTest): @skipUnlessPassed('test_smart_channel_add') def test_smart_remove_package(self): self.smart('install -y psplash') - self.smart('remove -y psplash') + self.smart('remove -y psplash')
Signature · 1 line
1.7.9.5
PATCH 2/3 oeqa/runtime/logrotate: fix hardcoded root directory
In reply to Yi ZhaoUse $HOME instead of /home/root in case user changes the default root directory by ROOT_HOME
--- meta/lib/oeqa/runtime/logrotate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
meta/lib/oeqa/runtime/logrotate.py +4 -4
@@ -14,9 +14,9 @@ class LogrotateTest(oeRuntimeTest): @skipUnlessPassed("test_ssh") def test_1_logrotate_setup(self): - (status, output) = self.target.run('mkdir /home/root/logrotate_dir') + (status, output) = self.target.run('mkdir $HOME/logrotate_dir') self.assertEqual(status, 0, msg = "Could not create logrotate_dir. Output: %s" % output) - (status, output) = self.target.run("sed -i 's#wtmp {#wtmp {\\n olddir /home/root/logrotate_dir#' /etc/logrotate.conf") + (status, output) = self.target.run("sed -i \"s#wtmp {#wtmp {\\n olddir $HOME/logrotate_dir#\" /etc/logrotate.conf") self.assertEqual(status, 0, msg = "Could not write to logrotate.conf file. Status and output: %s and %s)" % (status, output)) @testcase(289)
@@ -24,5 +24,5 @@ class LogrotateTest(oeRuntimeTest): def test_2_logrotate(self): (status, output) = self.target.run('logrotate -f /etc/logrotate.conf') self.assertEqual(status, 0, msg = "logrotate service could not be reloaded. Status and output: %s and %s" % (status, output)) - output = self.target.run('ls -la /home/root/logrotate_dir/ | wc -l')[1] - self.assertTrue(int(output)>=3, msg = "new logfile could not be created. List of files within log directory: %s" %(self.target.run('ls -la /home/root/logrotate_dir')[1])) + output = self.target.run('ls -la $HOME/logrotate_dir/ | wc -l')[1] + self.assertTrue(int(output)>=3, msg = "new logfile could not be created. List of files within log directory: %s" %(self.target.run('ls -la $HOME/logrotate_dir')[1]))
Signature · 1 line
1.7.9.5
PATCH 3/3 oeqa/runtime/parselogs: escape special character for grep
In reply to Yi ZhaoSometimes the grep output is not correct if the log message contains some special characters. Use re.escape to escape all non-alphanumerics before grep
--- meta/lib/oeqa/runtime/parselogs.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
meta/lib/oeqa/runtime/parselogs.py +4 -2
@@ -1,6 +1,7 @@ import os import unittest import subprocess +import re from oeqa.oetest import oeRuntimeTest from oeqa.utils.decorators import *
@@ -50,7 +51,7 @@ x86_common = [ qemux86_common = [ 'wrong ELF class', "fail to add MMCONFIG information, can't access extended PCI configuration space under this bridge.", - "can't claim BAR ", + "can\'t claim BAR ", ] + common_errors ignore_errors = {
@@ -221,7 +222,8 @@ class ParseLogsTest(oeRuntimeTest): results[log.replace('target_logs/','')] = {} rez = result.splitlines() for xrez in rez: - command = "grep \"\\"+str(xrez)+"\" -B "+str(lines_before)+" -A "+str(lines_after)+" "+str(log) + nxrez = re.escape(xrez) + command = "grep -E \""+str(nxrez)+"\" -B "+str(lines_before)+" -A "+str(lines_after)+" "+str(log) try: grep_output = subprocess.check_output(command, shell=True) except:
Signature · 1 line
1.7.9.5
Re: [PATCH 3/3] oeqa/runtime/parselogs: escape special character for grep
Quoted 4 lines · Yi Zhao
Sometimes the grep output is not correct if the log message contains some special characters. Use re.escape to escape all non-alphanumerics before grep
If we're going to insist that the strings are literal then instead of telling grep to use extended regexp's and passing escaped regexs, why not just use -F which tells grep to search for fixed strings, not expressions.
Ross
Re: [PATCH 3/3] oeqa/runtime/parselogs: escape special character for grep
Quoted 9 lines · Ross
On 7 January 2016 at 03:29, Yi Zhao <[email protected] <mailto:[email protected]>> wrote:
Sometimes the grep output is not correct if the log message contains some special characters. Use re.escape to escape all non-alphanumerics before grep
If we're going to insist that the strings are literal then instead of telling grep to use extended regexp's and passing escaped regexs, why not just use -F which tells grep to search for fixed strings, not expressions.
Hi Ross,
It still need to escape quotation marks if using -F option. Consider the following log:
[521514.737] (EE) evdev: Qemu Tablet: Unable to open evdev device "/dev/input/touchscreen0".
We still need an extra step to replace " with \" before grep
Yi
Quoted 2 lines
Ross
Re: [PATCH 3/3] oeqa/runtime/parselogs: escape special character for grep
Quoted 7 lines · Yi Zhao
It still need to escape quotation marks if using -F option. Consider the following log:
[521514.737] (EE) evdev: Qemu Tablet: Unable to open evdev device"
/dev/input/touchscreen0".We still need an extra step to replace " with \" before grep
Actually that's only true as the grep command is passed to subproces.check_output() as a string. If it was constructed as a list the shell wouldn't be parsing it and you wouldn't have to worry about quoting at all.
(always pass lists instead of strings to subprocess, it makes everything a lot easier)
Ross
Re: [PATCH 3/3] oeqa/runtime/parselogs: escape special character for grep
Quoted 8 lines · Ross
On 8 January 2016 at 08:44, Yi Zhao <[email protected] <mailto:[email protected]>> wrote:
It still need to escape quotation marks if using -F option. Consider the following log:
[521514.737] (EE) evdev: Qemu Tablet: Unable to open evdev device "/dev/input/touchscreen0".
Quoted 8 lines
We still need an extra step to replace " with \" before grep
Actually that's only true as the grep command is passed to
subproces.check_output()as a string. If it was constructed as a list the shell wouldn't be parsing it and you wouldn't have to worry about quoting at all.(always pass lists instead of strings to subprocess, it makes everything a lot easier)
Ross
Thanks, Ross.
I will test it and send the v2 patch.
Yi