[4/4] p.haul: improve subprocess output logging

Submitted by Nikita Spiridonov on April 21, 2016, 12:46 p.m.

Details

Message ID 1461242792-635567-5-git-send-email-nspiridonov@virtuozzo.com
State New
Series "improve p.haul logging"
Headers show

Commit Message

Nikita Spiridonov April 21, 2016, 12:46 p.m.
Add log_subprocess_output function which add offset and prefix to
subprocess output.

Signed-off-by: Nikita Spiridonov <nspiridonov@virtuozzo.com>
---
 phaul/p_haul_vz.py |   10 +++++-----
 phaul/util.py      |    5 +++++
 2 files changed, 10 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/phaul/p_haul_vz.py b/phaul/p_haul_vz.py
index 578e5e8..0f1d251 100644
--- a/phaul/p_haul_vz.py
+++ b/phaul/p_haul_vz.py
@@ -178,7 +178,7 @@  class p_haul_type:
 				self._ctid, "--skip_arpdetect", "--dumpfile", img.image_dir()],
 				stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 			proc_output = proc.communicate()[0]
-			logging.info(proc_output)
+			util.log_subprocess_output(proc_output)
 			if proc.returncode != 0:
 				raise Exception("Restore failed ({0})".format(proc.returncode))
 		finally:
@@ -196,7 +196,7 @@  class p_haul_type:
 			[vzctl_bin, "--skipowner", "--skiplock", "mount", self._ctid],
 			stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 		proc_output = proc.communicate()[0]
-		logging.info(proc_output)
+		util.log_subprocess_output(proc_output)
 		self._fs_mounted = True
 		return self._ct_root
 
@@ -208,7 +208,7 @@  class p_haul_type:
 				[vzctl_bin, "--skipowner", "--skiplock", "umount", self._ctid],
 				stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 			proc_output = proc.communicate()[0]
-			logging.info(proc_output)
+			util.log_subprocess_output(proc_output)
 			self._fs_mounted = False
 
 	def migration_complete(self, fs, target_host):
@@ -231,7 +231,7 @@  class p_haul_type:
 			[vzctl_bin, "--skipowner", "--skiplock", "start", self._ctid],
 			stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 		proc_output = proc.communicate()[0]
-		logging.info(proc_output)
+		util.log_subprocess_output(proc_output)
 		self._fs_mounted = True
 
 	def stop(self, umount):
@@ -243,7 +243,7 @@  class p_haul_type:
 		proc = subprocess.Popen(
 			args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 		proc_output = proc.communicate()[0]
-		logging.info(proc_output)
+		util.log_subprocess_output(proc_output)
 		self._fs_mounted = not umount
 
 	def get_fs(self, fdfs=None):
diff --git a/phaul/util.py b/phaul/util.py
index 1f17e5b..3776c52 100644
--- a/phaul/util.py
+++ b/phaul/util.py
@@ -88,3 +88,8 @@  def log_header():
 	OFFSET_LINES_COUNT = 3
 	for i in range(OFFSET_LINES_COUNT):
 		logging.info("")
+
+
+def log_subprocess_output(output):
+	for line in output.splitlines():
+		logging.info("\t> %s", line)