Ubuntu Pastebin

Paste from Andrew Jorgensen at Wed, 14 Jun 2017 16:48:35 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 415ca37..672d3e4 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@canonical.com>
 # Author: Juerg Haefliger <juerg.haefliger@hp.com>
 # Author: Joshua Harlow <harlowja@yahoo-inc.com>
+# Author: Andrew Jorgensen <ajorgens@amazon.com>
 #
 # This file is part of cloud-init. See LICENSE file for license information.
 
@@ -1776,7 +1778,6 @@ 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):
-
     # 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:
@@ -1805,10 +1806,9 @@ def subp(args, data=None, rcs=None, env=None, capture=True, shell=False,
                        "input/output logstring: %s"), logstring)
 
         stdin = None
-        stdout = None
         stderr = None
+        stdout = subprocess.PIPE
         if capture:
-            stdout = subprocess.PIPE
             stderr = subprocess.PIPE
         if data is None:
             # using devnull assures any reads get null, rather
@@ -1823,7 +1823,15 @@ def subp(args, data=None, rcs=None, env=None, capture=True, shell=False,
         sp = subprocess.Popen(args, stdout=stdout,
                               stderr=stderr, stdin=stdin,
                               env=env, shell=shell)
-        (out, err) = sp.communicate(data)
+
+        if capture:
+            (out, err) = sp.communicate(data)
+        else:
+            # Some processes are less chatty when disconnected from a tty.
+            (out, err) = None, None
+            while sp.poll() is None:
+                sys.stdout.write(p.stdout.readline())
+                sys.stdout.flush()
 
         # Just ensure blank instead of none.
         if not out and capture:
Download as text