test/e2e/run: Adjust tests to make script and TF plan work in offline environments - #1500
test/e2e/run: Adjust tests to make script and TF plan work in offline environments#1500ggouzi wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Adjusts the e2e Terraform plan and runner script to support offline environments by making LXD image sourcing and project/profile selection configurable, instead of relying on hardcoded defaults.
Changes:
- Adds new Terraform variables to configure image remote/project and whether to copy image aliases, plus project/profile creation toggles.
- Updates Terraform resources to use the new variables (optional project/profile creation; configurable image caching behavior).
- Updates the
test/e2e/runhelper to consistently operate against a configurable LXD project and pass it into Terraform.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
test/e2e/variables.tf |
Introduces new variables for image sourcing and project/profile configuration. |
test/e2e/main.tf |
Applies new variables to LXD project/profile, cached images, and instance creation (including optional resource creation). |
test/e2e/run |
Uses a configurable PROJECT for lxc operations and passes project into terraform apply/destroy. |
test/e2e/terraform.tfvars.offline.example |
Adds an offline example tfvars file showing how to set the new variables. |
Suppressed comments (2)
test/e2e/variables.tf:26
copy_image_aliasesdescription referencessource_remote, but the variable exposed to users isimage_remoteand main.tf usesvar.image_remote. This is confusing when configuring offline environments.
variable "copy_image_aliases" {
description = "Whether to copy the source image's aliases to the cached image copy. Set to true if source_remote's images carry aliases"
type = bool
default = false
}
test/e2e/terraform.tfvars.offline.example:16
- Minor grammar: "Can be configure" should be "Can be configured" (and "re-use" is usually written as "reuse").
# LXD project/profile to use. By default, a project and profile named e2e-testing
# Can be configure to re-use an existing project/profile
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
roosterfish
left a comment
There was a problem hiding this comment.
Thanks for this, please have a look at my comments.
Also please make sure the commits are squashed accordingly, I saw there were some from the copilot suggestions I assume. They should be integrated with the actual code changes.
It might also help to commit the changes in smaller chunks. One commit that adds new vars, one that uses it and so on.
| default = "e2e-testing" | ||
| } | ||
|
|
||
| variable "create_project" { |
There was a problem hiding this comment.
Same for project and profile: Can we please check if the project exists and if not simply create it?
Otherwise when you want to reuse an existing one, you have to not only provide its name, but also have to set create_* var to false.
| # Project | ||
| resource "lxd_project" "e2e" { | ||
| name = "e2e-testing" | ||
| count = var.create_project ? 1 : 0 |
There was a problem hiding this comment.
Instead let's check whether or not the project/profile already exists.
There was a problem hiding this comment.
Checking if profile/project exist implies using local-exec bash commands no ? Or is there a better way to check ?
There was a problem hiding this comment.
My thinking was you could maybe use the profile or project resource to check if they exist?
There was a problem hiding this comment.
data lxd_project and data lxd_profile are plain read data sources but the real objects in LXD API can have been created outside TF (not managed by TF plan)
Won't they error if the resource doesn't exist ?
Switched to external type with bash commands for now
| project = lxd_project.e2e.name | ||
| remote = lxd_project.e2e.remote | ||
| count = var.create_profile ? 1 : 0 | ||
| name = var.profile |
There was a problem hiding this comment.
I guess we can still derive the project/remote from the lxd_project? It's id doesn't change, only its display name based on the var.
|
Please also |
… environments Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Gaëtan GOUZI <gouzi.gaetan@gmail.com> remove boolean create_profile/create_project + check exist instead + rename example file Signed-off-by: ggouzi <gaetan.gouzi@canonical.com>
0046f9e to
8f116f5
Compare
| # Project | ||
| # Check whether the project already exists | ||
| data "external" "project_exists" { | ||
| program = ["bash", "-c", "lxc project list \"${var.remote}:\" -f csv | awk -F, '{gsub(/ \\(current\\)$/, \"\", $1); print $1}' | grep -qxF \"${var.project}\" && echo '{\"exists\": \"true\"}' || echo '{\"exists\": \"false\"}'"] |
There was a problem hiding this comment.
Used AI for this ugly command FYI.
In offline environments, the e2e tests do not work because we relied on:
ubuntu-minimal-dailyIn offline envs, we have an additional remote pointing to custom simplestreams LXD mirrors. We also have custom profiles with
cloud-init-user-dataso the images apt sources and snap proxy are overridden to point to local mirrors. We may also share images across projects (features.images=false)This PR aims to tackle down those changes to make the script and TF plan work in offline environments. Tested and confirmed to be working in an offline production environment.
Added the following variables
image_remote(string)image_project(string)copy_image_aliases(bool)project(string)create_project(bool)profile(string)create_profile(bool)Checklist
I have read the contributing guidelines and attest that all commits in this PR are signed off, cryptographically signed, and follow this project's commit structure.
I have checked and added or updated relevant documentation.