Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add integration test for validating Azure UUID case-insentive
- Loading branch information
1 parent
67db296
commit 5566f9b
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" Integration test for LP #1835584 | ||
Kernels prior to 4.14 report dmi product_uuid as uppercase, Azure | ||
relies on system UUID as their "instance-id". Upgrades to kernels >= 4.14 | ||
will represent the same product_uuid as lowercase. System UUID should be a | ||
case-insensitive comparison and avoid triggering "new instance" detection | ||
in cloud-init on Azure platform. | ||
The test will launch an Ubuntu image which has a 5.4 kernel. We allow | ||
cloud-init to detect the instance-id on the 5.4 kernel, set a 4.14 kernel as | ||
default and reboot the system. Expectation is that cloud-init retains same | ||
instance-id status and avoids triggering ssh host key regeneration across that | ||
reboot. | ||
Across the reboot, assert that we didn't re-run config_ssh by virtue of | ||
seeing only one semaphore creation log entry of type: | ||
Writing to /var/lib/cloud/instances/<UUID>/sem/config_ssh - | ||
https://bugs.launchpad.net/cloud-init/+bug/1835584 | ||
""" | ||
import re | ||
|
||
import pytest | ||
|
||
from tests.integration_tests.instances import IntegrationInstance | ||
|
||
|
||
KERNEL_URL = "https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.14.120/" | ||
PKG_VER = "4.14.120-0414120-generic_4.14.120-0414120.201905161610_amd64" | ||
PKGS = [ | ||
"linux-headers-4.14.120-0414120_4.14.120-0414120.201905161610_all.deb", | ||
"linux-headers-{pkg_ver}.deb".format(pkg_ver=PKG_VER), | ||
"linux-image-unsigned-{pkg_ver}.deb".format(pkg_ver=PKG_VER), | ||
"linux-modules-{pkg_ver}.deb".format(pkg_ver=PKG_VER), | ||
] | ||
|
||
# create a list of wgets to inject in #cloud-config runcmd below | ||
wgets = "\n".join( | ||
[" - 'wget {url}{pkg}'".format(url=KERNEL_URL, pkg=pkg) for pkg in PKGS] | ||
) | ||
|
||
USER_DATA = """\ | ||
#cloud-config | ||
runcmd: | ||
{wgets} | ||
- 'dpkg -i *.deb' | ||
""".format(wgets=wgets) | ||
|
||
|
||
@pytest.mark.azure | ||
@pytest.mark.sru_next | ||
@pytest.mark.user_data(USER_DATA) | ||
def test_azure_kernel_upgrade_case_insensitive_uuid( | ||
client: IntegrationInstance | ||
): | ||
uuid = client.read_from_file('/sys/class/dmi/id/product_uuid') | ||
assert uuid.islower(), "Expected lowercase UUID on 5.4 kernel {}".format( | ||
uuid | ||
) | ||
orig_kernel = client.execute('uname -r').strip() | ||
assert "azure" in orig_kernel | ||
client.write_to_file( | ||
"/etc/default/grub.d/90-generic.cfg", | ||
"GRUB_FLAVOUR_ORDER=\"generic\"\n" | ||
) | ||
result = client.execute("update-grub") | ||
if not result.ok: | ||
pytest.fail( | ||
"Unable to update grub for generic default: {}".format(result) | ||
) | ||
client.restart() | ||
new_kernel = client.execute('uname -r').strip() | ||
assert orig_kernel != new_kernel | ||
assert 'generic' in new_kernel | ||
new_uuid = client.read_from_file('/sys/class/dmi/id/product_uuid') | ||
assert uuid.upper() == new_uuid, ( | ||
"Expected UUID on 4.14 kernel to be uppercase of UUID on 5.4 kernel" | ||
) | ||
log = client.read_from_file('/var/log/cloud-init.log') | ||
RE_CONFIG_SSH_SEMAPHORE = r'Writing.*sem/config_ssh ' | ||
ssh_runs = len(re.findall(RE_CONFIG_SSH_SEMAPHORE, log)) | ||
assert 1 == ssh_runs, "config_ssh ran too many times {}".format(ssh_runs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters