def testSubmitNonManifestChanges(self):
        """Simple test to make sure we can submit non-manifest changes."""
        pool = self.MakePool(dryrun=False)
        patch1, patch2 = passed = self.GetPatches(2)
        pool.non_manifest_changes = passed[:]

        self.mox.StubOutWithMock(pool, '_SubmitChange')
        self.mox.StubOutWithMock(pool, '_HandleCouldNotSubmit')

        self.mox.StubOutWithMock(gerrit.GerritHelper, 'IsChangeCommitted')

        pool._SubmitChange(patch1).AndReturn(None)
        gerrit.GerritHelper.IsChangeCommitted(str(patch1.gerrit_number),
                                              False).AndReturn(True)

        pool._SubmitChange(patch2).AndReturn(None)
        gerrit.GerritHelper.IsChangeCommitted(str(patch2.gerrit_number),
                                              False).AndReturn(True)

        cros_build_lib.TreeOpen(
            validation_pool.ValidationPool.STATUS_URL,
            validation_pool.ValidationPool.SLEEP_TIMEOUT).AndReturn(True)

        self.mox.ReplayAll()
        pool.SubmitNonManifestChanges()
        self.mox.VerifyAll()
    def testSubmitPool(self):
        pool = self.MakePool(dryrun=False)
        passed = self.GetPatches(3)
        failed = self.GetPatches(3)
        pool.changes = passed
        pool.changes_that_failed_to_apply_earlier = failed[:]

        self.mox.StubOutWithMock(pool, '_SubmitChange')
        self.mox.StubOutWithMock(pool, '_HandleCouldNotSubmit')
        self.mox.StubOutWithMock(pool, '_HandleApplyFailure')

        self.mox.StubOutWithMock(gerrit.GerritHelper, 'IsChangeCommitted')

        for patch in passed:
            pool._SubmitChange(patch).AndReturn(None)
            gerrit.GerritHelper.IsChangeCommitted(str(patch.gerrit_number),
                                                  False).AndReturn(True)

        pool._HandleApplyFailure(failed)

        cros_build_lib.TreeOpen(
            validation_pool.ValidationPool.STATUS_URL,
            validation_pool.ValidationPool.SLEEP_TIMEOUT).AndReturn(True)

        self.mox.ReplayAll()
        pool.SubmitPool()
        self.mox.VerifyAll()
    def testSubmitPoolFailures(self):
        pool = self.MakePool(dryrun=False)
        patch1, patch2, patch3 = patches = self.GetPatches(3)
        failed = self.GetPatches(3)
        pool.changes = patches[:]
        # While we don't do anything w/ these patches, that's
        # intentional; we're verifying that it isn't submitted
        # if there is a failure.
        pool.changes_that_failed_to_apply_earlier = failed[:]

        self.mox.StubOutWithMock(pool, '_SubmitChange')
        self.mox.StubOutWithMock(pool, '_HandleCouldNotSubmit')
        pool._patch_series.CreateDisjointTransactions(patches).AndReturn(
            ([[patch2, patch1, patch3]], []))

        self.mox.StubOutWithMock(gerrit.GerritHelper, 'IsChangeCommitted')

        pool._SubmitChange(patch2).AndReturn(None)
        gerrit.GerritHelper.IsChangeCommitted(str(
            patch2.gerrit_number), False).InAnyOrder().AndReturn(False)

        pool._HandleCouldNotSubmit(patch1).InAnyOrder()
        pool._HandleCouldNotSubmit(patch2).InAnyOrder()
        pool._HandleCouldNotSubmit(patch3).InAnyOrder()

        cros_build_lib.TreeOpen(
            validation_pool.ValidationPool.STATUS_URL,
            validation_pool.ValidationPool.SLEEP_TIMEOUT).AndReturn(True)

        self.mox.ReplayAll()
        self.assertRaises(validation_pool.FailedToSubmitAllChangesException,
                          pool.SubmitPool)
        self.mox.VerifyAll()
Esempio n. 4
0
    def CommitNewLKGM(self):
        """Commits the new LKGM file using our template commit message."""
        lv = distutils.version.LooseVersion
        if not self._lkgm and not lv(self._lkgm) < lv(self._old_lkgm):
            raise LKGMNotFound('No valid LKGM found. Did you run FindNewLKGM?')

        # Add the new versioned file.
        osutils.WriteFile(
            os.path.join(self._checkout_dir, constants.CHROME_LKGM_FILE),
            self._lkgm)

        add_cmd = ['svn', 'add', constants.CHROME_LKGM_FILE]
        cros_build_lib.RunCommand(add_cmd, cwd=self._checkout_dir)

        # Commit it!
        commit_cmd = [
            'svn', 'commit', '--message',
            self._COMMIT_MSG % dict(version=self._lkgm)
        ]

        if not cros_build_lib.TreeOpen(gclient.STATUS_URL,
                                       self._SLEEP_TIMEOUT,
                                       max_timeout=self._TREE_TIMEOUT):
            raise LKGMNotCommitted('Chromium Tree is closed')

        # Sadly svn commit does not have a dryrun option.
        if not self._dryrun:
            try:
                cros_build_lib.RunCommand(commit_cmd, cwd=self._checkout_dir)
            except cros_build_lib.RunCommandError as e:
                raise LKGMNotCommitted('Could not submit LKGM: %r' % e)
        else:
            logging.info('Would have run: %s', ' '.join(commit_cmd))
Esempio n. 5
0
  def _TreeStatusTestHelper(self, tree_status, general_state, expected_return,
                            retries_500=0, max_timeout=0):
    """Tests whether we return the correct value based on tree_status."""
    return_status = self._TreeStatusFile(tree_status, general_state)
    self.mox.StubOutWithMock(urllib, 'urlopen')
    status_url = 'https://chromiumos-status.appspot.com/current?format=json'
    backoff = 1
    sleep_timeout = 1
    for _attempt in range(retries_500):
      urllib.urlopen(status_url).AndReturn(return_status)
      return_status.getcode().AndReturn(500)
      time.sleep(backoff)
      backoff *= 2

    urllib.urlopen(status_url).MultipleTimes().AndReturn(return_status)
    # Time is checked twice to bootstrap.
    start_time = 1
    self.mox.StubOutWithMock(time, 'time')
    time.time().AndReturn(start_time)
    time.time().AndReturn(start_time)

    if expected_return == False:
      for time_plus in xrange(max_timeout + 1):
        time.time().AndReturn(start_time + time_plus)
      self.mox.StubOutWithMock(cros_build_lib, 'Info')
      cros_build_lib.Info(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes()
      time.sleep(sleep_timeout).MultipleTimes()

    return_status.getcode().MultipleTimes().AndReturn(200)
    return_status.read().MultipleTimes().AndReturn(return_status.json)
    self.mox.ReplayAll()
    self.assertEqual(cros_build_lib.TreeOpen(status_url, sleep_timeout,
                                             max_timeout), expected_return)
    self.mox.VerifyAll()