Skip to content

Commit

Permalink
Merge branch 'main' into none_value_handling_in_l2_interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
KB-perByte authored Jan 9, 2025
2 parents 77e5f0b + f03aaee commit 774df10
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 9 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/nxos_telemetry_overridden.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "nxos_telemetry - Added support for 'overridden' state to provide complete configuration override capabilities."
5 changes: 5 additions & 0 deletions changelogs/fragments/tests_fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
bugfixes:
- Fixes mixed usage of f-string and format string in action plugin for consistency.
trivial:
- Added tests fixes for nxos_facts.
28 changes: 27 additions & 1 deletion docs/cisco.nxos.nxos_telemetry_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ Parameters
<li>replaced</li>
<li>deleted</li>
<li>gathered</li>
<li>overridden</li>
</ul>
</td>
<td>
Expand Down Expand Up @@ -653,7 +654,7 @@ Examples
# This action will replace telemetry configuration on the device with the
# telemetry configuration defined in the playbook.
- name: Override Telemetry Configuration
- name: Replace Telemetry Configuration
cisco.nxos.nxos_telemetry:
config:
certificate:
Expand All @@ -674,6 +675,31 @@ Examples
destination_group: 55
state: replaced
# Using overridden
# This action will override all telemetry configuration on the device with the
# telemetry configuration defined in the playbook.
- name: Override Telemetry Configuration
cisco.nxos.nxos_telemetry:
config:
certificate:
key: /bootflash/server.key
hostname: localhost
compression: gzip
source_interface: Ethernet1/1
vrf: management
destination_groups:
- id: 2
destination:
ip: 192.168.0.2
port: 50001
protocol: gRPC
encoding: GPB
subscriptions:
- id: 5
destination_group: 55
state: overridden
Return Values
Expand Down
3 changes: 1 addition & 2 deletions plugins/action/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def run(self, tmp=None, task_vars=None):
"msg": (
f"Connection type must be fully qualified name for "
f"network_cli connection type, got {self._play_context.connection}"
)
% self._play_context.connection,
),
}

conn = Connection(self._connection.socket_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class TelemetryArgs(object): # pylint: disable=R0903
"type": "dict",
},
"state": {
"choices": ["merged", "replaced", "deleted", "gathered"],
"choices": ["merged", "replaced", "deleted", "gathered", "overridden"],
"default": "merged",
"type": "str",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def execute_module(self):
warnings = list()

state = self._module.params["state"]
if "overridden" in state:
self._module.fail_json(msg="State <overridden> is invalid for this module.")
# When state is 'deleted', the module_params should not contain data
# under the 'config' key
if "deleted" in state and self._module.params.get("config"):
Expand Down Expand Up @@ -153,7 +151,7 @@ def set_state(self, want, have):
# and does not require any processing using NxosCmdRef objects.
if state == "deleted":
return self._state_deleted(want, have)
elif state == "replaced":
elif state in ["replaced", "overridden"]:
if want == have:
return []
return self._state_replaced(want, have)
Expand Down
28 changes: 27 additions & 1 deletion plugins/modules/nxos_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
- replaced
- deleted
- gathered
- overridden
default: merged
"""
Expand Down Expand Up @@ -267,7 +268,7 @@
# This action will replace telemetry configuration on the device with the
# telemetry configuration defined in the playbook.
- name: Override Telemetry Configuration
- name: Replace Telemetry Configuration
cisco.nxos.nxos_telemetry:
config:
certificate:
Expand All @@ -287,6 +288,31 @@
- id: 5
destination_group: 55
state: replaced
# Using overridden
# This action will override all telemetry configuration on the device with the
# telemetry configuration defined in the playbook.
- name: Override Telemetry Configuration
cisco.nxos.nxos_telemetry:
config:
certificate:
key: /bootflash/server.key
hostname: localhost
compression: gzip
source_interface: Ethernet1/1
vrf: management
destination_groups:
- id: 2
destination:
ip: 192.168.0.2
port: 50001
protocol: gRPC
encoding: GPB
subscriptions:
- id: 5
destination_group: 55
state: overridden
"""
RETURN = """
before:
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/targets/nxos_facts/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ available_network_resources:
- static_routes
- telemetry
- vlans
- vrf_address_family
- vrf_global
- vrf_interfaces
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

- ansible.builtin.assert:
that:
- result is search("argument 'file_pull_timeout' is of type .* and we were unable to convert to int")
- result.msg is ansible.builtin.search("argument 'file_pull_timeout' is of type .* and we were unable to convert to int", multiline=true)

- name: Input validation - param should be type <bool>
register: result
Expand Down
95 changes: 95 additions & 0 deletions tests/unit/modules/network/nxos/test_nxos_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,101 @@ def test_tms_names_idempotent(self):
)
self.execute_module(changed=False, commands=[])

def test_tms_overridden_n9k(self):
# Assumes feature telemetry is enabled
# Similar to replaced state:
# - Modify vrf global config, remove default all other global config.
# - destination-group 2 destination '192.168.0.1' idempotent
# - destination-group 2 destination '192.168.0.2' remove
# - remove all other destination-groups
# - Modify sensor-group 55 and delete all others
# - Modify subscription 7, add 10 and delete all others
self.execute_show_command.return_value = load_fixture(
"nxos_telemetry",
"N9K.cfg",
)
self.get_platform_shortname.return_value = "N9K"
set_module_args(
{
"state": "overridden",
"config": {
"vrf": "blue",
"destination_groups": [
{
"id": 2,
"destination": {
"ip": "192.168.0.1",
"port": 50001,
"protocol": "GRPC",
"encoding": "GPB",
},
},
],
"sensor_groups": [
{
"id": 55,
"data_source": "NX-API",
"path": {
"name": "sys/bgp",
"depth": 0,
"query_condition": "query_condition_xyz",
"filter_condition": "filter_condition_xyz",
},
},
],
"subscriptions": [
{
"id": 7,
"destination_group": 10,
"sensor_group": {
"id": 55,
"sample_interval": 1000,
},
},
{
"id": 10,
"destination_group": 2,
"sensor_group": {
"id": 55,
"sample_interval": 1000,
},
},
],
},
},
ignore_provider_arg,
)
self.execute_module(
changed=True,
commands=[
"telemetry",
"no subscription 3",
"no subscription 5",
"no subscription 4",
"subscription 7",
"no snsr-grp 2 sample-interval 1000",
"no subscription 6",
"no sensor-group 56",
"no sensor-group 2",
"no destination-group 10",
"destination-group 2",
"no ip address 192.168.0.2 port 60001 protocol grpc encoding gpb",
"sensor-group 55",
"data-source NX-API",
"path sys/bgp depth 0 query-condition query_condition_xyz filter-condition filter_condition_xyz",
"subscription 10",
"dst-grp 2",
"snsr-grp 55 sample-interval 1000",
"subscription 7",
"snsr-grp 55 sample-interval 1000",
"no certificate /bootflash/server.key localhost",
"destination-profile",
"no use-compression gzip",
"no source-interface loopback55",
"use-vrf blue",
],
)


def build_args(data, type, state=None, check_mode=None):
if state is None:
Expand Down

0 comments on commit 774df10

Please sign in to comment.