Skip to content

Commit 715b2e0

Browse files
committed
Fix DHCP KEA settings
1 parent 83ef54c commit 715b2e0

7 files changed

Lines changed: 72 additions & 29 deletions

File tree

src/features.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bmc:
4848
description: Power management for bare metal hosts (IPMI, Redfish)
4949
foreman_proxy:
5050
plugin_name: bmc
51-
dhcp-kea-external:
52-
description: KEA DHCP provider (external unmanaged server)
51+
dhcp:
52+
description: DHCP management
5353
foreman_proxy:
54-
plugin_name: dhcp_kea_api
54+
plugin_name: dhcp

src/roles/foreman_proxy/defaults/main.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ foreman_proxy_foreman_server_url: "https://{{ ansible_facts['fqdn'] }}"
2424
foreman_proxy_bmc_ipmi_implementation: ipmitool
2525
foreman_proxy_bmc_redfish_verify_ssl: true
2626

27-
# KEA DHCP settings (external unmanaged server)
28-
foreman_proxy_dhcp_kea_server: localhost
29-
foreman_proxy_dhcp_kea_url: "http://{{ foreman_proxy_dhcp_kea_server }}:8000"
30-
foreman_proxy_dhcp_kea_subnet: 192.168.0.0/24
27+
# DHCP settings
28+
foreman_proxy_dhcp_provider: dhcp_kea
29+
foreman_proxy_dhcp_subnets: []
30+
31+
# KEA DHCP provider settings (when foreman_proxy_dhcp_provider is dhcp_kea)
32+
foreman_proxy_dhcp_kea_api_url: "{{ undef(hint='You must specify the KEA API URL') }}"
33+
foreman_proxy_dhcp_kea_api_username: ""
34+
foreman_proxy_dhcp_kea_api_password: ""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
- name: Create config secret for DHCP provider {{ foreman_proxy_dhcp_provider }}
2+
containers.podman.podman_secret:
3+
state: present
4+
name: foreman-proxy-{{ foreman_proxy_dhcp_provider }}-yml
5+
data: "{{ lookup('ansible.builtin.template', 'settings.d/' + foreman_proxy_dhcp_provider + '.yml.j2') }}"
6+
notify:
7+
- Restart Foreman Proxy
8+
- Refresh Foreman Proxy
9+
10+
- name: Mount config secret for DHCP provider {{ foreman_proxy_dhcp_provider }}
11+
ansible.builtin.copy:
12+
dest: /etc/containers/systemd/foreman-proxy.container.d/{{ foreman_proxy_dhcp_provider }}.conf
13+
content: |
14+
[Container]
15+
Secret=foreman-proxy-{{ foreman_proxy_dhcp_provider }}-yml,type=mount,target=/etc/foreman-proxy/settings.d/{{ foreman_proxy_dhcp_provider }}.yml
16+
mode: '0644'
17+
owner: root
18+
group: root
19+
notify:
20+
- Restart Foreman Proxy
21+
- Refresh Foreman Proxy
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
# DHCP module configuration
3+
# This enables the DHCP module and selects the provider
4+
5+
:enabled: {{ feature_enabled }}
6+
:use_provider: {{ foreman_proxy_dhcp_provider }}
7+
{% if foreman_proxy_dhcp_subnets is defined and foreman_proxy_dhcp_subnets %}
8+
:subnets: {{ foreman_proxy_dhcp_subnets | to_json }}
9+
{% endif %}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
# KEA DHCP provider configuration
3+
# This configures Smart Proxy to use an external KEA DHCP server
4+
5+
:enabled: {{ feature_enabled }}
6+
:kea_api_url: {{ foreman_proxy_dhcp_kea_api_url }}
7+
{% if foreman_proxy_dhcp_kea_api_username is defined and foreman_proxy_dhcp_kea_api_username %}
8+
:kea_api_username: {{ foreman_proxy_dhcp_kea_api_username }}
9+
{% endif %}
10+
{% if foreman_proxy_dhcp_kea_api_password is defined and foreman_proxy_dhcp_kea_api_password %}
11+
:kea_api_password: {{ foreman_proxy_dhcp_kea_api_password }}
12+
{% endif %}
13+
{% if foreman_proxy_dhcp_subnets is defined and foreman_proxy_dhcp_subnets %}
14+
:managed_subnets:
15+
{% for subnet in foreman_proxy_dhcp_subnets %}
16+
- {{ subnet }}
17+
{% endfor %}
18+
{% endif %}

src/roles/foreman_proxy/templates/settings.d/dhcp_kea_api.yml.j2

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/foreman_proxy_test.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_foreman_proxy_features(server, certificates, server_fqdn, enabled_featu
2929
assert "bmc" in features
3030
else:
3131
assert "bmc" not in features
32-
if 'dhcp-kea-external' in enabled_features:
32+
if 'dhcp' in enabled_features:
3333
assert "dhcp" in features
3434
else:
3535
assert "dhcp" not in features
@@ -75,24 +75,24 @@ def test_bmc_default_provider(proxy_v2_features):
7575
assert settings.get('bmc_default_provider') == 'ipmitool'
7676

7777

78-
@pytest.mark.feature('dhcp-kea-external')
79-
def test_dhcp_kea_feature_present(proxy_v2_features):
78+
@pytest.mark.feature('dhcp')
79+
def test_dhcp_feature_present(proxy_v2_features):
8080
assert 'dhcp' in proxy_v2_features
8181

8282

83-
@pytest.mark.feature('dhcp-kea-external')
84-
def test_dhcp_kea_provider(proxy_v2_features):
83+
@pytest.mark.feature('dhcp')
84+
def test_dhcp_provider(proxy_v2_features):
8585
assert 'dhcp' in proxy_v2_features
8686
settings = proxy_v2_features['dhcp'].get('settings', {})
87-
assert settings.get('use_provider') == 'dhcp_kea_api'
87+
assert settings.get('use_provider') == 'dhcp_kea'
8888

8989

90-
@pytest.mark.feature('dhcp-kea-external')
91-
def test_dhcp_kea_server_settings(proxy_v2_features):
90+
@pytest.mark.feature('dhcp')
91+
def test_dhcp_kea_api_settings(proxy_v2_features):
9292
assert 'dhcp' in proxy_v2_features
9393
settings = proxy_v2_features['dhcp'].get('settings', {})
94-
assert 'server' in settings
95-
assert 'kea_url' in settings
96-
assert settings['kea_url'].endswith(':8000')
97-
assert 'kea_subnet' in settings
98-
assert '/' in settings['kea_subnet']
94+
assert 'kea_api_url' in settings
95+
assert settings['kea_api_url'].endswith(':8000')
96+
if settings.get('managed_subnets'):
97+
assert isinstance(settings['managed_subnets'], list)
98+
assert all('/' in subnet for subnet in settings['managed_subnets'])

0 commit comments

Comments
 (0)