diff --git a/osism/utils/rabbitmq.py b/osism/utils/rabbitmq.py index ad5b1dcf3..e11f1f21b 100644 --- a/osism/utils/rabbitmq.py +++ b/osism/utils/rabbitmq.py @@ -92,11 +92,11 @@ def get_rabbitmq_node_addresses(): logger.debug(f"Internal interface for {host}: {internal_interface}") - # Look for the interface in ansible facts - # Interface names with special chars are normalized (e.g., eth0.100 -> ansible_eth0_100) - normalized_interface = internal_interface.replace(".", "_").replace( - "-", "_" - ) + # Look for the interface in ansible facts. Ansible replaces "-" + # with "_" in fact names and leaves dots alone + # (PrefixFactNamespace._underscore), so "br-ex" is + # ansible_br_ex while "bond0.100" is ansible_bond0.100. + normalized_interface = internal_interface.replace("-", "_") interface_key = f"ansible_{normalized_interface}" interface_facts = facts.get(interface_key) diff --git a/tests/unit/utils/test_rabbitmq.py b/tests/unit/utils/test_rabbitmq.py index 874351fce..d061b2974 100644 --- a/tests/unit/utils/test_rabbitmq.py +++ b/tests/unit/utils/test_rabbitmq.py @@ -346,17 +346,18 @@ def test_template_traversal_hits_non_dict_skips_host( _assert_error_logged(loguru_logs, "Could not resolve template") @pytest.mark.parametrize( - "interface,normalized_key", - [("eth0.100", "ansible_eth0_100"), ("eth-0", "ansible_eth_0")], + "interface,fact_key", + [("eth0.100", "ansible_eth0.100"), ("eth-0", "ansible_eth_0")], ) - def test_interface_name_normalized_for_fact_lookup( - self, setup_addresses, loguru_logs, interface, normalized_key + def test_interface_name_mapped_to_fact_key( + self, setup_addresses, loguru_logs, interface, fact_key ): - # Facts are only stored under the normalized key, so a correct lookup - # is the only way the address can be found. + # Facts are only stored under the key Ansible actually uses, so a + # correct mapping is the only way the address can be found. Ansible + # replaces "-" with "_" and keeps dots. setup_addresses( hosts=["host1"], - redis_side_effect=[_facts(normalized_key, "10.0.0.7")], + redis_side_effect=[_facts(fact_key, "10.0.0.7")], check_output=[_GROUP_LISTING, _hostvars(interface)], )