Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

support transforming google images #419

Merged
merged 4 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
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
20 changes: 19 additions & 1 deletion src/cloudimagedirectory/transform/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cloudimagedirectory.connection import connection
from cloudimagedirectory.update_images import aws
from cloudimagedirectory.update_images import azure
from cloudimagedirectory.update_images import google


class Pipeline:
Expand Down Expand Up @@ -72,7 +73,24 @@ class TransformerGOOGLE(Transformer):

def run(self, data):
"""Transform the raw data."""
return []
entries = []
for d in data:
if d.filename.__contains__("google"):
entries.append(d)

results = []
for e in entries:
raw = self.src_conn.get_content(e)
for content in raw.content:
content["creation_timestamp"] = content["creationTimestamp"]
if content["name"].__contains__("rhel"):
r = google.format_image(content)
de = connection.DataEntry(
"google/" + "global/" + r["name"].replace(" ", "_").lower(), r
)
results.append(de)

return results


class TransformerAZURE(Transformer):
Expand Down
1 change: 0 additions & 1 deletion src/cloudimagedirectory/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ def run(origin_path: str, destination_path: str, api: str, arg_files: str) -> No
version_prefix = api + "/"
for result in results:
result.filename = destination_path + "/" + version_prefix + result.filename
print("put content to filesystem - filename: " + result.filename)
origin_connection.put_content(result)
1 change: 1 addition & 0 deletions tests/transformer/aws_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


def test_transformer_aws():
"""Run transformer end to end with AWS input data."""
assert 0 == os.system(
"poetry run cloudimagedirectory-transformer -f"
" ${PWD}/tests/transformer/testdata/input/aws/af-south-1.json -op=${PWD} "
Expand Down
1 change: 1 addition & 0 deletions tests/transformer/azure_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


def test_transformer_azure():
"""Run transformer end to end with Azure input data."""
assert 0 == os.system(
"poetry run cloudimagedirectory-transformer -f"
" ${PWD}/tests/transformer/testdata/input/azure/eastus.json -op=${PWD} "
Expand Down
14 changes: 14 additions & 0 deletions tests/transformer/google_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os


def test_transformer_google():
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a docstring to your tests as well as breaking test cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I can add a docstring. How would you model a breaking test? The only thing that I have in mind is, that the transformer would fail if we provide an invalid input file. Does this make sense to you?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that makes total sense to me. I would add

  • Files with a broken structure (test case: the retriever created a malformed file)
  • Files cannot be downloaded (test case: S3 bucket is down / cannot be reached)
    I want to make sure that we can catch those failures should they occur.

Copy link
Member Author

@miyunari miyunari Mar 23, 2023

Choose a reason for hiding this comment

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

Files with a broken structure (test case: the retriever created a malformed file)

Sure, I will create an issue 👍 #421

Files cannot be downloaded (test case: S3 bucket is down / cannot be reached)
I want to make sure that we can catch those failures should they occur.

Is that then a test of the s3cmd tool? 🤔

https://github.com/redhatcloudx/cloud-image-directory/blob/580b08b3e942866f2b1dcd1e28757a690fde5a21/.github/workflows/transformer.yaml#L54-L66

Since the transformer only uses files from the filesystem. We removed the s3 bucket connection (implementation), remember? 🥴

Copy link
Member

Choose a reason for hiding this comment

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

True. Strike the download! We'll cover empty inputs with the rest of the tests in the follow up task!

"""Run transformer end to end with google input data."""
assert 0 == os.system(
"poetry run cloudimagedirectory-transformer -f"
" ${PWD}/tests/transformer/testdata/input/google/all.json -op=${PWD} "
" -dp=${PWD}/tests/transformer/testdata -v output"
)
assert 0 == os.system(
"diff ${PWD}/tests/transformer/testdata/expected/google/global/rhel_7_x86_64"
" ${PWD}/tests/transformer/testdata/output/google/global/rhel_7_x86_64"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "RHEL 7 X86_64", "arch": "X86_64", "version": "7", "imageId": "rhel-7-v20230306", "date": "2023-03-06T12:57:17.210-08:00", "selflink": "https://console.cloud.google.com/compute/imagesDetail/projects/rhel-cloud/global/images/rhel-7-v20230306"}
40 changes: 40 additions & 0 deletions tests/transformer/testdata/input/google/all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[
{
"architecture": "X86_64",
"archiveSizeBytes": "4944263232",
"creationTimestamp": "2023-03-06T12:57:17.210-08:00",
"description": "Red Hat, Red Hat Enterprise Linux, 7, x86_64 built on 20230306, supports Shielded VM features",
"diskSizeGb": "20",
"family": "rhel-7",
"guestOsFeatures": [
{
"type": "UEFI_COMPATIBLE"
},
{
"type": "GVNIC"
}
],
"id": "8907890564493208899",
"kind": "compute#image",
"labelFingerprint": "42WmSpB8rSM=",
"licenseCodes": [
"1000006"
],
"licenses": [
"https://www.googleapis.com/compute/v1/projects/rhel-cloud/global/licenses/rhel-7-server"
],
"name": "rhel-7-v20230306",
"rawDisk": {
"containerType": "TAR",
"source": ""
},
"selfLink": "https://www.googleapis.com/compute/v1/projects/rhel-cloud/global/images/rhel-7-v20230306",
"sourceType": "RAW",
"status": "READY",
"storageLocations": [
"us",
"asia",
"eu"
]
}
]