Exemplo n.º 1
0
	def append(self,line):
		cmdLines=line.split()
		if (len(cmdLines)<2):
			print("Express error,such as: append key value")
			return
		redis=self.redis
		redis.append(cmdLines[1]," ".join(cmdLines[2:]))
		print(str(redis.get(cmdLines[1]),"utf8").strip())
Exemplo n.º 2
0
    def run_redis_test():
        redis = []

        redis_host = "10.218.128.122"
        redis_password = "******"
        # redis_database = "0"

        print("Test redis %s:" % redis_host)
        count = 100
        for i in range(count):
            t = test_redis(redis_host, redis_password)
            redis.append(t)
            print("Get a key from %s : 次数:%s  耗时: %s ms" %
                  (redis_host, "{:>5}".format(i + 1), "{:>5}".format(t)))

        print("共运行%d次,最长耗时:%d ms  最短耗时:%d ms  平均耗时:%d ms" %
              (count, max(redis), min(redis), np.mean(redis)))
Exemplo n.º 3
0
def set_status(repo, sha, state, target_url, description):
    redis.append("log:" + repo + "/" + sha,
                 "State %s: %s\n" % (state, description))
    if state == "error":
        print("Run {}/{} errored out: {}".format(repo, sha, description))
    if state in ["pending", "error"]:
        return
    data = {
        "state": state,
        "target_url": target_url,
        "description": description,
        "context": "rosie-ci/" + config["overall"]["node-name"]
    }
    r = requests.post("https://api.github.com/repos/" + repo + "/statuses/" +
                      sha,
                      json=data,
                      auth=(config["overall"]["github-username"],
                            github_personal_access_token))
Exemplo n.º 4
0
def start_test(self, repo, ref):
    base_repo = redis.get("source:" + repo).decode("utf-8")
    l = redis.lock(base_repo, timeout=60 * 60)
    log_key = "log:" + repo + "/" + ref
    log_url = "https://rosie-ci.ngrok.io/log/" + repo + "/" + ref
    print("grabbing lock " + base_repo)
    # Retry the task in 10 seconds if the lock can't be grabbed.
    if not l.acquire(blocking=False):
        if self.request.retries == 24:
            set_status(repo, ref, "error", log_url,
                       "Hit max retries. Please ping the owner.")
        raise self.retry(countdown=30, max_retries=25)
    print("Lock grabbed " + base_repo)
    redis.set("owner-" + base_repo, log_url)
    set_status(repo, ref, "pending", log_url, "Commencing Rosie test.")
    repo_path = cwd + "/repos/" + base_repo
    os.chdir(repo_path)
    try:
        redis.append(log_key, git.checkout(ref))
    except sh.ErrorReturnCode_128 as e:
        print("error 128")
        redis.append(
            log_key, e.full_cmd + "\n" + e.stdout.decode('utf-8') + "\n" +
            e.stderr.decode('utf-8'))
        final_status(repo, ref, "error", "Git error in Rosie.")
    except sh.ErrorReturnCode_1 as e:
        print("error 1")
        redis.append(
            log_key, e.full_cmd + "\n" + e.stdout.decode('utf-8') + "\n" +
            e.stderr.decode('utf-8'))
        final_status(repo, ref, "error", "Git checkout error in Rosie.")
    print("test started " + log_url)
    return l.local.token.decode("utf-8")
Exemplo n.º 5
0
def demo_append():
    redis.append('name', ' 111')
Exemplo n.º 6
0
def redis_log(key, message):
    redis.append(key, message)
Exemplo n.º 7
0
def test_board(repo_lock_token, ref=None, repo=None, tag=None, board=None):
    base_repo = redis.get("source:" + repo).decode("utf-8")
    repo_path = cwd + "/repos/" + base_repo
    log_key = "log:" + repo + "/" + ref
    os.chdir(repo_path)
    test_config_ok = True
    test_cfg = None
    if os.path.isfile(".rosie.yml"):
        with open(".rosie.yml", "r") as f:
            test_cfg = yaml.safe_load(f)

    if not test_cfg or "binaries" not in test_cfg or not (
            "prebuilt_s3" in test_cfg["binaries"]
            or "rosie_upload" in test_cfg["binaries"]):
        redis.append(log_key, "Missing or invalid .rosie.yml in repo.\n")
        return (repo_lock_token, False, True)

    version = ref[:7]
    if tag is not None:
        version = tag
    binary = None
    if "rosie_upload" in test_cfg["binaries"]:
        fn = None
        try:
            fn = test_cfg["binaries"]["rosie_upload"]["file_pattern"].format(
                board=board["board"],
                short_sha=version,
                version=version,
                extension="uf2")
        except KeyError as e:
            redis.append(
                log_key,
                "Unable to construct filename because of unknown key: {0}\n".
                format(str(e)))
            return (repo_lock_token, False, True)
        except Exception as e:
            e = sys.exc_info()[0]
            redis.append(log_key, "Other error: {0}\n".format(e))
            return (repo_lock_token, False, True)
        print("finding file in redis: " + fn)
        redis_file = None
        if "*" in fn:
            keys = redis.keys("file:" + fn)
            keys.sort()
            if len(keys) > 0:
                redis_file = redis.get(keys[-1])
        else:
            redis_file = redis.get("file:" + fn)
        if redis_file:
            random_portion = '%010x' % random.randrange(16**10)
            tmp_filename = ".tmp/" + random_portion + "-" + secure_filename(
                fn.rsplit("/", 1)[-1])
            os.makedirs(".tmp", exist_ok=True)
            with open(tmp_filename, "wb") as f:
                f.write(redis_file)
            binary = tmp_filename
    if binary is None and "prebuilt_s3" in test_cfg["binaries"]:
        print("looking in aws")
        fn = None
        try:
            fn = test_cfg["binaries"]["prebuilt_s3"]["file_pattern"].format(
                board=board["board"],
                short_sha=version,
                version=version,
                extension="uf2")
        except KeyError as e:
            redis.append(
                log_key,
                "Unable to construct filename because of unknown key: {0}\n".
                format(str(e)))
            return (repo_lock_token, False, True)
        except Exception as e:
            e = sys.exc_info()[0]
            redis.append(log_key, "Other error: {0}\n".format(e))
            return (repo_lock_token, False, True)
        b = anonymous_s3.Bucket(test_cfg["binaries"]["prebuilt_s3"]["bucket"])
        prefix = fn
        suffix = None
        if "*" in prefix:
            prefix, suffix = prefix.split("*", 1)
        if suffix and "*" in suffix:
            redis.append(log_key, "Only one * supported in file_pattern")
            return (repo_lock_token, False, True)

        for obj in b.objects.filter(Prefix=prefix):
            if obj.key.endswith(suffix):
                tmp_filename = ".tmp/" + obj.key.rsplit("/", 1)[1]
                try:
                    b.download_file(obj.key, tmp_filename)
                except FileNotFoundError as e:
                    redis.append(
                        log_key,
                        "Unable to download binary for board {0}.".format(
                            board))
                    return (repo_lock_token, False, True)
                binary = tmp_filename
                break
    if binary == None:
        redis.append(log_key,
                     "Unable to find binary for board {0}.\n".format(board))
        return (repo_lock_token, False, True)

    test_config_ok = True
    tests_ok = True
    # Grab a lock on the device we're using for testing.
    try:
        with redis.lock("lock:" + board["board"] + "-" + str(board["path"])):
            # Run the tests.
            try:
                tests_ok = tester.run_tests(board,
                                            binary,
                                            test_cfg,
                                            log_key=log_key)
            except Exception as e:
                redis.append(
                    log_key, "Exception while running tests on {0}:\n".format(
                        board["board"]))
                redis.append(log_key, traceback.format_exc())
                test_config_ok = False
    except Exception as e:
        # Redis exception so don't log it.
        test_config_ok = False

    # Delete the binary since we're done with it.
    try:
        os.remove(binary)
    except FileNotFoundError:
        redis.append(log_key, "Unable to remove file: {0}\n".format(binary))
    return (repo_lock_token, test_config_ok, tests_ok)
Exemplo n.º 8
0
def redis_update(data):
    for k in data.iterkeys():
        a = redis.append(k, "k")