|
|
42837f |
From 8c0b8f944be6eb05ce5a23c85fe8c19abdbe0c32 Mon Sep 17 00:00:00 2001
|
|
|
42837f |
From: Jake Hunsaker <jhunsake@redhat.com>
|
|
|
42837f |
Date: Mon, 15 Oct 2018 18:51:05 -0400
|
|
|
42837f |
Subject: [PATCH] [sosnode] Fix non-root local execution and collection of
|
|
|
42837f |
sosreport
|
|
|
42837f |
|
|
|
42837f |
Fixes an issue where a local non-root run of sosreport could fail due to
|
|
|
42837f |
incorrect process communication with the sosreport process started by
|
|
|
42837f |
sos-collector. Additionally, corrects local copying of generated
|
|
|
42837f |
sosreports to the sos-collector archive.
|
|
|
42837f |
|
|
|
42837f |
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
|
|
|
42837f |
---
|
|
|
42837f |
soscollector/sosnode.py | 23 ++++++++++++++++-------
|
|
|
42837f |
1 file changed, 16 insertions(+), 7 deletions(-)
|
|
|
42837f |
|
|
|
42837f |
diff --git a/soscollector/sosnode.py b/soscollector/sosnode.py
|
|
|
42837f |
index dd0664e..98f1765 100644
|
|
|
42837f |
--- a/soscollector/sosnode.py
|
|
|
42837f |
+++ b/soscollector/sosnode.py
|
|
|
42837f |
@@ -305,11 +305,16 @@ class SosNode():
|
|
|
42837f |
raise socket.timeout
|
|
|
42837f |
else:
|
|
|
42837f |
proc = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
|
|
42837f |
- stdout, stderr = proc.communicate()
|
|
|
42837f |
- if self.config['become_root']:
|
|
|
42837f |
- proc.communicate(input=self.config['root_password'] + '\n')
|
|
|
42837f |
- if self.config['need_sudo']:
|
|
|
42837f |
- proc.communicate(input=self.config['sude_pw'] + '\n')
|
|
|
42837f |
+ if self.config['become_root'] and need_root:
|
|
|
42837f |
+ stdout, stderr = proc.communicate(
|
|
|
42837f |
+ input=self.config['root_password'] + '\n'
|
|
|
42837f |
+ )
|
|
|
42837f |
+ elif self.config['need_sudo'] and need_root:
|
|
|
42837f |
+ stdout, stderr = proc.communicate(
|
|
|
42837f |
+ input=self.config['sudo_pw'] + '\n'
|
|
|
42837f |
+ )
|
|
|
42837f |
+ else:
|
|
|
42837f |
+ stdout, stderr = proc.communicate()
|
|
|
42837f |
rc = proc.returncode
|
|
|
42837f |
if stdout:
|
|
|
42837f |
sout = (stdout or True)
|
|
|
42837f |
@@ -591,7 +596,7 @@ class SosNode():
|
|
|
42837f |
return False
|
|
|
42837f |
else:
|
|
|
42837f |
self.log_debug("Moving %s to %s" % (path, destdir))
|
|
|
42837f |
- shutil.move(path, dest)
|
|
|
42837f |
+ shutil.copy(path, dest)
|
|
|
42837f |
return True
|
|
|
42837f |
except Exception as err:
|
|
|
42837f |
self.log_debug("Failed to retrieve %s: %s" % (path, err))
|
|
|
42837f |
@@ -628,6 +633,10 @@ class SosNode():
|
|
|
42837f |
except Exception:
|
|
|
42837f |
self.log_error('Failed to make archive readable')
|
|
|
42837f |
return False
|
|
|
42837f |
+ try:
|
|
|
42837f |
+ self.make_archive_readable(self.sos_path + '.md5')
|
|
|
42837f |
+ except Exception:
|
|
|
42837f |
+ self.log_debug('Failed to make md5 readable')
|
|
|
42837f |
self.logger.info('Retrieving sosreport from %s' % self.address)
|
|
|
42837f |
self.log_info('Retrieving sosreport...')
|
|
|
42837f |
ret = self.retrieve_file(self.sos_path)
|
|
|
42837f |
@@ -698,7 +707,7 @@ class SosNode():
|
|
|
42837f |
|
|
|
42837f |
This is only used when we're not connecting as root.
|
|
|
42837f |
'''
|
|
|
42837f |
- cmd = 'chmod +r %s' % filepath
|
|
|
42837f |
+ cmd = 'chmod o+r %s' % filepath
|
|
|
42837f |
res = self.run_command(cmd, timeout=10, need_root=True)
|
|
|
42837f |
if res['status'] == 0:
|
|
|
42837f |
return True
|
|
|
42837f |
--
|
|
|
42837f |
2.14.4
|
|
|
42837f |
|