summaryrefslogtreecommitdiff
path: root/test/integration/targets/aci_access_port_to_interface_policy_leaf_profile/tasks/main.yml
blob: ecfde3b9ed98a2a231e25950ddee1c825b6ee6c6 (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
# Test code for the ACI modules
# Copyright 2017, Bruno Calogero <bcalogero@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: Ensuring Interface Policy Leaf profile exists for kick off
  aci_interface_policy_leaf_profile: &aci_interface_policy_leaf_profile_present
    host: "{{ aci_hostname }}"
    username: "{{ aci_username }}"
    password: "{{ aci_password }}"
    leaf_interface_profile: leafintprftest
    validate_certs: no
    state: present
  register: leaf_profile_present

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

- name: Bind an Interface Access Port Selector to an Interface Policy Leaf Profile with a Policy Group - check mode works
  aci_access_port_to_interface_policy_leaf_profile: &aci_access_port_to_interface_policy_leaf_profile_present
    <<: *aci_interface_policy_leaf_profile_present
    access_port_selector: anstest_accessportselector
    leaf_port_blk: anstest_leafportblkname
    fromPort: 13
    toPort: 16
  check_mode: yes
  register: accessport_to_intf_check_mode_present

- name: Bind an Interface Access Port Selector to an Interface Policy Leaf Profile with a Policy Group - creation works
  aci_access_port_to_interface_policy_leaf_profile:
    <<: *aci_access_port_to_interface_policy_leaf_profile_present
  register: accessport_to_intf_present

- name: Bind an Interface Access Port Selector to an Interface Policy Leaf Profile with a Policy Group - idempotency works
  aci_access_port_to_interface_policy_leaf_profile:
    <<: *aci_access_port_to_interface_policy_leaf_profile_present
  register: accessport_to_intf_idempotent

- name: Bind an Interface Access Port Selector to an Interface Policy Leaf Profile with a Policy Group - update works
  aci_access_port_to_interface_policy_leaf_profile:
    <<: *aci_access_port_to_interface_policy_leaf_profile_present
    policy_group: anstest_policygroupname
  register: accessport_to_intf_update

# TODO: also test for errors
- name: present assertions
  assert:
    that:
    - accessport_to_intf_check_mode_present.changed == true
    - accessport_to_intf_present.changed == true
    - accessport_to_intf_present.existing == []
    - 'accessport_to_intf_present.config == {"infraHPortS": {"attributes": {"name": "anstest_accessportselector"}, "children": [{"infraPortBlk": {"attributes": {"fromPort": "13", "name": "anstest_leafportblkname", "toPort": "16"}}}, {"infraRsAccBaseGrp": {"attributes": {"tDn": "uni/infra/funcprof/accportgrp-None"}}}]}}'
    - accessport_to_intf_idempotent.changed == false
    - accessport_to_intf_idempotent.config == {}
    - accessport_to_intf_update.changed == true
    - 'accessport_to_intf_update.config == {"infraHPortS": {"attributes": {},"children": [{"infraRsAccBaseGrp": {"attributes": {"tDn": "uni/infra/funcprof/accportgrp-anstest_policygroupname"}}}]}}'

- name: Query Specific access_port_selector and leaf_interface_profile binding
  aci_access_port_to_interface_policy_leaf_profile:
    <<: *aci_interface_policy_leaf_profile_present
    access_port_selector: anstest_accessportselector # "{{ 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/accportprof-leafintprftest/hports-anstest_accessportselector-typ-range.json" in binding_query.url'

- name: Remove binding of interface access port selector and Interface Policy Leaf Profile - check mode
  aci_access_port_to_interface_policy_leaf_profile: &aci_access_port_to_interface_policy_leaf_profile_absent
    <<: *aci_interface_policy_leaf_profile_present
    access_port_selector: anstest_accessportselector
    state: absent
  check_mode: yes
  register: accessport_to_intf_check_mode_absent

- name: Remove binding of interface access port selector and Interface Policy Leaf Profile - delete works
  aci_access_port_to_interface_policy_leaf_profile:
    <<: *aci_access_port_to_interface_policy_leaf_profile_absent
  register: accessport_to_intf_absent

- name: Remove binding of interface access port selector and Interface Policy Leaf Profile - idempotency works
  aci_access_port_to_interface_policy_leaf_profile:
    <<: *aci_access_port_to_interface_policy_leaf_profile_absent
  register: accessport_to_intf_absent_idempotent

- name: Remove binding of interface access port selector and Interface Policy Leaf Profile - check mode
  aci_access_port_to_interface_policy_leaf_profile:
    <<: *aci_interface_policy_leaf_profile_present
    #access_port_selector: anstest_accessportselector
    state: absent
  ignore_errors: yes
  register: accessport_to_intf_absent_missing_param

- name: absent assertions
  assert:
    that:
      - accessport_to_intf_check_mode_absent.changed == true
      - accessport_to_intf_check_mode_absent.existing != []
      - accessport_to_intf_absent.changed == true
      - accessport_to_intf_absent.existing == accessport_to_intf_check_mode_absent.existing
      - accessport_to_intf_absent_idempotent.changed == false
      - accessport_to_intf_absent_idempotent.existing == []
      - accessport_to_intf_absent_missing_param.failed == true
      - 'accessport_to_intf_absent_missing_param.msg == "state is absent but all of the following are missing: access_port_selector"'


- name: Remove an interface access port selector associated with an Interface Policy Leaf Profile - Clean up
  aci_access_port_to_interface_policy_leaf_profile:
    <<: *aci_access_port_to_interface_policy_leaf_profile_absent
    state: absent

- name: Remove Interface policy leaf profile - Cleanup
  aci_interface_policy_leaf_profile:
    <<: *aci_interface_policy_leaf_profile_present
    state: absent