Esempio n. 1
0
 def test_is_cluster_first_node(self):
     conf = ConfStoreProvider(URL)
     hostname = socket.gethostname()
     machine_id = conf.get_machine_id()
     update_machine(machine_id, hostname)
     validator = Validator(
         ConfStoreProvider("json:///tmp/temp-test-conf-store.json"))
     self.assertEqual(True, validator.is_first_node_in_cluster())
Esempio n. 2
0
 def test_invalid_machine_id(self):
     conf = ConfStoreProvider(URL)
     hostname = 'invalid-hostname'
     machine_id = conf.get_machine_id()
     update_machine(machine_id, hostname)
     validator = Validator(
         ConfStoreProvider("json:///tmp/temp-test-conf-store.json"))
     with self.assertRaises(RuntimeError):
         validator._get_machine_id()
Esempio n. 3
0
def init_with_bootstrap(args):
    url = args.config[0]
    validator = Validator(ConfStoreProvider(url))
    disable_hare_consul_agent()
    if validator.is_first_node_in_cluster():
        if args.file:
            path_to_cdf = args.file[0]
        else:
            path_to_cdf = get_config_dir(url) + '/cluster.yaml'
        if not is_cluster_running() and bootstrap_cluster(
                path_to_cdf, True):
            raise RuntimeError('Failed to bootstrap the cluster')

        wait_for_cluster_start(url)
        shutdown_cluster()
    enable_hare_consul_agent()
Esempio n. 4
0
def test(args):
    try:
        url = args.config[0]
        validator = Validator(ConfStoreProvider(url))
        if validator.is_first_node_in_cluster():
            if args.file:
                path_to_cdf = args.file[0]
            else:
                path_to_cdf = get_config_dir(url) + '/cluster.yaml'
            if not is_cluster_running() and bootstrap_cluster(path_to_cdf):
                raise RuntimeError("Failed to bootstrap the cluster")
            cluster_status = check_cluster_status(path_to_cdf)

            wait_for_cluster_start(url)
            if cluster_status:
                raise RuntimeError(f'Cluster status reports failure :'
                                   f' {cluster_status}')

    finally:
        shutdown_cluster()
Esempio n. 5
0
def init(args):
    try:
        rc = 0
        url = args.config[0]
        validator = Validator(ConfStoreProvider(url))
        disable_hare_consul_agent()
        if validator.is_first_node_in_cluster():
            path_to_cdf = args.file[0]
            if not is_cluster_running() and bootstrap_cluster(
                    path_to_cdf, True):
                logging.error('Failed to bootstrap the cluster')
                rc = -1
            if rc == 0:
                wait_for_cluster_start(url)
            shutdown_cluster()
        enable_hare_consul_agent()
        exit(rc)
    except Exception as error:
        shutdown_cluster()
        raise RuntimeError(f'Error while initializing cluster :key={error}')
Esempio n. 6
0
def test(args):
    try:
        rc = 0
        url = args.config[0]
        validator = Validator(ConfStoreProvider(url))
        if validator.is_first_node_in_cluster():
            path_to_cdf = args.file[0]
            if not is_cluster_running() and bootstrap_cluster(path_to_cdf):
                logging.error('Failed to bootstrap the cluster')
                rc = -1
            cluster_status = check_cluster_status(path_to_cdf)
            if rc == 0:
                wait_for_cluster_start(url)
            shutdown_cluster()
            if cluster_status:
                logging.error('Cluster status reports failure')
                rc = -1
        exit(rc)
    except Exception as error:
        logging.error('Error while checking cluster status (%s)', error)
        shutdown_cluster()
        exit(-1)