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/CloudMaintenanceMigrationRe...

190 lines
7.8 KiB
PHP

<?php
$root = dirname(__DIR__);
$read = static function (string $path) use ($root): string {
$value = file_get_contents($root . '/' . $path);
if (!is_string($value)) {
throw new RuntimeException('Unreadable source: ' . $path);
}
return $value;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$slice = static function (string $source, string $start,
string $end): string {
$startAt = strpos($source, $start);
$endAt = $startAt === false ? false : strpos(
$source,
$end,
$startAt + strlen($start)
);
return $startAt === false || $endAt === false
? '' : substr($source, $startAt, $endAt - $startAt);
};
$migrationSource = $read(
'app/Services/Cloud/CloudInstanceMigrationService.php'
);
$identitySource = $read(
'app/Services/Cloud/CloudOperationRecoveryIdentity.php'
);
$queue = $slice(
$migrationSource,
'private static function queueTransferLocked(',
'private static function finishTransferLocked('
);
$finalize = $slice(
$migrationSource,
'private static function finalizeTargetSpec(',
'private static function decodeSpec('
);
$abortPrepare = $slice(
$migrationSource,
'private static function finishAbortPrepareLocked(',
'private static function queueTransferLocked('
);
$transferOutcome = $slice(
$migrationSource,
'private static function finishTransferLocked(',
'private static function restoreTargetReservationForRetryLocked('
);
$retryOutcome = $slice(
$migrationSource,
'private static function restoreTargetReservationForRetryLocked(',
'private static function verifiedTargetBundle('
);
$releaseOutcome = $slice(
$migrationSource,
'private static function releasePreparedTargetLocked(',
'private static function retryTransferLocked('
);
$rotateOutcome = $slice(
$migrationSource,
'private static function rotateTargetTransferOperationLocked(',
'private static function queueRollbackLocked('
);
$rollbackOutcome = $slice(
$migrationSource,
'private static function finishRollbackLocked(',
'private static function finishFirewallLocked('
);
$recovery = $slice(
$identitySource,
'private static function assertPeerTransferBody(',
'private static function createIdentity('
);
$assert($queue !== ''
&& str_contains($queue, 'preparedMaintenanceMigrationTarget(')
&& str_contains($queue, "'public_network' => \$publicNetwork->toArray()")
&& str_contains($queue, "'hostname' => ''")
&& str_contains($queue, "'migration_target' => [")
&& str_contains($queue, "'target_identity_json'")
&& str_contains($queue, "'target_identity_sha256'")
&& str_contains($queue, "'target_claim_set_sha256'")
&& str_contains($queue, "'target_public_network_json'")
&& str_contains($queue, "'target_public_network_sha256'")
&& str_contains($queue, "'target_agent_revision'")
&& str_contains($queue, "'target_agent_contract_sha256'")
&& str_contains($queue, "'vpc_port' => \$vpcPort")
&& !str_contains($queue, "'network' =>")
&& !str_contains($queue, "'public_pool_key' =>")
&& !str_contains($queue, "'public_pool_cidr' =>")
&& !str_contains($queue, "'public_ip_cidr' =>")
&& !str_contains($queue, "'gateway' =>")
&& !str_contains($queue, "'dns_servers' =>"),
'Maintenance receive queue retained scalar networking or lacks a frozen envelope.');
$assert($recovery !== ''
&& str_contains($recovery, "'public_network', 'vpc_port'")
&& str_contains($recovery,
'CloudPublicNetworkAllocationService::currentClaimSet(')
&& str_contains($recovery,
'CloudFrozenPublicNetworkIdentity::fromStored(')
&& str_contains($recovery,
'CloudPublicNetworkSnapshot::fromArray(')
&& str_contains($recovery,
'CloudPortableRestoreCompatibility::supported()->sha256()')
&& str_contains($recovery,
"\$frozenVpcPort !== \$requestedVpcPort")
&& !str_contains($recovery, 'CloudHostAgent')
&& !str_contains($recovery, 'public_ip_cidr')
&& !str_contains($recovery, 'public_pool_key'),
'Maintenance receive recovery does not rebuild the frozen dual-stack identity.');
$assert($finalize !== ''
&& str_contains($finalize,
'CloudPublicNetworkSnapshot::fromArray(')
&& str_contains($finalize, "'public_network' =>")
&& str_contains($finalize, "'public_ip_cidr', 'public_ip'")
&& !str_contains($finalize, "'public_pool_key' => \$expected")
&& !str_contains($finalize, "'gateway' => \$expected"),
'Maintenance target finalization retained the singular IPv4 snapshot.');
$outcomeSurface = $abortPrepare . $transferOutcome . $retryOutcome
. $releaseOutcome . $rotateOutcome;
$assert($abortPrepare !== ''
&& str_contains($abortPrepare,
'CloudPublicNetworkAllocationService::currentClaimSet(')
&& str_contains($abortPrepare,
'$reservation->network_attachment_id !== null')
&& str_contains($abortPrepare,
'$reservation->public_ip_pool_id !== null')
&& str_contains($abortPrepare,
'$reservation->public_ip_id !== null'),
'Prepare abort does not reject a legacy singular target ledger.');
$assert($transferOutcome !== ''
&& str_contains($transferOutcome,
'CloudPublicNetworkAllocationService::fenceBundle(')
&& str_contains($transferOutcome,
'handoffMigrationBundles(')
&& str_contains($transferOutcome,
'CloudInstanceMigrationSettlement::settleCutoverLocked(')
&& str_contains($transferOutcome, 'verifiedTargetBundle(')
&& !str_contains($transferOutcome, '$requestedIp'),
'Transfer outcomes are not committed or fenced as one dual-stack bundle.');
$assert($retryOutcome !== ''
&& str_contains($retryOutcome,
'CloudPublicNetworkAllocationService::reopenBundleForRetry(')
&& str_contains($retryOutcome, '$publicNetwork->fingerprint()'),
'Confirmed-not-applied transfer does not reopen the exact bundle.');
$assert($releaseOutcome !== ''
&& str_contains($releaseOutcome,
'CloudPublicNetworkAllocationService::releaseBundle(')
&& str_contains($releaseOutcome, "['held']")
&& !str_contains($releaseOutcome, "['held', 'uncertain']")
&& str_contains($releaseOutcome,
"'maintenance_migration_target_not_applied'")
&& str_contains($releaseOutcome, '$reservation->released_at = $now'),
'A proven target absence does not release both address families.');
$assert($rotateOutcome !== ''
&& str_contains($rotateOutcome,
'CloudPublicNetworkAllocationService::rotateHeldBundleOperation(')
&& str_contains($rotateOutcome, '$restore->operation_id = $operationId')
&& str_contains($rotateOutcome, '$restore->job_id = null'),
'Transfer retry does not rotate the restore and bundle operation together.');
$uncertainAt = strpos($rollbackOutcome, "if (\$status === 'uncertain')");
$failedAt = strpos($rollbackOutcome, "if (\$status === 'failed')");
$releaseAt = strpos($rollbackOutcome, 'releasePreparedTargetLocked(');
$assert($rollbackOutcome !== '' && $uncertainAt !== false
&& $failedAt !== false && $releaseAt !== false
&& $uncertainAt < $releaseAt && $failedAt < $releaseAt
&& str_contains($rollbackOutcome,
"self::setState(\$migration, 'attention_required',")
&& str_contains($rollbackOutcome,
"'operation_effect_unknown', 'reconcile_rollback'")
&& str_contains($rollbackOutcome,
"'migration_source_rollback_failed',"),
'Unknown or failed source rollback could release the target bundle.');
$assert(!str_contains($outcomeSurface,
'CloudPlacementService::finishBackupRestore(')
&& !str_contains($outcomeSurface,
'CloudPlacementService::preparedBackupRestorePlacement(')
&& !str_contains($outcomeSurface, 'CloudPublicIp::'),
'Maintenance target outcomes retained a singular-IP writer.');
echo "Maintenance migration receive dual-stack contract passed.\n";