Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
45 changes: 43 additions & 2 deletions test/scripts/boot-image
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,22 @@ def get_aws_config():
}


def get_azure_config():
return {
"subscription": os.environ.get("AZURE_SUBSCRIPTION"),
"tenant": os.environ.get("AZURE_TENANT"),
"client_id": os.environ.get("AZURE_CLIENT_ID"),
"client_secret": os.environ.get("AZURE_CLIENT_SECRET"),
"resource_group": os.environ.get("AZURE_RESOURCE_GROUP")
}


@contextlib.contextmanager
def create_ssh_key():
def create_ssh_key(key_type = None):
with TemporaryDirectory() as tmpdir:
keypath = os.path.join(tmpdir, "testkey")
if ci_priv_key := os.environ.get("CI_PRIV_SSH_KEY_2"):
ci_priv_key = os.environ.get("CI_PRIV_SSH_KEY_2")
if not key_type and ci_priv_key:
# running in CI: use key from env
with open(keypath, "w", encoding="utf-8") as keyfile:
keyfile.write(ci_priv_key + "\n")
Expand All @@ -36,6 +47,9 @@ def create_ssh_key():
pubkey = out.decode()
with open(keypath + ".pub", "w", encoding="utf-8") as pubkeyfile:
pubkeyfile.write(pubkey)
elif key_type == "rsa":
cmd = ["ssh-keygen", "-t", "rsa", "-b", "2048", "-m", "pem", "-N", "", "-f", keypath]
testlib.runcmd_nc(cmd)
else:
# create an ssh key pair with empty password
cmd = ["ssh-keygen", "-t", "ecdsa", "-b", "256", "-m", "pem", "-N", "", "-f", keypath]
Expand Down Expand Up @@ -148,6 +162,31 @@ def boot_container(distro, arch, image_type, image_path, manifest_id):
cmd_boot_aws(arch, image_name, privkey_file, pubkey_file, raw_image_path, [BASE_TEST_SCRIPT])


def boot_vhd(distro, arch, image_path, config):
cmd = [BASE_TEST_SCRIPT, config]
with ensure_uncompressed(image_path) as raw_image_path:
with create_ssh_key(key_type="rsa") as (privkey, pubkey):
# a lot of resources have <=64 character naming constraint
name = f"{distro}-" + str(uuid.uuid4())

# pylint: disable=too-many-arguments,too-many-positional-arguments
az_config = get_azure_config()
cmd = ["go", "run", "./cmd/boot-azure", "run",
"--subscription", az_config["subscription"],
"--tenant", az_config["tenant"],
"--client-id", az_config["client_id"],
"--client-secret", az_config["client_secret"],
"--resource-group", az_config["resource_group"],
"--username", "osbuild",
"--ssh-privkey", privkey,
"--ssh-pubkey", pubkey,
"--vm-name", name,
"--arch", arch,
"--image-name", name,
raw_image_path, *cmd]
testlib.runcmd_nc(cmd)


def main():
desc = "Boot an image in the cloud environment it is built for and validate the configuration"
parser = argparse.ArgumentParser(description=desc)
Expand All @@ -172,6 +211,8 @@ def main():
match image_type:
case "ami" | "ec2" | "ec2-ha" | "ec2-sap" | "edge-ami":
boot_ami(distro, arch, image_type, image_path, build_config_path)
case "vhd":
boot_vhd(distro, arch, image_path, build_config_path)
case "iot-bootable-container":
manifest_id = build_info["manifest-checksum"]
boot_container(distro, arch, image_type, image_path, manifest_id)
Expand Down
23 changes: 14 additions & 9 deletions test/scripts/imgtestlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@
OS_RELEASE_FILE = "/etc/os-release"

# image types that can be boot tested
CAN_BOOT_TEST = [
"ami",
"ec2",
"ec2-ha",
"ec2-sap",
"edge-ami",
"iot-bootable-container",
]
CAN_BOOT_TEST = {
"*": [
"ami",
"ec2",
"ec2-ha",
"ec2-sap",
"edge-ami",
"iot-bootable-container",
],
"x86_64": [
"vhd"
],
Comment on lines +32 to +34

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we test all vhd variants?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! but aarch64 didn't immediately work, and because the PR is already huge, I thought to focus on x86 first. It probably has to do with some combination of size and maybe some other options when creating the VM.

}

BIB_TYPES = [
"iot-bootable-container"
Expand Down Expand Up @@ -307,7 +312,7 @@ def check_for_build(manifest_fname, build_info_dir, errors):
print(" No PR/branch info available")

image_type = dl_config["image-type"]
if image_type not in CAN_BOOT_TEST:
if image_type not in CAN_BOOT_TEST.get("*", []) + CAN_BOOT_TEST.get(dl_config["arch"], []):
print(f" Boot testing for {image_type} is not yet supported")
return False

Expand Down