summaryrefslogtreecommitdiff
path: root/test/integration/targets/aci_switch_leaf_selector/tasks/main.yml
blob: 26761f06b20d102d54bd8e51516daf8d68fbe264 (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
# Test code for the ACI modules
# Copyright 2017, Bruno Calogero <bcaloger@cisco.com>

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- name: Test that we have an ACI APIC host, ACI username and ACI password
  fail:
    msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
  when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined

- name: Deleting Switch Policy Leaf profile exists for kick off
  aci_switch_policy_leaf_profile:
    host: "{{ aci_hostname }}"
    username: "{{ aci_username }}"
    password: "{{ aci_password }}"
    leaf_profile: sw_name_test
    validate_certs: no
    use_ssl: no
    use_proxy: no
    state: absent

- name: Ensuring Switch Policy Leaf profile exists for kick off
  aci_switch_policy_leaf_profile: &aci_switch_policy_leaf_profile_present
    host: "{{ aci_hostname }}"
    username: "{{ aci_username }}"
    password: "{{ aci_password }}"
    leaf_profile: sw_name_test
    validate_certs: no
    use_ssl: no
    use_proxy: no
    state: present
  register: leaf_profile_present

# TODO: Ensure that leaf Policy Group Exists (module missing) (infra:AccPortGrp)

- name: Adding a switch policy leaf profile selector associated Node Block range (w/o policy group) - check mode works
  aci_switch_leaf_selector: &aci_switch_leaf_selector_present
    <<: *aci_switch_policy_leaf_profile_present
    leaf: leaf_selector_name
    leaf_node_blk: node_blk_name
    from: 1011
    to: 1011
  check_mode: yes
  register: sw_leaf_selec_check_mode_present

- name: Adding a switch policy leaf profile selector associated Node Block range (w/o policy group) - creation works
  aci_switch_leaf_selector:
    <<: *aci_switch_leaf_selector_present
  register: sw_leaf_selec_present

- name: Adding a switch policy leaf profile selector associated Node Block range (w/o policy group) - idempotency works
  aci_switch_leaf_selector:
    <<: *aci_switch_leaf_selector_present
  register: sw_leaf_selec_idempotent

- name: Adding a switch policy leaf profile selector associated Node Block range (w/ policy group) - update works
  aci_switch_leaf_selector:
    <<: *aci_switch_leaf_selector_present
    policy_group: anstest_policygroupname
  register: sw_leaf_selec_update

# TODO: also test for errors
- name: present assertions
  assert:
    that:
    - sw_leaf_selec_check_mode_present.changed == true
    - sw_leaf_selec_present.changed == true
    - sw_leaf_selec_present.existing == []
    - 'sw_leaf_selec_present.config ==  {"infraLeafS": {"attributes": {"name": "leaf_selector_name"}, "children": [{"infraNodeBlk": {"attributes": {"from_": "1011", "name": "node_blk_name", "to_": "1011"}}},{"infraRsAccNodePGrp": {"attributes": {"tDn": "uni/infra/funcprof/accnodepgrp-None"}}}]}}'
    - sw_leaf_selec_idempotent.changed == false
    - sw_leaf_selec_idempotent.config == {}
    - sw_leaf_selec_update.changed == true
    - 'sw_leaf_selec_update.config == {"infraLeafS": {"attributes": {},"children": [{"infraRsAccNodePGrp": {"attributes": {"tDn": "uni/infra/funcprof/accnodepgrp-anstest_policygroupname"}}}]}}'

- name: Query Specific switch policy leaf profile selector
  aci_switch_leaf_selector:
    <<: *aci_switch_policy_leaf_profile_present
    leaf: leaf_selector_name # "{{ fake_var | default(omit) }}" ?
    state: query
  register: binding_query

- name: present assertions
  assert:
    that:
      - binding_query.changed == false
      - binding_query.existing | length >= 1
      - '"api/mo/uni/infra/nprof-sw_name_test/leaves-leaf_selector_name-typ-range.json" in binding_query.url'

- name: Remove binding of interface access port selector and Interface Policy Leaf Profile - check mode
  aci_switch_leaf_selector: &aci_switch_leaf_selector_absent
    <<: *aci_switch_policy_leaf_profile_present
    leaf: leaf_selector_name
    state: absent
  check_mode: yes
  register: sw_leaf_selec_check_mode_absent

- name: Remove switch policy leaf profile selector - delete works
  aci_switch_leaf_selector:
    <<: *aci_switch_leaf_selector_absent
  register: sw_leaf_selec_absent

- name: Remove switch policy leaf profile selector - idempotency works
  aci_switch_leaf_selector:
    <<: *aci_switch_leaf_selector_absent
  register: sw_leaf_selec_absent_idempotent

- name: Remove switch policy leaf profile selector - check mode
  aci_switch_leaf_selector:
    <<: *aci_switch_policy_leaf_profile_present
    #access_port_selector: anstest_accessportselector
    state: absent
  ignore_errors: yes
  register: sw_leaf_selec_absent_missing_param

- name: absent assertions
  assert:
    that:
      - sw_leaf_selec_check_mode_absent.changed == true
      - sw_leaf_selec_check_mode_absent.existing != []
      - sw_leaf_selec_absent.changed == true
      - sw_leaf_selec_absent.existing == sw_leaf_selec_check_mode_absent.existing
      - sw_leaf_selec_absent_idempotent.changed == false
      - sw_leaf_selec_absent_idempotent.existing == []
      - sw_leaf_selec_absent_missing_param.failed == true
      - 'sw_leaf_selec_absent_missing_param.msg == "state is absent but all of the following are missing: leaf"'


- name: Remove switch policy leaf profile selector - Clean up
  aci_switch_leaf_selector:
    <<: *aci_switch_leaf_selector_absent
    state: absent

- name: Deleting Switch Policy Leaf profile exists for kick off
  aci_switch_policy_leaf_profile:
    <<: *aci_switch_policy_leaf_profile_present
    state: absent