Exemplo n.º 1
0
class PackageFetch(BaseFetch):
    
    def __init__(self, systemId, baseURL, channelLabel, savePath):
        BaseFetch.__init__(self)
        self.systemId = systemId
        self.baseURL = baseURL
        self.rhnComm = RHNComm(baseURL, self.systemId)
        self.channelLabel = channelLabel
        self.savePath = savePath

    def login(self, refresh=False):
        """
        Returns authentication headers needed for RHN 'GET' requests.
        auth data is cached, if data needs to be updated, pass in refresh=True
        """
        return self.rhnComm.login(refresh)

    def getFetchURL(self, channelLabel, fetchName):
        return self.baseURL + "/SAT/$RHN/" + channelLabel + "/getPackage/" + fetchName;

    def fetchItem(self, itemInfo):
        authMap = self.login()
        fileName = itemInfo['filename']
        fetchName = itemInfo['fetch_name']
        itemSize = itemInfo['package_size']
        md5sum = itemInfo['md5sum']
        hashType = itemInfo['hashtype']
        fetchURL = self.getFetchURL(self.channelLabel, fetchName)
        status = self.fetch(fileName, fetchURL, itemSize, hashType, md5sum, self.savePath, headers=authMap)
        if status == BaseFetch.STATUS_UNAUTHORIZED:
            LOG.warn("Unauthorized request from fetch().  Will attempt to update authentication credentials and retry")
            authMap = self.login(refresh=True)
            return self.fetch(fileName, fetchURL, itemSize, md5sum, self.savePath, headers=authMap)
        return status
Exemplo n.º 2
0
class KickstartFetch(BaseFetch):

    def __init__(self, systemId, baseURL):
        BaseFetch.__init__(self)
        self.baseURL = baseURL
        self.systemId = systemId
        self.rhnComm = RHNComm(baseURL, self.systemId)

    def login(self, refresh=False):
        return self.rhnComm.login(refresh)
    
    def getFetchURL(self, channelLabel, ksLabel, ksFilePath):
        return self.baseURL + "/SAT/$RHN/" + channelLabel + "/getKickstartFile/" + ksLabel + "/" + ksFilePath;

    def fetchItem(self, itemInfo):
        authMap = self.login()

        fileName = itemInfo['relative-path']
        itemSize = itemInfo['size']
        md5sum = itemInfo['md5sum']
        hashType = itemInfo['hashtype']
        ksLabel = itemInfo['ksLabel']
        channelLabel = itemInfo['channelLabel']
        savePath = itemInfo['savePath']
        fetchURL = self.getFetchURL(channelLabel, ksLabel, fileName)
        status = self.fetch(fileName, fetchURL, itemSize, hashType, md5sum, savePath, headers=authMap)
        if status == BaseFetch.STATUS_UNAUTHORIZED:
            LOG.warn("Unauthorized request from fetch().  Will attempt to update authentication credentials and retry")
            authMap = self.login(refresh=True)
            return self.fetch(fileName, fetchURL, itemSize, md5sum, savePath, headers=authMap)
        return status
Exemplo n.º 3
0
 GrinderLog.setup(True)
 systemId = open("/etc/sysconfig/rhn/systemid").read()
 baseURL = "http://satellite.rhn.redhat.com"
 bf = BaseFetch()
 itemInfo = {}
 fileName = "Virtualization-es-ES-5.2-9.noarch.rpm"
 fetchName = "Virtualization-es-ES-5.2-9:.noarch.rpm"
 channelLabel = "rhel-i386-server-vt-5"
 fetchURL = baseURL + "/SAT/$RHN/" + channelLabel + "/getPackage/" + fetchName;
 itemSize = "1731195"
 md5sum = "91b0f20aeeda88ddae4959797003a173" 
 hashtype = "md5"
 savePath = "./test123"
 from RHNComm import RHNComm
 rhnComm = RHNComm(baseURL, systemId)
 authMap = rhnComm.login()
 status = bf.fetch(fileName, fetchURL, itemSize, hashtype, md5sum, savePath, headers=authMap, retryTimes=2)
 print status
 assert(status in [BaseFetch.STATUS_DOWNLOADED, BaseFetch.STATUS_NOOP])
 print "Test Download or NOOP passed"
 status = bf.fetch(fileName, fetchURL, itemSize, hashtype, md5sum, savePath, headers=authMap, retryTimes=2)
 assert(status == BaseFetch.STATUS_NOOP)
 print "Test for NOOP passed"
 authMap['X-RHN-Auth'] = "Bad Value"
 fileName = "Virtualization-en-US-5.2-9.noarch.rpm"
 fetchName = "Virtualization-en-US-5.2-9:.noarch.rpm"
 status = bf.fetch(fileName, fetchURL, itemSize, hashtype, md5sum, savePath, headers=authMap, retryTimes=2)
 print status
 assert(status == BaseFetch.STATUS_UNAUTHORIZED)
 print "Test for unauthorized passed"
 print "Repo Sync Test"