summaryrefslogtreecommitdiff
path: root/test/integration/targets/nxos_telemetry/tests/common/replaced.yaml
blob: 6ddcaaad8ded3b34bdc09f947ecc88347ca4d014 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
---
- debug: msg="START connection={{ ansible_connection }} nxos_telemetry replaced sanity test"

- set_fact: source_interface="Loopback55"
  when: imagetag and (major_version is version_compare('9.1', 'ge'))

- set_fact: command_list_length=27
- set_fact: command_list_length=28
  when: imagetag and (major_version is version_compare('9.1', 'ge'))

- set_fact: dict_facts_length=6
- set_fact: dict_facts_length=7
  when: imagetag and (major_version is version_compare('9.1', 'ge'))

- name: Setup - disable feature telemetry
  nxos_feature: &setup_teardown
    feature: telemetry
    state: disabled
  ignore_errors: yes

- name: Setup - enable feature telemetry
  nxos_feature:
    feature: telemetry
    state: enabled

- name: Setup - add initial telemetry config
  cli_config:
    config: |
      telemetry
        certificate test_cert host.example.com
        destination-profile
          use-vrf blue
          use-compression gzip
        destination-group 2
          ip address 192.168.0.1 port 50001 protocol gRPC encoding GPB
          ip address 192.168.0.2 port 60001 protocol gRPC encoding GPB
        destination-group 10
          ip address 192.168.0.1 port 50001 protocol gRPC encoding GPB
          ip address 192.168.0.2 port 60001 protocol gRPC encoding GPB
          ip address 192.168.1.1 port 55 protocol HTTP encoding JSON
          ip address 192.168.1.2 port 100 protocol gRPC encoding GPB
        destination-group 99
        sensor-group 2
          data-source NX-API
          path "show bgp l2vpn evpn summary" depth unbounded query-condition foo filter-condition foo
        sensor-group 8
          data-source NX-API
          path "show ip bgp neighbors" depth 0 query-condition foo filter-condition foo
        sensor-group 55
          data-source DME
          path sys/bgp/inst/dom-default/peer-[10.10.10.11]/ent-[10.10.10.11] depth 0 query-condition foo filter-condition foo
          path sys/ospf depth 0 query-condition foo filter-condition or(eq(ethpmPhysIf.operSt,"down"),eq(ethpmPhysIf.operSt,"up"))
        sensor-group 77
        subscription 44
          dst-grp 2
          dst-grp 10
          snsr-grp 2 sample-interval 2000
          snsr-grp 8 sample-interval 2000
        subscription 55
          dst-grp 10
          snsr-grp 55 sample-interval 2000
        subscription 99
          dst-grp 2
          dst-grp 99
          snsr-grp 8 sample-interval 90000
          snsr-grp 77 sample-interval 2000
- name: Setup - add initial source-interface telemetry config
  cli_config:
    config: |
      telemetry
        destination-profile
          source-interface loopback55
  when: imagetag and (major_version is version_compare('9.1', 'ge'))

- block:
  - name: Gather Telemetry Facts Before Changes
    nxos_facts: &facts
      gather_subset:
        - '!all'
        - '!min'
      gather_network_resources:
        - telemetry

  - name: Telemetry - replaced
    nxos_telemetry: &replace
      state: 'replaced'
      config:
        certificate:
          key: /file_dir/new_server.key
          hostname: newhost.example.com
        vrf: management
        compression: gzip
        destination_groups:
          - id: 2
            destination:
              ip: 192.168.0.1
              port: 65001
              protocol: grpc
              encoding: gpb
          - id: 2
            destination:
              ip: 192.168.0.3
              port: 55001
              protocol: grpc
              encoding: gpb
        sensor_groups:
          - id: 100
            data_source: NX-API
            path:
              name: '"show bgp l2vpn evpn summary"'
              depth: unbounded
              query_condition: foo
              filter_condition: foo
        subscriptions:
          - id: 99
            destination_group: 2
            sensor_group:
              id: 100
              sample_interval: 2000
    register: result

  - assert:
      that:
        - "result.changed == true"
        - "result.before|length == {{ dict_facts_length }}"
        - "result.before.certificate|length == 2"
        - "result.before.destination_groups|length == 7"
        - "result.before.sensor_groups|length == 8"
        - "result.before.subscriptions|length == 10"
        - "'telemetry' in result.commands"
        - "'no subscription 55' in result.commands"
        - "'subscription 99' in result.commands"
        - "'no dst-grp 99' in result.commands"
        - "'no snsr-grp 8 sample-interval 90000' in result.commands"
        - "'no snsr-grp 77 sample-interval 2000' in result.commands"
        - "'no subscription 44' in result.commands"
        - "'no sensor-group 55' in result.commands"
        - "'no sensor-group 8' in result.commands"
        - "'no sensor-group 2' in result.commands"
        - "'no sensor-group 77' in result.commands"
        - "'no destination-group 99' in result.commands"
        - "'no destination-group 10' in result.commands"
        - "'destination-group 2' in result.commands"
        - "'no ip address 192.168.0.1 port 50001 protocol grpc encoding gpb' in result.commands"
        - "'no ip address 192.168.0.2 port 60001 protocol grpc encoding gpb' in result.commands"
        - "'destination-group 2' in result.commands"
        - "'ip address 192.168.0.1 port 65001 protocol grpc encoding gpb' in result.commands"
        - "'ip address 192.168.0.3 port 55001 protocol grpc encoding gpb' in result.commands"
        - "'sensor-group 100' in result.commands"
        - result.commands is search("path .*show bgp l2vpn evpn summary.* depth unbounded query-condition foo filter-condition foo")
        - "'data-source NX-API' in result.commands"
        - "'subscription 99' in result.commands"
        - "'snsr-grp 100 sample-interval 2000' in result.commands"
        - "'certificate /file_dir/new_server.key newhost.example.com' in result.commands"
        - "'destination-profile' in result.commands"
        - "'use-vrf management' in result.commands"
        - "result.commands|length == {{ command_list_length }}"

  # Source interface may or may not be included based on the image version.
  - assert:
      that:
        - "'no source-interface loopback55' in result.commands"
    when: imagetag and (major_version is version_compare('9.1', 'ge'))

  - assert:
      that:
        - "(ansible_facts.network_resources.telemetry|dict2items)|symmetric_difference(result.before|dict2items)|length == 0"

  - name: Gather Telemetry Facts After Changes
    nxos_facts: *facts

  - assert:
      that:
        - "(ansible_facts.network_resources.telemetry|dict2items)|symmetric_difference(result.after|dict2items)|length == 0"

  - name: Telemetry - replaced - idempotence
    nxos_telemetry: *replace
    register: result

  - assert:
      that:
        - "result.changed == false"
        - "result.commands|length == 0"

  always:
  - name: Teardown
    nxos_feature: *setup_teardown
    ignore_errors: yes

  - debug: msg="END connection={{ ansible_connection }} nxos_telemetry replaced sanity test"