def testLoadSpecs(self):
        """Tests whether we can load specs correctly."""
        info = manifest_version.VersionInfo(FAKE_VERSION_STRING,
                                            CHROME_BRANCH,
                                            incr_type='branch')
        mpath = os.path.join(self.manager.manifest_dir, 'buildspecs',
                             CHROME_BRANCH)
        m1, m2, m3, m4 = [
            os.path.join(mpath, '1.2.%d.xml' % x) for x in [2, 3, 4, 5]
        ]
        for_build = os.path.join(self.manager.manifest_dir, 'build-name',
                                 self.build_name)

        # Create fake buildspecs.
        osutils.SafeMakedirs(os.path.join(mpath))
        for m in [m1, m2, m3, m4]:
            osutils.Touch(m)

        # Fail 1, pass 2, leave 3,4 unprocessed.
        manifest_version.CreateSymlink(
            m1,
            os.path.join(for_build, 'fail', CHROME_BRANCH,
                         os.path.basename(m1)))
        manifest_version.CreateSymlink(
            m1,
            os.path.join(for_build, 'pass', CHROME_BRANCH,
                         os.path.basename(m2)))
        self.mox.ReplayAll()
        self.manager.InitializeManifestVariables(info)
        self.mox.VerifyAll()
        self.assertEqual(self.manager.latest_unprocessed, '1.2.5')
Beispiel #2
0
    def PromoteCandidate(self, retries=manifest_version.NUM_RETRIES):
        """Promotes the current LKGM candidate to be a real versioned LKGM."""
        assert self.current_version, 'No current manifest exists.'

        last_error = None
        path_to_candidate = self.GetLocalManifest(self.current_version)
        assert os.path.exists(
            path_to_candidate), 'Candidate not found locally.'

        # This may potentially fail for not being at TOT while pushing.
        for attempt in range(0, retries + 1):
            try:
                if attempt > 0:
                    self.RefreshManifestCheckout()
                git.CreatePushBranch(manifest_version.PUSH_BRANCH,
                                     self.manifest_dir,
                                     sync=False)
                manifest_version.CreateSymlink(path_to_candidate,
                                               self.lkgm_path)
                cros_build_lib.RunCommand(['git', 'add', self.LKGM_PATH],
                                          cwd=self.manifest_dir)
                self.PushSpecChanges('Automatic: %s promoting %s to LKGM' %
                                     (self.build_name, self.current_version))
                return
            except cros_build_lib.RunCommandError as e:
                last_error = 'Failed to promote manifest. error: %s' % e
                logging.error(last_error)
                logging.error('Retrying to promote manifest:  Retry %d/%d',
                              attempt + 1, retries)

        else:
            raise PromoteCandidateException(last_error)
    def testCreateSymlink(self):
        """Tests that we can create symlinks and remove a previous one."""
        srcfile = os.path.join(self.tempdir, 'src')
        osutils.Touch(srcfile)
        other_dir = os.path.join(self.tempdir, 'other_dir')
        os.makedirs(other_dir)
        destfile = os.path.join(other_dir, 'dest')

        manifest_version.CreateSymlink(srcfile, destfile)
        self.assertTrue(os.path.lexists(destfile),
                        'Unable to create symlink to %s' % destfile)