Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added overridden state for cisco.nxos_telemetry #918

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."
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
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
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
Loading