Skip to content

Commit 58bc720

Browse files
krcmarikdasm
authored andcommitted
dnsmasq: Fix start_v[4|6] is None
The task[1] has started to fail recently on following error: "object of type 'NoneType' has no len(). object of type 'NoneType' has no len()" I can see that cifmw_dnsmasq_network_definition in my case is: name: osp_trunk original_name: cifmw-osp_trunk ranges: - label: osp_trunk options: - option:dns-server,192.168.122.1 - option:router prefix_length_v4: 24 prefix_length_v6: null start_v4: 192.168.122.2 start_v6: null Which means that start_v6 is None and that's defined but of NoneType so length filter can't be used on it. The filter does not need to be used tho It's enough to condition, i.e. "if variable" (instead of "If variable | length > 0") which would be false if values is None, false, 0, empty string, dictionary or list. [1] https://github.com/openstack-k8s-operators/ci-framework/blob/main/roles/dnsmasq/tasks/manage_network.yml#L35
1 parent 06bfb9d commit 58bc720

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

roles/config_drive/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
register: _net_data_change
6464
when:
6565
- cifmw_config_drive_networkconfig is defined
66-
- cifmw_config_drive_networkconfig | length > 0
66+
- cifmw_config_drive_networkconfig
6767
ansible.builtin.template:
6868
backup: true
6969
src: "network-config.j2"
@@ -101,6 +101,6 @@
101101
-joliet
102102
-rock user-data meta-data
103103
{% if cifmw_config_drive_networkconfig is defined and
104-
cifmw_config_drive_networkconfig | length > 0 -%}
104+
cifmw_config_drive_networkconfig -%}
105105
network-config
106106
{%- endif -%}

roles/dnsmasq/templates/network.conf.j2

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Managed by ci-framework/dnsmasq
22
{% if cifmw_dnsmasq_network_definition.ranges | selectattr('start_v6', 'defined') |
3-
rejectattr('start_v6', 'match', '^$') -%}
3+
rejectattr('start_v6', 'none') | rejectattr('start_v6', 'match', '^$') -%}
44
enable-ra
55
{% endif -%}
66

77
{% for range in cifmw_dnsmasq_network_definition['ranges'] -%}
8-
{% if range.start_v4 is defined and range.start_v4 | length > 0 -%}
8+
{% if range.start_v4 is defined and range.start_v4 -%}
99
dhcp-range=set:{{ range.label }},{{ range.start_v4 }},static,{{ (range.start_v4 + "/" + range.prefix_length_v4 | default(24) | string) | ansible.utils.ipaddr('netmask') }},{{ range.ttl | default('1h') }}
10-
{% if range.domain is defined and range.domain | length > 0 -%}
10+
{% if range.domain is defined and range.domain -%}
1111
{% set range_v4_allowed = (range.start_v4 ~ "/" ~ range.prefix_length_v4 | default('24')) |
1212
ansible.utils.ipaddr('range_usable') | replace("-",",") %}
1313
domain={{ range.domain }},{{ range_v4_allowed }},local
1414
{% endif %}
1515
{% endif %}
16-
{% if range.start_v6 is defined and range.start_v6 | length > 0 -%}
16+
{% if range.start_v6 is defined and range.start_v6 -%}
1717
dhcp-range=set:{{ range.label }},{{ range.start_v6 }},static,{{ range.prefix_length_v6 | default('64') }},{{ range.ttl | default('1h') }}
18-
{% if range.domain is defined and range.domain | length > 0 -%}
18+
{% if range.domain is defined and range.domain -%}
1919
{% set range_v6_allowed = (range.start_v6 ~ "/" ~ range.prefix_length_v6 | default('64')) |
2020
ansible.utils.ipaddr('range_usable') | replace("-",",") %}
2121
domain={{ range.domain }},{{ range_v6_allowed }},local

roles/libvirt_manager/tasks/generate_networking_data.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@
180180
{% set ns = namespace(ip_start=30) %}
181181
networks:
182182
{{ _lnet_data.name | replace('cifmw_', '') }}:
183-
{% if _lnet_data.ranges[0].start_v4 is defined and _lnet_data.ranges[0].start_v4 | length > 0 %}
183+
{% if _lnet_data.ranges[0].start_v4 is defined and _lnet_data.ranges[0].start_v4 %}
184184
{% set net_4 = _lnet_data.ranges[0].start_v4 | ansible.utils.ipsubnet(_lnet_data.ranges[0].prefix_length_v4) %}
185185
network-v4: {{ net_4}}
186186
{% endif %}
187-
{% if _lnet_data.ranges[0].start_v6 is defined and _lnet_data.ranges[0].start_v6 | length > 0 %}
187+
{% if _lnet_data.ranges[0].start_v6 is defined and _lnet_data.ranges[0].start_v6 %}
188188
{% set net_6 = _lnet_data.ranges[0].start_v6 | ansible.utils.ipsubnet(_lnet_data.ranges[0].prefix_length_v6) %}
189189
network-v6: {{ net_6 }}
190190
{% endif %}

0 commit comments

Comments
 (0)