|
47 | 47 | import os |
48 | 48 | import re |
49 | 49 | import subprocess |
| 50 | +import tempfile |
50 | 51 | import time |
51 | 52 | from typing import Dict, List, Optional, Tuple # noqa: H301 |
52 | 53 |
|
@@ -618,33 +619,40 @@ def _piped_execute(self, cmd1: list, cmd2: list) -> Tuple[int, bytes]: |
618 | 619 | LOG.debug("Piping cmd1='%s' into...", ' '.join(cmd1)) |
619 | 620 | LOG.debug("cmd2='%s'", ' '.join(cmd2)) |
620 | 621 |
|
621 | | - try: |
622 | | - p1 = subprocess.Popen(cmd1, stdout=subprocess.PIPE, |
623 | | - stderr=subprocess.PIPE, |
624 | | - close_fds=True) |
625 | | - except OSError as e: |
626 | | - LOG.error("Pipe1 failed - %s ", e) |
627 | | - raise |
| 622 | + with tempfile.TemporaryFile() as errfile: |
628 | 623 |
|
629 | | - # NOTE(dosaboy): ensure that the pipe is blocking. This is to work |
630 | | - # around the case where evenlet.green.subprocess is used which seems to |
631 | | - # use a non-blocking pipe. |
632 | | - assert p1.stdout is not None |
633 | | - flags = fcntl.fcntl(p1.stdout, fcntl.F_GETFL) & (~os.O_NONBLOCK) |
634 | | - fcntl.fcntl(p1.stdout, fcntl.F_SETFL, flags) |
635 | | - |
636 | | - try: |
637 | | - p2 = subprocess.Popen(cmd2, stdin=p1.stdout, |
638 | | - stdout=subprocess.PIPE, |
639 | | - stderr=subprocess.PIPE, |
640 | | - close_fds=True) |
641 | | - except OSError as e: |
642 | | - LOG.error("Pipe2 failed - %s ", e) |
643 | | - raise |
| 624 | + try: |
| 625 | + p1 = subprocess.Popen(cmd1, stdout=subprocess.PIPE, |
| 626 | + stderr=errfile, |
| 627 | + close_fds=True) |
| 628 | + except OSError as e: |
| 629 | + LOG.error("Pipe1 failed - %s ", e) |
| 630 | + raise |
| 631 | + |
| 632 | + # NOTE(dosaboy): ensure that the pipe is blocking. This is to work |
| 633 | + # around the case where evenlet.green.subprocess is used which |
| 634 | + # seems to use a non-blocking pipe. |
| 635 | + assert p1.stdout is not None |
| 636 | + flags = fcntl.fcntl(p1.stdout, fcntl.F_GETFL) & (~os.O_NONBLOCK) |
| 637 | + fcntl.fcntl(p1.stdout, fcntl.F_SETFL, flags) |
644 | 638 |
|
645 | | - p1.stdout.close() |
646 | | - stdout, stderr = p2.communicate() |
647 | | - return p2.returncode, stderr |
| 639 | + try: |
| 640 | + p2 = subprocess.Popen(cmd2, stdin=p1.stdout, |
| 641 | + stdout=subprocess.PIPE, |
| 642 | + stderr=errfile, |
| 643 | + close_fds=True) |
| 644 | + except OSError as e: |
| 645 | + LOG.error("Pipe2 failed - %s ", e) |
| 646 | + raise |
| 647 | + |
| 648 | + p1.stdout.close() |
| 649 | + p2.communicate() |
| 650 | + p1.wait() |
| 651 | + |
| 652 | + errfile.seek(0) |
| 653 | + px_stderr = errfile.read() |
| 654 | + |
| 655 | + return p1.returncode or p2.returncode, px_stderr |
648 | 656 |
|
649 | 657 | def _rbd_diff_transfer(self, src_name: str, src_pool: str, |
650 | 658 | dest_name: str, dest_pool: str, |
|
0 commit comments