Skip to content

Commit

Permalink
Merge pull request #71 from release-engineering/improve_collector
Browse files Browse the repository at this point in the history
Adds cloud_info to the pushcollector's clouds.json
  • Loading branch information
JAVGan authored Oct 31, 2024
2 parents dc548fe + bae483a commit 2008bb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/pubtools/_marketplacesvm/tasks/community_push/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import os
from collections import namedtuple
from typing import Any, Dict, Iterator, List, Optional, TypedDict, cast
from typing import Any, Dict, Iterator, List, Optional, Tuple, TypedDict, cast

from attrs import asdict, evolve
from more_executors import Executors
Expand Down Expand Up @@ -358,7 +358,7 @@ def _upload(
push_item: VMIPushItem,
custom_tags: Optional[Dict[str, str]] = None,
**kwargs,
) -> VMIPushItem:
) -> Tuple[VMIPushItem, str]:
# First we do the AMI upload in a similar way of the base class
ship = not self.args.pre_push
container = "%s-%s" % (self.args.container_prefix, push_item.region)
Expand Down Expand Up @@ -395,7 +395,7 @@ def _upload(
stack_info=True,
)
pi = evolve(push_item, state=State.UPLOADFAILED)
return pi
return pi, marketplace

# Then, if we're shipping the community image, we should update the RHSM
# and change the the AWS group to "all" for the uploaded image
Expand All @@ -418,12 +418,12 @@ def _upload(
except Exception as exc:
log.exception("Failed to publish %s: %s", push_item.name, str(exc), stack_info=True)
pi = evolve(push_item, state=State.NOTPUSHED)
return pi
return pi, marketplace

# Finally, if everything went well we return the updated push item
log.info("Successfully uploaded %s [%s] [%s]", pi.name, pi.region, image.id)
pi = evolve(pi, state=State.PUSHED)
return pi
return pi, marketplace

def _check_product_in_rhsm(self, enriched_push_items: List[EnrichedPushItem]) -> bool:
for enriched_item in enriched_push_items:
Expand Down Expand Up @@ -466,8 +466,12 @@ def _push_to_community(self, push_queue: Iterator[UploadParams]) -> List[Dict[st
"state": pi.state,
"image_id": pi.image_id,
"image_name": name_from_push_item(pi),
"cloud_info": {
"account": marketplace,
"provider": "aws",
},
}
for pi in upload_result
for pi, marketplace in upload_result
]

def _data_to_upload(
Expand Down
7 changes: 6 additions & 1 deletion src/pubtools/_marketplacesvm/tasks/push/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ async def push_function(mapped_item, marketplace, starmap_query) -> Dict[str, An
return {
"push_item": push_item_for_collection,
"state": pi.state,
"marketplace": marketplace,
"cloud_info": {
"account": marketplace,
"provider": mapped_item.starmap_query_entity.cloud,
},
"destinations": mapped_item.starmap_query_entity.mappings[marketplace].destinations,
"starmap_query": starmap_query,
}
Expand Down Expand Up @@ -337,6 +340,8 @@ def convert(obj):
res_dict = asdict(result["push_item"])
if result.get("starmap_query"):
res_dict["starmap_query"] = asdict(result["starmap_query"])
if result.get("cloud_info"):
res_dict["cloud_info"] = result["cloud_info"]
# dict can't be modified during iteration.
# so iterate over list of keys.
for key in list(res_dict):
Expand Down

0 comments on commit 2008bb2

Please sign in to comment.