Skip to content

Commit

Permalink
+ [e2e] add terraform test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lanfon72 committed Nov 14, 2023
1 parent a6e0057 commit ee12599
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion harvester_e2e_tests/integration/test_z_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pytest_plugins = [
"harvester_e2e_tests.fixtures.api_client",
"harvester_e2e_tests.fixtures.images",
"harvester_e2e_tests.fixtures.terraform"
]

Expand All @@ -20,6 +21,14 @@ def volume_resource(unique_name, tf_resource):
return spec, unique_name, size


@pytest.fixture(scope="module")
def image_resource(unique_name, image_opensuse, tf_resource):
spec = tf_resource.image_download(
f"tf_{unique_name}", unique_name, unique_name, image_opensuse.url
)
return spec, unique_name, image_opensuse


@pytest.mark.dependency(name="create_ssh_key")
def test_create_ssh_key(api_client, tf_harvester, ssh_key_resource):
spec, unique_name, _ = ssh_key_resource
Expand Down Expand Up @@ -60,10 +69,51 @@ def test_create_volume(api_client, tf_harvester, volume_resource):
@pytest.mark.dependency(depends=["create_volume"])
def test_delete_volume(api_client, tf_harvester, volume_resource):
spec, unique_name, _ = volume_resource
tf_harvester.save_as(spec.ctx, "volumes")

out, err, code = tf_harvester.destroy_resource(spec.type, spec.name)
assert not err and 0 == code

code, data = api_client.volumes.get(unique_name)
assert 404 == code


@pytest.mark.dependency(name="create_image")
def test_create_image(api_client, tf_harvester, image_resource):
spec, unique_name, img_info = image_resource
tf_harvester.save_as(spec.ctx, "images")

out, err, code = tf_harvester.apply_resource(spec.type, spec.name)
assert not err and 0 == code

code, data = api_client.images.get(unique_name)
assert 200 == code
assert img_info.url == data['spec']['url']


def test_create_volume_from_image(api_client, tf_harvester, tf_resource, image_resource):
spec, unique_name, img_info = image_resource
tf_harvester.save_as(spec.ctx, "images")

out, err, code = tf_harvester.apply_resource(spec.type, spec.name)
assert not err and 0 == code

code, data = api_client.images.get(unique_name)
spec = tf_resource.volume(
f"tf_{unique_name}", unique_name, "10Gi",
image=f"{data['metadata']['namespace']}/{unique_name}"
)
tf_harvester.save_as(spec.ctx, "vol_from_img")

out, err, code = tf_harvester.apply_resource(spec.type, spec.name)
assert not err and 0 == code


@pytest.mark.dependency(depends=["create_image"])
def test_delete_image(api_client, tf_harvester, image_resource):
spec, unique_name, _ = image_resource

out, err, code = tf_harvester.destroy_resource(spec.type, spec.name)
assert not err and 0 == code

code, data = api_client.images.get(unique_name)
assert 404 == code

0 comments on commit ee12599

Please sign in to comment.