Exemple #1
0
def shortTroveSpec(spec):
    n, v, f = parseTroveSpec(spec)
    try:
        v = versions.VersionFromString(v)
    except conary.errors.ParseError: # we got a frozen version string
        v = versions.ThawVersion(v)
    return "%s=%s (%s)" % (n, str(v.trailingRevision()), getArchFromFlavor(f))
Exemple #2
0
 def _getBaseFileName(self, baseFileName, hostname,
         troveName, troveVersion, troveFlavor):
     baseFileName = self._sanitizeString(baseFileName)
     if baseFileName:
         return baseFileName
     troveVersion = helperfuncs.parseVersion(troveVersion)
     troveArch = helperfuncs.getArchFromFlavor(troveFlavor)
     baseFileName = "%(name)s-%(version)s-%(arch)s" % dict(
         # XXX One would assume hostname == troveName, but that's
         # how server.py had the code written
         name = hostname,
         version = troveVersion.trailingRevision().version,
         arch = troveArch)
     return baseFileName
Exemple #3
0
    def computeSyntheticFields(self, sender, **kwargs):
        if self.trove_flavor is not None:
            self.architecture = helperfuncs.getArchFromFlavor(str(self.trove_flavor))

        if self.trove_version is not None:
            tv_obj = helperfuncs.parseVersion(self.trove_version)
            if tv_obj is not None:
                self.trailing_version = str(tv_obj.trailingRevision())

        if self.files is not None:
            self.num_image_files = len(self.files.all())
        else:
            self.num_image_files = 0;

        self.build_log = modellib.HrefFieldFromModel(self,
            viewName="BuildLog")

        if self._image_type is not None:
            self.image_type = ImageType.fromImageTypeId(self._image_type)
        self.jobs = modellib.HrefFieldFromModel(self, "ImageJobs")

        self._computeActions()
Exemple #4
0
 def getArch(self):
     """Return a printable representation of the build's architecture."""
     return helperfuncs.getArchFromFlavor(self.getTrove()[2])
Exemple #5
0
    def getAllBuildsByType(self, imageType, requestingUserId, 
                           limitToUserId=False):
        # By default, select builds that have at least one file that is
        # not a failed build log.
        extraSelect = ', NULL AS baseBuildId'
        extraJoin = ' LEFT JOIN buildFiles bdf ON (bdf.buildId = b.buildId)'
        extraWhere = ''' AND EXISTS (
            SELECT * FROM BuildFiles bf
            WHERE bf.buildId = b.buildId
            AND bf.title != 'Failed build log' ) '''
        if imageType == 'VWS':
            # VWS as a build type doesn't currently exist, but any
            # image that is RAW_FS_IMAGE and build as a DOMU works.
            imageType = 'RAW_FS_IMAGE'
            extraJoin += ''' JOIN buildData bd ON (bd.buildId  = b.buildId
                                                   AND bd.name = 'XEN_DOMU')'''
        try:
            imageTypeId = buildtypes.validBuildTypes[imageType]
        except KeyError:
            raise ParameterError('Unknown image type %r' % (imageType,))
        cu = self.db.cursor()
        # Get the list of hidden projects to accept if we need to filter
        okHiddenProjectIds = []
        if limitToUserId:
            cu.execute("""
                 SELECT pu.projectId
                 FROM   projectUsers pu JOIN projects p USING (projectId)
                 WHERE  p.hidden AND pu.userId = ?
                 """, requestingUserId)
            okHiddenProjectIds = [result[0] for result in cu.fetchall()]


        queryTmpl = """SELECT p.projectId,
                    p.hostname,
                    b.buildId,
                    p.name AS productName,
                    p.description AS productDescription,
                    b.name AS buildName,
                    b.troveFlavor AS troveFlavor,
                    COALESCE(b.description,'') AS buildDescription,
                    COALESCE(pr.timePublished,0) != 0 AS isPublished,
                    p.hidden AS isPrivate,
                    COALESCE(u.username, 'Unknown') AS createdBy,
                    CASE
                        WHEN pu.level = 0 THEN 'Product Owner'
                        WHEN pu.level = 1 THEN 'Product Developer'
                        WHEN pu.level = 2 THEN 'Product User'
                        ELSE ''
                    END AS role
                    %(extraSelect)s
                 FROM projects p
                 JOIN builds b USING (projectId)
                 LEFT OUTER JOIN publishedReleases pr USING (pubReleaseId)
                 LEFT OUTER JOIN users u ON (b.createdBy = u.userId)
                 LEFT OUTER JOIN projectUsers pu
                    ON (b.projectId = pu.projectId AND pu.userId = ?)
                 %(extraJoin)s
             WHERE b.buildType = ?
             %(extraWhere)s"""
        query = queryTmpl % {'extraWhere' : extraWhere,
                         'extraSelect' : extraSelect,
                         'extraJoin' : extraJoin}
        keys = ['projectId', 'hostname', 'buildId', 'productName',
                'productDescription', 'buildName', 'buildDescription',
                'isPublished', 'isPrivate', 'createdBy', 'role',
                'troveFlavor', 'baseBuildId',
                ]

        imageIdToImageHash = {}
        cu.execute(query, requestingUserId, imageTypeId)
        out = []
        for row in cu:
            if not self._filterBuildVisibility(row,
                    okHiddenProjectIds, limitToUserId):
                continue
            outRow = {}
            for key in keys:
                value = row.pop(key, None)
                if key == 'troveFlavor':
                    key = 'architecture'
                    if value:
                        value = helperfuncs.getArchFromFlavor(value)
                if value is not None:
                    outRow[key] = value
            # Expose the build type as well
            outRow['imageType'] = imageType
            assert not row.fields
            out.append(outRow)
            imageIdToImageHash[outRow['buildId']] = outRow
        return out
Exemple #6
0
    def _getImages(self, fqdn, extraJoin='', extraWhere='',
                   extraArgs=None, getOne=False):
        hostname = fqdn.split('.')[0]
        cu = self.db.cursor()

        sql = '''
            SELECT
                p.hostname,
                pv.name AS version,
                b.buildId AS imageId,
                    b.buildType AS imageType, b.name, b.description,
                    b.troveName, b.troveVersion, b.troveFlavor,
                    b.troveLastChanged, b.timeCreated, b.timeUpdated,
                    b.status AS statusCode, b.statusMessage, b.buildCount,
                    b.stageName AS stage,
                cr_user.username AS creator, up_user.username AS updater

            FROM Builds b
                JOIN Projects p USING ( projectId )
                %(join)s
                LEFT JOIN ProductVersions pv ON (
                    b.productVersionId = pv.productVersionId )
                LEFT JOIN Users cr_user ON ( b.createdBy = cr_user.userId )
                LEFT JOIN Users up_user ON ( b.updatedBy = up_user.userId )

            WHERE hostname = ? AND troveVersion IS NOT NULL
            %(where)s
            '''
        sql %= dict(where=extraWhere, join=extraJoin)
        args = (hostname,)
        if extraArgs:
            args += tuple(extraArgs)
        cu.execute(sql, *args)
        if getOne:
            row = self.db._getOne(cu, errors.ImageNotFound, args)
            rows = [row]
        else:
            rows = cu

        images = []
        for row in rows:
            imageType = row['imageType']
            if row['troveFlavor'] is not None:
                row['troveFlavor'] = deps.ThawFlavor(row['troveFlavor'])
                row['architecture'] = helperfuncs.getArchFromFlavor(
                        row['troveFlavor'])
            else:
                row['architecture'] = None

            if row['troveVersion'] is not None:
                row['troveVersion'] = helperfuncs.parseVersion(row['troveVersion'])
                row['trailingVersion'] = str(row['troveVersion'].trailingRevision())
            else:
                row['trailingVersion'] = None

            row['imageType'] = buildtypes.imageTypeXmlTagNameMap.get(imageType, 'imageless')
            row['imageTypeName'] = buildtypes.typeNamesMarketing.get(imageType, 'Unknown')

            status = models.ImageStatus()
            status.hostname = row['hostname']
            status.imageId = row['imageId']
            status.set_status(code=row.pop('statusCode'),
                    message=row.pop('statusMessage'))

            image = models.Image(row)
            image.imageStatus = status
            images.append(image)

        imageIds = [ x.imageId for x in images ]
        imagesBaseFileNameMap = self.getImagesBaseFileName(hostname, imageIds)

        imagesFiles = self._getFilesForImages(hostname, imageIds)
        for image, imageFiles in zip(images, imagesFiles):
            image.files = imageFiles
            image.baseFileName = imagesBaseFileNameMap[image.imageId]

        if getOne:
            return images[0]
        return models.ImageList(images)