Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: avoid undocumented lxd key #5748

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions tests/integration_tests/test_instance_id.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uuid
from typing import cast

import pytest
Expand All @@ -8,21 +9,21 @@
from tests.integration_tests.integration_settings import PLATFORM
from tests.integration_tests.releases import CURRENT_RELEASE, FOCAL

_INSTANCE_ID = 0
_INSTANCE_ID = uuid.uuid4()


def setup_meta_data(instance: LXDInstance):
"""Increment the instance id and apply it to the instance."""
global _INSTANCE_ID
_INSTANCE_ID += 1
_INSTANCE_ID = uuid.UUID(int=(1 + _INSTANCE_ID.int))
command = [
"lxc",
"config",
"set",
instance.name,
f"user.meta-data=instance-id: test_{_INSTANCE_ID}",
f"volatile.cloud-init.instance-id={_INSTANCE_ID}",
]
subp.subp(command)
assert subp.subp(command)


# class TestInstanceID:
Expand All @@ -41,11 +42,11 @@ def test_instance_id_changes(client: IntegrationInstance):
client.execute("cloud-init status --wait")
# check that instance id is the one we set
assert (
"test_1"
str(_INSTANCE_ID)
== client.execute("cloud-init query instance-id").stdout.rstrip()
)
assert (
"/var/lib/cloud/instances/test_1"
f"/var/lib/cloud/instances/{_INSTANCE_ID}"
== client.execute(
"readlink -f /var/lib/cloud/instance"
).stdout.rstrip()
Expand All @@ -57,11 +58,11 @@ def test_instance_id_changes(client: IntegrationInstance):
client.execute("cloud-init status --wait")
# check that instance id is the one we reset
assert (
"test_2"
str(_INSTANCE_ID)
== client.execute("cloud-init query instance-id").stdout.rstrip()
)
assert (
"/var/lib/cloud/instances/test_2"
f"/var/lib/cloud/instances/{_INSTANCE_ID}"
== client.execute(
"readlink -f /var/lib/cloud/instance"
).stdout.rstrip()
Expand Down