← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~ajorgens/cloud-init:pipe-cat into cloud-init:master

 

Andrew Jorgensen has proposed merging ~ajorgens/cloud-init:pipe-cat into cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~ajorgens/cloud-init/+git/cloud-init/+merge/325512

util: Add an option for subp to pipe the process through cat

Some processes are less chatty when piped through cat, because they won't
detect a terminal (the Yum package manager being a prime example).
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~ajorgens/cloud-init:pipe-cat into cloud-init:master.
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index 1fecb61..849927d 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -1,10 +1,12 @@
 # Copyright (C) 2012 Canonical Ltd.
 # Copyright (C) 2012, 2013 Hewlett-Packard Development Company, L.P.
 # Copyright (C) 2012 Yahoo! Inc.
+# Copyright (C) 2017 Amazon.com, Inc. or its affiliates.
 #
 # Author: Scott Moser <scott.moser@xxxxxxxxxxxxx>
 # Author: Juerg Haefliger <juerg.haefliger@xxxxxx>
 # Author: Joshua Harlow <harlowja@xxxxxxxxxxxxx>
+# Author: Andrew Jorgensen <ajorgens@xxxxxxxxxx>
 #
 # This file is part of cloud-init. See LICENSE file for license information.
 
@@ -212,7 +214,8 @@ class Distro(distros.Distro):
         cmd.extend(pkglist)
 
         # Allow the output of this to flow outwards (ie not be captured)
-        util.subp(cmd, capture=False)
+        # Also, pipe it through cat so it won't display progress bars.
+        util.subp(cmd, capture=False, pipe_cat=True)
 
     def update_package_sources(self):
         self._runner.run("update-sources", self.package_command,
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 415ca37..c49150c 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1,10 +1,12 @@
 # Copyright (C) 2012 Canonical Ltd.
 # Copyright (C) 2012, 2013 Hewlett-Packard Development Company, L.P.
 # Copyright (C) 2012 Yahoo! Inc.
+# Copyright (C) 2017 Amazon.com, Inc. or its affiliates.
 #
 # Author: Scott Moser <scott.moser@xxxxxxxxxxxxx>
 # Author: Juerg Haefliger <juerg.haefliger@xxxxxx>
 # Author: Joshua Harlow <harlowja@xxxxxxxxxxxxx>
+# Author: Andrew Jorgensen <ajorgens@xxxxxxxxxx>
 #
 # This file is part of cloud-init. See LICENSE file for license information.
 
@@ -1775,8 +1777,8 @@ def delete_dir_contents(dirname):
 
 
 def subp(args, data=None, rcs=None, env=None, capture=True, shell=False,
-         logstring=False, decode="replace", target=None, update_env=None):
-
+         logstring=False, decode="replace", target=None, update_env=None,
+         pipe_cat=False):
     # not supported in cloud-init (yet), for now kept in the call signature
     # to ease maintaining code shared between cloud-init and curtin
     if target is not None:
@@ -1820,10 +1822,20 @@ def subp(args, data=None, rcs=None, env=None, capture=True, shell=False,
             if not isinstance(data, bytes):
                 data = data.encode()
 
+        # Some processes are less chatty when piped through cat, because they
+        # won't detect a terminal (yum being a prime example).
+        if pipe_cat:
+            cat = subprocess.Popen('cat', stdout=stdout, stderr=stderr,
+                                   stdin=subprocess.PIPE)
+            stdout = cat.stdin
+
         sp = subprocess.Popen(args, stdout=stdout,
                               stderr=stderr, stdin=stdin,
                               env=env, shell=shell)
+
         (out, err) = sp.communicate(data)
+        if pipe_cat:
+            (out, _err) = cat.communicate()
 
         # Just ensure blank instead of none.
         if not out and capture:

Follow ups