summaryrefslogtreecommitdiff
path: root/tests
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 /tests
parent053302db7217feadec96f30e65f15951082d98d5 (diff)
downloadvyos-ansible-collection-9d5f8043ef86abb5584fb2b4cb2955e8df4501c1.tar.gz
vyos-ansible-collection-9d5f8043ef86abb5584fb2b4cb2955e8df4501c1.zip
Support openvpn vtu interface (#86)
Support openvpn vtu interface Reviewed-by: https://github.com/apps/ansible-zuul
Diffstat (limited to 'tests')
-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
2 files changed, 106 insertions, 0 deletions
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)