Charm hooks fails due to netifaces newer version

Bug #2029374 reported by Gui Maluf Balzana
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Graylog Charm
Fix Committed
Medium
Mert Kirpici

Bug Description

While changing a config on graylog charm I got hit by

```
unit-graylog-0: 12:03:23 ERROR unit.graylog/0.juju-log Hook error:
Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-graylog-0/.venv/lib/python3.6/site-packages/charms/reactive/__init__.py", line 74, in main
    bus.dispatch(restricted=restricted_mode)
  File "/var/lib/juju/agents/unit-graylog-0/.venv/lib/python3.6/site-packages/charms/reactive/bus.py", line 390, in dispatch
    _invoke(other_handlers)
  File "/var/lib/juju/agents/unit-graylog-0/.venv/lib/python3.6/site-packages/charms/reactive/bus.py", line 359, in _invoke
    handler.invoke()
  File "/var/lib/juju/agents/unit-graylog-0/.venv/lib/python3.6/site-packages/charms/reactive/bus.py", line 181, in invoke
    self._action(*args)
  File "/var/lib/juju/agents/unit-graylog-0/charm/reactive/graylog.py", line 238, in configure_graylog
    validate_api_uri("{}://0.0.0.0:{}/".format(get_api_protocol(), api_port)),
  File "lib/charms/layer/graylog/utils.py", line 63, in validate_api_uri
    netloc="{}:{}".format(get_ip_address(), parsed_url.port)
  File "lib/charms/layer/graylog/utils.py", line 81, in get_ip_address
    iface = netifaces.gateways()["default"][netifaces.AF_INET][1]
KeyError: 2
```

This showed up to be due to netifaces version in the virtual env of the charm

```
# netifaces==0.10.4
python3 -c 'import netifaces ; print(netifaces.gateways()["default"])'
{2: ('10.116.72.11', 'eth0'), 10: ('fa80::111:cdaf:eee8:19aa', 'eth1')}

# netifaces==0.11.0
/var/lib/juju/agents/unit-graylog-?/.venv/bin/python -c 'import netifaces ; print(netifaces.gateways()["default"])'
{10: ('fa80::111:cdaf:eee8:19aa', 'eth1')}
```

Downgrading netifaces<0.11 fixed the issue

```
/var/lib/juju/agents/unit-graylog-?/.venv/bin/python -m pip install 'netifaces<0.11'
```

Tags: bseng-1410

Related branches

Eric Chen (eric-chen)
Changed in charm-graylog:
status: New → Triaged
importance: Undecided → Medium
tags: added: bseng-1410
Changed in charm-graylog:
assignee: nobody → Mert Kirpici (mertkirpici)
status: Triaged → In Progress
Changed in charm-graylog:
status: In Progress → Triaged
status: Triaged → Confirmed
Changed in charm-graylog:
assignee: Mert Kirpici (mertkirpici) → nobody
Revision history for this message
Mert Kirpici (mertkirpici) wrote :

Root cause analysis shows that starting from netifaces v0.11.0:
1 - netifaces only considers routes as default if they are defined on the main table
2 - netifaces selects the route with the lowest metric(highest prio) to show as the "default"
3 - combining 1 and 2: if the default route with the lowest metric is not on the main table, netifaces.gateways()["default"] returns empty
4 - charm-advanced-routing introduces a new table called "apitable" upon installation with a default route on it
5 - the issue is observed when the default route with the lowest metric is not on the main table. Hence the error:

iface = netifaces.gateways()["default"][netifaces.AF_INET][1]
KeyError: 2

where 2 represents netifaces.AF_INET.

The issue can be resolved by any of the following:
- making sure the default route with the lowest metric is on the main table.
- pinning down the netifaces package
- proposing a patch to netifaces-plus if this _should_ not be the right behavior.(I am not exactly convinced that the default route MUST be in the main table..)

Relating the bug to the charm-advanced-routing project as well

Revision history for this message
Andrea Ieri (aieri) wrote :

Removing advanced-routing since this bug does not affect it (though it can be triggered by its presence)

no longer affects: charm-advanced-routing
Changed in charm-graylog:
assignee: nobody → Mert Kirpici (mertkirpici)
status: Confirmed → In Progress
Tianqi Xiao (txiao)
Changed in charm-graylog:
milestone: none → 23.10
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.