application = <iqe.base.application.Application object at 0x7fed72153f80>
@pytest.mark.post_stage_deploy
def test_tally_nightly_rhel_els_addons(application):
"""Verify calculation of is_migrated rhel ELS addons.
metadata:
assignee: nkathole
negative: false
test_steps:
1. Read existing tally data.
2. Add RHEL ELS addon migrated and non-migrated with product in candlepin.
3. Sync Conduit and Tally data for account.
4. Read new tally data.
5. Verify tally data and system table for RHEL add-ons/variants.
expected_results:
1. Tally data shown is correct.
"""
product_ids = list(
set(config_parser.get_swatch_engineering_ids(engId="204"))
- set(config_parser.get_swatch_payg_products())
)
for product_id in product_ids:
logging.info(f"Testing RHEL ELS : {product_id}")
metric_id = config_parser.get_swatch_metric_id_from_tag_metrics(product_id=product_id)[0]
extra_candlepin_facts = {}
extra_hbi_system_profile_facts = {}
if product_id in config_parser.get_swatch_is_migrated_products():
extra_candlepin_facts = {"conversions.activity": "conversion"}
extra_hbi_system_profile_facts = {"conversions": {"activity": True}}
current_usage = application.rhsm_subscriptions.get_today_tally_report(
product_id=product_id,
metric_id=metric_id,
)
expected_value = current_usage["value"] + 1
host = application.rhsm_subscriptions.create_virtual_rhel(
rh_prod=config_parser.get_swatch_engineering_ids(product_id=product_id),
extra_facts=extra_candlepin_facts,
extra_hbi_system_profile_facts=extra_hbi_system_profile_facts,
)
> application.rhsm_subscriptions.sync_swatch(
wait=True,
product_id=product_id,
hostname=host["display_name"],
expected_metric_id=metric_id,
expected_metric_value=expected_value,
)
/iqe_venv/lib/python3.12/site-packages/iqe_rhsm_subscriptions/tests/integration/swatch_tally/test_tally_rhel_addons.py:260:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/iqe_venv/lib/python3.12/site-packages/iqe_rhsm_subscriptions/__init__.py:840: in sync_swatch
self._wait_for_tally_sync_daily(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = ApplicationRhsmSubscriptions(config=<iqe.base.settings.VaultLoaderAwareSetting object at 0x7fed72026510>)
product_id = 'rhel-for-x86-els-unconverted', metric_id = 'Sockets'
expected_metric_value = 4, pre_tally_value = 3, wait_time = 5
timeout_tries = 12, kwargs = {}, attempt = 11, current_value = 1
system_table = [{'_labeled_measurements': {'Sockets': 1.0}, 'category': 'virtual', 'display_name': 'virtual_3664f4e5nvhxmzyn.example.org', 'id': '0f8edcd9-e229-49ff-bfd9-fa3138e91c21', ...}]
system_table_count = 1, system_table_total = 1.0
def _wait_for_tally_sync_daily(
self,
product_id: str,
metric_id: str,
expected_metric_value: float,
pre_tally_value: float,
wait_time: int,
timeout_tries: int,
**kwargs,
) -> None:
"""Wait for daily tally sync completion"""
logging.info(
f"Waiting for {metric_id} tally to reach expected value: {expected_metric_value}"
)
for attempt in range(timeout_tries):
current_value = self._get_current_tally_daily(
product_id=product_id, metric_id=metric_id, **kwargs
)
# Check system table on each attempt for debugging
system_table = self.search_system_table(
product_id, **{k: v for k, v in kwargs.items() if k in ["sla", "usage"]}
)
system_table_count = len(system_table) if system_table else 0
system_table_total = (
sum(
host.get("_labeled_measurements", {}).get(metric_id, 0) for host in system_table
)
if system_table
else 0
)
logging.info(
f"Attempt {attempt + 1}/{timeout_tries}: Tally={current_value}, Expected={expected_metric_value}, SystemTable={system_table_count} hosts with {system_table_total} total {metric_id}"
)
if self._is_tally_updated_daily(current_value, expected_metric_value):
logging.info(f"Tally value updated successfully: {current_value}")
return
if attempt < timeout_tries - 1:
time.sleep(wait_time)
# If we get here, tally didn't update as expected
> raise ValueError(
f"Tally value not updated after sync. Expected: {expected_metric_value}, "
f"Got: {current_value} (initial: {pre_tally_value})"
)
E ValueError: Tally value not updated after sync. Expected: 4, Got: 1 (initial: 3)
/iqe_venv/lib/python3.12/site-packages/iqe_rhsm_subscriptions/__init__.py:1170: ValueError