Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions osism/utils/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions tests/unit/utils/test_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
)

Expand Down