コード例 #1
0
ファイル: test_client.py プロジェクト: fmdeng/xtahcew
    def setUp(self):
        from kazoo.client import KazooClient
        from kazoo.protocol.states import KazooState
        from kazoo.testing.common import ZookeeperCluster
        ZK_HOME = os.environ.get("ZOOKEEPER_PATH")
        self.cluster = ZookeeperCluster(ZK_HOME, size=1, port_offset=21000)
        self.cluster.start()
        atexit.register(lambda cluster: self.cluster.terminate(), self.cluster)
        self.client = KazooClient(self.cluster[0].address, max_retries=5)
        self.ev = threading.Event()

        def back(state):
            if state == KazooState.CONNECTED:
                self.ev.set()

        self.client.start()
        self.path = self.client.create(uuid.uuid4().hex)
        self.client.add_listener(back)
コード例 #2
0
def get_global_cluster():
    global CLUSTER
    if CLUSTER is None:
        ZK_HOME = os.environ.get("ZOOKEEPER_PATH")
        assert ZK_HOME, (
            "ZOOKEEPER_PATH environment variable must be defined.\n "
            "For deb package installations this is /usr/share/java")

        CLUSTER = ZookeeperCluster(ZK_HOME)
        atexit.register(lambda cluster: cluster.terminate(), CLUSTER)
    return CLUSTER
コード例 #3
0
ファイル: test_client.py プロジェクト: dalinhuang/xtahcew
    def setUp(self):
        from kazoo.client import KazooClient
        from kazoo.protocol.states import KazooState
        from kazoo.testing.common import ZookeeperCluster
        ZK_HOME = os.environ.get("ZOOKEEPER_PATH")
        self.cluster = ZookeeperCluster(ZK_HOME, size=1, port_offset=21000)
        self.cluster.start()
        atexit.register(lambda cluster: self.cluster.terminate(), self.cluster)
        self.client = KazooClient(self.cluster[0].address, max_retries=5)
        self.ev = threading.Event()

        def back(state):
            if state == KazooState.CONNECTED:
                self.ev.set()
        self.client.start()
        self.path = self.client.create(uuid.uuid4().hex)
        self.client.add_listener(back)
コード例 #4
0
    def set_up_kazoo_base(self):
        if not ZK_HOME:
            raise nose.plugins.skip.SkipTest(
                "ZOOKEEPER_PATH environment variable is not set")

        # There is no way to vary the size of the zk cluster by just using
        # the KazooTestHarness, so directly set the cluster here.
        if harness.CLUSTER:
            logging.warn("harness.CLUSTER is not None. Tearing down.")
            self.tear_down_kazoo_base()
        logging.info("Starting ZooKeeper")
        harness.CLUSTER = ZookeeperCluster(install_path=ZK_HOME,
                                           classpath=ZK_CLASSPATH,
                                           size=1,
                                           port_offset=DEFAULT_ZK_PORT)

        # Start the cluster
        self.cluster.start()
コード例 #5
0
ファイル: harness.py プロジェクト: mchawla84/kazoo
def get_global_cluster():
    global CLUSTER
    if CLUSTER is None:
        ZK_HOME = os.environ.get("ZOOKEEPER_PATH")
        ZK_CLASSPATH = os.environ.get("ZOOKEEPER_CLASSPATH")
        ZK_PORT_OFFSET = int(os.environ.get("ZOOKEEPER_PORT_OFFSET", 20000))

        assert ZK_HOME or ZK_CLASSPATH, (
            "Either ZOOKEEPER_PATH or ZOOKEEPER_CLASSPATH environment "
            "variable must be defined.\n"
            "For deb package installations this is /usr/share/java")

        CLUSTER = ZookeeperCluster(
            install_path=ZK_HOME,
            classpath=ZK_CLASSPATH,
            port_offset=ZK_PORT_OFFSET,
        )
        atexit.register(lambda cluster: cluster.terminate(), CLUSTER)
    return CLUSTER
コード例 #6
0
ファイル: harness.py プロジェクト: mylove132/web_backed
def get_global_cluster():
    global CLUSTER
    if CLUSTER is None:
        ZK_HOME = os.environ.get("ZOOKEEPER_PATH")
        ZK_CLASSPATH = os.environ.get("ZOOKEEPER_CLASSPATH")
        ZK_PORT_OFFSET = int(os.environ.get("ZOOKEEPER_PORT_OFFSET", 20000))
        ZK_CLUSTER_SIZE = int(os.environ.get("ZOOKEEPER_CLUSTER_SIZE", 3))
        ZK_VERSION = os.environ.get("ZOOKEEPER_VERSION")
        if '-' in ZK_VERSION:
            # Ignore pre-release markers like -alpha
            ZK_VERSION = ZK_VERSION.split('-')[0]
        ZK_VERSION = tuple([int(n) for n in ZK_VERSION.split('.')])

        ZK_OBSERVER_START_ID = int(
            os.environ.get("ZOOKEEPER_OBSERVER_START_ID", -1))

        assert ZK_HOME or ZK_CLASSPATH or ZK_VERSION, (
            "Either ZOOKEEPER_PATH or ZOOKEEPER_CLASSPATH or "
            "ZOOKEEPER_VERSION environment variable must be defined.\n"
            "For deb package installations this is /usr/share/java")

        if ZK_VERSION >= (3, 5):
            additional_configuration_entries = [
                "4lw.commands.whitelist=*", "reconfigEnabled=true"
            ]
            # If defines, this sets the superuser password to "test"
            additional_java_system_properties = [
                "-Dzookeeper.DigestAuthenticationProvider.superDigest="
                "super:D/InIHSb7yEEbrWz8b9l71RjZJU="
            ]
        else:
            additional_configuration_entries = []
            additional_java_system_properties = []
        CLUSTER = ZookeeperCluster(
            install_path=ZK_HOME,
            classpath=ZK_CLASSPATH,
            port_offset=ZK_PORT_OFFSET,
            size=ZK_CLUSTER_SIZE,
            observer_start_id=ZK_OBSERVER_START_ID,
            configuration_entries=additional_configuration_entries,
            java_system_properties=additional_java_system_properties)
        atexit.register(lambda cluster: cluster.terminate(), CLUSTER)
    return CLUSTER
コード例 #7
0
ファイル: test_client.py プロジェクト: mrtheb/kazoo
class TestSessions(unittest.TestCase):

    def setUp(self):
        from kazoo.client import KazooClient
        from kazoo.protocol.states import KazooState
        from kazoo.testing.common import ZookeeperCluster
        ZK_HOME = os.environ.get("ZOOKEEPER_PATH")
        ZK_CLASSPATH = os.environ.get("ZOOKEEPER_CLASSPATH")
        self.cluster = ZookeeperCluster(ZK_HOME, size=1, port_offset=21000, classpath=ZK_CLASSPATH)
        self.cluster.start()
        atexit.register(lambda cluster: self.cluster.terminate(), self.cluster)
        self.client = KazooClient(self.cluster[0].address, max_retries=5)
        self.ev = threading.Event()

        def back(state):
            if state == KazooState.CONNECTED:
                self.ev.set()
        self.client.start()
        self.path = self.client.create(uuid.uuid4().hex)
        self.client.add_listener(back)

    def test_restarted_server(self):
        raise SkipTest('Patch missing')
        self.cluster.stop()
        self.cluster.start()
        self.ev.wait(5)
        eq_(self.ev.is_set(), True)
        self.assertTrue(self.client.retry(self.client.exists, self.path))

    def test_terminated_server(self):
        raise SkipTest('Patch missing')
        self.cluster.reset()
        self.cluster.start()
        self.ev.wait(5)
        eq_(self.ev.is_set(), True)
        self.assertFalse(self.client.retry(self.client.exists, self.path))

    def tearDown(self):
        self.ev.clear()
        self.client.stop()
        self.cluster.stop()
コード例 #8
0
ファイル: test_client.py プロジェクト: fmdeng/xtahcew
class TestSessions(unittest.TestCase):
    def setUp(self):
        from kazoo.client import KazooClient
        from kazoo.protocol.states import KazooState
        from kazoo.testing.common import ZookeeperCluster
        ZK_HOME = os.environ.get("ZOOKEEPER_PATH")
        self.cluster = ZookeeperCluster(ZK_HOME, size=1, port_offset=21000)
        self.cluster.start()
        atexit.register(lambda cluster: self.cluster.terminate(), self.cluster)
        self.client = KazooClient(self.cluster[0].address, max_retries=5)
        self.ev = threading.Event()

        def back(state):
            if state == KazooState.CONNECTED:
                self.ev.set()

        self.client.start()
        self.path = self.client.create(uuid.uuid4().hex)
        self.client.add_listener(back)

    def test_restarted_server(self):
        raise SkipTest('Patch missing')
        self.cluster.stop()
        self.cluster.start()
        self.ev.wait(5)
        eq_(self.ev.is_set(), True)
        self.assertTrue(self.client.retry(self.client.exists, self.path))

    def test_terminated_server(self):
        raise SkipTest('Patch missing')
        self.cluster.reset()
        self.cluster.start()
        self.ev.wait(5)
        eq_(self.ev.is_set(), True)
        self.assertFalse(self.client.retry(self.client.exists, self.path))

    def tearDown(self):
        self.ev.clear()
        self.client.stop()
        self.cluster.stop()
コード例 #9
0
ファイル: harness.py プロジェクト: zimiao552147572/hue
def get_global_cluster():
    global CLUSTER, CLUSTER_CONF
    cluster_conf = {
        k: os.environ.get(k, CLUSTER_DEFAULTS.get(k))
        for k in ["ZOOKEEPER_PATH",
                  "ZOOKEEPER_CLASSPATH",
                  "ZOOKEEPER_PORT_OFFSET",
                  "ZOOKEEPER_CLUSTER_SIZE",
                  "ZOOKEEPER_VERSION",
                  "ZOOKEEPER_OBSERVER_START_ID",
                  "ZOOKEEPER_JAAS_AUTH"]
    }
    if CLUSTER is not None:
        if CLUSTER_CONF == cluster_conf:
            return CLUSTER
        else:
            log.info('Config change detected. Reconfiguring cluster...')
            CLUSTER.terminate()
            CLUSTER = None
    # Create a new cluster
    ZK_HOME = cluster_conf.get("ZOOKEEPER_PATH")
    ZK_CLASSPATH = cluster_conf.get("ZOOKEEPER_CLASSPATH")
    ZK_PORT_OFFSET = int(cluster_conf.get("ZOOKEEPER_PORT_OFFSET"))
    ZK_CLUSTER_SIZE = int(cluster_conf.get("ZOOKEEPER_CLUSTER_SIZE"))
    ZK_VERSION = cluster_conf.get("ZOOKEEPER_VERSION")
    if '-' in ZK_VERSION:
        # Ignore pre-release markers like -alpha
        ZK_VERSION = ZK_VERSION.split('-')[0]
    ZK_VERSION = tuple([int(n) for n in ZK_VERSION.split('.')])
    ZK_OBSERVER_START_ID = int(cluster_conf.get("ZOOKEEPER_OBSERVER_START_ID"))

    assert ZK_HOME or ZK_CLASSPATH or ZK_VERSION, (
        "Either ZOOKEEPER_PATH or ZOOKEEPER_CLASSPATH or "
        "ZOOKEEPER_VERSION environment variable must be defined.\n"
        "For deb package installations this is /usr/share/java")

    if ZK_VERSION >= (3, 5):
        additional_configuration_entries = [
            "4lw.commands.whitelist=*",
            "reconfigEnabled=true"
        ]
        # If defined, this sets the superuser password to "test"
        additional_java_system_properties = [
            "-Dzookeeper.DigestAuthenticationProvider.superDigest="
            "super:D/InIHSb7yEEbrWz8b9l71RjZJU="
        ]
    else:
        additional_configuration_entries = []
        additional_java_system_properties = []
    ZOOKEEPER_JAAS_AUTH = cluster_conf.get("ZOOKEEPER_JAAS_AUTH")
    if ZOOKEEPER_JAAS_AUTH == "digest":
        jaas_config = """
Server {
    org.apache.zookeeper.server.auth.DigestLoginModule required
    user_super="super_secret"
    user_jaasuser="******";
};"""
    elif ZOOKEEPER_JAAS_AUTH == "gssapi":
        # Configure Zookeeper to use our test KDC.
        additional_java_system_properties += [
            "-Djava.security.krb5.conf=%s" % os.path.expandvars(
                "${KRB5_CONFIG}"
            ),
            "-Dsun.security.krb5.debug=true",
        ]
        jaas_config = """
Server {
  com.sun.security.auth.module.Krb5LoginModule required
  debug=true
  isInitiator=false
  useKeyTab=true
  keyTab="%s"
  storeKey=true
  useTicketCache=false
  principal="zookeeper/[email protected]";
};""" % os.path.expandvars("${KRB5_TEST_ENV}/server.keytab")
    else:
        jaas_config = None

    CLUSTER = ZookeeperCluster(
        install_path=ZK_HOME,
        classpath=ZK_CLASSPATH,
        port_offset=ZK_PORT_OFFSET,
        size=ZK_CLUSTER_SIZE,
        observer_start_id=ZK_OBSERVER_START_ID,
        configuration_entries=additional_configuration_entries,
        java_system_properties=additional_java_system_properties,
        jaas_config=jaas_config
    )
    CLUSTER_CONF = cluster_conf
    atexit.register(lambda cluster: cluster.terminate(), CLUSTER)
    return CLUSTER