1
1
import logging
2
2
import pytest
3
+ from uuid import uuid4
3
4
4
5
from lib import commands , installer , pxe
5
- from lib .common import wait_for
6
+ from lib .common import safe_split , wait_for
6
7
from lib .installer import AnswerFile
8
+ from lib .pif import PIF
7
9
from lib .pool import Pool
10
+ from lib .vdi import VDI
8
11
9
12
from data import NETWORKS
10
13
assert "MGMT" in NETWORKS
16
19
# ssh-rsa keys, a public ssh-ed25519 key listed in TEST_SSH_PUBKEY should be
17
20
# there)
18
21
22
+ @pytest .fixture
23
+ def helper_vm_with_plugged_disk (running_vm , create_vms ):
24
+ helper_vm = running_vm
25
+ host_vm , = create_vms
26
+
27
+ all_vdis = [VDI (uuid , host = host_vm .host ) for uuid in host_vm .vdi_uuids ()]
28
+ disk_vdis = [vdi for vdi in all_vdis if not vdi .readonly ()]
29
+ vdi , = disk_vdis
30
+
31
+ vbd = helper_vm .create_vbd ("1" , vdi .uuid )
32
+ try :
33
+ vbd .plug ()
34
+
35
+ yield helper_vm
36
+
37
+ finally :
38
+ vbd .unplug ()
39
+ vbd .destroy ()
40
+
19
41
@pytest .mark .dependency ()
20
42
class TestNested :
21
43
@pytest .mark .parametrize ("iso_version" , (
@@ -61,7 +83,44 @@ def test_install(self, vm_booted_with_installer, install_disk,
61
83
host_vm = vm_booted_with_installer
62
84
installer .monitor_install (ip = host_vm .ip )
63
85
64
- def _test_firstboot (self , create_vms , mode , is_restore = False ):
86
+ @pytest .mark .usefixtures ("xcpng_chained" )
87
+ @pytest .mark .parametrize ("machine" , ("host1" , "host2" ))
88
+ @pytest .mark .parametrize ("version" , (
89
+ "83nightly" ,
90
+ "83rc1" , "83b2" , "83b1" ,
91
+ "821.1" ,
92
+ "81" , "80" ,
93
+ "76" , "75" ,
94
+ "xs8" , "ch821.1" ,
95
+ "xs70" ,
96
+ ))
97
+ @pytest .mark .parametrize ("firmware" , ("uefi" , "bios" ))
98
+ @pytest .mark .continuation_of (
99
+ lambda version , firmware : [dict (
100
+ vm = "vm1" ,
101
+ image_test = f"TestNested::test_install[{ firmware } -{ version } ]" )])
102
+ @pytest .mark .small_vm
103
+ def test_tune_firstboot (self , create_vms , helper_vm_with_plugged_disk ,
104
+ firmware , version , machine ):
105
+ helper_vm = helper_vm_with_plugged_disk
106
+
107
+ helper_vm .ssh (["mount /dev/xvdb1 /mnt" ])
108
+ try :
109
+ # hostname
110
+ logging .info ("Setting hostname to %r" , machine )
111
+ helper_vm .ssh (["echo > /mnt/etc/hostname" , machine ])
112
+ # UUIDs
113
+ logging .info ("Randomizing UUIDs" )
114
+ helper_vm .ssh (
115
+ ['sed -i' ,
116
+ f'''-e "/^INSTALLATION_UUID=/ s/.*/INSTALLATION_UUID='{ uuid4 ()} '/"''' ,
117
+ f'''-e "/^CONTROL_DOMAIN_UUID=/ s/.*/CONTROL_DOMAIN_UUID='{ uuid4 ()} '/"''' ,
118
+ '/mnt/etc/xensource-inventory' ])
119
+ helper_vm .ssh (["grep UUID /mnt/etc/xensource-inventory" ])
120
+ finally :
121
+ helper_vm .ssh (["umount /dev/xvdb1" ])
122
+
123
+ def _test_firstboot (self , create_vms , mode , * , machine = 'DEFAULT' , is_restore = False ):
65
124
host_vm = create_vms [0 ]
66
125
vif = host_vm .vifs ()[0 ]
67
126
mac_address = vif .param_get ('MAC' )
@@ -98,7 +157,6 @@ def _test_firstboot(self, create_vms, mode, is_restore=False):
98
157
expected_dist = "XCP-ng"
99
158
100
159
try :
101
- # FIXME: evict MAC from ARP cache first?
102
160
host_vm .start ()
103
161
wait_for (host_vm .is_running , "Wait for host VM running" )
104
162
@@ -225,11 +283,12 @@ def _test_firstboot(self, create_vms, mode, is_restore=False):
225
283
))
226
284
@pytest .mark .parametrize ("firmware" , ("uefi" , "bios" ))
227
285
@pytest .mark .continuation_of (
228
- lambda firmware , version : [
229
- dict (vm = "vm1" , image_test = f"TestNested::test_install[{ firmware } -{ version } ]" )])
286
+ lambda firmware , version , machine : [
287
+ dict (vm = "vm1" ,
288
+ image_test = f"TestNested::test_tune_firstboot[None-{ firmware } -{ version } -{ machine } ]" )])
230
289
def test_boot_inst (self , create_vms ,
231
290
firmware , version , machine ):
232
- self ._test_firstboot (create_vms , version )
291
+ self ._test_firstboot (create_vms , version , machine = machine )
233
292
234
293
@pytest .mark .usefixtures ("xcpng_chained" )
235
294
@pytest .mark .parametrize ("machine" , ("host1" , "host2" ))
@@ -252,7 +311,7 @@ def test_boot_inst(self, create_vms,
252
311
image_test = (f"TestNested::test_upgrade[{ firmware } -{ mode } -{ machine } ]" ))])
253
312
def test_boot_upg (self , create_vms ,
254
313
firmware , mode , machine ):
255
- self ._test_firstboot (create_vms , mode )
314
+ self ._test_firstboot (create_vms , mode , machine = machine )
256
315
257
316
@pytest .mark .usefixtures ("xcpng_chained" )
258
317
@pytest .mark .parametrize ("mode" , (
0 commit comments