-
Notifications
You must be signed in to change notification settings - Fork 112
/
test_discoveredhost.py
448 lines (315 loc) · 12.8 KB
/
test_discoveredhost.py
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
"""Test class for CLI Foreman Discovery
:Requirement: Discoveredhost
:CaseAutomation: Automated
:CaseComponent: DiscoveryImage
:Team: Rocket
"""
import pytest
from wait_for import wait_for
from robottelo.utils.issue_handlers import is_open
pytestmark = [pytest.mark.run_in_one_thread]
@pytest.mark.e2e
@pytest.mark.on_premises_provisioning
@pytest.mark.parametrize('module_provisioning_sat', ['discovery'], indirect=True)
@pytest.mark.parametrize('pxe_loader', ['bios', 'uefi'], indirect=True)
@pytest.mark.rhel_ver_match('7')
def test_rhel_pxe_discovery_provisioning(
module_provisioning_rhel_content,
module_discovery_sat,
provisioning_host,
provisioning_hostgroup,
request,
):
"""Provision a PXE-based discovered host
:id: b32a3b05-86bc-4ba6-ab6c-22b2f81e4315
:parametrized: yes
:Setup: Satellite with Provisioning and Discovery features configured
:steps:
1. Boot up the host to discover
2. Provision the host
:expectedresults: Host should be successfully discovered and provisioned
:CaseImportance: Critical
:BZ: 1731112
"""
sat = module_discovery_sat.sat
provisioning_host.power_control(ensure=False)
mac = provisioning_host._broker_args['provisioning_nic_mac_addr']
wait_for(
lambda: sat.api.DiscoveredHost().search(query={'mac': mac}) != [],
timeout=1500,
delay=40,
)
discovered_host = sat.api.DiscoveredHost().search(query={'mac': mac})[0]
discovered_host.hostgroup = provisioning_hostgroup
discovered_host.location = provisioning_hostgroup.location[0]
discovered_host.organization = provisioning_hostgroup.organization[0]
discovered_host.build = True
result = sat.cli.DiscoveredHost.provision(
{
'id': discovered_host.id,
'hostgroup-id': discovered_host.hostgroup.id,
'organization-id': discovered_host.organization.id,
'location-id': discovered_host.location.id,
}
)
assert 'Host created' in result[0]['message']
host = sat.api.Host().search(query={"search": f'id={discovered_host.id}'})[0]
request.addfinalizer(lambda: sat.provisioning_cleanup(host.name))
assert host
wait_for(
lambda: host.read().build_status_label != 'Pending installation',
timeout=1500,
delay=10,
)
assert host.read().build_status_label == 'Installed'
assert not sat.api.DiscoveredHost().search(query={'mac': mac})
@pytest.mark.e2e
@pytest.mark.on_premises_provisioning
@pytest.mark.parametrize('module_provisioning_sat', ['discovery'], indirect=True)
@pytest.mark.parametrize('pxe_loader', ['bios', 'uefi'], indirect=True)
@pytest.mark.rhel_ver_match('7')
def test_rhel_pxeless_discovery_provisioning(
module_discovery_sat,
pxeless_discovery_host,
module_provisioning_rhel_content,
provisioning_hostgroup,
request,
):
"""Provision a PXE-less discovered host
:id: e75ee13a-9edc-4182-b02a-6b106a459751
:Setup: Provisioning should be configured and a host should be
discovered via cli
:expectedresults: Host should be provisioned successfully
:CaseImportance: Critical
"""
sat = module_discovery_sat.sat
pxeless_discovery_host.power_control(ensure=False)
mac = pxeless_discovery_host._broker_args['provisioning_nic_mac_addr']
wait_for(
lambda: sat.api.DiscoveredHost().search(query={'mac': mac}) != [],
timeout=1500,
delay=40,
)
discovered_host = sat.api.DiscoveredHost().search(query={'mac': mac})[0]
discovered_host.hostgroup = provisioning_hostgroup
discovered_host.location = provisioning_hostgroup.location[0]
discovered_host.organization = provisioning_hostgroup.organization[0]
discovered_host.build = True
result = sat.cli.DiscoveredHost.provision(
{
'id': discovered_host.id,
'hostgroup-id': discovered_host.hostgroup.id,
'organization-id': discovered_host.organization.id,
'location-id': discovered_host.location.id,
}
)
assert 'Host created' in result[0]['message']
host = sat.api.Host().search(query={"search": f'id={discovered_host.id}'})[0]
request.addfinalizer(lambda: sat.provisioning_cleanup(host.name))
assert host
wait_for(
lambda: host.read().build_status_label != 'Pending installation',
timeout=1500,
delay=10,
)
assert host.read().build_status_label == 'Installed'
assert not sat.api.DiscoveredHost().search(query={'mac': mac})
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_provision_pxeless_bios_syslinux():
"""Provision and discover the pxe-less BIOS host from cli using SYSLINUX
loader
:id: ae7f3ce2-e66e-44dc-85cb-0c3c4782cbb1
:Setup:
1. Craft the FDI with remaster the image to have ssh enabled
:steps:
1. Create a BIOS VM and set it to boot from the FDI
2. Run assertion steps #1-2
3. Provision the discovered host using PXELinux loader
4. Run assertion steps #3-7
:expectedresults: Host should be provisioned successfully
1. [TBD] Ensure FDI loaded and successfully sent out facts
1.1 ping vm
1.2 ssh to the VM and read the logs (if ssh enabled)
1.3 optionally sniff the HTTP traffic coming from the host
2. Ensure host appeared in Discovered Hosts on satellite
3. [TBD] Ensure the kexec was successful (e.g. the kexec request
result in production.log)
4. [TBD] Ensure anaconda loaded and the installation finished
5. [TBD] Ensure the host is provisioned with correct attributes
6. Ensure the host is created in Hosts
7. Ensure the entry from discovered host list disappeared
:CaseImportance: High
:BZ: 1731112
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_provision_pxe_host_with_bios_syslinux():
"""Provision the pxe-based BIOS discovered host from cli using SYSLINUX
loader
:id: b5385fe3-d532-4373-af64-5492275ff8d4
:Setup:
1. Create a BIOS VM and set it to boot from a network
2. for getting more detailed info from FDI, remaster the image to
have ssh enabled
:steps:
1. Build a default PXE template
2. Run assertion step #1
3. Boot the VM (from NW)
4. Run assertion steps #2-4
5. Provision the discovered host
6. Run assertion steps #5-9
:expectedresults: Host should be provisioned successfully
1. [TBD] Ensure the tftpboot files are updated
1.1 Ensure fdi-image files have been placed under tftpboot/boot/
1.2 Ensure the 'default' pxelinux config has been placed under
tftpboot/pxelinux.cfg/
1.3 Ensure the discovery section exists inside pxelinux config,
it leads to the FDI kernel and the ONTIMEOUT is set to discovery
2. [TBD] Ensure PXE handoff goes as expected (tcpdump -p tftp)
3. [TBD] Ensure FDI loaded and successfully sent out facts
3.1 ping vm
3.2 ssh to the VM and read the logs (if ssh enabled)
3.3 optionally sniff the HTTP traffic coming from the host
4. Ensure host appeared in Discovered Hosts on satellite
5. [TBD] Ensure the tftpboot files are updated for the hosts mac
6. [TBD] Ensure PXE handoff goes as expected (tcpdump -p tftp)
7. [TBD] Optionally ensure anaconda loaded and the installation
finished
8. [TBD] Ensure the host is provisioned with correct attributes
9. Ensure the entry from discovered host list disappeared
:CaseImportance: High
:BZ: 1731112
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_delete():
"""Delete the selected discovered host
:id: c4103de8-145c-4a7d-b837-a1dec97231a2
:Setup: Host should already be discovered
:expectedresults: Selected host should be removed successfully
:CaseImportance: High
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_refresh_facts_pxe_host():
"""Refresh the facts of pxe based discovered hosts by adding a new NIC
:id: 410eaa5d-cc6a-44f7-8c6f-e8cfa81610f0
:Setup: Host should already be discovered
:expectedresults: Facts should be refreshed successfully with a new NIC
:CaseAutomation: NotAutomated
:CaseImportance: Medium
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_refresh_facts_of_pxeless_host():
"""Refresh the facts of pxeless discovered hosts by adding a new NIC
:id: 2e199eaa-9651-47b1-a2fd-622778dfe68e
:Setup: Host should already be discovered
:expectedresults: Facts should be refreshed successfully with a new NIC
:CaseAutomation: NotAutomated
:CaseImportance: Medium
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_reboot_pxe_host():
"""Reboot pxe based discovered hosts
:id: 9cc17742-f810-4be7-b410-a6c68e6cc64a
:Setup: Host should already be discovered
:expectedresults: Host is rebooted
:CaseAutomation: NotAutomated
:CaseImportance: High
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_reboot_pxeless_host():
"""Reboot pxe-less discovered hosts
:id: e72e1607-8778-45b6-b8b9-8215514546f0
:Setup: PXELess host should already be discovered
:expectedresults: Host is rebooted
:CaseAutomation: NotAutomated
:CaseImportance: High
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_auto_provision_pxe_host():
"""Discover a pxe based host and auto-provision it with
discovery rule and by enabling auto-provision flag
:id: 701a1892-1c6a-4ba1-bbd8-a37b7fb02fa0
:expectedresults: Host should be successfully rebooted and provisioned
:CaseAutomation: NotAutomated
:CaseImportance: Critical
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_auto_provision_pxeless_host():
"""Discover a pxe-less host and auto-provision it with
discovery rule and by enabling auto-provision flag
:id: 298417b3-d242-4999-89f9-198095704c0e
:expectedresults: Host should be successfully rebooted and provisioned
:CaseAutomation: NotAutomated
:CaseImportance: Critical
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_assign_discovery_manager_role():
"""Assign 'Discovery_Manager' role to a normal user
:id: f694c361-5fbb-4c3a-b2ff-6dfe6ea14820
:expectedresults: User should be able to view, provision, edit and destroy one or more
discovered host as well as view, create_new, edit, execute and delete discovery rules
:CaseAutomation: NotAutomated
:CaseImportance: Medium
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_assign_discovery_role():
"""Assign 'Discovery" role to a normal user
:id: 873e8411-563d-4bf9-84ce-62e522410cfe
:expectedresults: User should be able to list, provision, and destroy
one or more discovered hosts
:CaseAutomation: NotAutomated
:CaseImportance: Medium
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_update_discover_hostname_settings():
"""Update the hostname_prefix and Hostname_facts settings and
discover a host.
:id: 10071eb1-ec2a-4061-b798-480643d8f4ed
:expectedresults: Host should be discovered with name as 'hostname_prefix + hostname_facts'
:CaseAutomation: NotAutomated
:CaseImportance: Medium
"""
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_list_facts():
"""Check if defined facts of a discovered host are
correctly displayed under host's facts
:id: 2c65925c-05d9-4f6d-b1b7-1fa1492c95a8
:Setup: 1. Provisioning is configured and Host is already discovered
:steps: Validate specified builtin and custom facts
:expectedresults: All checked facts should be displayed correctly
:CaseAutomation: NotAutomated
:CaseImportance: High
"""
@pytest.mark.tier1
def test_positive_verify_updated_fdi_image(target_sat):
"""Verify foreman-discovery-image is built on latest up-to-date RHEL
:id: 2ab2ad88-4470-4d4c-8e0b-5892ad8d688e
:steps:
1. Register Satellite to CDN and install foreman-discovery-image
:expectedresults: Installed foreman-discovery-image is built on latest up-to-date RHEL
Verifies: SAT-24197, SAT-25275
:BZ: 2271598
:customerscenario: true
:CaseImportance: Critical
"""
discovery_ks_path = '/usr/share/foreman-discovery-image/foreman-discovery-image.ks'
target_sat.register_to_cdn()
target_sat.execute('yum -y --disableplugin=foreman-protector install foreman-discovery-image')
if target_sat.os_version.major == 9:
version = '8.9' if is_open('SAT-25275') else str(target_sat.os_version)
elif target_sat.os_version.major == 8:
version = '8.9' if is_open('SAT-24197') else str(target_sat.os_version)
result = target_sat.execute(f'grep "url=" {discovery_ks_path}')
assert version in result.stdout