Exemplo n.º 1
0
    def testNameDiffersFromId(self):
        name = self._clusterId
        id_inside = "id_inside"
        cluster = C._getCluster(name)
        cfg_name = cluster._getConfigFileName()
        logging.debug("cfg_name = %s", cfg_name)
        #/opt/qbase3/cfg//qconfig/arakoon/cluster_name
        ok = cfg_name.endswith(name)
        assert_true(ok)
        cluster.addNode('node_0')

        cfg = X.getConfig(cfg_name)
        logging.debug("cfg = %s", X.cfg2str(cfg))
        id0 = cfg.get('global', 'cluster_id')
        assert_equals(id0, name)
        # now set it to id
        cfg.set('global', 'cluster_id', id_inside)
        X.writeConfig(cfg, cfg_name)
        logging.debug('cfg_after = %s', X.cfg2str(cfg))

        cluster = C._getCluster(name)
        #ccfg = cluster.getClientConfig()
        #print ccfg

        client = cluster.getClient()
        ccfg2 = client._config
        logging.debug("ccfg2=%s", ccfg2)
        ccfg_id = ccfg2.getClusterId()

        assert_equals(ccfg_id, id_inside)
Exemplo n.º 2
0
def test_learner():
    op_count = 54321
    Common.iterate_n_times(op_count, Common.simple_set)
    cluster = Common._getCluster(Common.cluster_id)
    logging.info("adding learner")
    name = Common.node_names[2]
    (db_dir, log_dir, tlf_dir, head_dir) = Common.build_node_dir_names(name)
    cluster.addNode(name,
                    Common.node_ips[2],
                    clientPort=Common.node_client_base_port + 2,
                    messagingPort=Common.node_msg_base_port + 2,
                    logDir=log_dir,
                    tlfDir=tlf_dir,
                    headDir=head_dir,
                    logLevel='debug',
                    home=db_dir,
                    isLearner=True,
                    targets=[Common.node_names[0]])
    cfg = cluster._getConfigFile()
    logging.info("cfg=%s", X.cfg2str(cfg))
    cluster.disableFsync([name])
    cluster.addLocalNode(name)
    cluster.createDirs(name)
    cluster.startOne(name)

    time.sleep(1.0)

    Common.assert_running_nodes(3)
    time.sleep(op_count / 1000 + 1)  # 1000/s in catchup should be no problem
    #use a client ??"
    Common.stop_all()
    i2 = int(Common.get_last_i_tlog(name))
    assert_true(i2 >= op_count - 1)
Exemplo n.º 3
0
    def setUp(self):
        logging.debug("setUp")
        for node in self._nodes:
            home = '%s/%s' % (self._root, node)
            X.removeDirTree(home)
            X.createDir(home)

        self._server.start()
        cfg = self._config()
        cfg_s = X.cfg2str(cfg)
        logging.debug("cfg_s='%s'", cfg_s)
        self._etcdClient.set(self._cluster_id, cfg_s)
Exemplo n.º 4
0
    def testEtcdUsage(self):
        logging.debug("testUsage")
        url = self._server.url(self._cluster_id)

        subprocess.call(
            "for x in $(pgrep arakoon); do cat /proc/$x/cmdline; echo; done",
            shell=True)

        # startup
        def _arakoon_cli(x, tail=None):
            cmd = [C.get_arakoon_binary()]
            cmd.extend(x)
            cmd.extend(["-config", url])
            if tail <> None:
                cmd.extend(tail)
            return cmd

        cmd = _arakoon_cli(["--node", 'etcd_ara0'], tail=["-daemonize"])
        logging.debug('calling: %s', ' '.join(cmd))
        r = subprocess.call(cmd, close_fds=True)

        # cli node-state, & verify server's running
        def wait_for_master():
            time.sleep(1.0)
            have_master = False
            count = 0
            master_states = [
                'Stable_master', 'Master_dictate', 'Accepteds_check_done'
            ]

            while (not have_master) and (count < 10):
                cmd = _arakoon_cli(['--node-state', 'etcd_ara0'])
                logging.debug('calling: %s', ' '.join(cmd))
                r = subprocess.check_output(cmd).strip()
                logging.debug("node state:%s", r)

                if r in master_states:
                    have_master = True
                else:
                    count = count + 1

            if have_master:
                return
            else:
                raise Exception("no master")

        wait_for_master()

        key = "some_key"
        value = "some_value"
        cmd = _arakoon_cli(['--set', key, value])
        subprocess.call(cmd)

        cmd = _arakoon_cli(['--get', key])
        v2 = subprocess.check_output(cmd).strip()
        self.assertEquals(v2, '"%s"' % value)

        cmd = _arakoon_cli(['--delete', key])
        subprocess.call(cmd)

        def get():
            cmd = _arakoon_cli(['--get', key])
            return subprocess.check_output(cmd)

        self.assertRaises(Exception, get)

        # log_level:
        cfg = self._config()
        node = 'etcd_ara0'
        cfg.set(node, 'log_level', 'debug')
        cfg_s = X.cfg2str(cfg)
        logging.debug("cfg_s= '%s'", cfg_s)
        self._etcdClient.set(self._cluster_id, cfg_s)
        cmd = ["fuser", "-n", "tcp", "4000", "-k", "-%s" % 'USR1']
        subprocess.call(cmd)
        time.sleep(5)
        # check if we see stuff in logging
        log_file = '%s/%s/%s.log' % (self._root, node, node)
        tail = subprocess.check_output("tail -40 %s" % log_file, shell=True)
        logging.debug("tail of %s = %s", log_file, tail)
        cmd = "grep ETCD %s | wc" % log_file
        r = subprocess.check_output(cmd, shell=True).strip().split()[0]
        logging.debug("#ETCD counts:%s", r)
        self.assertTrue(int(r) >= 1)  # note:first retrieval dumps to stderr