Esempio n. 1
0
    def setUp(self):

        config.zk_acl = zk_test_acl
        config.zk_auth = zk_test_auth

        self.counter = 0
        self.running = True

        utdocker.create_network()
        utdocker.start_container(
            zk_test_name,
            zk_test_tag,
            env={
                "ZOO_MY_ID": 1,
                "ZOO_SERVERS": "server.1=0.0.0.0:2888:3888",
            },
            port_bindings={
                2181: 21811,
            }
        )

        self.zk = KazooClient(hosts='127.0.0.1:21811')
        self.zk.start()
        scheme, name, passw = zk_test_auth
        self.zk.add_auth(scheme, name + ':' + passw)

        # create lock base dir
        acl = zkutil.make_kazoo_digest_acl(zk_test_acl)
        self.zk.create('lock/', acl=acl)

        self.lck = zkutil.ZKLock('foo_name', zkclient=self.zk)
Esempio n. 2
0
    def test_make_kazoo_digest_acl(self):

        inp = (('foo', 'bar', 'cd'), ('xp', '123', 'cdrwa'))

        dd(inp)

        rst = zkutil.make_kazoo_digest_acl(inp)
        dd(rst)

        self.assertEqual(2, len(rst))

        ac = rst[0]
        self.assertEqual('digest', ac.id.scheme)
        self.assertEqual('foo', ac.id.id.split(':')[0])
        self.assertEqual(set(['CREATE', 'DELETE']), set(ac.acl_list))

        ac = rst[1]
        self.assertEqual('digest', ac.id.scheme)
        self.assertEqual('xp', ac.id.id.split(':')[0])
        self.assertEqual(set(['ALL']), set(ac.acl_list))

        self.assertIsNone(zkutil.make_kazoo_digest_acl(None))
    def test_make_kazoo_digest_acl(self):

        inp = (('foo', 'bar', 'cd'),
               ('xp', '123', 'cdrwa'))

        dd(inp)

        rst = zkutil.make_kazoo_digest_acl(inp)
        dd(rst)

        self.assertEqual(2, len(rst))

        ac = rst[0]
        self.assertEqual('digest', ac.id.scheme)
        self.assertEqual('foo', ac.id.id.split(':')[0])
        self.assertEqual(set(['CREATE', 'DELETE']), set(ac.acl_list))

        ac = rst[1]
        self.assertEqual('digest', ac.id.scheme)
        self.assertEqual('xp', ac.id.id.split(':')[0])
        self.assertEqual(set(['ALL']), set(ac.acl_list))

        self.assertIsNone(zkutil.make_kazoo_digest_acl(None))
Esempio n. 4
0
    def test_specified(self):

        c = zkutil.ZKConf(
            hosts='hosts',
            tx_dir='tx_dir/',
            record_dir='record_dir/',
            seq_dir='seq_dir/',
            lock_dir='lock_dir/',
            node_id='node_id',
            auth=('digest', 'a', 'b'),
            acl=(('foo', 'bar', 'cd'), ('xp', '123', 'cdrwa'))
        )

        self.assertEqual('hosts',              c.hosts())
        self.assertEqual('tx_dir/',            c.tx_dir())
        self.assertEqual('record_dir/',        c.record_dir())
        self.assertEqual('seq_dir/',           c.seq_dir())
        self.assertEqual('lock_dir/',          c.lock_dir())
        self.assertEqual('node_id',            c.node_id())
        self.assertEqual(('digest', 'a', 'b'), c.auth())

        self.assertEqual((('foo', 'bar', 'cd'),
                          ('xp', '123', 'cdrwa')),
                         c.acl())

        self.assertEqual('lock_dir/',                 c.lock())
        self.assertEqual('lock_dir/a',                c.lock('a'))
        self.assertEqual('record_dir/',               c.record())
        self.assertEqual('record_dir/a',              c.record('a'))
        self.assertEqual('tx_dir/alive/',             c.tx_alive())
        self.assertEqual('tx_dir/alive/a',            c.tx_alive('a'))
        self.assertEqual('tx_dir/alive/0000000001',   c.tx_alive(1))
        self.assertEqual('tx_dir/state/',             c.tx_state())
        self.assertEqual('tx_dir/state/a',            c.tx_state('a'))
        self.assertEqual('tx_dir/state/0000000001',   c.tx_state(1))
        self.assertEqual('tx_dir/journal/',           c.journal())
        self.assertEqual('tx_dir/journal/a',          c.journal('a'))
        self.assertEqual('tx_dir/journal/0000000001', c.journal(1))
        self.assertEqual('tx_dir/txidset',            c.txidset())
        self.assertEqual('tx_dir/txid_maker',         c.txid_maker())
        self.assertEqual('seq_dir/',                  c.seq())
        self.assertEqual('seq_dir/a',                 c.seq('a'))

        self.assertEqual(zkutil.make_kazoo_digest_acl((('foo', 'bar', 'cd'), ('xp', '123', 'cdrwa'))),
                         c.kazoo_digest_acl())
        self.assertEqual(('digest', 'a:b'), c.kazoo_auth())
    def test_specified(self):

        c = zkutil.ZKConf(
            hosts='hosts',
            tx_dir='tx_dir/',
            record_dir='record_dir/',
            seq_dir='seq_dir/',
            lock_dir='lock_dir/',
            node_id='node_id',
            auth=('digest', 'a', 'b'),
            acl=(('foo', 'bar', 'cd'), ('xp', '123', 'cdrwa'))
        )

        self.assertEqual('hosts',              c.hosts())
        self.assertEqual('tx_dir/',            c.tx_dir())
        self.assertEqual('record_dir/',        c.record_dir())
        self.assertEqual('seq_dir/',           c.seq_dir())
        self.assertEqual('lock_dir/',          c.lock_dir())
        self.assertEqual('node_id',            c.node_id())
        self.assertEqual(('digest', 'a', 'b'), c.auth())

        self.assertEqual((('foo', 'bar', 'cd'),
                          ('xp', '123', 'cdrwa')),
                         c.acl())

        self.assertEqual('lock_dir/',                 c.lock())
        self.assertEqual('lock_dir/a',                c.lock('a'))
        self.assertEqual('record_dir/',               c.record())
        self.assertEqual('record_dir/a',              c.record('a'))
        self.assertEqual('tx_dir/alive/',             c.tx_alive())
        self.assertEqual('tx_dir/alive/a',            c.tx_alive('a'))
        self.assertEqual('tx_dir/alive/0000000001',   c.tx_alive(1))
        self.assertEqual('tx_dir/state/',             c.tx_state())
        self.assertEqual('tx_dir/state/a',            c.tx_state('a'))
        self.assertEqual('tx_dir/state/0000000001',   c.tx_state(1))
        self.assertEqual('tx_dir/journal/',           c.journal())
        self.assertEqual('tx_dir/journal/a',          c.journal('a'))
        self.assertEqual('tx_dir/journal/journal_id0000000001', c.journal(1))
        self.assertEqual('tx_dir/journal_id_set',          c.journal_id_set())
        self.assertEqual('tx_dir/txid_maker',         c.txid_maker())
        self.assertEqual('seq_dir/',                  c.seq())
        self.assertEqual('seq_dir/a',                 c.seq('a'))

        self.assertEqual(zkutil.make_kazoo_digest_acl((('foo', 'bar', 'cd'), ('xp', '123', 'cdrwa'))),
                         c.kazoo_digest_acl())
        self.assertEqual(('digest', 'a:b'), c.kazoo_auth())
Esempio n. 6
0
    def test_default(self):
        old = (
            config.zk_hosts,
            config.zk_tx_dir,
            config.zk_record_dir,
            config.zk_lock_dir,
            config.zk_node_id,
            config.zk_auth,
            config.zk_acl,
        )

        config.zk_hosts = 'HOSTS'
        config.zk_tx_dir = 'TX_DIR/'
        config.zk_record_dir = 'RECORD_DIR/'
        config.zk_seq_dir = 'SEQ_DIR/'
        config.zk_lock_dir = 'LOCK_DIR/'
        config.zk_node_id = 'NODE_ID'
        config.zk_auth = ('DIGEST', 'A', 'B')
        config.zk_acl = (('FOO', 'BAR', 'CD'), ('XP', '123', 'CDRWA'))

        c = zkutil.ZKConf()

        self.assertEqual('HOSTS',              c.hosts())
        self.assertEqual('TX_DIR/',            c.tx_dir())
        self.assertEqual('RECORD_DIR/',        c.record_dir())
        self.assertEqual('SEQ_DIR/',           c.seq_dir())
        self.assertEqual('LOCK_DIR/',          c.lock_dir())
        self.assertEqual('NODE_ID',            c.node_id())
        self.assertEqual(('DIGEST', 'A', 'B'), c.auth())

        self.assertEqual((('FOO', 'BAR', 'CD'),
                          ('XP', '123', 'CDRWA')),
                         c.acl())

        self.assertEqual('LOCK_DIR/',                 c.lock())
        self.assertEqual('LOCK_DIR/a',                c.lock('a'))
        self.assertEqual('RECORD_DIR/',               c.record())
        self.assertEqual('RECORD_DIR/a',              c.record('a'))
        self.assertEqual('SEQ_DIR/',                  c.seq())
        self.assertEqual('SEQ_DIR/a',                 c.seq('a'))
        self.assertEqual('TX_DIR/alive/',             c.tx_alive())
        self.assertEqual('TX_DIR/alive/a',            c.tx_alive('a'))
        self.assertEqual('TX_DIR/alive/0000000001',   c.tx_alive(1))
        self.assertEqual('TX_DIR/state/',             c.tx_state())
        self.assertEqual('TX_DIR/state/a',            c.tx_state('a'))
        self.assertEqual('TX_DIR/state/0000000001',   c.tx_state(1))
        self.assertEqual('TX_DIR/journal/',           c.journal())
        self.assertEqual('TX_DIR/journal/a',          c.journal('a'))
        self.assertEqual('TX_DIR/journal/0000000001', c.journal(1))
        self.assertEqual('TX_DIR/txidset',            c.txidset())
        self.assertEqual('TX_DIR/txid_maker',         c.txid_maker())

        self.assertEqual(zkutil.make_kazoo_digest_acl((('FOO', 'BAR', 'CD'), ('XP', '123', 'CDRWA'))),
                         c.kazoo_digest_acl())
        self.assertEqual(('DIGEST', 'A:B'), c.kazoo_auth())

        (
            config.zk_hosts,
            config.zk_tx_dir,
            config.zk_record_dir,
            config.zk_lock_dir,
            config.zk_node_id,
            config.zk_auth,
            config.zk_acl,
        ) = old
    def test_default(self):
        old = (
            config.zk_hosts,
            config.zk_tx_dir,
            config.zk_record_dir,
            config.zk_lock_dir,
            config.zk_node_id,
            config.zk_auth,
            config.zk_acl,
        )

        config.zk_hosts = 'HOSTS'
        config.zk_tx_dir = 'TX_DIR/'
        config.zk_record_dir = 'RECORD_DIR/'
        config.zk_seq_dir = 'SEQ_DIR/'
        config.zk_lock_dir = 'LOCK_DIR/'
        config.zk_node_id = 'NODE_ID'
        config.zk_auth = ('DIGEST', 'A', 'B')
        config.zk_acl = (('FOO', 'BAR', 'CD'), ('XP', '123', 'CDRWA'))

        c = zkutil.ZKConf()

        self.assertEqual('HOSTS',              c.hosts())
        self.assertEqual('TX_DIR/',            c.tx_dir())
        self.assertEqual('RECORD_DIR/',        c.record_dir())
        self.assertEqual('SEQ_DIR/',           c.seq_dir())
        self.assertEqual('LOCK_DIR/',          c.lock_dir())
        self.assertEqual('NODE_ID',            c.node_id())
        self.assertEqual(('DIGEST', 'A', 'B'), c.auth())

        self.assertEqual((('FOO', 'BAR', 'CD'),
                          ('XP', '123', 'CDRWA')),
                         c.acl())

        self.assertEqual('LOCK_DIR/',                 c.lock())
        self.assertEqual('LOCK_DIR/a',                c.lock('a'))
        self.assertEqual('RECORD_DIR/',               c.record())
        self.assertEqual('RECORD_DIR/a',              c.record('a'))
        self.assertEqual('SEQ_DIR/',                  c.seq())
        self.assertEqual('SEQ_DIR/a',                 c.seq('a'))
        self.assertEqual('TX_DIR/alive/',             c.tx_alive())
        self.assertEqual('TX_DIR/alive/a',            c.tx_alive('a'))
        self.assertEqual('TX_DIR/alive/0000000001',   c.tx_alive(1))
        self.assertEqual('TX_DIR/state/',             c.tx_state())
        self.assertEqual('TX_DIR/state/a',            c.tx_state('a'))
        self.assertEqual('TX_DIR/state/0000000001',   c.tx_state(1))
        self.assertEqual('TX_DIR/journal/',           c.journal())
        self.assertEqual('TX_DIR/journal/a',          c.journal('a'))
        self.assertEqual('TX_DIR/journal/journal_id0000000001', c.journal(1))
        self.assertEqual('TX_DIR/journal_id_set',          c.journal_id_set())
        self.assertEqual('TX_DIR/txid_maker',         c.txid_maker())

        self.assertEqual(zkutil.make_kazoo_digest_acl((('FOO', 'BAR', 'CD'), ('XP', '123', 'CDRWA'))),
                         c.kazoo_digest_acl())
        self.assertEqual(('DIGEST', 'A:B'), c.kazoo_auth())

        (
            config.zk_hosts,
            config.zk_tx_dir,
            config.zk_record_dir,
            config.zk_lock_dir,
            config.zk_node_id,
            config.zk_auth,
            config.zk_acl,
        ) = old