Skip to content

Commit

Permalink
fix: current tests
Browse files Browse the repository at this point in the history
Signed-off-by: Leandro Mendes <[email protected]>
  • Loading branch information
theflockers committed Feb 25, 2025
1 parent 0f1fde5 commit f4f49c9
Show file tree
Hide file tree
Showing 14 changed files with 438 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ spec:
mkdir -p "$DISK_IMAGE_DIR"
process_component() { # Expected argument is [component json]
set -x
COMPONENT=$1
PULLSPEC=$(jq -er '.containerImage' <<< "${COMPONENT}")
PULLSPEC=$(jq -er '.containerImage' <<< "${COMPONENT}") \
|| (echo "Missing containerImage for component." && exit 1 )
DESTINATION="${DISK_IMAGE_DIR}/$(jq -er '.staged.destination' <<< "${COMPONENT}")/FILES" \
|| (echo "Missing staged.destination value for component. This should be an existing pulp repo. \
Failing" && exit 1)
Expand All @@ -182,8 +183,10 @@ spec:
NUM_MAPPED_FILES=$(jq '.staged.files | length' <<< "${COMPONENT}")
for ((i = 0; i < NUM_MAPPED_FILES; i++)) ; do
FILE=$(jq -c --arg i "$i" '.staged.files[$i|tonumber]' <<< "$COMPONENT")
SOURCE=$(jq -er '.source' <<< "$FILE")
FILENAME=$(jq -er '.filename' <<< "$FILE")
SOURCE=$(jq -er '.source' <<< "$FILE") \
|| (echo "Missing staged.files.source for component." && exit 1 )
FILENAME=$(jq -er '.filename' <<< "$FILE") \
|| (echo "Missing staged.files.filename for component." && exit 1 )
# The .qcow2 images are not zipped
if [ -f "${SOURCE}.gz" ] ; then
gzip -d "${SOURCE}.gz"
Expand All @@ -193,8 +196,8 @@ spec:
# The race condition is if two files have the same $DESTINATION_FILE and both
# if checks are run before either mv is run a few lines below.
if [ -f "${DESTINATION_FILE}" ] ; then
echo -n "Multiple files use the same destination value: $DESTINATION" >&2
echo " and filename value: $FILENAME. Failing..." >&2
echo "Multiple files use the same destination value: $DESTINATION" \
"and filename value: $FILENAME. Failing..." >&2
exit 1
fi
mv "$SOURCE" "${DESTINATION_FILE}" || echo "didn't find mapped file: ${SOURCE}"
Expand Down Expand Up @@ -720,7 +723,6 @@ spec:
# get all of the signed binaries into a common directory
CONTENT_DIR=/shared/artifacts
find $CONTENT_DIR
SIGNED_DIR="$CONTENT_DIR/signed"
mkdir -p "$SIGNED_DIR"
mkdir -p "$CONTENT_DIR"/linux
Expand Down Expand Up @@ -853,10 +855,9 @@ spec:
if [ "$err" -eq 0 ] ; then
echo -n "Success" > "$(results.result.path)"
else
echo "$0: ERROR '$command' failed at line $line - exited with status $err" \
> "$(results.result.path)"
echo "$0: ERROR '$command' failed at line $line - exited with status $err" > "$(results.result.path)"
if [ -f "$STDERR_FILE" ] ; then
tail -n 20 "$STDERR_FILE" >> "$(results.result.path)"
tail -n 20 "$STDERR_FILE" | tee -a "$(results.result.path)"
fi
fi
exit 0 # exit the script cleanly as there is no point in proceeding past an error or exit call
Expand Down Expand Up @@ -899,22 +900,32 @@ spec:
return
fi
# using { ;} to avoid subshell
productName="$(jq -er '.productName' <<< "${contentGatewayConfig}")" \
|| { echo "Missing contentGateway.productName value for component. This should be an existing product \
in the Developer Portal. Failing" && exit 1; }
productCode="$(jq -er '.productCode' <<< "${contentGatewayConfig}")" \
|| { echo "Missing contentGateway.productCode value for component. This should be an existing product \
in the Developer Portal. Failing" && exit 1; }
productName="$(jq -r '.productName' <<< "${contentGatewayConfig}")"
if [ "${productName}" == "null" ]; then
echo "Missing contentGateway.productName value for component. This should be an existing product" \
"in the Developer Portal. Failing" >&2
exit 1
fi
productCode="$(jq -r '.productCode' <<< "${contentGatewayConfig}")"
if [ "${productCode}" == "null" ]; then
echo "Missing contentGateway.productCode value for component. This should be an existing product" >&2
exit 1
fi
productVersionName="$(jq -er '.productVersionName' <<< "${contentGatewayConfig}")" \
|| { echo "Missing contentGateway.productVersionName value for component. This should be an existing \
product in the Developer Portal. Failing" && exit 1; }
productVersionName="$(jq -r '.productVersionName' <<< "${contentGatewayConfig}")"
if [ "${productVersionName}" == "null" ]; then
echo "Missing contentGateway.productVersionName value for component. This should be an existing" \
"product in the Developer Portal. Failing" >&2
exit 1
fi
filePrefix="$(jq -er '.filePrefix' <<< "${contentGatewayConfig}")" \
|| { echo "Missing contentGateway.filePrefix value for component. This should be the prefix for files to \
upload to the Developer Portal. Failing" && exit 1; }
filePrefix="$(jq -r '.filePrefix' <<< "${contentGatewayConfig}")"
if [ "${filePrefix}" == "null" ]; then
echo "Missing contentGateway.filePrefix value for component. This should be the prefix for files to" \
"upload to the Developer Portal. Failing" >&2
exit 1
fi
developer_portal_wrapper --debug --product-name "${productName}" \
--product-code "${productCode}" \
Expand Down Expand Up @@ -966,5 +977,6 @@ spec:
NUM_COMPONENTS=$(jq '.components | length' <<< "$SNAPSHOT_JSON")
for ((i = 0; i < NUM_COMPONENTS; i++)) ; do
COMPONENT=$(jq -c --arg i "$i" '.components[$i|tonumber]' <<< "$SNAPSHOT_JSON")
process_component_for_developer_portal "$COMPONENT" "${component_destinations[$i]}" 2> "$STDERR_FILE"
# eventually the function does not redirect the error to stderr, so looking for all output
process_component_for_developer_portal "$COMPONENT" "${component_destinations[$i]}" 2> "$STDERR_FILE"
done
9 changes: 4 additions & 5 deletions tasks/internal/push-artifacts-to-cdn-task/tests/mocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ function select-oci-auth() {

function oras() {
echo Mock oras called with: $*

if [[ "$*" =~ login.* ]]; then
echo Simulating oras quay login
elif [[ "$*" =~ push.* ]]; then
echo Simulating oras push
echo "Digest: sha256:$(echo | sha256sum |awk '{ print $1}')"
elif [[ "$*" == *"nonexistent-disk-image"* ]]; then
echo Simulating failing oras pull call >&2
exit 1
elif [[ "$*" == "pull --registry-config"* ]]; then
echo "Mocking pulling files"
touch binary-windows-amd64.zip
Expand All @@ -26,9 +28,6 @@ function oras() {
touch windows/binary-windows-amd64.exe
touch linux/binary-linux-amd64
touch macos/binary-darwin-amd64
elif [[ "$*" == *"nonexistent-disk-image"* ]]; then
echo Simulating failing oras pull call
exit 1
fi
touch fail_gzip.raw.gz
}
Expand All @@ -37,7 +36,7 @@ function oras() {
function ziputil() {
echo Mock a compressing tool with: $*
if [ "$2" == "fail_gzip.raw.gz" ] ; then
echo gzip failed
echo gzip failed >&2
exit 1
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,38 @@ spec:
params:
- name: snapshot_json
value: >-
{"application":"amd-bootc-1-3-qcow2-disk-image","artifacts":{},"components":[{
"containerImage":"quay.io/org/tenant/qcow-disk-image/qcow2-disk-image@sha256:abcdef12345",
"contentGateway":{"filePrefix":"amd-1.3","productName":"Disk Image for Linux",
"productVersionName":"1.3-staging"},"staged":{"destination":"x86_64-isos","files":[{
"filename":"amd-1.3-x86_64-kvm.qcow2","source":"disk.qcow2"},{"filename":"amd-1.3-x86_64-kvm.raw",
"source":"disk.raw"}],"version":"1.3"}}]}
{
"application": "amd-bootc-1-3-qcow2-disk-image",
"artifacts": {},
"components": [
{
"containerImage": "quay.io/org/tenant/qcow-disk-image/qcow2-disk-image@sha256:abcdef12345",
"contentGateway": {
"filePrefix": "amd-1.3",
"productName": "MyName",
"productVersionName": "1.3-staging"
},
"staged": {
"destination": "test-product-amd64",
"files": [
{
"filename": "binary-windows-amd64.zip",
"source": "binary-windows-amd64.zip"
},
{
"filename": "binary-darwin-amd64.tar.gz",
"source": "binary-darwin-amd64.tar.gz"
},
{
"filename": "binary-linux-amd64.tar.gz",
"source": "binary-linux-amd64.tar.gz"
}
],
"version": "1.3"
}
}
]
}
- name: exodusGwSecret
value: "pulp-task-exodus-secret"
- name: exodusGwEnv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,39 @@ spec:
params:
- name: snapshot_json
value: >-
{"application":"amd-bootc-1-3-qcow2-disk-image","artifacts":{},"components":[{
"containerImage":"quay.io/org/tenant/qcow-disk-image/qcow2-disk-image@sha256:abcdef12345",
"contentGateway":{"filePrefix":"amd-1.3","productCode":"DISK",
"productVersionName":"1.3-staging"},"staged":{"destination":"x86_64-isos","files":[{
"filename":"amd-1.3-x86_64-kvm.qcow2","source":"disk.qcow2"},{"filename":"amd-1.3-x86_64-kvm.raw",
"source":"disk.raw"}],"version":"1.3"}}]}
{
"application": "amd-bootc-1-3-qcow2-disk-image",
"artifacts": {},
"components": [
{
"containerImage": "quay.io/org/tenant/qcow-disk-image/qcow2-disk-image@sha256:abcdef12345",
"contentGateway": {
"filePrefix": "amd-1.3",
"productCode": "Code",
"productVersionName": "1.3-staging"
},
"staged": {
"destination": "test-product-amd64",
"files": [
{
"filename": "binary-windows-amd64.zip",
"source": "binary-windows-amd64.zip"
},
{
"filename": "binary-darwin-amd64.tar.gz",
"source": "binary-darwin-amd64.tar.gz"
},
{
"filename": "binary-linux-amd64.tar.gz",
"source": "binary-linux-amd64.tar.gz"
}
],
"version": "1.3"
}
}
]
}
- name: exodusGwSecret
value: "pulp-task-exodus-secret"
- name: exodusGwEnv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,38 @@ spec:
params:
- name: snapshot_json
value: >-
{"application":"amd-bootc-1-3-qcow2-disk-image","artifacts":{},"components":[{
"containerImage":"quay.io/org/tenant/qcow-disk-image/qcow2-disk-image@sha256:abcdef12345",
"contentGateway":{"filePrefix":"amd-1.3","productCode":"DISK","productName":"Disk Image for Linux"},
"staged":{"destination":"x86_64-isos","files":[{
"filename":"amd-1.3-x86_64-kvm.qcow2","source":"disk.qcow2"},{"filename":"amd-1.3-x86_64-kvm.raw",
"source":"disk.raw"}],"version":"1.3"}}]}
{
"application": "amd-bootc-1-3-qcow2-disk-image",
"artifacts": {},
"components": [
{
"containerImage": "quay.io/org/tenant/qcow-disk-image/qcow2-disk-image@sha256:abcdef12345",
"contentGateway": {
"filePrefix": "amd-1.3",
"productCode": "Code",
"productName": "Name"
},
"staged": {
"destination": "test-product-amd64",
"files": [
{
"filename": "binary-windows-amd64.zip",
"source": "binary-windows-amd64.zip"
},
{
"filename": "binary-darwin-amd64.tar.gz",
"source": "binary-darwin-amd64.tar.gz"
},
{
"filename": "binary-linux-amd64.tar.gz",
"source": "binary-linux-amd64.tar.gz"
}
],
"version": "1.3"
}
}
]
}
- name: exodusGwSecret
value: "pulp-task-exodus-secret"
- name: exodusGwEnv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,38 @@ spec:
params:
- name: snapshot_json
value: >-
{"application":"amd-bootc-1-3-qcow2-disk-image","artifacts":{},"components":[{
"contentGateway":{"filePrefix":"amd-1.3","productCode":"DISK","productName":"Disk Image for Linux",
"productVersionName":"1.3-staging"},"staged":{"destination":"x86_64-isos","files":[{
"filename":"amd-1.3-x86_64-kvm.qcow2","source":"disk.qcow2"},{"filename":"amd-1.3-x86_64-kvm.raw",
"source":"disk.raw"}],"version":"1.3"}}]}
{
"application": "amd-bootc-1-3-qcow2-disk-image",
"artifacts": {},
"components": [
{
"contentGateway": {
"filePrefix": "amd-1.3",
"productCode": "Code",
"productName": "MyName",
"productVersionName": "1.3-staging"
},
"staged": {
"destination": "test-product-amd64",
"files": [
{
"filename": "binary-windows-amd64.zip",
"source": "binary-windows-amd64.zip"
},
{
"filename": "binary-darwin-amd64.tar.gz",
"source": "binary-darwin-amd64.tar.gz"
},
{
"filename": "binary-linux-amd64.tar.gz",
"source": "binary-linux-amd64.tar.gz"
}
],
"version": "1.3"
}
}
]
}
- name: exodusGwSecret
value: "pulp-task-exodus-secret"
- name: exodusGwEnv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,35 @@ spec:
params:
- name: snapshot_json
value: >-
{"application":"amd-bootc-1-3-qcow2-disk-image","artifacts":{},"components":[{
"containerImage":"quay.io/org/tenant/qcow-disk-image/qcow2-disk-image@sha256:abcdef12345",
"contentGateway":{"filePrefix":"amd-1.3","productCode":"DISK","productName":"Disk Image for Linux",
"productVersionName":"1.3-staging"},"staged":{"destination":"x86_64-isos","files":[{
"source":"disk.qcow2"},{"filename":"amd-1.3-x86_64-kvm.raw",
"source":"disk.raw"}],"version":"1.3"}}]}
{
"application": "amd-bootc-1-3-qcow2-disk-image",
"artifacts": {},
"components": [
{
"containerImage": "quay.io/org/tenant/qcow-disk-image/qcow2-disk-image@sha256:abcdef12345",
"contentGateway": {
"filePrefix": "amd-1.3",
"productCode": "Code",
"productName": "Name",
"productVersionName": "1.3-staging"
},
"staged": {
"destination": "test-product-amd64",
"files": [
{
"source": "binary-windows-amd64.zip"
},
{
"source": "binary-darwin-amd64.tar.gz"
},
{
"source": "binary-linux-amd64.tar.gz"
}
]
}
}
]
}
- name: exodusGwSecret
value: "pulp-task-exodus-secret"
- name: exodusGwEnv
Expand All @@ -32,6 +55,8 @@ spec:
value: "https://content-gateway.com"
- name: cgwSecret
value: "pulp-task-cgw-secret"
- name: author
value: testuser
- name: check-result
runAfter:
- run-task
Expand Down
Loading

0 comments on commit f4f49c9

Please sign in to comment.