Skip to content

Commit 93ab539

Browse files
committed
install: adjust host IP, name, UUIDs in firstboot data before booting
Uses a helper VM to modify firstboot data in installed disk Signed-off-by: Yann Dirson <[email protected]>
1 parent c33a13d commit 93ab539

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

tests/install/test-sequences/inst.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
tests/install/test.py::TestNested::test_install[uefi-83nightly]
2+
tests/install/test.py::TestNested::test_tune_firstboot[None-uefi-83nightly-host1]
23
tests/install/test.py::TestNested::test_boot_inst[uefi-83nightly-host1]

tests/install/test.py

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import logging
22
import pytest
3+
from uuid import uuid4
34

45
from lib import commands, installer, pxe
5-
from lib.common import wait_for
6+
from lib.common import safe_split, wait_for
67
from lib.installer import AnswerFile
8+
from lib.pif import PIF
79
from lib.pool import Pool
10+
from lib.vdi import VDI
811

912
from data import NETWORKS
1013
assert "MGMT" in NETWORKS
@@ -16,6 +19,25 @@
1619
# ssh-rsa keys, a public ssh-ed25519 key listed in TEST_SSH_PUBKEY should be
1720
# there)
1821

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+
1941
@pytest.mark.dependency()
2042
class TestNested:
2143
@pytest.mark.parametrize("iso_version", (
@@ -61,7 +83,44 @@ def test_install(self, vm_booted_with_installer, install_disk,
6183
host_vm = vm_booted_with_installer
6284
installer.monitor_install(ip=host_vm.ip)
6385

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):
65124
host_vm = create_vms[0]
66125
vif = host_vm.vifs()[0]
67126
mac_address = vif.param_get('MAC')
@@ -98,7 +157,6 @@ def _test_firstboot(self, create_vms, mode, is_restore=False):
98157
expected_dist = "XCP-ng"
99158

100159
try:
101-
# FIXME: evict MAC from ARP cache first?
102160
host_vm.start()
103161
wait_for(host_vm.is_running, "Wait for host VM running")
104162

@@ -225,11 +283,12 @@ def _test_firstboot(self, create_vms, mode, is_restore=False):
225283
))
226284
@pytest.mark.parametrize("firmware", ("uefi", "bios"))
227285
@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}]")])
230289
def test_boot_inst(self, create_vms,
231290
firmware, version, machine):
232-
self._test_firstboot(create_vms, version)
291+
self._test_firstboot(create_vms, version, machine=machine)
233292

234293
@pytest.mark.usefixtures("xcpng_chained")
235294
@pytest.mark.parametrize("machine", ("host1", "host2"))
@@ -252,7 +311,7 @@ def test_boot_inst(self, create_vms,
252311
image_test=(f"TestNested::test_upgrade[{firmware}-{mode}-{machine}]"))])
253312
def test_boot_upg(self, create_vms,
254313
firmware, mode, machine):
255-
self._test_firstboot(create_vms, mode)
314+
self._test_firstboot(create_vms, mode, machine=machine)
256315

257316
@pytest.mark.usefixtures("xcpng_chained")
258317
@pytest.mark.parametrize("mode", (

0 commit comments

Comments
 (0)