|
15 | 15 | import requests
|
16 | 16 | import semver
|
17 | 17 | from kubetester.automation_config_tester import AutomationConfigTester
|
18 |
| -from kubetester.kubetester import build_agent_auth, build_auth, run_periodically |
| 18 | +from kubetester.kubetester import ( |
| 19 | + KubernetesTester, |
| 20 | + build_agent_auth, |
| 21 | + build_auth, |
| 22 | + run_periodically, |
| 23 | +) |
19 | 24 | from kubetester.mongotester import BackgroundHealthChecker
|
20 | 25 | from kubetester.om_queryable_backups import OMQueryableBackup
|
21 | 26 | from opentelemetry import trace
|
22 | 27 | from requests.adapters import HTTPAdapter, Retry
|
| 28 | +from tests import test_logger |
23 | 29 | from tests.common.ops_manager.cloud_manager import is_cloud_qa
|
24 | 30 |
|
25 | 31 | skip_if_cloud_manager = pytest.mark.skipif(is_cloud_qa(), reason="Do not run in Cloud Manager")
|
26 | 32 |
|
| 33 | +logger = test_logger.get_test_logger(__name__) |
| 34 | + |
27 | 35 |
|
28 | 36 | class BackupStatus(str, Enum):
|
29 | 37 | """Enum for backup statuses in Ops Manager. Note that 'str' is inherited to fix json serialization issues"""
|
@@ -414,7 +422,7 @@ def om_request():
|
414 | 422 | span.set_attribute(key=f"mck.om.request.retries", value=retries - retry_count)
|
415 | 423 | return resp
|
416 | 424 | except Exception as e:
|
417 |
| - print(f"Encountered exception: {e} on retry number {retries-retry_count}") |
| 425 | + print(f"Encountered exception: {e} on retry number {retries - retry_count}") |
418 | 426 | span.set_attribute(key=f"mck.om.request.exception", value=str(e))
|
419 | 427 | last_exception = e
|
420 | 428 | time.sleep(1)
|
@@ -678,6 +686,42 @@ def api_update_version_manifest(self, major_version: str = "8.0"):
|
678 | 686 | body = requests.get(url=f"https://opsmanager.mongodb.com/static/version_manifest/{major_version}.json").json()
|
679 | 687 | self.om_request("put", "/versionManifest", json_object=body)
|
680 | 688 |
|
| 689 | + def api_get_automation_status(self) -> dict[str, str]: |
| 690 | + return self.om_request("get", f"/groups/{self.context.project_id}/automationStatus").json() |
| 691 | + |
| 692 | + def wait_agents_ready(self, timeout: Optional[int] = 600): |
| 693 | + """Waits until all the agents reached the goal automation config version.""" |
| 694 | + log_prefix = f"[{self.context.group_name}/{self.context.project_id}] " |
| 695 | + |
| 696 | + def agents_are_ready(): |
| 697 | + auto_status = self.api_get_automation_status() |
| 698 | + goal_version = auto_status.get("goalVersion") |
| 699 | + |
| 700 | + logger.info(f"{log_prefix}Checking if all agent processes have reached goal version: {goal_version}") |
| 701 | + processes_not_ready = [] |
| 702 | + for process in auto_status.get("processes", []): |
| 703 | + process_name = process.get("name", "unknown") |
| 704 | + process_version = process.get("lastGoalVersionAchieved") |
| 705 | + if process_version != goal_version: |
| 706 | + logger.info( |
| 707 | + f"{log_prefix}Process {process_name} at version {process_version}, expected {goal_version}" |
| 708 | + ) |
| 709 | + processes_not_ready.append(process_name) |
| 710 | + |
| 711 | + all_processes_ready = len(processes_not_ready) == 0 |
| 712 | + if all_processes_ready: |
| 713 | + logger.info(f"{log_prefix}All agent processes have reached the goal version") |
| 714 | + else: |
| 715 | + logger.info(f"{log_prefix}{len(processes_not_ready)} processes have not yet reached the goal version") |
| 716 | + |
| 717 | + return all_processes_ready |
| 718 | + |
| 719 | + KubernetesTester.wait_until( |
| 720 | + agents_are_ready, |
| 721 | + timeout=timeout, |
| 722 | + sleep_time=3, |
| 723 | + ) |
| 724 | + |
681 | 725 |
|
682 | 726 | class OMBackgroundTester(BackgroundHealthChecker):
|
683 | 727 | """
|
|
0 commit comments