def checkRpmExists(rpmName, sha, rpmNameDetails, config, logger): """ This method reads the rpmName from sha.json from the bucket builds.numenta.com, and then checks if the rpm is present on rpmbuild.YOMPsolutions.com or in S3 :param rpmName: For now, this is always YOMP i.e., builds.numenta.com/YOMP if checking for YOMP rpm :param sha: The sha of YOMP which we are searching for :rpmNameDetails: This is a dict which is used to store the RPM name which we are searching for :returns: True if rpm exists on S3 and rpmbuild.YOMPsolutions.com else False :raises: re-raising the base exceptions. """ try: bucket = s3.getS3Connection().get_bucket("builds.numenta.com") path = "/rpm_sha_mappings" if "YOMP" is rpmName: uploadPath = os.path.join(path, rpmName) else: uploadPath = os.path.join(path, rpmName) key = bucket.get_key(os.path.join(uploadPath, "%s.json" % sha)) if key: mappingDetails = json.loads(key.get_contents_as_string()) if mappingDetails["sha"] == sha: # updating rpm details rpmNameDetails.update({rpmName: mappingDetails["rpm"]}) rpmName = mappingDetails["rpm"] # check if it exists on rpmbuild existsOnRpmbuild = checkExistsOnRpmbuild( rpmName, config, logger) logger.info("%s rpm exists on rpmbuild: %s" % (rpmName, existsOnRpmbuild)) # check if it exists on s3 existsOnS3 = checkExistsOnS3(rpmName) logger.info("%s rpm exists on S3: %s" % (rpmName, existsOnS3)) if existsOnRpmbuild and existsOnS3: logger.info("%s rpm with %s sha exists on rpmbuild and S3" % (rpmName, sha)) return True else: logger.info( "%s rpm with %s sha does not exist on rpmbuild or S3" % (rpmName, sha)) return False else: logger.info("%s rpm with %s sha does not exist." % (rpmName, sha)) return False except Exception: logger.exception("Failed while checking if RPM exists on s3 and " "rpmbuild.YOMPsolutions.com") raise
def checkExistsOnS3(rpmName): """ This method checks if a particular rpm is present in S3. :param rpmName: The actuall rpm name which needs to be checked. :returns: True if the rpm exists on S3 else False """ bucket = s3.getS3Connection().get_bucket("public.numenta.com") key = bucket.get_key(os.path.join("/yum/x86_64", "%s" % rpmName)) return True if key else False
def checkRpmExists(rpmName, sha, rpmNameDetails, config, logger): """ This method reads the rpmName from sha.json from the bucket builds.numenta.com, and then checks if the rpm is present on rpmbuild.htm-itsolutions.com or in S3 :param rpmName: For now, this is always HTM-IT i.e., builds.numenta.com/htm-it if checking for htm-it rpm :param sha: The sha of htm-it which we are searching for :rpmNameDetails: This is a dict which is used to store the RPM name which we are searching for :returns: True if rpm exists on S3 and rpmbuild.htm-itsolutions.com else False :raises: re-raising the base exceptions. """ try: bucket = s3.getS3Connection().get_bucket("builds.numenta.com") path = "/rpm_sha_mappings" if "htm-it" is rpmName: uploadPath = os.path.join(path, rpmName) else: uploadPath = os.path.join(path, rpmName) key = bucket.get_key(os.path.join(uploadPath, "%s.json" % sha)) if key: mappingDetails = json.loads(key.get_contents_as_string()) if mappingDetails["sha"] == sha: # updating rpm details rpmNameDetails.update({rpmName: mappingDetails["rpm"]}) rpmName = mappingDetails["rpm"] # check if it exists on rpmbuild existsOnRpmbuild = checkExistsOnRpmbuild(rpmName, config, logger) logger.info("%s rpm exists on rpmbuild: %s" % (rpmName, existsOnRpmbuild)) # check if it exists on s3 existsOnS3 = checkExistsOnS3(rpmName) logger.info("%s rpm exists on S3: %s" % (rpmName, existsOnS3)) if existsOnRpmbuild and existsOnS3: logger.info("%s rpm with %s sha exists on rpmbuild and S3" % (rpmName, sha)) return True else: logger.info("%s rpm with %s sha does not exist on rpmbuild or S3" % (rpmName, sha)) return False else: logger.info("%s rpm with %s sha does not exist." % (rpmName, sha)) return False except Exception: logger.exception("Failed while checking if RPM exists on s3 and " "rpmbuild.htm-itsolutions.com") raise
def uploadShaFiletoBucket(rpmName, filename, logger): """ Uploads sha.json to bucket "builds.numenta.com" :param rpmName: For now, this is always YOMP i.e., builds.numenta.com/YOMP. :param filename: The sha.json file which should be uploaded. :raises: re-raising the base exceptions.. """ try: bucket = s3.getS3Connection().get_bucket("builds.numenta.com") k = Key(bucket) path = "/rpm_sha_mappings" if "YOMP" is rpmName: uploadPath = os.path.join(path, rpmName) else: uploadPath = os.path.join(path, rpmName) k.key = os.path.join(uploadPath, filename) k.set_contents_from_filename(filename) except: logger.exception("Failed to upload sha %s file to bucket." % filename) raise
def uploadShaFiletoBucket(rpmName, filename, logger): """ Uploads sha.json to bucket "builds.numenta.com" :param rpmName: For now, this is always HTM-IT i.e., builds.numenta.com/htm-it. :param filename: The sha.json file which should be uploaded. :raises: re-raising the base exceptions.. """ try: bucket = s3.getS3Connection().get_bucket("builds.numenta.com") k = Key(bucket) path = "/rpm_sha_mappings" if "htm-it" is rpmName: uploadPath = os.path.join(path, rpmName) else: uploadPath = os.path.join(path, rpmName) k.key = os.path.join(uploadPath, filename) k.set_contents_from_filename(filename) except: logger.exception("Failed to upload sha %s file to bucket." % filename) raise
def uploadShaFiletoBucket(rpmName, filename, logger): """ Uploads sha.json to bucket "builds.numenta.com" :param rpmName: Which rpm either grok or nupic, according to this the bucket is decided. for eg:builds.numenta.com/grok. :param filename: The sha.json file which should be uploaded. :raises: re-raising the base exceptions.. """ try: bucket = s3.getS3Connection().get_bucket("builds.numenta.com") k = Key(bucket) path = "/rpm_sha_mappings" if "grok" is rpmName: uploadPath = os.path.join(path, rpmName) else: uploadPath = os.path.join(path, rpmName) k.key = os.path.join(uploadPath, filename) k.set_contents_from_filename(filename) except: logger.exception("Failed to upload sha %s file to bucket." % filename) raise