def test_acl_delete(host): """ Check if can delete acls """ # Given test_acl_configuration = acl_defaut_configuration.copy() test_acl_configuration.update({ 'name': get_acl_name(), 'state': 'present', **sasl_default_configuration }) ensure_acl( host, test_acl_configuration ) time.sleep(0.3) # When test_acl_configuration.update({ 'state': 'absent' }) ensure_idempotency( ensure_acl, host, test_acl_configuration ) time.sleep(0.3) # Then for kafka_host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9094" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_acl(kafka_host, test_acl_configuration, kfk_addr)
def test_update_partitions_without_zk(host): """ Check if can update partitions numbers without zk (only > 1.0.0) """ # Given topic_name = get_topic_name() ensure_kafka_topic(host, topic_defaut_configuration, topic_name) time.sleep(0.3) # When test_topic_configuration = topic_defaut_configuration.copy() test_topic_configuration.update({'partitions': 2}) ensure_idempotency(ensure_kafka_topic, host, test_topic_configuration, topic_name, minimal_api_version="1.0.0") time.sleep(0.3) # Then for host, host_vars in kafka_hosts.items(): if (parse_version( host_protocol_version[host_vars['inventory_hostname']]) < parse_version("1.0.0")): continue kfk_addr = "%s:9092" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_topic(host, test_topic_configuration, topic_name, kfk_addr)
def test_delete_options(host): """ Check if can remove topic options """ # Given init_topic_configuration = topic_defaut_configuration.copy() init_topic_configuration.update( {'options': { 'retention.ms': 66574936, 'flush.ms': 564939 }}) topic_name = get_topic_name() ensure_kafka_topic(host, init_topic_configuration, topic_name) time.sleep(0.3) # When test_topic_configuration = topic_defaut_configuration.copy() test_topic_configuration.update({'options': {'flush.ms': 564939}}) ensure_idempotency(ensure_kafka_topic, host, test_topic_configuration, topic_name) time.sleep(0.3) # Then deleted_options = { 'retention.ms': 66574936, } for host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9092" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_topic(host, test_topic_configuration, topic_name, kfk_addr, deleted_options=deleted_options)
def test_update_partitions(host): """ Check if can update partitions numbers """ # Given topic_name = get_topic_name() ensure_topic( host, topic_defaut_configuration, topic_name ) time.sleep(0.3) # When test_topic_configuration = topic_defaut_configuration.copy() test_topic_configuration.update({ 'partitions': 2 }) ensure_idempotency( ensure_topic, host, test_topic_configuration, topic_name ) time.sleep(0.3) # Then for kafka_host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9092" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_topic(kafka_host, test_topic_configuration, topic_name, kfk_addr)
def test_update_replica_factor(): """ Check if can update replication factor """ # Given topic_name = get_topic_name() ensure_kafka_topic( localhost, topic_defaut_configuration, topic_name ) time.sleep(0.5) # When test_topic_configuration = topic_defaut_configuration.copy() test_topic_configuration.update({ 'replica_factor': 2 }) ensure_idempotency( ensure_kafka_topic_with_zk, localhost, test_topic_configuration, topic_name ) time.sleep(0.5) # Then for host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9092" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_topic(host, test_topic_configuration, topic_name, kfk_addr)
def test_delete_topic(): """ Check if can delete topic """ # Given topic_name = get_topic_name() ensure_kafka_topic( localhost, topic_defaut_configuration, topic_name ) time.sleep(0.5) # When test_topic_configuration = topic_defaut_configuration.copy() test_topic_configuration.update({ 'state': 'absent' }) ensure_idempotency( ensure_kafka_topic, localhost, test_topic_configuration, topic_name ) time.sleep(0.5) # Then for host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9092" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_topic(host, test_topic_configuration, topic_name, kfk_addr)
def test_acls_create(host): """ Check if can create acls """ # Given def get_acl_config(): acl_configuration = acl_defaut_configuration.copy() acl_configuration.update({'name': get_acl_name(), 'state': 'absent'}) return acl_configuration test_acl_configuration = {'acls': [get_acl_config(), get_acl_config()]} test_acl_configuration.update(sasl_default_configuration) ensure_kafka_acls(host, test_acl_configuration) time.sleep(0.3) # When for acl in test_acl_configuration['acls']: acl['state'] = 'present' ensure_idempotency(ensure_kafka_acls, host, test_acl_configuration) time.sleep(0.3) # Then for host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9094" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] for acl in test_acl_configuration['acls']: check_configured_acl(host, acl, kfk_addr)
def delete_consumer_offset(host, partitions=None): """ Check if can delete consumer group for topic """ # Given consumer_group = get_consumer_group() topic_name1 = get_topic_name() ensure_kafka_topic(host, topic_defaut_configuration, topic_name1, minimal_api_version="2.4.0") time.sleep(0.3) produce_and_consume_topic(topic_name1, 1, consumer_group, True, "2.4.0") time.sleep(0.3) # When test_cg_configuration = cg_defaut_configuration.copy() test_cg_configuration.update({ 'consumer_group': consumer_group, 'action': 'delete', 'api_version': '2.4.0' }) if partitions is None: test_cg_configuration.update({'topics': [{'name': topic_name1}]}) else: test_cg_configuration.update( {'topics': [{ 'name': topic_name1, 'partitions': partitions }]}) test_cg_configuration.update(sasl_default_configuration) ensure_idempotency(ensure_kafka_consumer_group, host, test_cg_configuration, minimal_api_version="2.4.0") time.sleep(0.3) # Then for host, host_vars in kafka_hosts.items(): if (parse_version( host_protocol_version[host_vars['inventory_hostname']]) < parse_version("2.4.0")): continue kfk_addr = "%s:9092" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_unconsumed_topic(consumer_group, topic_name1, kfk_addr)
def test_quotas_create_ssl_full_text(host): """ Check if can create quotas """ # Given test_quotas_configuration = quotas_default_configuration.copy() test_quotas_configuration.update({ 'entries': [{ 'entity': { 'client': get_entity_name(), 'user': get_entity_name() }, 'quotas': { 'producer_byte_rate': 104101 } }] }) test_quotas_configuration.update(ssl_default_configuration) test_quotas_configuration['ssl_cafile'] = \ host.file(ssl_default_configuration['ssl_cafile']).content_string test_quotas_configuration['ssl_certfile'] = \ host.file(ssl_default_configuration['ssl_certfile']).content_string test_quotas_configuration['ssl_keyfile'] = \ host.file(ssl_default_configuration['ssl_keyfile']).content_string ensure_kafka_quotas(host, test_quotas_configuration) time.sleep(0.3) # When test_quotas_configuration['entries'][0].update({ 'quotas': { 'producer_byte_rate': 104101, 'consumer_byte_rate': 104101 } }) ensure_idempotency(ensure_kafka_quotas, host, test_quotas_configuration) time.sleep(0.3) # Then for host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9094" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_quotas_kafka(host, test_quotas_configuration, kfk_addr) for host, host_vars in zookeeper_hosts.items(): zk_addr = "%s:2181" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_quotas_zookeeper(host, test_quotas_configuration, zk_addr)
def test_acl_create(): """ Check if can create acls """ # Given test_acl_configuration = acl_defaut_configuration.copy() test_acl_configuration.update({'state': 'absent'}) test_acl_configuration.update(sasl_default_configuration) ensure_kafka_acl(localhost, test_acl_configuration) time.sleep(0.5) # When test_acl_configuration.update({'state': 'present'}) ensure_idempotency(ensure_kafka_acl, localhost, test_acl_configuration) time.sleep(0.5) # Then for host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9094" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_acl(host, test_acl_configuration, kfk_addr)
def test_delete_options_topics(host): """ Check if can remove topics options """ # Given def get_topic_config(): topic_configuration = topic_defaut_configuration.copy() topic_configuration.update({ 'name': get_topic_name(), 'options': { 'retention.ms': 66574936, 'flush.ms': 564939 } }) return topic_configuration topic_configuration = {'topics': [get_topic_config(), get_topic_config()]} ensure_kafka_topics(host, topic_configuration) time.sleep(0.3) # When for topic in topic_configuration['topics']: topic['options'] = {'flush.ms': 564939} ensure_idempotency(ensure_kafka_topics, host, topic_configuration) time.sleep(0.3) # Then deleted_options = { 'retention.ms': 66574936, } for host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9092" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] for topic in topic_configuration['topics']: check_configured_topic(host, topic, topic['name'], kfk_addr, deleted_options=deleted_options)