Exemplo n.º 1
0
  def testToken(self):
    """Test Token."""
    failure_result = cros_build_lib.CommandResult(
        error='error', output=None, returncode=1)
    self.PatchObject(
        cros_build_lib, 'RunCommand', return_value=failure_result)
    self.assertIsNone(auth.Token())

    success_result = cros_build_lib.CommandResult(
        output='token', returncode=0)
    self.PatchObject(
        cros_build_lib, 'RunCommand', return_value=success_result)
    self.assertEqual(auth.Token(), 'token')
Exemplo n.º 2
0
  def testLogin(self):
    """Test Login."""
    failure_result = cros_build_lib.CommandResult(
        error='error', output=None, returncode=1)
    self.PatchObject(
        cros_build_lib, 'RunCommand', return_value=failure_result)
    self.assertFalse(auth.Login())

    success_result = cros_build_lib.CommandResult(
        output=None, returncode=0)
    self.PatchObject(
        cros_build_lib, 'RunCommand', return_value=success_result)
    self.assertTrue(auth.Login())
Exemplo n.º 3
0
    def testListFiles(self):
        files = [
            '%s/some/path' % self.bucket_uri,
            '%s/some/file/path' % self.bucket_uri,
        ]
        directories = [
            '%s/some/dir/' % self.bucket_uri,
            '%s/some/dir/path/' % self.bucket_uri,
        ]

        gs_uri = '%s/**' % self.bucket_uri
        cmd = [self.gsutil, 'ls', gs_uri]

        # Prepare cmd_result for a good run.
        # Fake a trailing empty line.
        output = '\n'.join(files + directories + [''])
        cmd_result_ok = cros_test_lib.EasyAttr(output=output, returncode=0)

        # Prepare exception for a run that finds nothing.
        stderr = 'CommandException: One or more URLs matched no objects.\n'
        cmd_result_empty = cros_build_lib.CommandResult(error=stderr)
        empty_exception = cros_build_lib.RunCommandError(
            stderr, cmd_result_empty)

        # Prepare exception for a run that triggers a GS failure.
        error = cros_build_lib.RunCommandError(GS_RETRY_FAILURE,
                                               self.cmd_result)

        # Set up the test replay script.
        # Run 1, runs ok.
        cros_build_lib.RunCommand(
            cmd, redirect_stdout=True,
            redirect_stderr=True).AndReturn(cmd_result_ok)
        # Run 2, runs ok, sorts files.
        cros_build_lib.RunCommand(
            cmd, redirect_stdout=True,
            redirect_stderr=True).AndReturn(cmd_result_ok)
        # Run 3, finds nothing.
        cros_build_lib.RunCommand(
            cmd, redirect_stdout=True,
            redirect_stderr=True).AndRaise(empty_exception)
        # Run 4, failure in GS.
        for _ix in xrange(gslib.RETRY_ATTEMPTS + 1):
            cros_build_lib.RunCommand(cmd,
                                      redirect_stdout=True,
                                      redirect_stderr=True).AndRaise(error)
        self.mox.ReplayAll()

        # Run the test verification.
        result = gslib.ListFiles(self.bucket_uri, recurse=True)
        self.assertEqual(files, result)
        result = gslib.ListFiles(self.bucket_uri, recurse=True, sort=True)
        self.assertEqual(sorted(files), result)
        result = gslib.ListFiles(self.bucket_uri, recurse=True)
        self.assertEqual([], result)
        self.assertRaises(gslib.GSLibError,
                          gslib.ListFiles,
                          self.bucket_uri,
                          recurse=True)
        self.mox.VerifyAll()
  def testPushChange(self):
    git_log = 'Marking test_one as stable\nMarking test_two as stable\n'
    fake_description = 'Marking set of ebuilds as stable\n\n%s' % git_log
    self.mox.StubOutWithMock(cros_mark_as_stable, '_DoWeHaveLocalCommits')
    self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'CreateBranch')
    self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'Exists')
    self.mox.StubOutWithMock(git, 'PushWithRetry')
    self.mox.StubOutWithMock(git, 'GetTrackingBranch')
    self.mox.StubOutWithMock(git, 'SyncPushBranch')
    self.mox.StubOutWithMock(git, 'CreatePushBranch')
    self.mox.StubOutWithMock(git, 'RunGit')

    cros_mark_as_stable._DoWeHaveLocalCommits(
        self._branch, self._target_manifest_branch, '.').AndReturn(True)
    git.GetTrackingBranch('.', for_push=True).AndReturn(
        ['gerrit', 'refs/remotes/gerrit/master'])
    git.SyncPushBranch('.', 'gerrit', 'refs/remotes/gerrit/master')
    cros_mark_as_stable._DoWeHaveLocalCommits(
        self._branch, 'refs/remotes/gerrit/master', '.').AndReturn(True)
    result = cros_build_lib.CommandResult(output=git_log)
    cros_build_lib.RunCommandCaptureOutput(
        ['git', 'log', '--format=format:%s%n%n%b',
         'refs/remotes/gerrit/master..%s' % self._branch],
        cwd='.').AndReturn(result)
    git.CreatePushBranch('merge_branch', '.')
    git.RunGit('.', ['merge', '--squash', self._branch])
    git.RunGit('.', ['commit', '-m', fake_description])
    git.RunGit('.', ['config', 'push.default', 'tracking'])
    git.PushWithRetry('merge_branch', '.', dryrun=False)
    self.mox.ReplayAll()
    cros_mark_as_stable.PushChange(self._branch, self._target_manifest_branch,
                                   False, '.')
    self.mox.VerifyAll()
Exemplo n.º 5
0
def _JsonLintFile(path, _output_format, _debug):
    """Returns result of running json lint checks on |path|."""
    result = cros_build_lib.CommandResult('python -mjson.tool "%s"' % path,
                                          returncode=0)

    data = osutils.ReadFile(path)

    # Strip off leading UTF-8 BOM if it exists.
    if data.startswith(u'\ufeff'):
        data = data[1:]

    # Strip out comments for JSON parsing.
    stripped_data = re.sub(r'^\s*#.*', '', data, flags=re.M)

    # See if it validates.
    try:
        json.loads(stripped_data)
    except ValueError as e:
        result.returncode = 1
        logging.notice('%s: %s', path, e)

    # Check whitespace.
    if not _WhiteSpaceLintData(path, data):
        result.returncode = 1

    return result
Exemplo n.º 6
0
    def test_RepoSelfupdateSucceeds(self):
        mock_rm = self.PatchObject(osutils, 'RmDir')
        cmd_result = cros_build_lib.CommandResult()
        self.PatchObject(cros_build_lib, 'RunCommand', return_value=cmd_result)
        self.repo._RepoSelfupdate()

        self.assertFalse(mock_rm.called)
    def testHEAD(self):
        """Test the parsing of the git.GetChangeId function for HEAD."""

        log_output = """
lib/git: break out ChangeId into its own function

Code in Commit() will get the Change-Id after doing a git commit,
but in some use cases, we want to get the Change-Id of a commit
that already exists, without changing it. Move this code into its
own function that Commit() calls or an external user can call it
directly.

BUG=None
TEST=Start python3
>>> from chromite.lib import git
>>> print(git.GetChangeId('.'))
>>> exit(0)
$ git show
Compare the Change-Id printed by the python code with that shown

Change-Id: Ia7b712c42ff83c52c0fb5d88d1ef6c62f49da88d
"""
        result = cros_build_lib.CommandResult(output=log_output)
        self.PatchObject(git, 'RunGit', return_value=result)

        changeid = git.GetChangeId('git/repo/path')
        self.assertEqual(changeid, 'Ia7b712c42ff83c52c0fb5d88d1ef6c62f49da88d')
Exemplo n.º 8
0
def TestingSymUpload(upload_url, sym_item, _product_name):
    """A stub version of SymUpload for --testing usage"""
    cmd = ['sym_upload', sym_item.sym_file, upload_url]
    # Randomly fail 80% of the time (the retry logic makes this 80%/3 per file).
    returncode = random.randint(1, 100) <= 80
    logging.debug('would run (and return %i): %s', returncode,
                  cros_build_lib.CmdToStr(cmd))
    if returncode:
        output = 'Failed to send the symbol file.'
    else:
        output = 'Successfully sent the symbol file.'
    result = cros_build_lib.CommandResult(cmd=cmd,
                                          error=None,
                                          output=output,
                                          returncode=returncode)
    if returncode:
        exceptions = (
            socket.error('[socket.error] forced test fail'),
            httplib.BadStatusLine('[BadStatusLine] forced test fail'),
            urllib2.HTTPError(upload_url, 400, '[HTTPError] forced test fail',
                              {}, None),
            urllib2.URLError('[URLError] forced test fail'),
        )
        raise random.choice(exceptions)
    else:
        return result
    def testNoChangeId(self):
        """Test git.GetChangeId function if there is no Change-Id."""

        log_output = """
lib/git: break out ChangeId into its own function

Code in Commit() will get the Change-Id after doing a git commit,
but in some use cases, we want to get the Change-Id of a commit
that already exists, without changing it. Move this code into its
own function that Commit() calls or an external user can call it
directly.

BUG=None
TEST=Start python3
>>> from chromite.lib import git
>>> print(git.GetChangeId('.'))
>>> exit(0)
$ git show
Compare the Change-Id printed by the python code with that shown
"""
        result = cros_build_lib.CommandResult(output=log_output)
        self.PatchObject(git, 'RunGit', return_value=result)

        changeid = git.GetChangeId('git/repo/path')
        self.assertIsNone(changeid)
Exemplo n.º 10
0
    def testExceptionEquality(self):
        """Verify equality methods for RunCommandError"""

        c1 = cros_build_lib.CommandResult(cmd=['ls', 'arg'], returncode=1)
        c2 = cros_build_lib.CommandResult(cmd=['ls', 'arg1'], returncode=1)
        c3 = cros_build_lib.CommandResult(cmd=['ls', 'arg'], returncode=2)
        e1 = cros_build_lib.RunCommandError('Message 1', c1)
        e2 = cros_build_lib.RunCommandError('Message 1', c1)
        e_diff_msg = cros_build_lib.RunCommandError('Message 2', c1)
        e_diff_cmd = cros_build_lib.RunCommandError('Message 1', c2)
        e_diff_code = cros_build_lib.RunCommandError('Message 1', c3)

        self.assertEqual(e1, e2)
        self.assertNotEqual(e1, e_diff_msg)
        self.assertNotEqual(e1, e_diff_cmd)
        self.assertNotEqual(e1, e_diff_code)
Exemplo n.º 11
0
    def testRawDiff(self):
        """Test the parsing of the git.RawDiff function."""

        diff_output = """
:100644 100644 ac234b2... 077d1f8... M\tchromeos-base/chromeos-chrome/Manifest
:100644 100644 9e5d11b... 806bf9b... R099\tchromeos-base/chromeos-chrome/chromeos-chrome-40.0.2197.0_rc-r1.ebuild\tchromeos-base/chromeos-chrome/chromeos-chrome-40.0.2197.2_rc-r1.ebuild
:100644 100644 70d6e94... 821c642... M\tchromeos-base/chromeos-chrome/chromeos-chrome-9999.ebuild
:100644 100644 be445f9... be445f9... R100\tchromeos-base/chromium-source/chromium-source-40.0.2197.0_rc-r1.ebuild\tchromeos-base/chromium-source/chromium-source-40.0.2197.2_rc-r1.ebuild
"""
        result = cros_build_lib.CommandResult(output=diff_output)
        self.PatchObject(git, 'RunGit', return_value=result)

        entries = git.RawDiff('foo', 'bar')
        self.assertEqual(
            entries,
            [('100644', '100644', 'ac234b2', '077d1f8', 'M', None,
              'chromeos-base/chromeos-chrome/Manifest', None),
             ('100644', '100644', '9e5d11b', '806bf9b', 'R', '099',
              'chromeos-base/chromeos-chrome/'
              'chromeos-chrome-40.0.2197.0_rc-r1.ebuild',
              'chromeos-base/chromeos-chrome/'
              'chromeos-chrome-40.0.2197.2_rc-r1.ebuild'),
             ('100644', '100644', '70d6e94', '821c642', 'M', None,
              'chromeos-base/chromeos-chrome/chromeos-chrome-9999.ebuild',
              None),
             ('100644', '100644', 'be445f9', 'be445f9', 'R', '100',
              'chromeos-base/chromium-source/'
              'chromium-source-40.0.2197.0_rc-r1.ebuild',
              'chromeos-base/chromium-source/'
              'chromium-source-40.0.2197.2_rc-r1.ebuild')])
Exemplo n.º 12
0
    def testFailureOutputHandling(self):
        """Test failed package handling."""
        # Prevent argument validation error.
        self.PatchObject(sysroot_lib.Sysroot,
                         'IsToolchainInstalled',
                         return_value=True)

        in_proto = self._InputProto(build_target=self.build_target,
                                    sysroot_path=self.sysroot)
        out_proto = self._OutputProto()

        # Failed package info and expected list for verification.
        err_pkgs = ['cat/pkg', 'cat2/pkg2']
        err_cpvs = [
            portage_util.SplitCPV(cpv, strict=False) for cpv in err_pkgs
        ]
        expected = [('cat', 'pkg'), ('cat2', 'pkg2')]

        # Force error to be raised with the packages.
        error = sysroot_lib.PackageInstallError('Error',
                                                cros_build_lib.CommandResult(),
                                                packages=err_cpvs)
        self.PatchObject(sysroot_service, 'BuildPackages', side_effect=error)

        rc = sysroot_controller.InstallPackages(in_proto, out_proto,
                                                self.api_config)
        # This needs to return 2 to indicate the available error response.
        self.assertEqual(
            controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)
        for package in out_proto.failed_packages:
            cat_pkg = (package.category, package.package_name)
            self.assertIn(cat_pkg, expected)
Exemplo n.º 13
0
    def testPackageFailure(self):
        """Test package failure handling."""
        failed = ['cat/pkg', 'foo/bar']
        cpvs = [package_info.SplitCPV(p, strict=False) for p in failed]
        self.PatchObject(portage_util,
                         'ParseDieHookStatusFile',
                         return_value=cpvs)

        config = sysroot.BuildPackagesRunConfig()
        command = self.base_command + config.GetBuildPackagesArgs()

        result = cros_build_lib.CommandResult(cmd=command, returncode=1)
        error = cros_build_lib.RunCommandError('Error', result)

        self.rc.AddCmdResult(command, side_effect=error)

        try:
            sysroot.BuildPackages(self.target, self.sysroot, config)
        except sysroot_lib.PackageInstallError as e:
            self.assertEqual(cpvs, e.failed_packages)
            self.assertEqual(result, e.result)
        except Exception as e:
            self.fail('Unexpected exception type: %s' % type(e))
        else:
            self.fail('Expected an exception to be thrown.')
Exemplo n.º 14
0
  def testRunGeneratorCmd(self):
    """Test the specialized command to run programs from au-generate.zip."""
    test_cmd = ['cmd', 'bar', 'jo nes']
    expected_cmd = ['/foo/au-generator/cmd', 'bar', 'jo nes']
    original_environ = os.environ.copy()
    gen = self._GetStdGenerator(work_dir='/foo')

    self.mox.StubOutWithMock(cros_build_lib, 'RunCommand')

    mock_result = cros_build_lib.CommandResult()
    mock_result.output = 'foo output'

    # Set up the test replay script.
    cros_build_lib.RunCommand(
        expected_cmd, cwd='/foo/au-generator',
        redirect_stdout=True,
        combine_stdout_stderr=True,
        error_code_ok=True,
        extra_env=mox.IgnoreArg()).AndReturn(mock_result)

    # Run the test verification.
    self.mox.ReplayAll()
    self.assertEqual(gen._RunGeneratorCmd(test_cmd),
                     'foo output')

    # Demonstrate that the PATH was restored.
    self.assertEqual(os.environ, original_environ)
 def AddRunGitResult(self,
                     cmd,
                     cwd=None,
                     returncode=0,
                     output='',
                     error='',
                     kwargs=None,
                     strict=False,
                     side_effect=None):
     """Adds git command and results."""
     cwd = self.cwd if cwd is None else cwd
     result = cros_build_lib.CommandResult(returncode=returncode,
                                           output=output,
                                           error=error)
     if returncode != 0 and not side_effect:
         side_effect = cros_build_lib.RunCommandError(
             'non-zero returncode', result)
     self._results['RunGit'].AddResultForParams((
         cwd,
         cmd,
     ),
                                                result,
                                                kwargs=kwargs,
                                                side_effect=side_effect,
                                                strict=strict)
    def testRun(self):
        """Tests Run()."""
        bisector_mock = self.StartPatcher(GitBisectorMock())
        bisector_mock.good_commit_info = copy.deepcopy(self.GOOD_COMMIT_INFO)
        bisector_mock.bad_commit_info = copy.deepcopy(self.BAD_COMMIT_INFO)
        bisector_mock.threshold = self.THRESHOLD
        bisector_mock.git_bisect_args_result = [
            (['reset'], (None, False)),
            (['start'], (None, False)),
            (['bad', self.BAD_COMMIT_SHA1], (None, False)),
            (['good', self.GOOD_COMMIT_SHA1], (None, False)),
            (['bad'],
             (cros_build_lib.CommandResult(
                 cmd=['git', 'bisect', 'bad'],
                 output='%s is the first bad commit\ncommit %s' %
                 (self.CULPRIT_COMMIT_SHA1, self.CULPRIT_COMMIT_SHA1),
                 returncode=0),
              True)),  # bisect bad (assume it found the first bad commit).
            (['log'], (None, False)),
            (['reset'], (None, False))
        ]
        bisector_mock.build_deploy_eval_current_commit = [
            self.CULPRIT_COMMIT_INFO
        ]
        bisector_mock.build_deploy_eval_result = [self.CULPRIT_COMMIT_SCORE]
        bisector_mock.label_build_result = ['bad']

        run_result = self.bisector.Run()

        self.assertTrue(bisector_mock.patched['PrepareBisect'].called)
        self.assertEqual(7, bisector_mock.patched['GitBisect'].call_count)
        self.assertTrue(bisector_mock.patched['BuildDeployEval'].called)
        self.assertTrue(bisector_mock.patched['LabelBuild'].called)
        self.assertEqual(self.CULPRIT_COMMIT_SHA1, run_result)
Exemplo n.º 17
0
    def testReportStageFailureOnPackageBuildFailure(self):
        """Test ReportStageFailure On PackageBuildFailure."""
        fake_db = fake_cidb.FakeCIDBConnection()
        msg = 'run command error'
        short_name = 'short name'
        failed_packages = ['chromeos-base/autotest', 'chromeos-base/telemetry']
        error = cros_build_lib.RunCommandError(msg,
                                               cros_build_lib.CommandResult())
        build_failure = failures_lib.PackageBuildFailure(
            error, short_name, failed_packages)
        mock_build_stage_id = 1
        failure_id = failures_lib.ReportStageFailure(fake_db,
                                                     mock_build_stage_id,
                                                     build_failure)

        extra_info_json_string = json.dumps({
            'shortname': short_name,
            'failed_packages': failed_packages
        })
        self.assertEqual(len(fake_db.failureTable), 1)
        values = fake_db.failureTable[failure_id]
        self.assertEqual(values['exception_message'], str(build_failure))
        self.assertEqual(values['outer_failure_id'], None)
        self.assertEqual(values['extra_info'], extra_info_json_string)
        self.assertEqual(
            json.loads(values['extra_info'])['failed_packages'],
            failed_packages)
Exemplo n.º 18
0
    def SetDefaultCmdResult(self,
                            returncode=0,
                            output=None,
                            error=None,
                            stdout=None,
                            stderr=None,
                            side_effect=None,
                            mock_attr=None):
        """Specify the default command result if no command is matched.

    Args:
      returncode: See AddCmdResult.
      output: (Deprecated) Alias to stdout.
      error: (Deprecated) Alias to stderr.
      stdout: See AddCmdResult.
      stderr: See AddCmdResult.
      side_effect: See MockedCallResults.AddResultForParams
      mock_attr: Which attributes's mock is being referenced.
    """
        if stdout is None:
            stdout = output
        elif output is not None:
            raise ValueError('Only specify |stdout|, not |output|')
        if stdout is None:
            stdout = ''
        if stderr is None:
            stderr = error
        elif error is not None:
            raise ValueError('Only specify |stderr|, not |error|')
        if stderr is None:
            stderr = ''
        result = cros_build_lib.CommandResult(returncode=returncode,
                                              stdout=stdout,
                                              stderr=stderr)
        self._results[mock_attr].SetDefaultResult(result, side_effect)
Exemplo n.º 19
0
 def _OverrideRunCommand(cmd, *_args, **_kwargs):
     """A mock of cros_build_lib.RunCommand that injects arguments."""
     # In this test setup, |test| and |remote| should be the third and fourth
     # last argument respectively.
     test = cmd[-3]
     remote = cmd[-4]
     actual_tests_run.append(dict(remote=remote, test=test))
     return cros_build_lib.CommandResult()
  def _GetBuildFailure(pkg):
    """Create a PackageBuildFailure for the specified |pkg|.

    Args:
      pkg: Package that failed to build.
    """
    ex = cros_build_lib.RunCommandError('foo', cros_build_lib.CommandResult())
    return failures_lib.PackageBuildFailure(ex, 'bar', [pkg])
Exemplo n.º 21
0
 def testFetchRemoteTarballsEmpty(self):
   """Test FetchRemoteTarballs with no results."""
   m = self.PatchObject(retry_util, 'RunCurl')
   with self.assertRaises(ValueError):
     cros_sdk.FetchRemoteTarballs(self.tempdir, [], 'tarball')
   m.return_value = cros_build_lib.CommandResult(stdout=b'Foo: bar\n')
   with self.assertRaises(ValueError):
     cros_sdk.FetchRemoteTarballs(self.tempdir, ['gs://x.tar'], 'tarball')
Exemplo n.º 22
0
    def testForceSyncWorks(self):
        """Test the --force-sync probe logic"""
        # pylint: disable=protected-access

        m = self.PatchObject(cros_build_lib, 'RunCommand')

        m.return_value = cros_build_lib.CommandResult(output='Nope!')
        self.assertFalse(self.repo._ForceSyncSupported())

        help_fragment = """
  -f, --force-broken    continue sync even if a project fails to sync
  --force-sync          overwrite an existing git directory if it needs to
                        point to a different object directory. WARNING: this
                        may cause loss of data
"""
        m.return_value = cros_build_lib.CommandResult(output=help_fragment)
        self.assertTrue(self.repo._ForceSyncSupported())
Exemplo n.º 23
0
    def test_RepoSelfupdateRaisesException(self):
        """Test _RepoSelfupdate when exception is raised."""
        mock_rm = self.PatchObject(osutils, 'RmDir')
        ex = cros_build_lib.RunCommandError('msg',
                                            cros_build_lib.CommandResult())
        self.PatchObject(cros_build_lib, 'RunCommand', side_effect=ex)
        self.repo._RepoSelfupdate()

        mock_rm.assert_called_once_with(mock.ANY, ignore_missing=True)
Exemplo n.º 24
0
    def testFailure(self):
        """Test failure creating tarball."""
        result = cros_build_lib.CommandResult(returncode=1)
        self.PatchObject(cros_build_lib, 'CreateTarball', return_value=result)

        path = test.BuildTargetUnitTestTarball(self.chroot, self.sysroot,
                                               self.result_path)

        self.assertIsNone(path)
Exemplo n.º 25
0
    def testSuccess(self):
        """Test success handling."""
        result = cros_build_lib.CommandResult(returncode=0)
        self.PatchObject(cros_build_lib, 'CreateTarball', return_value=result)

        path = test.BuildTargetUnitTestTarball(self.chroot, self.sysroot,
                                               self.result_path)

        self.assertStartsWith(path, self.result_path)
Exemplo n.º 26
0
def _GolintFile(path, _, debug):
    """Returns result of running golint on |path|."""
    # Try using golint if it exists.
    try:
        cmd = ['golint', '-set_exit_status', path]
        return _LinterRunCommand(cmd, debug)
    except cros_build_lib.RunCommandError:
        logging.notice('Install golint for additional go linting.')
        return cros_build_lib.CommandResult('gofmt "%s"' % path, returncode=0)
Exemplo n.º 27
0
  def _FakeRunBuildScript(self, buildroot, cmd, chromite_cmd=False, **kwargs):
    """Fake implemenation of commands.RunBuildScript."""
    del buildroot, chromite_cmd, kwargs
    if (isinstance(cmd, list) or isinstance(cmd, tuple)) and \
        len(cmd) >= 3 and cmd[0] == 'equery' and 'f' in cmd:
      files = self._portage_package_files.get(cmd[-1], [])
      return cros_build_lib.CommandResult(returncode=0, output='\n'.join(files))

    raise RuntimeError('Command %s not handled by test' % str(cmd))
Exemplo n.º 28
0
    def testStagesReportError(self):
        """Tests Stage reporting with exceptions."""

        sync_stages.ManifestVersionedSyncStage.manifest_manager = None

        # Store off a known set of results and generate a report
        results_lib.Results.Record('Sync', results_lib.Results.SUCCESS, time=1)
        results_lib.Results.Record('Build',
                                   results_lib.Results.SUCCESS,
                                   time=2)
        results_lib.Results.Record('Test',
                                   FailStage.FAIL_EXCEPTION,
                                   'failException Msg\nLine 2',
                                   time=3)
        result = cros_build_lib.CommandResult(cmd=['/bin/false', '/nosuchdir'],
                                              returncode=2)
        results_lib.Results.Record(
            'Archive',
            cros_build_lib.RunCommandError(
                'Command "/bin/false /nosuchdir" failed.\n', result),
            'FailRunCommand msg',
            time=4)

        results = StringIO()

        results_lib.Results.Report(results)

        expectedResults = (
            '************************************************************\n'
            '** Stage Results\n'
            '************************************************************\n'
            '** PASS Sync (0:00:01)\n'
            '************************************************************\n'
            '** PASS Build (0:00:02)\n'
            '************************************************************\n'
            '** FAIL Test (0:00:03) with StepFailure\n'
            '************************************************************\n'
            '** FAIL Archive (0:00:04) in /bin/false\n'
            '************************************************************\n'
            '\n'
            'Failed in stage Test:\n'
            '\n'
            'failException Msg\n'
            'Line 2\n'
            '\n'
            'Failed in stage Archive:\n'
            '\n'
            'FailRunCommand msg\n')

        expectedLines = expectedResults.split('\n')
        actualLines = results.getvalue().split('\n')

        # Break out the asserts to be per item to make debugging easier
        for i in range(min(len(actualLines), len(expectedLines))):
            self.assertEqual(expectedLines[i], actualLines[i])
        self.assertEqual(len(expectedLines), len(actualLines))
 def testFetchRemoteTarballsSuccess(self):
     """Test FetchRemoteTarballs with a successful download."""
     curl = cros_build_lib.CommandResult(stdout=(b'HTTP/1.0 200\n'
                                                 b'Foo: bar\n'
                                                 b'Content-Length: 100\n'))
     self.PatchObject(retry_util, 'RunCurl', return_value=curl)
     self.assertEqual(
         os.path.join(self.tempdir, 'tar'),
         cros_sdk.FetchRemoteTarballs(self.tempdir, ['gs://x/tar'],
                                      'tarball'))
Exemplo n.º 30
0
 def testApplyUpdates(self):
     """Test ApplyUpdates."""
     self.PatchObject(
         cros_build_lib,
         'run',
         return_value=cros_build_lib.CommandResult(returncode=0))
     for version in self.success_versions:
         self.chroot.SetVersion(version)
         self.chroot.ApplyUpdates()
         self.assertEqual(self.latest_version, self.chroot.GetVersion())