예제 #1
0
def test_zookeeper_get(mock_kazoo):
    mock_kazoo.return_value.get.return_value = [b'value']
    zk = ZookeeperDatabase(
            ['https://127.0.0.1:2181', 'https://127.0.0.2:2181'],
            'zk_namespace')
    value = zk.get(b'key')
    assert value == b'value'
예제 #2
0
    def create(self):
        if self.db_type == 'local':

            if self.directory is None or self.directory == '':
                raise ImproperDirectoryError(
                    "Please set a directory for local database")
            return LocalDatabase(self.directory)

        elif self.db_type == 'zookeeper':
            if self.host is None or self.host == '':
                raise ImproperHostError(
                    "Please provide a ip:port for zookeeper database")
            return ZookeeperDatabase(self.host, self.namespace, self.timeout,
                                     self.ssl)

        elif self.db_type == 'etcd':

            if isinstance(self.host, str):
                hosts = [_format_host_for_etcd(self.host)]
            elif isinstance(self.host, list):
                hosts = [_format_host_for_etcd(h) for h in self.host]
            return EtcdDatabase(hosts, self.timeout, self.api_path, self.ssl)
        else:
            raise ImproperDatabaseTypeError(
                "The agent only support 1)local 2)zookeeper 3)etcd databases")
예제 #3
0
def test_zookeeper_pass_ssl_cert_as_string(mock_kazoo_client):
    ZookeeperDatabase(['https://127.0.0.1:2181', 'https://127.0.0.2:2181'],
                      'zk_namespace',
                      ssl=SSL(server_verify='/path/to/sever_cert'))
예제 #4
0
def test_zookeeper_raise_exception_when_invalid_ssl(mock_kazoo_client):
    with pytest.raises(ValidationError):
        ZookeeperDatabase(['https://127.0.0.1:2181', 'https://127.0.0.2:2181'],
                          'zk_namespace',
                          ssl=SSL(server_verify=123))