Skip to content

Commit

Permalink
tests: add integration test for validating Azure UUID case-insentive
Browse files Browse the repository at this point in the history
  • Loading branch information
blackboxsw committed Feb 12, 2021
1 parent f059ac4 commit bf190cd
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/integration_tests/bugs/test_lp1835584.py
@@ -0,0 +1,70 @@
""" Integration test for LP #1835584
Kernels prior to 4.15 report dmi product_uuid as uppercase, Azure
relies on system UUID as their "instance-id". Upgrades to kernels >= 4.15
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.15 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/1897099
"""
import re

import pytest

from tests.integration_tests.instances import IntegrationInstance


USER_DATA = """\
#cloud-config
runcmd:
- 'wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.14.120/linux-headers-4.14.120-0414120_4.14.120-0414120.201905161610_all.deb'
- 'wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.14.120/linux-headers-4.14.120-0414120-generic_4.14.120-0414120.201905161610_amd64.deb'
- 'wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.14.120/linux-image-unsigned-4.14.120-0414120-generic_4.14.120-0414120.201905161610_amd64.deb'
- 'wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.14.120/linux-modules-4.14.120-0414120-generic_4.14.120-0414120.201905161610_amd64.deb'
- 'dpkg -i *.deb'
"""


def _check_iid_insensitive_across_kernel_upgrade(client):
uuid = client.read_from_file('/sys/class/dmi/id/product_uuid')
assert uuid.islower(), "UUID does not appear to be lowercase {}".format(
uuid
)
orig_kernel = client.execute('uname -r').strip()
assert "azure" in orig_kernel
orig_kernel = client.execute('uname -r').strip()
client.write_to_file(
"/etc/default/grub.d/90-generic.cfg",
"GRUB_FLAVOUR_ORDER=\"generic\"\n"
)
client.execute("update-grub")
client.restart()
new_kernel = client.execute('uname -r').strip()
assert orig_kernel != new_kernel
assert 'generic' in new_kernel
uuid = client.read_from_file('/sys/class/dmi/id/product_uuid')
assert uuid.isupper(), "UUID does not appear to be uppercase {}".format(
uuid
)
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)


@pytest.mark.azure
@pytest.mark.sru_next
@pytest.mark.user_data(USER_DATA)
def test_azure_kernel_upgrade_case_insensitive_uuid(client: IntegrationInstance):
_check_iid_insensitive_across_kernel_upgrade(client)
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -184,5 +184,6 @@ markers =
instance_name: the name to be used for the test instance
sru_2020_11: test is part of the 2020/11 SRU verification
sru_2021_01: test is part of the 2021/01 SRU verification
sru_next: test is part of the next SRU verification
ubuntu: this test should run on Ubuntu
unstable: skip this test because it is flakey

0 comments on commit bf190cd

Please sign in to comment.