You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudTemplateHostBackfillCo...

46 lines
1.7 KiB
PHP

<?php
$root = dirname(__DIR__);
$worker = file_get_contents(
$root . '/app/Services/Cloud/CloudWorkerService.php'
);
$agent = file_get_contents(
$root . '/app/Services/Cloud/CloudAgentSettingsService.php'
);
$service = file_get_contents(
$root . '/app/Services/Cloud/CloudTemplateHostBackfillService.php'
);
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$transactionEnd = strpos($worker, '}, 3);', strpos(
$worker,
'private function finish('
));
$storageHook = strpos(
$worker,
'$this->scheduleTemplateBackfillAfterStorage(',
$transactionEnd === false ? 0 : $transactionEnd
);
$assert($transactionEnd !== false && $storageHook !== false
&& $storageHook > $transactionEnd,
'Storage completion schedules template backfill before its transaction commits.');
$assert(str_contains($agent,
"scheduleTemplateBackfill(\$hostId, \$actor, 'agent_ready')"),
'A successful Agent readiness test does not trigger host backfill.');
$assert(str_contains($service, "->where('is_default', 1)")
&& str_contains($service,
"private const TEMPLATE_STATES = ['active', 'degraded', 'error']")
&& str_contains($service, 'CloudAgentSettingsService::enabledHostIds()')
&& str_contains($service,
'CloudTemplateReplicaCoordinator::isExactReplica('),
'Host backfill is not constrained to ready hosts and current generations.');
$assert(str_contains($service, 'foreach ($plan[\'pending\'] as $templateId)')
&& str_contains($service, '} catch (\\Throwable $error) {'),
'One template failure can abort the remaining ready-host backfill plan.');
echo "Template ready-host backfill contracts passed.\n";