Skip to content

Commit 90e1237

Browse files
authored
SWATCH-5116: Add workaround moto patch to support CustomerAWSAccountId (#6415)
Jira issue: SWATCH-5116 ## Description The IQE tests use Moto to validate the happy path scenarios when submitting AWS usages. However, moto does not support the CustomerAWSAccountId field (I contributed to moto to support this getmoto/moto#10133). In the mean time, this is a workaround / hack to support CustomerAWSAccountId and CustomerIdentifier both fields. This is necessary to validate the CustomerAWSAccountId (AWS concurrent agreements epic) in the IQE tests. I also reported https://redhat.atlassian.net/browse/SWATCH-5317 to stop using Moto (which does not guarantee the compatibility with AWS SDK) and start using Wiremock as done in the component tests. ## Testing IQE MR: https://gitlab.cee.redhat.com/insights-qe/iqe-rhsm-subscriptions-plugin/-/merge_requests/1560 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved AWS Marketplace metering compatibility by correctly handling customer account identifiers during batch usage reporting. - Enhanced local service startup reliability and validation for metering workflows. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 583bd66 + c52e611 commit 90e1237

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

swatch-producer-aws/deploy/clowdapp.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,35 @@ objects:
284284
containers:
285285
- name: moto
286286
image: 'motoserver/moto:5.1.8'
287+
# Workaround until https://github.com/getmoto/moto/pull/10133 is released:
288+
# BatchMeterUsage must accept CustomerAWSAccountId. Image is read-only and
289+
# PWD=/moto shadows PYTHONPATH, so copy+patch under /tmp then start.
290+
command: ["/bin/sh", "-c"]
291+
args:
292+
- |
293+
set -eu
294+
mkdir -p /tmp/moto-src && cp -a /moto/moto /tmp/moto-src/moto
295+
python3 <<'PY'
296+
from pathlib import Path
297+
path = Path("/tmp/moto-src/moto/meteringmarketplace/models.py")
298+
text = path.read_text()
299+
text = text.replace(
300+
'customer_identifier=kwargs["CustomerIdentifier"],',
301+
'customer_identifier=kwargs.get("CustomerIdentifier") or kwargs.get("CustomerAWSAccountId"),',
302+
1,
303+
)
304+
needle = 'self["MeteringRecordId"] = self.usage_record.metering_record_id'
305+
insert = (
306+
'if kwargs.get("CustomerAWSAccountId") is not None:\n'
307+
' self.usage_record["CustomerAWSAccountId"] = kwargs["CustomerAWSAccountId"]\n'
308+
' ' + needle
309+
)
310+
if needle not in text:
311+
raise SystemExit("CustomerAWSAccountId moto patch failed")
312+
path.write_text(text.replace(needle, insert, 1))
313+
PY
314+
export PYTHONPATH=/tmp/moto-src
315+
cd /tmp && exec moto_server -H 0.0.0.0
287316
env:
288317
- name: MOTO_PORT
289318
value: '5000'

0 commit comments

Comments
 (0)