Exemplo n.º 1
0
    def validatePackage(filename, propFilename=None):
        """ validate the package
        returns True or False """

        if (propFilename == None):
            propFilename = filename + '.prop'

        if (not PackageUtil.validateProp(propFilename)):
            return False

        try:
            # check that the file exists
            if (not os.path.exists(filename)):
                LOG.warning('Package (%s) does not exists' % (filename))
                return False

            # load in the prop file
            propFile = open(propFilename, 'r')
            prop = json.load(propFile)
            propFile.close()

            size = os.path.getsize(filename)
            if (size != int(prop['size'])):
                LOG.warning('package size = %s : %s' %
                            (str(size), str(prop['size'])))
                return False

            md5Sum = md5sum(filename)
            propmd5 = prop['md5']
            if (md5Sum != propmd5):
                LOG.warning('package md5 = %s : %s' % (md5Sum, prop['md5']))
                return False

            # make sure the tar file has the expected structure
            # TPY to do after we fix the cronus-deploy

        except Exception, excep:
            LOG.error('validatePackage exception %s' % excep)
            return False
Exemplo n.º 2
0
    def validatePackage(filename, propFilename = None):
        """ validate the package
        returns True or False """

        if (propFilename == None):
            propFilename = filename + '.prop'

        if (not PackageUtil.validateProp(propFilename)):
            return False

        try:
            # check that the file exists
            if (not os.path.exists(filename)):
                LOG.warning('Package (%s) does not exists' % (filename))
                return False

            # load in the prop file
            propFile = open(propFilename, 'r')
            prop = json.load(propFile)
            propFile.close()

            size = os.path.getsize(filename)
            if (size != int(prop['size'])):
                LOG.warning('package size = %s : %s' % (str(size), str(prop['size'])))
                return False

            md5Sum = md5sum(filename)
            propmd5 = prop['md5']
            if (md5Sum != propmd5):
                LOG.warning('package md5 = %s : %s' % (md5Sum, prop['md5']))
                return False

            # make sure the tar file has the expected structure
            # TPY to do after we fix the cronus-deploy

        except Exception, excep:
            LOG.error('validatePackage exception %s' % excep)
            return False
Exemplo n.º 3
0
    def uploadPackage(self):
        """ take an upload file """
        try:
            utils.checkDiskFull()

            agt_root = pylons.config['agent_root']
            pkg_root = pylons.config['repo_root']

            md5 = str(request.POST['md5']) if 'md5' in request.POST else None
            dest = str(request.POST['dest']) if 'dest' in request.POST else None

            myfile = request.POST['file']
            filename = myfile.filename.lstrip(os.sep)
            permanent_file = open(os.path.join(pkg_root, filename), 'w')

            shutil.copyfileobj(myfile.file, permanent_file)
            myfile.file.close()
            permanent_file.close()
            
            if md5:
                md5Sum = utils.md5sum(permanent_file)
                if (md5Sum != md5):
                    msg = 'package md5 = %s : %s' % (md5Sum, md5)
                    LOG.warning(msg)
                    raise AgentException(Errors.DC_FAILED_VALIDATE, msg)
            
            if filename and dest:
                utils.copyFile(pkg_root, os.path.join(agt_root, 'service_nodes', dest), filename) 

            return doneResult(request, response, controller=self)
        
        except AgentException as excp:
            return errorResult(request, response, excp.getCode(), excp.getMsg(), controller = self)
        
        except Exception as excp:
            errorMsg = 'Exception downloading %s - traceback %s' % (str(excp), traceback.format_exc(2))
            return errorResult(request, response, error = Errors.UNKNOWN_ERROR, errorMsg = errorMsg, controller = self)
Exemplo n.º 4
0
    def uploadPackage(self):
        """ take an upload file """
        try:
            utils.checkDiskFull()

            agt_root = pylons.config['agent_root']
            pkg_root = pylons.config['repo_root']

            md5 = str(request.POST['md5']) if 'md5' in request.POST else None
            dest = str(request.POST['dest']) if 'dest' in request.POST else None

            myfile = request.POST['file']
            filename = myfile.filename.lstrip(os.sep)
            permanent_file = open(os.path.join(pkg_root, filename), 'w')

            shutil.copyfileobj(myfile.file, permanent_file)
            myfile.file.close()
            permanent_file.close()
            
            if md5:
                md5Sum = utils.md5sum(permanent_file)
                if (md5Sum != md5):
                    msg = 'package md5 = %s : %s' % (md5Sum, md5)
                    LOG.warning(msg)
                    raise AgentException(Errors.DC_FAILED_VALIDATE, msg)
            
            if filename and dest:
                utils.copyFile(pkg_root, os.path.join(agt_root, 'service_nodes', dest), filename) 

            return doneResult(request, response, controller=self)
        
        except AgentException as excp:
            return errorResult(request, response, excp.getCode(), excp.getMsg(), controller = self)
        
        except Exception as excp:
            errorMsg = 'Exception downloading %s - traceback %s' % (str(excp), traceback.format_exc(2))
            return errorResult(request, response, error = Errors.UNKNOWN_ERROR, errorMsg = errorMsg, controller = self)