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_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_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_check_mode(): """ Check if can check mode do nothing """ # 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_kafka_topic_with_zk( localhost, test_topic_configuration, topic_name, check=True ) time.sleep(0.5) test_topic_configuration.update({ 'state': 'present', 'partitions': topic_defaut_configuration['partitions'] + 1, 'replica_factor': topic_defaut_configuration['replica_factor'] + 1, 'options': { 'retention.ms': 1000 } }) ensure_kafka_topic_with_zk( localhost, test_topic_configuration, topic_name, check=True ) time.sleep(0.5) new_topic_name = get_topic_name() ensure_kafka_topic_with_zk( localhost, test_topic_configuration, new_topic_name, check=True ) time.sleep(0.5) # Then expected_topic_configuration = topic_defaut_configuration.copy() for host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9092" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_topic(host, expected_topic_configuration, topic_name, kfk_addr) test_topic_configuration.update({ 'state': 'absent' }) check_configured_topic(host, test_topic_configuration, new_topic_name, kfk_addr)
def test_update_partitions_and_replica_factor_default_value(host): """ Check if can update partitions numbers make sure -1 values are considered, but warning + step is skipped """ # 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': -1, 'replica_factor': -1}) ensure_kafka_topic(host, test_topic_configuration, topic_name) time.sleep(0.3) # Then expected_topic_configuration = topic_defaut_configuration.copy() expected_topic_configuration.update({'partitions': 1, 'replica_factor': 1}) for host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9092" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_topic(host, expected_topic_configuration, topic_name, 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)
def test_check_mode(host): """ Check if can check mode do nothing """ # Given topic_name = get_topic_name() ensure_topic( host, topic_defaut_configuration, topic_name ) time.sleep(0.3) 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_topic_configuration = topic_defaut_configuration.copy() test_topic_configuration.update({ 'state': 'absent' }) ensure_topic( host, test_topic_configuration, topic_name, check=True ) time.sleep(0.3) test_topic_configuration.update({ 'state': 'present', 'partitions': topic_defaut_configuration['partitions'] + 1, 'replica_factor': topic_defaut_configuration['replica_factor'] + 1, 'options': { 'retention.ms': 1000 } }) ensure_topic( host, test_topic_configuration, topic_name, check=True ) time.sleep(0.3) new_topic_name = get_topic_name() ensure_topic( host, test_topic_configuration, new_topic_name, check=True ) time.sleep(0.3) check_acl_configuration = test_acl_configuration.copy() check_acl_configuration.update({ 'state': 'absent' }) ensure_acl( host, check_acl_configuration, check=True ) time.sleep(0.3) check_acl_configuration.update({ 'state': 'present', 'name': get_topic_name() }) ensure_acl( host, check_acl_configuration, check=True ) time.sleep(0.3) # Then expected_topic_configuration = topic_defaut_configuration.copy() for kafka_host, host_vars in kafka_hosts.items(): kfk_addr = "%s:9092" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] kfk_sasl_addr = "%s:9094" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_topic(kafka_host, expected_topic_configuration, topic_name, kfk_addr) check_configured_acl(kafka_host, test_acl_configuration, kfk_sasl_addr) test_topic_configuration.update({ 'state': 'absent' }) check_configured_topic(kafka_host, test_topic_configuration, new_topic_name, kfk_addr) check_acl_configuration.update({ 'state': 'absent' }) check_configured_acl(kafka_host, test_acl_configuration, kfk_sasl_addr)