1---
2- debug:
3    msg:
4      START iosxr_static_routes merged integration tests on connection={{ ansible_connection
5      }}
6
7- include_tasks: _remove_config.yaml
8
9- block:
10    - name: Merge the provided configuration with the existing running configuration
11      register: result
12      cisco.iosxr.iosxr_static_routes: &id001
13        config:
14          - address_families:
15              - afi: ipv4
16                safi: unicast
17                routes:
18                  - dest: 192.0.2.16/28
19                    next_hops:
20                      - forward_router_address: 192.0.2.10
21                        interface: FastEthernet0/0/0/1
22                        description: LAB
23                        metric: 120
24                        tag: 10
25
26                      - interface: FastEthernet0/0/0/5
27                        track: ip_sla_1
28
29                  - dest: 192.0.2.32/28
30                    next_hops:
31                      - forward_router_address: 192.0.2.11
32                        admin_distance: 100
33
34              - afi: ipv6
35                safi: unicast
36                routes:
37                  - dest: 2001:db8:1000::/36
38                    next_hops:
39                      - interface: FastEthernet0/0/0/7
40                        description: DC
41
42                      - interface: FastEthernet0/0/0/8
43                        forward_router_address: 2001:db8:2000:2::1
44
45          - vrf: DEV_SITE
46            address_families:
47              - afi: ipv4
48                safi: unicast
49                routes:
50                  - dest: 192.0.2.48/28
51                    next_hops:
52                      - forward_router_address: 192.0.2.12
53                        description: DEV
54                        dest_vrf: test_1
55
56                  - dest: 192.0.2.80/28
57                    next_hops:
58                      - interface: FastEthernet0/0/0/2
59                        forward_router_address: 192.0.2.14
60                        dest_vrf: test_1
61                        track: ip_sla_2
62                        vrflabel: 124
63        state: merged
64
65    - name: Assert that before dicts were correctly generated
66      assert:
67        that:
68          "{{ merged['before'] | symmetric_difference(result['before']) |length\
69          \ == 0 }}"
70
71    - name: Assert that correct set of commands were generated
72      assert:
73        that:
74          - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\
75            \ == 0 }}"
76
77    - set_fact:
78        diff: "{{ merged['after'] | symmetric_difference(result['after'])  }}"
79
80    - name: Assert that after dicts was correctly generated
81      assert:
82        that:
83          - "{{ merged['after'] | symmetric_difference(result['after']) |length\
84            \ == 0 }}"
85
86    - name:
87        Merge the provided configuration with the existing running configuration
88        (IDEMPOTENT)
89      register: result
90      cisco.iosxr.iosxr_static_routes: *id001
91
92    - name: Assert that the previous task was idempotent
93      assert:
94        that:
95          - result['changed'] == false
96          - result.commands|length == 0
97
98    - name: Assert that before dicts were correctly generated
99      assert:
100        that:
101          - "{{ merged['after'] | symmetric_difference(result['before']) |length\
102            \ == 0 }}"
103
104    - name: Update existing configuration using merged
105      register: result
106      cisco.iosxr.iosxr_static_routes: &id002
107        config:
108          - vrf: DEV_SITE
109            address_families:
110              - afi: ipv4
111                safi: unicast
112                routes:
113                  - dest: 192.0.2.48/28
114                    next_hops:
115                      - forward_router_address: 192.0.2.12
116                        vrflabel: 2301
117                        dest_vrf: test_1
118
119                  - dest: 192.0.2.80/28
120                    next_hops:
121                      - interface: FastEthernet0/0/0/2
122                        forward_router_address: 192.0.2.14
123                        dest_vrf: test_1
124                        description: rt_test_1
125
126    - name: Assert that before dicts were correctly generated
127      assert:
128        that:
129          "{{ merged['after'] | symmetric_difference(result['before']) |length\
130          \ == 0 }}"
131
132    - name: Assert that correct set of commands were generated
133      assert:
134        that:
135          - "{{ merged['update_commands'] | symmetric_difference(result['commands'])\
136            \ |length == 0 }}"
137
138    - name: Assert that after dicts were correctly generated
139      assert:
140        that:
141          "{{ merged['update_after'] | symmetric_difference(result['after'])\
142          \ |length == 0 }}"
143
144    - name: Update existing static_routes configuration using merged (IDEMPOTENT)
145      register: result
146      cisco.iosxr.iosxr_static_routes: *id002
147
148    - name: Assert that the previous task was idempotent
149      assert:
150        that:
151          - result['changed'] == false
152          - result.commands|length == 0
153  always:
154    - include_tasks: _remove_config.yaml
155