[PATCH 0/2] Add option to run_command to log error in debug mode

- Sometimes the run_command caller doesn't want to have a failure logged as error, since such failure can be expected. This patch adds an option in run_command to log errors in debug mode to avoid give false positives to users. Jose Ricardo Ziviani (2): Add option 'silent' in run_command Change getsebool to run silently. src/kimchi/model/vmhostdevs.py | 3 ++- src/kimchi/utils.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) -- 1.9.1

- With this new option the caller can choose if run_command errors will be logged as error or debug. There are cases where a command error is expected and don't need to alert users. Signed-off-by: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com> --- src/kimchi/utils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py index ff3a5da..baf2d62 100644 --- a/src/kimchi/utils.py +++ b/src/kimchi/utils.py @@ -165,11 +165,13 @@ def check_url_path(path): return True -def run_command(cmd, timeout=None): +def run_command(cmd, timeout=None, silent=False): """ cmd is a sequence of command arguments. timeout is a float number in seconds. timeout default value is None, means command run without timeout. + silent is bool, it will log errors using debug handler not error. + silent default value is False. """ # subprocess.kill() can leave descendants running # and halting the execution. Using psutil to @@ -206,8 +208,14 @@ def run_command(cmd, timeout=None): kimchi_log.debug("out:\n%s", out) if proc.returncode != 0: - kimchi_log.error("rc: %s error: %s returned from cmd: %s", - proc.returncode, error, ' '.join(cmd)) + msg = "rc: %s error: %s returned from cmd: %s" %\ + (proc.returncode, error, ' '.join(cmd)) + + if silent: + kimchi_log.debug(msg) + + else: + kimchi_log.error(msg) elif error: kimchi_log.debug("error: %s returned from cmd: %s", error, ' '.join(cmd)) -- 1.9.1

- getsebool virt_use_sysfs exists in RHEL6 and older distributions only. Newer distros don't have it but run_command alerts there is an error in Kimchi. This is not an error but a expected behavior. For this reason, this command now will only log for debugging purposes. Signed-off-by: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com> --- src/kimchi/model/vmhostdevs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/kimchi/model/vmhostdevs.py b/src/kimchi/model/vmhostdevs.py index 3e711cb..9a7d03b 100644 --- a/src/kimchi/model/vmhostdevs.py +++ b/src/kimchi/model/vmhostdevs.py @@ -102,7 +102,8 @@ class VMHostDevsModel(object): # Enable virt_use_sysfs on RHEL6 and older distributions # In recent Fedora, there is no virt_use_sysfs. - out, err, rc = run_command(['getsebool', 'virt_use_sysfs']) + out, err, rc = run_command(['getsebool', 'virt_use_sysfs'], + silent=True) if rc == 0 and out.rstrip('\n') != "virt_use_sysfs --> on": out, err, rc = run_command(['setsebool', '-P', 'virt_use_sysfs=on']) -- 1.9.1

Reviewed-By: Ramon Medeiros <ramonn@br.ibm.com> On 07/23/2015 10:56 AM, Jose Ricardo Ziviani wrote:
- getsebool virt_use_sysfs exists in RHEL6 and older distributions only. Newer distros don't have it but run_command alerts there is an error in Kimchi. This is not an error but a expected behavior. For this reason, this command now will only log for debugging purposes.
Signed-off-by: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com> --- src/kimchi/model/vmhostdevs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/kimchi/model/vmhostdevs.py b/src/kimchi/model/vmhostdevs.py index 3e711cb..9a7d03b 100644 --- a/src/kimchi/model/vmhostdevs.py +++ b/src/kimchi/model/vmhostdevs.py @@ -102,7 +102,8 @@ class VMHostDevsModel(object):
# Enable virt_use_sysfs on RHEL6 and older distributions # In recent Fedora, there is no virt_use_sysfs. - out, err, rc = run_command(['getsebool', 'virt_use_sysfs']) + out, err, rc = run_command(['getsebool', 'virt_use_sysfs'], + silent=True) if rc == 0 and out.rstrip('\n') != "virt_use_sysfs --> on": out, err, rc = run_command(['setsebool', '-P', 'virt_use_sysfs=on'])
-- Ramon Nunes Medeiros Kimchi Developer Linux Technology Center Brazil IBM Systems & Technology Group Phone : +55 19 2132 7878 ramonn@br.ibm.com

Patch applied to master branch of https://github.com/danielhb/kimchi Thanks! On 07/23/2015 10:57 AM, Ramon Medeiros wrote:
Reviewed-By: Ramon Medeiros <ramonn@br.ibm.com>
On 07/23/2015 10:56 AM, Jose Ricardo Ziviani wrote:
- getsebool virt_use_sysfs exists in RHEL6 and older distributions only. Newer distros don't have it but run_command alerts there is an error in Kimchi. This is not an error but a expected behavior. For this reason, this command now will only log for debugging purposes.
Signed-off-by: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com> --- src/kimchi/model/vmhostdevs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/kimchi/model/vmhostdevs.py b/src/kimchi/model/vmhostdevs.py index 3e711cb..9a7d03b 100644 --- a/src/kimchi/model/vmhostdevs.py +++ b/src/kimchi/model/vmhostdevs.py @@ -102,7 +102,8 @@ class VMHostDevsModel(object):
# Enable virt_use_sysfs on RHEL6 and older distributions # In recent Fedora, there is no virt_use_sysfs. - out, err, rc = run_command(['getsebool', 'virt_use_sysfs']) + out, err, rc = run_command(['getsebool', 'virt_use_sysfs'], + silent=True) if rc == 0 and out.rstrip('\n') != "virt_use_sysfs --> on": out, err, rc = run_command(['setsebool', '-P', 'virt_use_sysfs=on'])
participants (4)
-
Aline Manera
-
Daniel Henrique Barboza
-
Jose Ricardo Ziviani
-
Ramon Medeiros