application = <iqe.base.application.Application object at 0x7fed72153f80>
metric_id = 'Instance-hours'
@pytest.mark.post_stage_deploy
@pytest.mark.parametrize(
"metric_id", get_random_choices_or_leading_elements(["Cores", "Instance-hours"])
)
def test_validate_retally_triggered_older_events(application, metric_id):
"""Validate that tally pull in new events added to previous months. SWATCH-1579
metadata:
assignee: aunayak
negative: false
importance: critical
requirements: payg_tally
test_steps:
1. Read tally counts for test range
2. Create and send mock events
3. Re-tally for range that does not include the added events
4. Check new counts should be re-tallied
expected_results:
1. Re-tally should also included the events added in previous range
"""
product_id = "OpenShift-dedicated-metrics"
# Start Dates for Events
start_times_list = [
today().replace(microsecond=0, day=1, hour=0, minute=0, second=0),
today().replace(microsecond=0, day=1, hour=0, minute=0, second=0) - relativedelta(months=1),
today().replace(microsecond=0, day=2, hour=0, minute=0, second=0) - relativedelta(months=1),
today().replace(microsecond=0, day=3, hour=0, minute=0, second=0) - relativedelta(months=1),
]
start_current_month, end_current_month = get_monthly_range(start_times_list[0])
initial_current_month_tally = application.rhsm_subscriptions.get_tally_report(
product_id=product_id,
beginning=start_current_month,
ending=end_current_month,
granularity="Daily",
metric_id=metric_id,
)
initial_tally = application.rhsm_subscriptions.get_tally_report(
product_id=product_id,
beginning=start_times_list[1],
ending=start_times_list[-1],
granularity="Daily",
metric_id=metric_id,
)
assert initial_tally
# Create Mock Data
event_ids = []
for start_time in start_times_list[1:]:
event_id = application.rhsm_subscriptions.create_mock_payg_cluster(
product_id=product_id,
start_time=start_time,
)
event_ids.append(event_id)
log.debug(event_ids)
system_table = False
tries = 1
# Sync Tally, outside event range,
# To avoid the wait times in syn_hourly_tally
# Added a local system_table check.
# It checks if new hosts added or not,
# and if yes,it returns without further delay.
while not system_table and tries < 4:
application.rhsm_subscriptions.sync_tally_hourly(
product_id=product_id,
start=datetime_to_iso8601_format(start_times_list[0]),
wait=False,
perform_metering=False,
)
system_table = application.rhsm_subscriptions.get_instances_report(
product_id=product_id,
beginning=start_times_list[1],
ending=start_times_list[-1],
limit=100,
display_name_contains=get_random_choice_or_first(event_ids),
)
if not system_table:
time.sleep(4)
tries += 1
# Compare Results
new_tally = application.rhsm_subscriptions.get_tally_report(
product_id=product_id,
beginning=start_times_list[1],
ending=start_times_list[-1],
granularity="Daily",
metric_id=metric_id,
)
# Tally will happen for the last month. Tally Hourly will not have start and end time.
# It will tally all events after the last processed record_data on event
assert new_tally
> assert (
sum([t["value"] for t in new_tally["data"]])
== sum([t["value"] for t in initial_tally["data"]]) + 3
), f"Tally sum should be increased by 3, since we added three new events for {metric_id}"
E AssertionError: Tally sum should be increased by 3, since we added three new events for Instance-hours
E assert 8090 == (8090 + 3)
E + where 8090 = sum([2353, 2283, 3454])
E + and 8090 = sum([2353, 2283, 3454])
/iqe_venv/lib/python3.12/site-packages/iqe_rhsm_subscriptions/tests/integration/swatch_tally/test_tally_retally.py:122: AssertionError2025-10-07 17:50:58Jump To