1---
2# © 2020 Nokia
3# Licensed under the GNU General Public License v3.0 only
4# SPDX-License-Identifier: GPL-3.0-only
5##
6##
7### NETBOX_FRONT_PORT
8##
9##
10- name: "FRONT_PORT 1: Necessary info creation"
11  netbox.netbox.netbox_front_port:
12    netbox_url: http://localhost:32768
13    netbox_token: 0123456789abcdef0123456789abcdef01234567
14    data:
15      name: Front Port
16      device: test100
17      type: bnc
18      rear_port: Rear Port
19    state: present
20  register: test_one
21
22- name: "FRONT_PORT 1: ASSERT - Necessary info creation"
23  assert:
24    that:
25      - test_one is changed
26      - test_one['diff']['before']['state'] == "absent"
27      - test_one['diff']['after']['state'] == "present"
28      - test_one['front_port']['name'] == "Front Port"
29      - test_one['front_port']['device'] == 1
30      - test_one['front_port']['type'] == "bnc"
31      - test_one['front_port']['rear_port'] == 1
32      - test_one['msg'] == "front_port Front Port created"
33
34- name: "FRONT_PORT 2: Create duplicate"
35  netbox.netbox.netbox_front_port:
36    netbox_url: http://localhost:32768
37    netbox_token: 0123456789abcdef0123456789abcdef01234567
38    data:
39      name: Front Port
40      device: test100
41      type: bnc
42      rear_port: Rear Port
43    state: present
44  register: test_two
45
46- name: "FRONT_PORT 2: ASSERT - Create duplicate"
47  assert:
48    that:
49      - not test_two['changed']
50      - test_two['front_port']['name'] == "Front Port"
51      - test_two['front_port']['device'] == 1
52      - test_two['front_port']['type'] == "bnc"
53      - test_two['front_port']['rear_port'] == 1
54      - test_two['msg'] == "front_port Front Port already exists"
55
56- name: "FRONT_PORT 3: Update Front Port with other fields"
57  netbox.netbox.netbox_front_port:
58    netbox_url: http://localhost:32768
59    netbox_token: 0123456789abcdef0123456789abcdef01234567
60    data:
61      name: Front Port
62      device: test100
63      type: bnc
64      rear_port: Rear Port
65      rear_port_position: 5
66      description: test description
67    state: present
68  register: test_three
69
70- name: "FRONT_PORT 3: ASSERT - Update Front Port with other fields"
71  assert:
72    that:
73      - test_three is changed
74      - test_three['diff']['after']['rear_port_position'] == 5
75      - test_three['diff']['after']['description'] == "test description"
76      - test_three['front_port']['name'] == "Front Port"
77      - test_three['front_port']['device'] == 1
78      - test_three['front_port']['type'] == "bnc"
79      - test_three['front_port']['rear_port'] == 1
80      - test_three['front_port']['rear_port_position'] == 5
81      - test_three['front_port']['description'] == "test description"
82      - test_three['msg'] == "front_port Front Port updated"
83
84- name: "FRONT_PORT 4: Create Front Port for Delete Test"
85  netbox.netbox.netbox_front_port:
86    netbox_url: http://localhost:32768
87    netbox_token: 0123456789abcdef0123456789abcdef01234567
88    data:
89      name: Front Port 2
90      device: test100
91      type: bnc
92      rear_port: Rear Port
93    state: present
94  register: test_four
95
96- name: "FRONT_PORT 4: ASSERT - Create Front Port for Delete Test"
97  assert:
98    that:
99      - test_four is changed
100      - test_four['diff']['before']['state'] == "absent"
101      - test_four['diff']['after']['state'] == "present"
102      - test_four['front_port']['name'] == "Front Port 2"
103      - test_four['front_port']['device'] == 1
104      - test_four['front_port']['type'] == "bnc"
105      - test_four['front_port']['rear_port'] == 1
106      - test_four['msg'] == "front_port Front Port 2 created"
107
108- name: "FRONT_PORT 5: Delete Front Port"
109  netbox.netbox.netbox_front_port:
110    netbox_url: http://localhost:32768
111    netbox_token: 0123456789abcdef0123456789abcdef01234567
112    data:
113      name: Front Port 2
114      device: test100
115      type: bnc
116      rear_port: Rear Port
117    state: absent
118  register: test_five
119
120- name: "FRONT_PORT 5: ASSERT - Delete Front Port"
121  assert:
122    that:
123      - test_five is changed
124      - test_five['diff']['before']['state'] == "present"
125      - test_five['diff']['after']['state'] == "absent"
126      - test_five['msg'] == "front_port Front Port 2 deleted"
127
128- name: "FRONT_PORT 6: Create duplicate with rear_port dictionary"
129  netbox.netbox.netbox_front_port:
130    netbox_url: http://localhost:32768
131    netbox_token: 0123456789abcdef0123456789abcdef01234567
132    data:
133      name: Front Port
134      device: test100
135      type: bnc
136      rear_port:
137        device: test100
138        name: Rear Port
139    state: present
140  register: test_six
141
142- name: "FRONT_PORT 6: ASSERT - Create duplicate with rear_port dictionary"
143  assert:
144    that:
145      - not test_six['changed']
146      - test_six['front_port']['name'] == "Front Port"
147      - test_six['front_port']['device'] == 1
148      - test_six['front_port']['type'] == "bnc"
149      - test_six['front_port']['rear_port'] == 1
150      - test_six['msg'] == "front_port Front Port already exists"
151