summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRohit Thakur <rohitthakur2590@outlook.com>2020-05-06 20:20:08 +0530
committerRohit Thakur <rohitthakur2590@outlook.com>2020-05-06 20:20:08 +0530
commit3ab82e0e018bf0ca02f14391d03e15b3c259da0a (patch)
tree2181da8342fbe2d47b46ff78b4ca532ed68c3f34
parent77e8b041b2983415ac36eb6264f6e385ac87b074 (diff)
downloadvyos-ansible-old-3ab82e0e018bf0ca02f14391d03e15b3c259da0a.tar.gz
vyos-ansible-old-3ab82e0e018bf0ca02f14391d03e15b3c259da0a.zip
linters fix
Signed-off-by: Rohit Thakur <rohitthakur2590@outlook.com>
-rw-r--r--plugins/module_utils/network/vyos/config/static_routes/static_routes.py8
-rw-r--r--plugins/modules/vyos_static_routes.py257
-rw-r--r--tests/integration/targets/vyos_static_routes/tests/cli/deleted.yaml62
-rw-r--r--tests/integration/targets/vyos_static_routes/tests/cli/deleted_nh.yaml68
-rw-r--r--tests/integration/targets/vyos_static_routes/vars/main.yaml26
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_static_routes.py12
6 files changed, 23 insertions, 410 deletions
diff --git a/plugins/module_utils/network/vyos/config/static_routes/static_routes.py b/plugins/module_utils/network/vyos/config/static_routes/static_routes.py
index e93d4ee..b359dbb 100644
--- a/plugins/module_utils/network/vyos/config/static_routes/static_routes.py
+++ b/plugins/module_utils/network/vyos/config/static_routes/static_routes.py
@@ -160,7 +160,7 @@ class Static_routes(ConfigBase):
routes = self._get_routes(want)
for r in routes:
h_item = self.search_route_in_have(have, r["dest"])
- if self.state == "merged" or self.state == "rendered":
+ if self.state in ("merged", "rendered"):
commands.extend(self._state_merged(want=r, have=h_item))
elif self.state == "replaced":
commands.extend(self._state_replaced(want=r, have=h_item))
@@ -253,12 +253,6 @@ class Static_routes(ConfigBase):
afi=item["afi"], remove=True
)
)
- for r in routes:
- h_route = self.search_route_in_have(have, r["dest"])
- if h_route:
- commands.extend(
- self._render_updates(r, h_route, opr=False)
- )
else:
routes = self._get_routes(have)
if self._is_ip_route_exist(routes):
diff --git a/plugins/modules/vyos_static_routes.py b/plugins/modules/vyos_static_routes.py
index 6e50203..e71114a 100644
--- a/plugins/modules/vyos_static_routes.py
+++ b/plugins/modules/vyos_static_routes.py
@@ -30,16 +30,13 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-ANSIBLE_METADATA = {
- "metadata_version": "1.1",
- "status": ["preview"],
- "supported_by": "network",
-}
+ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}
DOCUMENTATION = """module: vyos_static_routes
-short_description: Manages attributes of static routes on VyOS network devices.
+short_description: Static routes resource module
description: This module manages attributes of static routes on VyOS network devices.
notes:
+version_added: "1.0.0"
- Tested against VyOS 1.1.8 (helium).
- This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html).
author:
@@ -114,13 +111,12 @@ options:
type: str
running_config:
description:
- - The module, by default, will connect to the remote device and retrieve the current
- running-config to use as a base for comparing against the contents of source.
- There are times when it is not desirable to have the task get the current running-config
- for every task in a playbook. The I(running_config) argument allows the implementer
- to pass in the configuration to use as the base config for comparison. This
- value of this option should be the output received from device by executing
- command C(show configuration commands | grep 'static route')
+ - This option is used only with state I(parsed).
+ - The value of this option should be the output received from the VyOS device by executing
+ the command B(show configuration commands | grep static route).
+ - The state I(parsed) reads the configuration from C(running_config) option and transforms
+ it into Ansible structured data as per the resource module's argspec and the value is then
+ returned in the I(parsed) key within the result.
type: str
state:
description:
@@ -145,7 +141,7 @@ EXAMPLES = """
# vyos@vyos:~$ show configuration commands | grep static
#
- name: Merge the provided configuration with the exisiting running configuration
- vyos_static_routes:
+ vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: 'ipv4'
@@ -259,7 +255,7 @@ EXAMPLES = """
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
#
- name: Replace device configurations of listed static routes with provided configurations
- vyos_static_routes:
+ vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: 'ipv4'
@@ -435,7 +431,7 @@ EXAMPLES = """
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
#
- name: Overrides all device configuration with provided configuration
- vyos_static_routes:
+ vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: 'ipv4'
@@ -531,92 +527,6 @@ EXAMPLES = """
# set protocols static route 198.0.2.48/28 next-hop '192.0.2.18'
-# Using deleted to delete static route based on destination
-#
-# Before state
-# -------------
-#
-# vyos@vyos:~$ show configuration commands| grep static
-# set protocols static route 192.0.2.32/28 'blackhole'
-# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'
-# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'
-# set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
-# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
-# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
-#
-- name: Delete static route per destination.
- vyos_static_routes:
- config:
- - address_families:
- - afi: 'ipv4'
- routes:
- - dest: '192.0.2.32/28'
- - afi: 'ipv6'
- routes:
- - dest: '2001:db8:1000::/36'
- state: deleted
-#
-#
-# ------------------------
-# Module Execution Results
-# ------------------------
-#
-# "before": [
-# {
-# "address_families": [
-# {
-# "afi": "ipv4",
-# "routes": [
-# {
-# "blackhole_config": {
-# "type": "blackhole"
-# },
-# "dest": "192.0.2.32/28",
-# "next_hops": [
-# {
-# "forward_router_address": "192.0.2.6"
-# },
-# {
-# "forward_router_address": "192.0.2.7"
-# }
-# ]
-# }
-# ]
-# },
-# {
-# "afi": "ipv6",
-# "routes": [
-# {
-# "blackhole_config": {
-# "distance": 2
-# },
-# "dest": "2001:db8:1000::/36",
-# "next_hops": [
-# {
-# "forward_router_address": "2001:db8:2000:2::1"
-# },
-# {
-# "forward_router_address": "2001:db8:2000:2::2"
-# }
-# ]
-# }
-# ]
-# }
-# ]
-# }
-# ]
-# "commands": [
-# "delete protocols static route 192.0.2.32/28",
-# "delete protocols static route6 2001:db8:1000::/36"
-# ]
-#
-# "after": []
-# After state
-# ------------
-# vyos@vyos# run show configuration commands | grep static
-# set protocols 'static'
-
-
# Using deleted to delete static route based on afi
#
# Before state
@@ -631,7 +541,7 @@ EXAMPLES = """
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
#
- name: Delete static route based on afi.
- vyos_static_routes:
+ vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: 'ipv4'
@@ -713,7 +623,7 @@ EXAMPLES = """
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
#
- name: Delete all the static routes.
- vyos_static_routes:
+ vyos.vyos.vyos_static_routes:
config:
state: deleted
#
@@ -778,141 +688,11 @@ EXAMPLES = """
# set protocols 'static'
-# Using deleted to delete static route based on next-hop
-#
-# Before state
-# -------------
-#
-# vyos@vyos:~$ show configuration commands| grep static
-# set protocols static route 192.0.2.32/28 'blackhole'
-# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'
-# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'
-# set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
-# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
-# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
-#
-- name: Delete static routes per next-hops
- vyos_static_routes:
- config:
- - address_families:
- - afi: 'ipv4'
- routes:
- - dest: '192.0.2.32/28'
- next-hops:
- - forward_router_address: '192.0.2.6'
- - afi: 'ipv6'
- routes:
- - dest: '2001:db8:1000::/36'
- next-hops:
- - forward_router_address: '2001:db8:2000:2::1'
- state: deleted
-#
-#
-# ------------------------
-# Module Execution Results
-# ------------------------
-#
-# "before": [
-# {
-# "address_families": [
-# {
-# "afi": "ipv4",
-# "routes": [
-# {
-# "blackhole_config": {
-# "type": "blackhole"
-# },
-# "dest": "192.0.2.32/28",
-# "next_hops": [
-# {
-# "forward_router_address": "192.0.2.6"
-# },
-# {
-# "forward_router_address": "192.0.2.7"
-# }
-# ]
-# }
-# ]
-# },
-# {
-# "afi": "ipv6",
-# "routes": [
-# {
-# "blackhole_config": {
-# "distance": 2
-# },
-# "dest": "2001:db8:1000::/36",
-# "next_hops": [
-# {
-# "forward_router_address": "2001:db8:2000:2::1"
-# },
-# {
-# "forward_router_address": "2001:db8:2000:2::2"
-# }
-# ]
-# }
-# ]
-# }
-# ]
-# }
-# ]
-# "commands": [
-# "delete protocols static route 192.0.2.32/28 next-hop '192.0.2.6'",
-# "delete protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'"
-# ]
-#
-# "after": [
-# {
-# "address_families": [
-# {
-# "afi": "ipv4",
-# "routes": [
-# {
-# "blackhole_config": {
-# "type": "blackhole"
-# },
-# "dest": "192.0.2.32/28",
-# "next_hops": [
-# {
-# "forward_router_address": "192.0.2.7"
-# }
-# ]
-# }
-# ]
-# },
-# {
-# "afi": "ipv6",
-# "routes": [
-# {
-# "blackhole_config": {
-# "distance": 2
-# },
-# "dest": "2001:db8:1000::/36",
-# "next_hops": [
-# {
-# "forward_router_address": "2001:db8:2000:2::2"
-# }
-# ]
-# }
-# ]
-# }
-# ]
-# }
-# ]
-# After state
-# ------------
-# vyos@vyos:~$ show configuration commands| grep static
-# set protocols static route 192.0.2.32/28 'blackhole'
-# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'
-# set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
-# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
-
-
# Using rendered
#
#
- name: Render the commands for provided configuration
- vyos_static_routes:
+ vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: 'ipv4'
@@ -955,8 +735,8 @@ EXAMPLES = """
# Using parsed
#
#
-- name: Render the commands for provided configuration
- vyos_static_routes:
+- name: Parse the provided running configuration
+ vyos.vyos.vyos_static_routes:
running_config:
"set protocols static route 192.0.2.32/28 'blackhole'
set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'
@@ -1026,7 +806,7 @@ EXAMPLES = """
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
#
- name: Gather listed static routes with provided configurations
- vyos_static_routes:
+ vyos.vyos.vyos_static_routes:
config:
state: gathered
#
@@ -1137,6 +917,7 @@ def main():
required_if = [
("state", "merged", ("config",)),
("state", "replaced", ("config",)),
+ ("state", "rendered", ("config",)),
("state", "overridden", ("config",)),
("state", "parsed", ("running_config",)),
]
diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/deleted.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/deleted.yaml
deleted file mode 100644
index 7f098f5..0000000
--- a/tests/integration/targets/vyos_static_routes/tests/cli/deleted.yaml
+++ /dev/null
@@ -1,62 +0,0 @@
----
-- debug:
- msg: Start vyos_static_routes deleted integration tests ansible_connection={{
- ansible_connection }}
-
-- include_tasks: _populate.yaml
-
-- block:
-
- - name: Delete static route based on destiation.
- register: result
- vyos.vyos.vyos_static_routes: &id001
- config:
-
- - address_families:
-
- - afi: ipv4
- routes:
-
- - dest: 192.0.2.32/28
-
- - afi: ipv6
- routes:
-
- - dest: 2001:db8:1000::/36
- state: deleted
-
- - name: Assert that the before dicts were correctly generated
- assert:
- that:
- - "{{ populate | symmetric_difference(result['before']) |length == 0 }}"
-
- - name: Assert that the correct set of commands were generated
- assert:
- that:
- - "{{ deleted_dest['commands'] | symmetric_difference(result['commands'])\
- \ |length == 0 }}"
-
- - name: Assert that the after dicts were correctly generated
- assert:
- that:
- - "{{ deleted_dest['after'] | symmetric_difference(result['after']) |length\
- \ == 0 }}"
-
- - name: Delete attributes of given interfaces (IDEMPOTENT)
- register: result
- vyos.vyos.vyos_static_routes: *id001
-
- - name: Assert that the previous task was idempotent
- assert:
- that:
- - result.changed == false
- - result.commands|length == 0
-
- - name: Assert that the before dicts were correctly generated
- assert:
- that:
- - "{{ deleted_dest['after'] | symmetric_difference(result['before']) |length\
- \ == 0 }}"
- always:
-
- - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/deleted_nh.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/deleted_nh.yaml
deleted file mode 100644
index f6075d2..0000000
--- a/tests/integration/targets/vyos_static_routes/tests/cli/deleted_nh.yaml
+++ /dev/null
@@ -1,68 +0,0 @@
----
-- debug:
- msg: Start vyos_static_routes deleted integration tests ansible_connection={{
- ansible_connection }}
-
-- include_tasks: _populate.yaml
-
-- block:
-
- - name: Delete static route based on next_hop.
- register: result
- vyos.vyos.vyos_static_routes: &id001
- config:
-
- - address_families:
-
- - afi: ipv4
- routes:
-
- - dest: 192.0.2.32/28
- next_hops:
-
- - forward_router_address: 192.0.2.9
-
- - afi: ipv6
- routes:
-
- - dest: 2001:db8:1000::/36
- next_hops:
-
- - forward_router_address: 2001:db8:2000:2::1
- state: deleted
-
- - name: Assert that the before dicts were correctly generated
- assert:
- that:
- - "{{ populate | symmetric_difference(result['before']) |length == 0 }}"
-
- - name: Assert that the correct set of commands were generated
- assert:
- that:
- - "{{ deleted_nh['commands'] | symmetric_difference(result['commands'])\
- \ |length == 0 }}"
-
- - name: Assert that the after dicts were correctly generated
- assert:
- that:
- - "{{ deleted_nh['after'] | symmetric_difference(result['after']) |length\
- \ == 0 }}"
-
- - name: Delete attributes of given interfaces (IDEMPOTENT)
- register: result
- vyos.vyos.vyos_static_routes: *id001
-
- - name: Assert that the previous task was idempotent
- assert:
- that:
- - result.changed == false
- - result.commands|length == 0
-
- - name: Assert that the before dicts were correctly generated
- assert:
- that:
- - "{{ deleted_nh['after'] | symmetric_difference(result['before']) |length\
- \ == 0 }}"
- always:
-
- - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_static_routes/vars/main.yaml b/tests/integration/targets/vyos_static_routes/vars/main.yaml
index 93b875f..6ce4cea 100644
--- a/tests/integration/targets/vyos_static_routes/vars/main.yaml
+++ b/tests/integration/targets/vyos_static_routes/vars/main.yaml
@@ -94,31 +94,7 @@ rendered:
- set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
- set protocols static route6 2001:db8:1000::/36 blackhole distance '2'
- set protocols static route6 2001:db8:1000::/36
-deleted_dest:
- commands:
- - delete protocols static route 192.0.2.32/28
- - delete protocols static route6 2001:db8:1000::/36
- after: []
-deleted_nh:
- commands:
- - delete protocols static route 192.0.2.32/28 next-hop '192.0.2.9'
- - delete protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'
- after:
- - address_families:
- - afi: ipv4
- routes:
- - dest: 192.0.2.32/28
- blackhole_config:
- type: blackhole
- next_hops:
- - forward_router_address: 192.0.2.10
- - afi: ipv6
- routes:
- - dest: 2001:db8:1000::/36
- blackhole_config:
- distance: 2
- next_hops:
- - forward_router_address: 2001:db8:2000:2::2
+
deleted_afi_all:
commands:
- delete protocols static route
diff --git a/tests/unit/modules/network/vyos/test_vyos_static_routes.py b/tests/unit/modules/network/vyos/test_vyos_static_routes.py
index 3646d61..85c0842 100644
--- a/tests/unit/modules/network/vyos/test_vyos_static_routes.py
+++ b/tests/unit/modules/network/vyos/test_vyos_static_routes.py
@@ -277,17 +277,9 @@ class TestVyosStaticRoutesModule(TestVyosModule):
def test_vyos_static_routes_deleted(self):
set_module_args(
dict(
- config=[
- dict(
- address_families=[
- dict(
- afi="ipv4", routes=[dict(dest="192.0.2.32/28")]
- )
- ]
- )
- ],
+ config=[dict(address_families=[dict(afi="ipv4")])],
state="deleted",
)
)
- commands = ["delete protocols static route 192.0.2.32/28"]
+ commands = ["delete protocols static route"]
self.execute_module(changed=True, commands=commands)