Debian Codegraph @

ansible_collections/community/general/tests/unit/plugins/modules/test_open_iscsi.yaml

raw
1 # Copyright (c) 2026 Alexei Znamensky ([email protected])
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 ---
6 anchors:
7 target: &target "iqn.2006-01.com.example:storage.disk1"
8 target_iscsi_node_out: &target-node-out "10.1.2.3:3260,1 iqn.2006-01.com.example:storage.disk1\n"
9 target_session_out: &target-session-out "tcp: [1] 10.1.2.3:3260,1 iqn.2006-01.com.example:storage.disk1 (non-flash)\n"
10
11 iscsiadm_node_cached: &iscsiadm-node-cached
12 command: [/testbin/iscsiadm, --mode, node]
13 environ: {}
14 rc: 0
15 out: *target-node-out
16 err: ''
17 iscsiadm_node_empty: &iscsiadm-node-empty
18 command: [/testbin/iscsiadm, --mode, node]
19 environ: {}
20 rc: 21
21 out: ''
22 err: 'iscsiadm: No records found'
23 iscsiadm_session_active: &iscsiadm-session-active
24 command: [/testbin/iscsiadm, --mode, session]
25 environ: {}
26 rc: 0
27 out: *target-session-out
28 err: ''
29 iscsiadm_session_empty: &iscsiadm-session-empty
30 command: [/testbin/iscsiadm, --mode, session]
31 environ: {}
32 rc: 21
33 out: ''
34 err: ''
35 ipv6_target_node_out: &ipv6-target-node-out "fd00::1:3260,1 iqn.2006-01.com.example:storage.disk1\n"
36
37 test_cases:
38 # --- show_nodes ---
39
40 - id: show_nodes_only
41 input:
42 show_nodes: true
43 output:
44 changed: false
45 nodes:
46 - *target
47 mocks:
48 run_command:
49 - *iscsiadm-node-cached
50
51 - id: show_nodes_empty
52 input:
53 show_nodes: true
54 output:
55 changed: false
56 nodes: []
57 mocks:
58 run_command:
59 - *iscsiadm-node-empty
60
61 # --- discover ---
62
63 - id: discover_new_nodes
64 input:
65 portal: "10.1.2.3"
66 discover: true
67 show_nodes: true
68 output:
69 changed: true
70 cache_updated: true
71 nodes:
72 - *target
73 mocks:
74 socket_getaddrinfo:
75 return: "10.1.2.3"
76 run_command:
77 - *iscsiadm-node-empty
78 - command: [/testbin/iscsiadm, --mode, discovery, --type, sendtargets, --portal, "10.1.2.3:3260"]
79 environ: {check_rc: true}
80 rc: 0
81 out: *target-node-out
82 err: ''
83 - *iscsiadm-node-cached
84
85 - id: discover_no_change
86 input:
87 portal: "10.1.2.3"
88 discover: true
89 output:
90 changed: false
91 mocks:
92 socket_getaddrinfo:
93 return: "10.1.2.3"
94 run_command:
95 - *iscsiadm-node-cached
96 - command: [/testbin/iscsiadm, --mode, discovery, --type, sendtargets, --portal, "10.1.2.3:3260"]
97 environ: {check_rc: true}
98 rc: 0
99 out: *target-node-out
100 err: ''
101 - *iscsiadm-node-cached
102
103 # --- login ---
104
105 - id: login_already_loggedon
106 input:
107 login: true
108 target: *target
109 output:
110 changed: false
111 devicenodes: []
112 mocks:
113 glob_glob:
114 return: []
115 run_command:
116 - *iscsiadm-node-cached
117 - *iscsiadm-session-active
118
119 - id: login_needed
120 # Note: target_login() is called as target_login(module, target, portal, port)
121 # where portal=None is passed as check_rc — a known bug at line 484.
122 # The login command therefore has check_rc=None and no --portal flag appended.
123 input:
124 login: true
125 target: *target
126 output:
127 changed: true
128 connection_changed: true
129 devicenodes: []
130 mocks:
131 glob_glob:
132 return: []
133 time_sleep: true
134 run_command:
135 - *iscsiadm-node-cached
136 - *iscsiadm-session-empty
137 - command: [/testbin/iscsiadm, --mode, node, --targetname, *target, --login]
138 environ: {check_rc: null}
139 rc: 0
140 out: ''
141 err: ''
142
143 - id: logout_already_off
144 input:
145 login: false
146 target: *target
147 output:
148 changed: false
149 mocks:
150 run_command:
151 - *iscsiadm-node-cached
152 - *iscsiadm-session-empty
153
154 - id: logout_needed
155 input:
156 login: false
157 target: *target
158 output:
159 changed: true
160 connection_changed: true
161 mocks:
162 run_command:
163 - *iscsiadm-node-cached
164 - *iscsiadm-session-active
165 - command: [/testbin/iscsiadm, --mode, node, --targetname, *target, --logout]
166 environ: {check_rc: true}
167 rc: 0
168 out: ''
169 err: ''
170
171 - id: check_mode_login
172 flags:
173 check: true
174 input:
175 login: true
176 target: *target
177 output:
178 changed: true
179 connection_changed: true
180 mocks:
181 run_command:
182 - *iscsiadm-node-cached
183 - *iscsiadm-session-empty
184
185 # --- auto_node_startup ---
186
187 - id: auto_node_startup_already_auto
188 input:
189 auto_node_startup: true
190 target: *target
191 output:
192 changed: false
193 automatic_changed: false
194 mocks:
195 run_command:
196 - *iscsiadm-node-cached
197 - command: [/testbin/iscsiadm, --mode, node, --targetname, *target]
198 environ: {check_rc: true}
199 rc: 0
200 out: "node.startup = automatic\n"
201 err: ''
202
203 - id: auto_node_startup_set_auto
204 input:
205 auto_node_startup: true
206 target: *target
207 output:
208 changed: true
209 automatic_changed: true
210 mocks:
211 run_command:
212 - *iscsiadm-node-cached
213 - command: [/testbin/iscsiadm, --mode, node, --targetname, *target]
214 environ: {check_rc: true}
215 rc: 0
216 out: "node.startup = manual\n"
217 err: ''
218 - command: [/testbin/iscsiadm, --mode, node, --targetname, *target, --op=update, --name, node.startup, --value, automatic]
219 environ: {check_rc: true}
220 rc: 0
221 out: ''
222 err: ''
223
224 - id: auto_node_startup_set_manual
225 input:
226 auto_node_startup: false
227 target: *target
228 output:
229 changed: true
230 automatic_changed: true
231 mocks:
232 run_command:
233 - *iscsiadm-node-cached
234 - command: [/testbin/iscsiadm, --mode, node, --targetname, *target]
235 environ: {check_rc: true}
236 rc: 0
237 out: "node.startup = automatic\n"
238 err: ''
239 - command: [/testbin/iscsiadm, --mode, node, --targetname, *target, --op=update, --name, node.startup, --value, manual]
240 environ: {check_rc: true}
241 rc: 0
242 out: ''
243 err: ''
244
245 # --- rescan ---
246
247 - id: rescan_target
248 input:
249 rescan: true
250 target: *target
251 output:
252 changed: true
253 sessions: ''
254 mocks:
255 run_command:
256 - *iscsiadm-node-cached
257 - command: [/testbin/iscsiadm, --mode, node, --rescan, -T, *target]
258 environ: {}
259 rc: 0
260 out: ''
261 err: ''
262
263 - id: rescan_all
264 input:
265 rescan: true
266 output:
267 changed: true
268 sessions: ''
269 mocks:
270 run_command:
271 - *iscsiadm-node-cached
272 - command: [/testbin/iscsiadm, --mode, session, --rescan]
273 environ: {}
274 rc: 0
275 out: ''
276 err: ''
277
278 # --- IPv6 portal ---
279
280 - id: discover_ipv6_portal
281 # Verifies that the discovery command uses RFC-2732 bracket notation for IPv6:
282 # --portal [fd00::1]:3260 (not --portal fd00::1:3260)
283 # Note: post-discover node-list filtering is also broken for IPv6 (separate issue):
284 # iscsi_get_cached_nodes splits on ':' so target_portal="fd00" != portal="fd00::1",
285 # meaning nodes is always [] for IPv6 portals and changed stays false.
286 input:
287 portal: "fd00::1"
288 discover: true
289 show_nodes: true
290 output:
291 changed: false
292 nodes: []
293 mocks:
294 socket_getaddrinfo:
295 return: "fd00::1"
296 run_command:
297 - *iscsiadm-node-empty
298 - command: [/testbin/iscsiadm, --mode, discovery, --type, sendtargets, --portal, "[fd00::1]:3260"]
299 environ: {check_rc: true}
300 rc: 0
301 out: *ipv6-target-node-out
302 err: ''
303 - command: [/testbin/iscsiadm, --mode, node]
304 environ: {}
305 rc: 0
306 out: *ipv6-target-node-out
307 err: ''