summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGomathiselviS <gomathiselvi@gmail.com>2020-10-08 12:09:25 -0400
committerGitHub <noreply@github.com>2020-10-08 16:09:25 +0000
commit9d5f8043ef86abb5584fb2b4cb2955e8df4501c1 (patch)
treeebba0ae38dbaaa891e19cea5f3bef0989996d2eb
parent053302db7217feadec96f30e65f15951082d98d5 (diff)
downloadvyos.vyos-9d5f8043ef86abb5584fb2b4cb2955e8df4501c1.tar.gz
vyos.vyos-9d5f8043ef86abb5584fb2b4cb2955e8df4501c1.zip
Support openvpn vtu interface (#86)
Support openvpn vtu interface Reviewed-by: https://github.com/apps/ansible-zuul
-rw-r--r--changelogs/fragments/86-openvpn_vtu_interface.yaml3
-rw-r--r--plugins/module_utils/network/vyos/facts/interfaces/interfaces.py9
-rw-r--r--plugins/module_utils/network/vyos/utils/utils.py2
-rw-r--r--tests/unit/modules/network/vyos/fixtures/vyos_interfaces_config.cfg6
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_interfaces.py100
5 files changed, 118 insertions, 2 deletions
diff --git a/changelogs/fragments/86-openvpn_vtu_interface.yaml b/changelogs/fragments/86-openvpn_vtu_interface.yaml
new file mode 100644
index 0000000..287f05b
--- /dev/null
+++ b/changelogs/fragments/86-openvpn_vtu_interface.yaml
@@ -0,0 +1,3 @@
+---
+bugfixes:
+ - Added openvpn vtu interface support.
diff --git a/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py b/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py
index 358dd9d..13f22e1 100644
--- a/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py
+++ b/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py
@@ -42,6 +42,11 @@ class InterfacesFacts(object):
self.generated_spec = utils.generate_dict(facts_argument_spec)
+ def get_device_data(self, connection):
+
+ data = connection.get_config(flags=["| grep interfaces"])
+ return data
+
def populate_facts(self, connection, ansible_facts, data=None):
"""Populate the facts for interfaces
:param connection: the device connection
@@ -51,11 +56,11 @@ class InterfacesFacts(object):
:returns: facts
"""
if not data:
- data = connection.get_config(flags=["| grep interfaces"])
+ data = self.get_device_data(connection)
objs = []
interface_names = findall(
- r"^set interfaces (?:ethernet|bonding|vti|loopback|vxlan) (?:\'*)(\S+)(?:\'*)",
+ r"^set interfaces (?:ethernet|bonding|vti|loopback|vxlan|openvpn) (?:\'*)(\S+)(?:\'*)",
data,
M,
)
diff --git a/plugins/module_utils/network/vyos/utils/utils.py b/plugins/module_utils/network/vyos/utils/utils.py
index bcf6fc2..7ce4688 100644
--- a/plugins/module_utils/network/vyos/utils/utils.py
+++ b/plugins/module_utils/network/vyos/utils/utils.py
@@ -31,6 +31,8 @@ def get_interface_type(interface):
return "vti"
elif interface.startswith("lo"):
return "loopback"
+ elif interface.startswith("vtun"):
+ return "openvpn"
def dict_delete(base, comparable):
diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_interfaces_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_interfaces_config.cfg
new file mode 100644
index 0000000..0876916
--- /dev/null
+++ b/tests/unit/modules/network/vyos/fixtures/vyos_interfaces_config.cfg
@@ -0,0 +1,6 @@
+set interfaces ethernet eth0 address 'dhcp'
+set interfaces ethernet eth0 hw-id '08:00:27:7c:85:05'
+set interfaces ethernet eth1 description 'test-interface'
+set interfaces ethernet eth2 hw-id '08:00:27:04:85:99'
+set interfaces ethernet eth3 hw-id '08:00:27:1c:82:d1'
+set interfaces loopback 'lo'
diff --git a/tests/unit/modules/network/vyos/test_vyos_interfaces.py b/tests/unit/modules/network/vyos/test_vyos_interfaces.py
new file mode 100644
index 0000000..9b832a0
--- /dev/null
+++ b/tests/unit/modules/network/vyos/test_vyos_interfaces.py
@@ -0,0 +1,100 @@
+# (c) 2016 Red Hat Inc.
+#
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+
+# Make coding more python3-ish
+from __future__ import absolute_import, division, print_function
+
+__metaclass__ = type
+
+from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch
+from ansible_collections.vyos.vyos.plugins.modules import (
+ vyos_interfaces,
+)
+from ansible_collections.vyos.vyos.tests.unit.modules.utils import (
+ set_module_args,
+)
+from .vyos_module import TestVyosModule, load_fixture
+
+
+class TestVyosFirewallInterfacesModule(TestVyosModule):
+
+ module = vyos_interfaces
+
+ def setUp(self):
+ super(TestVyosFirewallInterfacesModule, self).setUp()
+ self.mock_get_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config"
+ )
+ self.get_config = self.mock_get_config.start()
+
+ self.mock_load_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config"
+ )
+ self.load_config = self.mock_load_config.start()
+
+ self.mock_get_resource_connection_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection"
+ )
+ self.get_resource_connection_config = (
+ self.mock_get_resource_connection_config.start()
+ )
+
+ self.mock_get_resource_connection_facts = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection"
+ )
+ self.get_resource_connection_facts = (
+ self.mock_get_resource_connection_facts.start()
+ )
+
+ self.mock_execute_show_command = patch(
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos."
+ "facts.interfaces.interfaces.InterfacesFacts.get_device_data"
+ )
+ self.execute_show_command = self.mock_execute_show_command.start()
+
+ def tearDown(self):
+ super(TestVyosFirewallInterfacesModule, self).tearDown()
+ self.mock_get_resource_connection_config.stop()
+ self.mock_get_resource_connection_facts.stop()
+ self.mock_get_config.stop()
+ self.mock_load_config.stop()
+ self.mock_execute_show_command.stop()
+
+ def load_fixtures(self, commands=None):
+ def load_from_file(*args, **kwargs):
+ return load_fixture("vyos_interfaces_config.cfg")
+
+ self.execute_show_command.side_effect = load_from_file
+
+ def test_vyos_interfaces_merged(self):
+ set_module_args(
+ dict(
+ config=[
+ dict(name="bond1", description="Bond - 1", enabled=True),
+ dict(name="vtun1", description="vtun - 1", enabled=True),
+ ],
+ state="merged",
+ )
+ )
+
+ commands = [
+ "set interfaces bonding bond1 description 'Bond - 1'",
+ "delete interfaces bonding bond1 disable",
+ "set interfaces openvpn vtun1 description 'vtun - 1'",
+ "delete interfaces openvpn vtun1 disable",
+ ]
+ self.execute_module(changed=True, commands=commands)