From d81a86b8775044872527397471177d9daa646646 Mon Sep 17 00:00:00 2001 From: Roberto Alfieri Date: Fri, 28 Jul 2023 11:58:46 +0200 Subject: [PATCH] Add templating support for nmstate defined networking configuration * Fixed `nmstate` molecule scenario for `edpm_network_config` role Signed-off-by: Roberto Alfieri --- roles/edpm_network_config/defaults/main.yml | 1 + .../molecule/default/prepare.yml | 6 ++++-- .../molecule/nmstate/converge.yml | 15 +++++++-------- roles/edpm_network_config/tasks/main.yml | 3 +++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/roles/edpm_network_config/defaults/main.yml b/roles/edpm_network_config/defaults/main.yml index 5a6863e74..3d8c31d9d 100644 --- a/roles/edpm_network_config/defaults/main.yml +++ b/roles/edpm_network_config/defaults/main.yml @@ -48,5 +48,6 @@ edpm_network_config_manage_service: true edpm_network_config_nmstate: false edpm_network_config_os_net_config_mappings: {} edpm_network_config_safe_defaults: true +edpm_network_config_with_ansible: true edpm_network_config_template: "" edpm_bond_interface_ovs_options: "bond_mode=active-backup" diff --git a/roles/edpm_network_config/molecule/default/prepare.yml b/roles/edpm_network_config/molecule/default/prepare.yml index d1f006f0c..d41fea67d 100644 --- a/roles/edpm_network_config/molecule/default/prepare.yml +++ b/roles/edpm_network_config/molecule/default/prepare.yml @@ -15,6 +15,7 @@ # under the License. - name: Prepare test_deps hosts: all + become: true roles: - role: ../../../../molecule/common/test_deps test_deps_setup_edpm: true @@ -27,12 +28,13 @@ tasks: - name: Ensure legacy scripts installed - become: true ansible.builtin.package: name: network-scripts state: present when: - ansible_facts['distribution_major_version'] is version('8', '==') - name: Create a dummy network interface - become: true ansible.builtin.command: "ip link add dummy0 type dummy" + register: ip_command_output + changed_when: ip_command_output.rc == 0 + failed_when: ip_command_output.rc != 0 diff --git a/roles/edpm_network_config/molecule/nmstate/converge.yml b/roles/edpm_network_config/molecule/nmstate/converge.yml index dc6a0b896..31cd002de 100644 --- a/roles/edpm_network_config/molecule/nmstate/converge.yml +++ b/roles/edpm_network_config/molecule/nmstate/converge.yml @@ -19,13 +19,12 @@ hosts: all vars: edpm_network_config_tool: nmstate - network_provider: nm - network_state: + edpm_network_config_template: | interfaces: - - name: dummy0 - type: dummy - state: down - ipv4: - enabled: false + - name: dummy0 + type: dummy + state: up + ipv4: + enabled: false roles: - - role: "osp.edpm.edpm_network_config" + - role: osp.edpm.edpm_network_config diff --git a/roles/edpm_network_config/tasks/main.yml b/roles/edpm_network_config/tasks/main.yml index 70f320f11..e469ce240 100644 --- a/roles/edpm_network_config/tasks/main.yml +++ b/roles/edpm_network_config/tasks/main.yml @@ -38,6 +38,9 @@ name: NetworkManager state: restarted when: nm_ovs_status.changed # noqa: no-handler + - name: Render network_config variable + ansible.builtin.set_fact: + network_state: "{{ edpm_network_config_template | from_yaml }}" - name: Load system-roles.network tasks [nmstate] ansible.builtin.include_role: name: "{{ systemrolename }}"