Esempio n. 1
0
def create_cassandra_store(config):
    retry_attempts = 0
    while retry_attempts < utils.max_retry_attempts:
        time.sleep(utils.sleep_time_secs)
        setup_exe = cli.exec_create(
            container=config["cassandra_container"],
            cmd="/files/setup_cassandra.sh",
        )
        show_exe = cli.exec_create(
            container=config["cassandra_container"],
            cmd='cqlsh -e "describe %s"' % config["cassandra_test_db"],
        )
        # by api design, exec_start needs to be called after exec_create
        # to run 'docker exec'
        resp = cli.exec_start(exec_id=setup_exe)
        if resp is "":
            resp = cli.exec_start(exec_id=show_exe)
            if "CREATE KEYSPACE peloton_test WITH" in resp:
                print_utils.okgreen("cassandra store is created")
                return
        print_utils.warn("failed to create cassandra store, retrying...")
        retry_attempts += 1

    print_utils.fail("Failed to create cassandra store after %d attempts, "
                     "aborting..." % utils.max_retry_attempts)
    sys.exit(1)
Esempio n. 2
0
def teardown_k8s():
    k8s = kind.Kind(PELOTON_K8S_NAME)
    try:
        return k8s.teardown()
    except OSError as e:
        if e.errno == 2:
            print_utils.warn("kubernetes was not running")
            return True
        else:
            raise
Esempio n. 3
0
def wait_for_up(app, port):
    count = 0
    error = ""
    url = "http://%s:%s/%s" % (default_host, port, healthcheck_path)
    while count < max_retry_attempts:
        try:
            r = requests.get(url)
            if r.status_code == 200:
                print_utils.okgreen("started %s" % app)
                return
        except Exception as e:
            print_utils.warn("app %s is not up yet, retrying..." % app)
            error = str(e)
            time.sleep(sleep_time_secs)
            count += 1

    raise Exception("failed to start %s on %d after %d attempts, err: %s" %
                    (app, port, max_retry_attempts, error))
Esempio n. 4
0
    def wait_for_mesos_master_leader(self, timeout_secs=20):
        """
        util method to wait for mesos master leader elected
        """

        port = self.config.get("local_master_port")
        url = "{}:{}/state.json".format(utils.HTTP_LOCALHOST, port)
        print_utils.warn("waiting for mesos master leader")
        deadline = time.time() + timeout_secs
        while time.time() < deadline:
            try:
                resp = requests.get(url)
                if resp.status_code != 200:
                    time.sleep(1)
                    continue
                print_utils.okgreen("mesos master is ready")
                return
            except Exception:
                pass

        assert False, "timed out waiting for mesos master leader"
Esempio n. 5
0
    def wait_for_all_agents_to_register(self, agent_count=3, timeout_secs=300):
        """
        util method to wait for all agents to register
        """
        port = self.config.get("local_master_port")
        url = "{}:{}/state.json".format(utils.HTTP_LOCALHOST, port)
        print_utils.warn("waiting for all mesos agents")

        deadline = time.time() + timeout_secs
        while time.time() < deadline:
            try:
                resp = requests.get(url)
                if resp.status_code == 200:
                    registered_agents = 0
                    for a in resp.json()['slaves']:
                        if a['active']:
                            registered_agents += 1

                    if registered_agents == agent_count:
                        print_utils.okgreen("all mesos agents are ready")
                        return
                time.sleep(1)
            except Exception:
                pass