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_check_mode(): """ Check if can check mode do nothing """ # Given test_acl_configuration = acl_defaut_configuration.copy() test_acl_configuration.update({'state': 'present'}) test_acl_configuration.update(sasl_default_configuration) ensure_kafka_acl(localhost, test_acl_configuration) time.sleep(0.5) # When check_acl_configuration = test_acl_configuration.copy() check_acl_configuration.update({'state': 'absent'}) ensure_kafka_acl(localhost, check_acl_configuration, check=True) time.sleep(0.5) check_acl_configuration.update({ 'state': 'present', 'name': "test_" + str(time.time()) }) ensure_kafka_acl(localhost, check_acl_configuration, check=True) time.sleep(0.5) # Then for host, host_vars in kafka_hosts.items(): kfk_sasl_addr = "%s:9094" % \ host_vars['ansible_eth0']['ipv4']['address']['__ansible_unsafe'] check_configured_acl(host, test_acl_configuration, kfk_sasl_addr) check_acl_configuration.update({'state': 'absent'}) check_configured_acl(host, test_acl_configuration, kfk_sasl_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 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_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)