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(host): """ Check if can check mode do nothing """ # Given test_acl_configuration = acl_defaut_configuration.copy() test_acl_configuration.update({'name': get_acl_name(), 'state': 'present'}) test_acl_configuration.update(sasl_default_configuration) ensure_kafka_acl(host, test_acl_configuration) time.sleep(0.3) # When check_acl_configuration = test_acl_configuration.copy() check_acl_configuration.update({'state': 'absent'}) ensure_kafka_acl(host, check_acl_configuration, check=True) time.sleep(0.3) check_acl_configuration.update({ 'state': 'present', 'name': "test_" + str(time.time()) }) ensure_kafka_acl(host, check_acl_configuration, check=True) time.sleep(0.3) # 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_duplicated_acls(host): """ Check if can create acls """ # Given duplicated_acl_name = get_acl_name() def get_acl_config(): acl_configuration = acl_defaut_configuration.copy() acl_configuration.update({ 'name': duplicated_acl_name, 'state': 'present' }) return acl_configuration test_acl_configuration = {'acls': [get_acl_config(), get_acl_config()]} test_acl_configuration.update(sasl_default_configuration) # When results = ensure_kafka_acls(host, test_acl_configuration) time.sleep(0.3) # Then for result in results: assert not result['changed'] assert 'duplicated acls' in result['msg']
def test_kafka_info_acl(host): """ Check if can get info on acl """ # Given test_acl_configuration = acl_defaut_configuration.copy() resource_name = get_acl_name() test_acl_configuration.update({ 'name': resource_name, 'state': 'present', **sasl_default_configuration }) ensure_acl( host, test_acl_configuration ) time.sleep(0.3) # When results = call_kafka_info( host, { 'resource': 'acl' } ) expected = { 'resource_type': 'topic', 'operation': 'write', 'permission_type': 'allow', 'resource_name': resource_name, 'principal': 'User:common', 'host': '*', 'pattern_type': 'literal' } # Then for r in results: assert expected in r['ansible_module_results']['topic'][resource_name]
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)
def get_acl_config(): acl_configuration = acl_defaut_configuration.copy() acl_configuration.update({'name': get_acl_name(), 'state': 'absent'}) return acl_configuration