Esempio n. 1
0
 def getProductLabelFromNameAndVersion(self, productName, versionName):
     versionId = self.getBranchIdFromName(productName, versionName)
     error, stream = self.server.getProductDefinitionForVersion(versionId)
     if error:
         raise errors.RbuilderError(*stream)
     product = proddef.ProductDefinition(stream)
     return product.getProductDefinitionLabel()
Esempio n. 2
0
    def getBranchIdFromName(self, productName, versionName):
        #pylint: disable-msg=R0914
        # not a great candidate for refactoring
        productId = self.getProductId(productName)
        error, versionList = self.server.getProductVersionListForProduct(
            productId)
        if error:
            raise errors.RbuilderError(*versionList)

        versionNames = []
        # W0612: leave unused variables as documentation
        # W0631: versionId is guaranteed to be defined
        #pylint: disable-msg=W0612,W0631
        for (versionId2, productId2, namespace, versionName2,
             desc) in versionList:
            versionNames.append(versionName2)
            if versionName == versionName2:
                return versionId2

        errstr = '%s is not a valid version for product %s.' % \
            (versionName, productName)
        if versionNames:
            errstr += '\nValid versions are: %s' % \
                ', '.join(versionNames)
        else:
            errstr += '\nNo versions found for product %s.' % productName
        raise errors.RbuildError(errstr)
Esempio n. 3
0
    def startProductBuilds(self,
                           productName,
                           versionName,
                           stageName,
                           force=False):
        productId = self.getProductId(productName)
        error, versionList = self.server.getProductVersionListForProduct(
            productId)
        if error:
            raise errors.RbuilderError(*versionList)

        versionId = None
        # W0612: leave unused variables as documentation
        # W0631: versionId is guaranteed to be defined
        #pylint: disable-msg=W0612,W0631
        if versionList:
            if len(versionList[0]) == 4:
                #This is an older rBuilder
                for (versionId2, productId2, versionName2,
                     desc) in versionList:
                    if versionName == versionName2:
                        versionId = versionId2
                        break
            else:
                for (versionId2, productId2, namespace, versionName2,
                     desc) in versionList:
                    if versionName == versionName2:
                        versionId = versionId2
                        break
        if versionId is None:
            raise errors.RbuildError(
                "could not find version %r for product %r" %
                (versionName, productName))
        error, buildIds = self.server.newBuildsFromProductDefinition(
            versionId, stageName, force)

        if error:
            if buildIds[0] == 'TroveNotFoundForBuildDefinition':
                errFlavors = '\n'.join(buildIds[1][0])
                raise errors.RbuildError(
                    '%s\n\nTo submit the partial set of '
                    'builds, re-run this command with --force' % errFlavors)
            else:
                raise errors.RbuilderError(*buildIds)
        return buildIds
Esempio n. 4
0
 def getProductId(self, productName):
     error, productId = self.server.getProjectIdByHostname(productName)
     if error:
         if productId[0] == 'ItemNotFound':
             raise errors.RbuildError('Product %s not found' % \
                 productName)
         else:
             raise errors.RbuilderError(*productId)
     return productId
Esempio n. 5
0
    def watchImages(self, buildIds, timeout=0, interval=5, quiet=False):
        interval = 10
        st = time.time()
        timedOut = False
        dropped = 0
        finalStatus = {}

        activeBuilds = dict.fromkeys(buildIds)
        while activeBuilds:
            for buildId in list(activeBuilds):
                try:
                    error, buildStatus = self.server.getBuildStatus(buildId)
                except socket.timeout:
                    dropped += 1
                    if dropped >= 3:
                        raise errors.RbuildError(
                            'rBuilder connection timed out after 3 attempts')
                    self._handle.ui.info(
                        'Status request timed out, trying again')
                    time.sleep(interval)
                    continue

                if error:
                    raise errors.RbuilderError(*buildStatus)
                dropped = 0
                if activeBuilds[buildId] != buildStatus:
                    st = time.time()  # reset timeout counter if status changes
                    activeBuilds[buildId] = buildStatus
                    if not quiet:
                        self._handle.ui.write(
                            '%s: %s "%s"', buildId,
                            self.statusNames.get(buildStatus['status'],
                                                 self.statusNames[-1]),
                            buildStatus['message'])
                    if activeBuilds[buildId]['status'] > 200:
                        finalStatus[buildId] = activeBuilds.pop(buildId)
            if activeBuilds:
                time.sleep(interval)
                if timeout and time.time() - st > timeout:
                    timedOut = True
                    break

        if timedOut:
            self._handle.ui.error(
                'Timed out while waiting for build status'
                ' to change (%d seconds)', timeout)
        else:
            self._handle.ui.write('All jobs completed')
        if activeBuilds:
            self._handle.ui.warning('Unfinished builds:')
            self._printStatus(activeBuilds, '    Last status: ')
        self._handle.ui.write('Finished builds:')
        self._printStatus(finalStatus, '    ')
        if any(x['status'] != 300 for x in finalStatus.values()):
            return False
        else:
            return True
Esempio n. 6
0
    def getBuildFiles(self, buildId):
        '''
        Get a list of dicts describing files associated with a build.
        Zero ore more of the following elements may be set in each dict:
        - C{sha1}: (string) SHA1 of the described file
        - C{size}: (int) Length in bytes
        - C{title}: (string) Title describing file (not necessarily file name)
        - C{downloadUrl}: (string) URL to use to download the file directly
        - C{torrentUrl}: (string) URL to use to downlad the file via bittorrent
        - C{baseFileName}: (string) basename of the file
        - C{fileId}: (int) unique identifier for this file
        Additional items may be set as well.
        @param buildId: unique identifier for a build
        @type buildId: int
        @return: list of dicts
        '''
        error, filenames = self.server.getBuildFilenames(buildId)
        if error:
            raise errors.RbuilderError(*filenames)

        baseUrl = self._getBaseDownloadUrl()

        LOCAL = 0
        AMAZONS3 = 1
        AMAZONS3TORRENT = 2
        GENERICMIRROR = 999

        buildFileList = []
        for filename in filenames:
            b = dict((x, y) for x, y in filename.iteritems()
                     if x in set(('sha1', 'title', 'fileId')))
            if 'size' in filename:
                # XML-RPC cannot marshal large ints, so size may be string
                b['size'] = int(filename['size'])
            fileId = b['fileId']
            for _, urlType, url in filename['fileUrls']:
                if 'baseFileName' not in b:
                    b['baseFileName'] = os.path.basename(
                        url.replace('%2F', '/'))
                if urlType == AMAZONS3TORRENT:
                    b['torrentUrl'] = '%s/downloadTorrent?fileId=%d' % (
                        baseUrl, fileId)
                else:
                    b['downloadUrl'] = '%s/downloadImage?fileId=%d' % (baseUrl,
                                                                       fileId)
            buildFileList.append(b)

        return buildFileList
Esempio n. 7
0
    def _pollBuild(self, buildId, interval=10, max_dropped=3):
        dropped = 0
        buildStatus = None
        while buildStatus is None:
            try:
                error, buildStatus = self.server.getBuildStatus(buildId)
            except socket.timeout:
                dropped += 1
                if dropped >= max_dropped:
                    raise errors.RbuildError(
                        'rBuilder connection timed out after 3 attempts')
                self._handle.ui.info('Status request timed out, trying again')
                time.sleep(interval)
                continue

        if error:
            raise errors.RbuilderError(*buildStatus)
        return buildStatus
Esempio n. 8
0
 def startProductBuilds(self,
                        productName,
                        versionName,
                        stageName,
                        buildNames=None,
                        groupSpecs=None):
     versionId = self.getBranchIdFromName(productName, versionName)
     methodArgs = [versionId, stageName, False, buildNames]
     if groupSpecs is not None:
         # image builds from system model was added later (Sept # 2013),
         # and it causes tracebacks on older rbuilders; only supply
         # it if really needed
         methodArgs.extend([None, groupSpecs])
     error, buildIds = self.server.newBuildsFromProductDefinition(
         *methodArgs)
     if error:
         raise errors.RbuilderError(*buildIds)
     return buildIds
Esempio n. 9
0
 def checkAuth(self):
     error, result = self.server.checkAuth()
     if error:
         raise errors.RbuilderError(*result)
     return result