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

[e2e] fix terraform fixture bug #1507

Merged
merged 1 commit into from
Sep 11, 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
45 changes: 23 additions & 22 deletions harvester_e2e_tests/fixtures/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ def tf_script_dir(request):
@pytest.fixture(scope="session")
def tf_provider_version(request, harvester_metadata):
version = request.config.getoption('--terraform-provider-harvester')
import requests
resp = requests.get("https://registry.terraform.io/v1/providers/harvester/harvester")
latest = max(resp.json()['versions'], key=parse_version)
version = None if version == '0.0.0-dev' else version
harvester_metadata['Terraform Harvester Provider Version'] = f"{version} || {latest}"
return version or latest
if not version:
import requests
resp = requests.get("https://registry.terraform.io/v1/providers/harvester/harvester")
version = max(resp.json()['versions'], key=parse_version)
harvester_metadata['Terraform Harvester Provider Version'] = f"{version}"
return version


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -223,7 +223,9 @@ def tf_rancher(rancher_api_client, tf_script_dir, tf_provider_rancher_ver, tf_ex
@pytest.fixture(scope="session")
def tf_resource(tf_provider_version):
converter = Path("./terraform_test_artifacts/json2hcl")
return TerraformResource.for_version(tf_provider_version)(converter)
# update `0.0.0-dev` to get newest class
version = "8.8.99" if tf_provider_version == '0.0.0-dev' else tf_provider_version
irishgordo marked this conversation as resolved.
Show resolved Hide resolved
return TerraformResource.for_version(version)(converter)


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -258,29 +260,28 @@ def initial_provider(self, kubeconfig, provider_version):
tf_version=">=0.13", config_path=kubefile.resolve(),
provider_source="harvester/harvester", provider_version=provider_version
))

# cleanup terraform plugin cache
local_plugin_path = "~/.terraform.d/plugins/registry.terraform.io"
local_plugin_tf = "harvester/harvester/0.0.0-dev/linux_amd64"
rv = run(
f"rm -rf ~/.terraform.d/plugins/registry.terraform.io/harvester/harvester &&"
f" mkdir -p {local_plugin_path}/{local_plugin_tf}",
shell=True, stdout=PIPE, stderr=PIPE, cwd=self.workdir)
assert not remove_ansicode(rv.stderr) and 0 == rv.returncode
init_arg = ""

if provider_version == "0.0.0-dev":
docker_plugin_path = "/root/.terraform.d/plugins/terraform.local/local"
docker_plugin_tf = "harvester/0.0.0-dev/linux_amd64/terraform-provider-harvester_v0.0.0-dev" # noqa: E501
local_plugin_path = "./registry.terraform.io/harvester/harvester/0.0.0-dev"
docker_plugin_path = (
"/root/.terraform.d/plugins/terraform.local/local/"
"harvester/0.0.0-dev/linux_amd64/terraform-provider-harvester_v0.0.0-dev"
)
rv = run(
f"docker run --pull=always -q --rm --name harv-tf-master-head"
f" -v {local_plugin_path}/{local_plugin_tf}:/_tf"
f"mkdir -p {local_plugin_path}"
f"&& mkdir linux_amd64"
f"&& docker run --pull=always -q --rm --name harv-tf-master-head"
f" -v ./linux_amd64:/_tf"
f" rancher/terraform-provider-harvester:master-head-amd64"
f' bash -c "cp {docker_plugin_path}/{docker_plugin_tf} /_tf/"',
f' bash -c "cp {docker_plugin_path} /_tf/"'
f"&& mv linux_amd64 {local_plugin_path}",
shell=True, stdout=PIPE, stderr=PIPE, cwd=self.workdir
)
assert not remove_ansicode(rv.stderr) and 0 == rv.returncode
init_arg = " -plugin-dir ."

return self.execute("init")
return self.execute(f"init {init_arg}")

def save_as(self, content, filename, ext=".tf"):
filepath = self.workdir / f"{filename}{ext}"
Expand Down