diff --git a/changelogs/fragments/nxos_telemetry_overridden.yaml b/changelogs/fragments/nxos_telemetry_overridden.yaml
new file mode 100644
index 000000000..c9a366efc
--- /dev/null
+++ b/changelogs/fragments/nxos_telemetry_overridden.yaml
@@ -0,0 +1,2 @@
+minor_changes:
+ - "nxos_telemetry - Added support for 'overridden' state to provide complete configuration override capabilities."
diff --git a/changelogs/fragments/tests_fix.yaml b/changelogs/fragments/tests_fix.yaml
new file mode 100644
index 000000000..bd6d86e79
--- /dev/null
+++ b/changelogs/fragments/tests_fix.yaml
@@ -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.
diff --git a/docs/cisco.nxos.nxos_telemetry_module.rst b/docs/cisco.nxos.nxos_telemetry_module.rst
index d1394ccf0..9d6e58535 100644
--- a/docs/cisco.nxos.nxos_telemetry_module.rst
+++ b/docs/cisco.nxos.nxos_telemetry_module.rst
@@ -565,6 +565,7 @@ Parameters
replaced
deleted
gathered
+ overridden
@@ -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:
@@ -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
diff --git a/plugins/action/nxos.py b/plugins/action/nxos.py
index e57c08aeb..c636c636d 100644
--- a/plugins/action/nxos.py
+++ b/plugins/action/nxos.py
@@ -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)
diff --git a/plugins/module_utils/network/nxos/argspec/telemetry/telemetry.py b/plugins/module_utils/network/nxos/argspec/telemetry/telemetry.py
index 7da72979b..b6b6c6ef3 100644
--- a/plugins/module_utils/network/nxos/argspec/telemetry/telemetry.py
+++ b/plugins/module_utils/network/nxos/argspec/telemetry/telemetry.py
@@ -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",
},
diff --git a/plugins/module_utils/network/nxos/config/telemetry/telemetry.py b/plugins/module_utils/network/nxos/config/telemetry/telemetry.py
index da3f77439..9f3e109ed 100644
--- a/plugins/module_utils/network/nxos/config/telemetry/telemetry.py
+++ b/plugins/module_utils/network/nxos/config/telemetry/telemetry.py
@@ -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 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"):
@@ -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)
diff --git a/plugins/modules/nxos_telemetry.py b/plugins/modules/nxos_telemetry.py
index 89a58e2d2..4020c80e0 100644
--- a/plugins/modules/nxos_telemetry.py
+++ b/plugins/modules/nxos_telemetry.py
@@ -199,6 +199,7 @@
- replaced
- deleted
- gathered
+ - overridden
default: merged
"""
@@ -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:
@@ -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:
diff --git a/tests/integration/targets/nxos_facts/vars/main.yml b/tests/integration/targets/nxos_facts/vars/main.yml
index f010eb0ac..65cf3ce18 100644
--- a/tests/integration/targets/nxos_facts/vars/main.yml
+++ b/tests/integration/targets/nxos_facts/vars/main.yml
@@ -28,4 +28,6 @@ available_network_resources:
- static_routes
- telemetry
- vlans
+ - vrf_address_family
- vrf_global
+ - vrf_interfaces
diff --git a/tests/integration/targets/nxos_file_copy/tests/cli/input_validation.yaml b/tests/integration/targets/nxos_file_copy/tests/cli/input_validation.yaml
index bcda7b4fa..e05edc3fb 100644
--- a/tests/integration/targets/nxos_file_copy/tests/cli/input_validation.yaml
+++ b/tests/integration/targets/nxos_file_copy/tests/cli/input_validation.yaml
@@ -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
register: result
diff --git a/tests/unit/modules/network/nxos/test_nxos_telemetry.py b/tests/unit/modules/network/nxos/test_nxos_telemetry.py
index 2c8027443..3e64d93b0 100644
--- a/tests/unit/modules/network/nxos/test_nxos_telemetry.py
+++ b/tests/unit/modules/network/nxos/test_nxos_telemetry.py
@@ -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:
|