Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 909c332f authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "releasetools: Clean up the logging while calling external commands."

parents 4e90c3f9 bec89c1e
Loading
Loading
Loading
Loading
+6 −25
Original line number Diff line number Diff line
@@ -169,7 +169,6 @@ import os.path
import shlex
import shutil
import struct
import subprocess
import sys
import tempfile
import zipfile
@@ -393,11 +392,7 @@ class PayloadSigner(object):
      cmd.extend(["-passin", "pass:" + pw] if pw else ["-nocrypt"])
      signing_key = common.MakeTempFile(prefix="key-", suffix=".key")
      cmd.extend(["-out", signing_key])

      get_signing_key = common.Run(cmd, verbose=False)
      stdoutdata, _ = get_signing_key.communicate()
      assert get_signing_key.returncode == 0, \
          "Failed to get signing key: {}".format(stdoutdata)
      common.RunAndCheckOutput(cmd, verbose=False)

      self.signer = "openssl"
      self.signer_args = ["pkeyutl", "-sign", "-inkey", signing_key,
@@ -410,10 +405,7 @@ class PayloadSigner(object):
    """Signs the given input file. Returns the output filename."""
    out_file = common.MakeTempFile(prefix="signed-", suffix=".bin")
    cmd = [self.signer] + self.signer_args + ['-in', in_file, '-out', out_file]
    signing = common.Run(cmd)
    stdoutdata, _ = signing.communicate()
    assert signing.returncode == 0, \
        "Failed to sign the input file: {}".format(stdoutdata)
    common.RunAndCheckOutput(cmd)
    return out_file


@@ -431,8 +423,6 @@ class Payload(object):
    Args:
      secondary: Whether it's generating a secondary payload (default: False).
    """
    # The place where the output from the subprocess should go.
    self._log_file = sys.stdout if OPTIONS.verbose else subprocess.PIPE
    self.payload_file = None
    self.payload_properties = None
    self.secondary = secondary
@@ -457,10 +447,7 @@ class Payload(object):
    if source_file is not None:
      cmd.extend(["--source_image", source_file])
    cmd.extend(additional_args)
    p = common.Run(cmd, stdout=self._log_file, stderr=subprocess.STDOUT)
    stdoutdata, _ = p.communicate()
    assert p.returncode == 0, \
        "brillo_update_payload generate failed: {}".format(stdoutdata)
    common.RunAndCheckOutput(cmd)

    self.payload_file = payload_file
    self.payload_properties = None
@@ -484,9 +471,7 @@ class Payload(object):
           "--signature_size", "256",
           "--metadata_hash_file", metadata_sig_file,
           "--payload_hash_file", payload_sig_file]
    p1 = common.Run(cmd, stdout=self._log_file, stderr=subprocess.STDOUT)
    p1.communicate()
    assert p1.returncode == 0, "brillo_update_payload hash failed"
    common.RunAndCheckOutput(cmd)

    # 2. Sign the hashes.
    signed_payload_sig_file = payload_signer.Sign(payload_sig_file)
@@ -501,9 +486,7 @@ class Payload(object):
           "--signature_size", "256",
           "--metadata_signature_file", signed_metadata_sig_file,
           "--payload_signature_file", signed_payload_sig_file]
    p1 = common.Run(cmd, stdout=self._log_file, stderr=subprocess.STDOUT)
    p1.communicate()
    assert p1.returncode == 0, "brillo_update_payload sign failed"
    common.RunAndCheckOutput(cmd)

    # 4. Dump the signed payload properties.
    properties_file = common.MakeTempFile(prefix="payload-properties-",
@@ -511,9 +494,7 @@ class Payload(object):
    cmd = ["brillo_update_payload", "properties",
           "--payload", signed_payload_file,
           "--properties_file", properties_file]
    p1 = common.Run(cmd, stdout=self._log_file, stderr=subprocess.STDOUT)
    p1.communicate()
    assert p1.returncode == 0, "brillo_update_payload properties failed"
    common.RunAndCheckOutput(cmd)

    if self.secondary:
      with open(properties_file, "a") as f:
+2 −2
Original line number Diff line number Diff line
@@ -1268,7 +1268,7 @@ class PayloadTest(test_utils.ReleaseToolsTestCase):
    target_file = construct_target_files()
    common.ZipDelete(target_file, 'IMAGES/vendor.img')
    payload = Payload()
    self.assertRaises(AssertionError, payload.Generate, target_file)
    self.assertRaises(common.ExternalError, payload.Generate, target_file)

  def test_Sign_full(self):
    payload = self._create_payload_full()
@@ -1316,7 +1316,7 @@ class PayloadTest(test_utils.ReleaseToolsTestCase):
    payload = self._create_payload_full()
    payload_signer = PayloadSigner()
    payload_signer.signer_args.append('bad-option')
    self.assertRaises(AssertionError, payload.Sign, payload_signer)
    self.assertRaises(common.ExternalError, payload.Sign, payload_signer)

  def test_WriteToZip(self):
    payload = self._create_payload_full()