From f848949c765f526f214dd9e7a5a79c54f21e15c8 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Sun, 29 Nov 2020 21:38:25 -0500 Subject: [PATCH] RFE: Support dummy interfaces Signed-off-by: Wen Liang --- examples/dummy_simple.yml | 17 +++++++++++ library/network_connections.py | 2 ++ .../network_lsr/argument_validator.py | 1 + tests/ensure_provider_tests.py | 1 + tests/playbooks/tests_dummy.yml | 30 +++++++++++++++++++ tests/tasks/create_dummy_profile.yml | 15 ++++++++++ tests/tests_dummy_nm.yml | 19 ++++++++++++ 7 files changed, 85 insertions(+) create mode 100644 examples/dummy_simple.yml create mode 100644 tests/playbooks/tests_dummy.yml create mode 100644 tests/tasks/create_dummy_profile.yml create mode 100644 tests/tests_dummy_nm.yml diff --git a/examples/dummy_simple.yml b/examples/dummy_simple.yml new file mode 100644 index 0000000..db2266a --- /dev/null +++ b/examples/dummy_simple.yml @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: BSD-3-Clause +--- +- hosts: all + vars: + network_connections: + # Specify the dummy profile + - name: dummy0 + state: up + type: dummy + interface_name: dummy0 + ip: + address: + - "192.0.2.42/30" + + roles: + - linux-system-roles.network +... diff --git a/library/network_connections.py b/library/network_connections.py index 6e07b8b..cefaa90 100644 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -821,6 +821,8 @@ class NMUtil: s_bond.add_option("miimon", str(connection["bond"]["miimon"])) elif connection["type"] == "team": s_con.set_property(NM.SETTING_CONNECTION_TYPE, NM.SETTING_TEAM_SETTING_NAME) + elif connection["type"] == "dummy": + s_con.set_property(NM.SETTING_CONNECTION_TYPE, NM.SETTING_DUMMY_SETTING_NAME) elif connection["type"] == "vlan": s_con.set_property(NM.SETTING_CONNECTION_TYPE, NM.SETTING_VLAN_SETTING_NAME) s_vlan = self.connection_ensure_setting(con, NM.SettingVlan) diff --git a/module_utils/network_lsr/argument_validator.py b/module_utils/network_lsr/argument_validator.py index 065b697..26ae253 100644 --- a/module_utils/network_lsr/argument_validator.py +++ b/module_utils/network_lsr/argument_validator.py @@ -1006,6 +1006,7 @@ class ArgValidator_DictConnection(ArgValidatorDict): "vlan", "macvlan", "wireless", + "dummy", ] VALID_SLAVE_TYPES = ["bridge", "bond", "team"] diff --git a/tests/ensure_provider_tests.py b/tests/ensure_provider_tests.py index 925746e..e4aee5f 100755 --- a/tests/ensure_provider_tests.py +++ b/tests/ensure_provider_tests.py @@ -59,6 +59,7 @@ EXTRA_RUN_CONDITION = "extra_run_condition" NM_ONLY_TESTS = { "playbooks/tests_802_1x_updated.yml": {}, "playbooks/tests_802_1x.yml": {}, + "playbooks/tests_dummy.yml": {}, "playbooks/tests_ethtool_features.yml": { MINIMUM_VERSION: "'1.20.0'", "comment": "# NetworkManager 1.20.0 introduced ethtool settings support", diff --git a/tests/playbooks/tests_dummy.yml b/tests/playbooks/tests_dummy.yml new file mode 100644 index 0000000..8fe8762 --- /dev/null +++ b/tests/playbooks/tests_dummy.yml @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: BSD-3-Clause +--- +- hosts: all + vars: + interface: dummy0 + profile: "{{ interface }}" + lsr_fail_debug: + - __network_connections_result + tasks: + - debug: + msg: "this is: playbooks/tests_dummy.yml" + tags: + - always + + - block: + - include_tasks: tasks/run_test.yml + vars: + lsr_description: Create a dummy interface + lsr_setup: + - tasks/delete_interface.yml + - tasks/assert_device_absent.yml + lsr_test: + - tasks/create_dummy_profile.yml + lsr_assert: + - tasks/assert_profile_present.yml + - tasks/assert_device_present.yml + lsr_cleanup: + - tasks/cleanup_profile+device.yml + tags: + - tests::dummy:create diff --git a/tests/tasks/create_dummy_profile.yml b/tests/tasks/create_dummy_profile.yml new file mode 100644 index 0000000..950be6b --- /dev/null +++ b/tests/tasks/create_dummy_profile.yml @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: BSD-3-Clause +--- +- include_role: + name: linux-system-roles.network + vars: + network_connections: + - name: "{{ interface }}" + state: up + type: dummy + ip: + address: + - "192.0.2.42/30" +- debug: + var: __network_connections_result +... diff --git a/tests/tests_dummy_nm.yml b/tests/tests_dummy_nm.yml new file mode 100644 index 0000000..63bb99b --- /dev/null +++ b/tests/tests_dummy_nm.yml @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: BSD-3-Clause +# This file was generated by ensure_provider_tests.py +--- +# set network provider and gather facts +- hosts: all + name: Run playbook 'playbooks/tests_dummy.yml' with nm as provider + tasks: + - name: Set network provider to 'nm' + set_fact: + network_provider: nm + tags: + - always + + +# The test requires or should run with NetworkManager, therefore it cannot run +# on RHEL/CentOS 6 +- import_playbook: playbooks/tests_dummy.yml + when: + - ansible_distribution_major_version != '6'